private static void addDomToMetadata(Element parentDE, MetadataElement parentME) { final HashMap<String, List<Element>> map = new HashMap<String, List<Element>>(25); List<Element> children = parentDE.getChildren(); for (Element childDE : children) { final String name = childDE.getName(); List<Element> elementList = map.get(name); if (elementList == null) { elementList = new ArrayList<Element>(3); map.put(name, elementList); } elementList.add(childDE); } for (Map.Entry<String, List<Element>> entry : map.entrySet()) { String name = entry.getKey(); final List<Element> elementList = entry.getValue(); if (elementList.size() > 1) { for (int i = 0; i < elementList.size(); i++) { addDomToMetadata(elementList.get(i), name + "." + i, parentME); } } else { addDomToMetadata(elementList.get(0), name, parentME); } } }
private static void createMDE(String name, ProfileReadContext ctx, MetadataElement eosElem) throws IOException { Element element = (Element) ctx.getProperty(name); if (element != null) { MetadataElement metadataElement = new MetadataElement(name); addDomToMetadata(element, metadataElement); eosElem.addElement(metadataElement); } }
private static void addDomToMetadata(Element childDE, String name, MetadataElement parentME) { if (childDE.getChildren().size() > 0 || childDE.getAttributes().size() > 0) { final MetadataElement childME = new MetadataElement(name); addDomToMetadata(childDE, childME); parentME.addElement(childME); if (childDE.getAttributes().size() != 0) { List attrList = childDE.getAttributes(); for (Object o : attrList) { Attribute attribute = (Attribute) o; String attributeName = attribute.getName(); String attributeValue = attribute.getValue(); final ProductData valueMEAtrr = ProductData.createInstance(attributeValue); final MetadataAttribute mdAttribute = new MetadataAttribute(attributeName, valueMEAtrr, true); childME.addAttribute(mdAttribute); } } } else { String valueDE = childDE.getValue(); if (valueDE == null) { valueDE = ""; } final ProductData valueME = ProductData.createInstance(valueDE); final MetadataAttribute attribute = new MetadataAttribute(name, valueME, true); parentME.addAttribute(attribute); } }