LocaleFilesProcessor { @VisibleForTesting boolean isXMLlocale( InputStream localeBundle ) { try { DocumentBuilderFactory builderFactory = XMLParserFactoryProducer.createSecureDocBuilderFactory(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); XPath xPath = XPathFactory.newInstance().newXPath(); Document document = builder.parse( localeBundle ); String name = xPath.compile( "/index/name" ).evaluate( document ); String desc = xPath.compile( "/index/description" ).evaluate( document ); if ( !name.isEmpty() && !desc.isEmpty() ) { return true; } } catch ( XPathExpressionException | ParserConfigurationException | SAXException | IOException e ) { return false; } return false; } LocaleFilesProcessor(); boolean isLocaleFile( IRepositoryFileBundle file, String parentPath, byte[] bytes ); Properties loadProperties( InputStream inputStream ); boolean createLocaleEntry( String filePath, String name, String title, String description,
      RepositoryFile file, InputStream is ); boolean createLocaleEntry( String filePath, String name, String title, String description,
      RepositoryFile file, InputStream is, int sourceVersion ); void processLocaleFiles( IPlatformImporter importer );  }
@Test public void isXMLLocaleTest() { String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<index>" + "<name>the name</name>" + "<description>the description</description>" + "</index>"; localeFilesProcessor = new LocaleFilesProcessor(); assertTrue( localeFilesProcessor.isXMLlocale( new ByteArrayInputStream( xml.getBytes() ) ) ); }
@Test public void isXMLLocaleWrongFormatTest() { String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<name>the name</name>" + "<description>the description</description>"; localeFilesProcessor = new LocaleFilesProcessor(); assertFalse( localeFilesProcessor.isXMLlocale( new ByteArrayInputStream( xml.getBytes() ) ) ); }
@Test public void isXMLLocaleEmptyValuesTest() { String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<index>" + "<name></name>" + "<description></description>" + "</index>"; localeFilesProcessor = new LocaleFilesProcessor(); assertFalse( localeFilesProcessor.isXMLlocale( new ByteArrayInputStream( xml.getBytes() ) ) ); }