Kyero_3 extends XmlConverter<KyeroDocument, KyeroVersion> { protected void removeUnsupportedLanguageElements(Document doc) throws JaxenException { String[] unsupportedLanguages = new String[]{ "ar", "bg", "ca", "cs", "da", "el", "et", "fa", "fi", "he", "hi", "hu", "id", "it", "ja", "ko", "lt", "lv", "no", "pl", "pt", "ro", "ru", "sk", "sl", "sv", "th", "tr", "uk", "vi", "zh", }; List nodes = XmlUtils.newXPath( "/io:root/io:property/io:desc | " + "/io:root/io:property/io:images/io:image/io:title", doc).selectNodes(doc); for (Object item : nodes) { Element node = (Element) item; List childNodes = XmlUtils.newXPath( "*", doc).selectNodes(node); for (Object childItem : childNodes) { Element langNode = (Element) childItem; String lang = langNode.getLocalName().toLowerCase(); if (ArrayUtils.contains(unsupportedLanguages, lang)) { node.removeChild(langNode); } } } }  @Override KyeroVersion getVersion(); @Override void downgradeToPreviousVersion(KyeroDocument doc); @Override void upgradeFromPreviousVersion(KyeroDocument doc);  }
@Test public void testRemoveUnsupportedLanguageElements() { String[] unsupportedLanguages = new String[]{ "ar", "bg", "ca", "cs", "da", "el", "et", "fa", "fi", "he", "hi", "hu", "id", "it", "ja", "ko", "lt", "lv", "no", "pl", "pt", "ro", "ru", "sk", "sl", "sv", "th", "tr", "uk", "vi", "zh", }; try { Document doc = buildDocumentForDowngrade(); int count; for (String lang : unsupportedLanguages) { count = XmlUtils.countNodes( "/io:root/io:property/io:desc/io:" + lang + " | " + "/io:root/io:property/io:images/io:image/io:title/io:" + lang, doc); Assert.assertEquals( "2 translations in \"" + lang + "\" available before conversion.", 2, count); } new Kyero_3().removeUnsupportedLanguageElements(doc); for (String lang : unsupportedLanguages) { count = XmlUtils.countNodes( "/io:root/io:property/io:desc/io:" + lang + " | " + "/io:root/io:property/io:images/io:image/io:title/io:" + lang, doc); Assert.assertEquals( "0 translations in \"" + lang + "\" available after conversion.", 0, count); } } catch (Exception ex) { LOGGER.error("Test of Kyero_3.removeUnsupportedLanguageElements failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of Kyero_3.removeUnsupportedLanguageElements failed!"); } }