List of usage examples for org.jdom2 Element getAttributes
public List<Attribute> getAttributes()
This returns the complete set of attributes for this element, as a List
of Attribute
objects in no particular order, or an empty list if there are none.
From source file:io.wcm.maven.plugins.contentpackage.unpacker.ContentUnpacker.java
License:Apache License
private void applyXmlExcludes(Element element, String parentPath) { String path = parentPath + "/" + element.getName(); if (exclude(path, this.excludeNodes)) { element.detach();//from w ww.j a v a2 s . co m return; } List<Attribute> attributes = new ArrayList<>(element.getAttributes()); for (Attribute attribute : attributes) { if (exclude(attribute.getQualifiedName(), this.excludeProperties)) { attribute.detach(); } } List<Element> children = new ArrayList<>(element.getChildren()); for (Element child : children) { applyXmlExcludes(child, path); } }
From source file:jmri.jmrix.loconet.cmdstnconfig.XmlConfig.java
License:Open Source License
@SuppressWarnings("unchecked") static void dumpNode(Element node, int depth) { int leader;/*from w ww . j a va 2 s. c om*/ for (leader = 0; leader < depth; leader++) { System.out.print('\t'); } System.out.print(node.getName()); Iterator<Attribute> attributes = node.getAttributes().iterator(); Attribute attribute; while (attributes.hasNext()) { attribute = attributes.next(); System.out.print(" " + attribute.getName() + " = " + attribute.getValue()); } System.out.println(); Iterator<Element> children = node.getChildren().iterator(); depth++; while (children.hasNext()) { dumpNode(children.next(), depth); } }
From source file:msi.gama.doc.util.UnifyDoc.java
License:Open Source License
private static Document mergeFiles(final HashMap<String, File> hmFilesPackages) { try {/*ww w . j ava2s . c om*/ SAXBuilder builder = new SAXBuilder(); Document doc = null; doc = new Document(new Element(XMLElements.DOC)); for (String elt : tabEltXML) { doc.getRootElement().addContent(new Element(elt)); } for (Entry<String, File> fileDoc : hmFilesPackages.entrySet()) { Document docTemp = builder.build(fileDoc.getValue()); for (String catXML : tabEltXML) { if (docTemp.getRootElement().getChild(catXML) != null) { List<Element> existingElt = doc.getRootElement().getChild(catXML).getChildren(); for (Element e : docTemp.getRootElement().getChild(catXML).getChildren()) { // Do not add the projectName for every kinds of // categories // if (!Arrays.asList(tabCategoriesEltXML).contains(catXML)) { e.setAttribute("projectName", fileDoc.getKey()); // } // Test whether the element is already in the merged // doc boolean found = false; for (Element exElt : existingElt) { boolean equals = exElt.getName().equals(e.getName()); for (Attribute att : exElt.getAttributes()) { String valueExElt = exElt.getAttribute(att.getName()) != null ? exElt.getAttributeValue(att.getName()) : ""; String valueE = e.getAttribute(att.getName()) != null ? e.getAttributeValue(att.getName()) : ""; equals = equals && valueExElt.equals(valueE); } found = found || equals; } // Add if it is not already in the merged doc if (!found) { doc.getRootElement().getChild(catXML).addContent(e.clone()); } } } } } // Add an element for the generated types doc.getRootElement().getChild(XMLElements.OPERATORS_CATEGORIES) .addContent(new Element(XMLElements.CATEGORY).setAttribute(XMLElements.ATT_CAT_ID, new TypeConverter().getProperCategory("Types"))); return doc; } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:no.imr.stox.functions.utils.JDOMUtils.java
public static void getDataHeadersFromAttributes(Element elm, String topLevel, Collection<HeaderElm> set) { if (elm == null) { return;// w w w . j av a2 s . com } if (!elm.getName().equals(topLevel)) { getDataHeadersFromAttributes(elm.getParentElement(), topLevel, set); } elm.getAttributes().stream().forEach(a -> { set.add(new HeaderElm(elm.getName(), a.getName())); }); }
From source file:no.imr.stox.functions.utils.JDOMUtils.java
public static void setAttribute(Element elm, boolean atStart, String name, String text) { List<Attribute> atts = new ArrayList<>(elm.getAttributes()); if (atStart) { atts.stream().forEach(a -> elm.removeAttribute(a)); }/*www. j ava 2s.c o m*/ elm.setAttribute(name, text); if (atStart) { atts.stream().forEach(a -> elm.setAttribute(a.getName(), a.getValue())); } }
From source file:org.apache.marmotta.ldclient.provider.mediawiki.MediawikiProvider.java
License:Apache License
private static Map<String, String> getDefaultParams(String prop, Element queryContinue) { HashMap<String, String> params = new LinkedHashMap<String, String>(); final String limit = "max"; if ("info".equals(prop)) { params.put("inprop", "url"); } else if ("revisions".equals(prop)) { // Revision info: first revision for creation params.put("rvdir", "newer"); params.put("rvlimit", "1"); params.put("rvprop", "ids|timestamp"); } else if ("categories".equals(prop)) { params.put("cllimit", limit); // Categories: only visible cats params.put("clshow", "!hidden"); } else if ("links".equals(prop)) { params.put("pllimit", limit); // Links: only links to same params.put("plnamespace", "0"); } else if ("categorymembers".equals(prop)) { params.put("cmlimit", limit); params.put("cmprop", "title|type"); }/*from w w w.j a v a 2s . c o m*/ if (queryContinue != null && queryContinue.getName().equals(prop) && queryContinue.getAttributes().size() == 1) { final Attribute a = queryContinue.getAttributes().get(0); params.put(a.getName(), a.getValue()); } return params; }
From source file:org.esa.snap.dataio.netcdf.metadata.profiles.hdfeos.HdfEosMetadataPart.java
License:Open Source License
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);/*from w w w . ja v a 2s . c o m*/ 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); } }
From source file:org.esa.snap.datamodel.metadata.AbstractMetadataIO.java
License:Open Source License
/** * Add metadata from an XML file into the Metadata of the product * * @param xmlRoot root element of xml file * @param metadataRoot MetadataElement to place it into *//* w w w.j a va2 s . co m*/ public static void AddXMLMetadata(final Element xmlRoot, final MetadataElement metadataRoot) { final String rootName = xmlRoot.getName(); final boolean rootChildrenEmpty = xmlRoot.getChildren().isEmpty(); if (rootChildrenEmpty && xmlRoot.getAttributes().isEmpty()) { if (!xmlRoot.getValue().isEmpty()) { addAttribute(metadataRoot, rootName, xmlRoot.getValue()); } } else if (rootChildrenEmpty) { final MetadataElement metaElem = new MetadataElement(rootName); if (!xmlRoot.getValue().isEmpty()) addAttribute(metaElem, rootName, xmlRoot.getValue()); final List<Attribute> xmlAttribs = xmlRoot.getAttributes(); for (Attribute aChild : xmlAttribs) { addAttribute(metaElem, aChild.getName(), aChild.getValue()); } metadataRoot.addElement(metaElem); } else { final MetadataElement metaElem = new MetadataElement(rootName); final List children = xmlRoot.getContent(); for (Object aChild : children) { if (aChild instanceof Element) { AddXMLMetadata((Element) aChild, metaElem); } else if (aChild instanceof Attribute) { final Attribute childAtrrib = (Attribute) aChild; addAttribute(metaElem, childAtrrib.getName(), childAtrrib.getValue()); } } final List<Attribute> xmlAttribs = xmlRoot.getAttributes(); for (Attribute aChild : xmlAttribs) { addAttribute(metaElem, aChild.getName(), aChild.getValue()); } metadataRoot.addElement(metaElem); } }
From source file:org.jumpmind.metl.core.runtime.component.XmlFormatter.java
License:Open Source License
private void removeAllAttributes(Element element) { List<Attribute> attributes = new ArrayList<Attribute>(); attributes.addAll(element.getAttributes()); for (Attribute attribute : attributes) { element.removeAttribute(attribute); }/* w w w.j av a 2 s .com*/ }
From source file:org.jumpmind.metl.ui.views.design.EditXmlFormatPanel.java
License:Open Source License
protected void buildXpathChoicesFromElement(String prefix, Element parentElement) { for (Element element : parentElement.getChildren()) { String text = prefix + "/" + element.getName(); xpathChoices.add(text);/*w ww. jav a2 s . c om*/ for (Attribute attr : element.getAttributes()) { String attrText = text + "/@" + attr.getName(); xpathChoices.add(attrText); } buildXpathChoicesFromElement(text, element); } }