ISO19139SchemaPlugin extends SchemaPlugin implements
    AssociatedResourcesSchemaPlugin,
    MultilingualSchemaPlugin,
    ExportablePlugin,
    ISOPlugin,
    LinkAwareSchemaPlugin { @Override public Element removeTranslationFromElement(Element element, List<String> langs) throws JDOMException { String mainLanguage = langs != null && langs.size() > 0 ? langs.get(0) : "#EN"; List<Element> nodesWithStrings = (List<Element>) Xml.selectNodes(element, "* for(Element e : nodesWithStrings) { Element mainCharacterString = ((Element)e.getParent()).getChild("CharacterString", GCO); if (mainCharacterString == null) { mainCharacterString = new Element("CharacterString", GCO); ((Element)e.getParent()).addContent(0, mainCharacterString); } List<Element> mainLangElement = (List<Element>) Xml.selectNodes( e, "* Arrays.asList(GMD)); if (mainLangElement.size() == 1) { String mainLangString = mainLangElement.get(0).getText(); if (StringUtils.isNotEmpty(mainLangString)) { mainCharacterString.setText(mainLangString); } else if (mainCharacterString.getAttribute("nilReason", GCO) == null){ ((Element)mainCharacterString.getParent()).setAttribute("nilReason", "missing", GCO); } } else if (StringUtils.isEmpty(mainCharacterString.getText())) { ((Element)mainCharacterString.getParent()).setAttribute("nilReason", "missing", GCO); } } List<Element> translationNodes = (List<Element>)Xml.selectNodes(element, "* for(Element el : translationNodes) { if(langs.size() <= 1 || !langs.contains(el.getAttribute("locale").getValue())) { Element parent = (Element)el.getParent(); parent.detach(); } } for(Element el : nodesWithStrings) { if (el.getChildren().size() == 0) { el.detach(); } } if (langs.size() > 1) { List<Element> elementList = (List<Element>)Xml.selectNodes(element, "./@locale='" + l + "']", Arrays.asList(GMD)); if (node != null && node.size() == 1) { orderedTextGroup.add((Element) node.get(0).clone()); } } ptFreeText.removeContent(); ptFreeText.addContent(orderedTextGroup); } } return element; } ISO19139SchemaPlugin(); Set<AssociatedResource> getAssociatedResourcesUUIDs(Element metadata); @Override Set<String> getAssociatedParentUUIDs(Element metadata); Set<String> getAssociatedDatasetUUIDs(Element metadata); Set<String> getAssociatedFeatureCatalogueUUIDs(Element metadata); Set<String> getAssociatedSourceUUIDs(Element metadata); @Override List<Element> getTranslationForElement(Element element, String languageIdentifier); @Override void addTranslationToElement(Element element, String languageIdentifier, String value); @Override Element removeTranslationFromElement(Element element, List<String> langs); @Override String getBasicTypeCharacterStringName(); @Override Element createBasicTypeCharacterString(); @Override Element addOperatesOn(Element serviceRecord,
                                 Map<String, String> layers,
                                 String serviceType,
                                 String baseUrl); @Override List<Extent> getExtents(Element record); @Override Map<String, Namespace> getCswTypeNames(); @Override Map<String, String> getExportFormats(); @Override Element processElement(Element el,
                                  String attributeRef,
                                  String parsedAttributeName,
                                  String attributeValue); static List<String> getLanguages(Element md); RawLinkPatternStreamer<L, M> createLinkStreamer(ILinkBuilder<L, M> linkbuilder); static final String IDENTIFIER; static ImmutableSet<Namespace> allNamespaces; }
@Test public void removeTranslationFromElement() throws Exception { Element multilingualElement = Xml.loadFile(this.getClass().getClassLoader().getResource("schema/iso19139/multilingual-contact.xml")); ISO19139SchemaPlugin plugin = new ISO19139SchemaPlugin(); plugin.removeTranslationFromElement(multilingualElement, Arrays.asList(new String[]{"#EN"})); String resultString = Xml.getString(multilingualElement); assertThat( resultString, hasXPath("count( ); assertThat( resultString, hasXPath("count( equalTo("0")).withNamespaceContext(ns) ); assertThat( resultString, hasXPath("count( equalTo("1")).withNamespaceContext(ns) ); }