List of usage examples for org.jdom2 Attribute getName
public String getName()
Attribute
. From source file:io.wcm.handler.link.Link.java
License:Apache License
/** * @return Map with all attributes of the anchor element. Returns null if anchor element is null. *//*from www. jav a2 s .c o m*/ public Map<String, String> getAnchorAttributes() { if (getAnchor() == null) { return null; } Map<String, String> attributes = new HashMap<>(); for (Attribute attribute : getAnchor().getAttributes()) { attributes.put(attribute.getName(), attribute.getValue()); } return attributes; }
From source file:io.wcm.handler.richtext.impl.RichTextRewriteContentHandlerImpl.java
License:Apache License
/** * Support data structures where link metadata is stored in mutliple HTML5 data-* attributes. * @param pResourceProps Valuemap to write link metadata to * @param element Link element/*from www . j a v a2 s . com*/ * @return true if any metadata attribute was found */ private boolean getAnchorMetadataFromData(ValueMap pResourceProps, Element element) { boolean foundAny = false; List<Attribute> attributes = element.getAttributes(); for (Attribute attribute : attributes) { if (DataPropertyUtil.isHtml5DataName(attribute.getName())) { String value = attribute.getValue(); if (StringUtils.isNotEmpty(value)) { String property = DataPropertyUtil.toHeadlessCamelCaseName(attribute.getName()); if (StringUtils.startsWith(value, "[") && StringUtils.endsWith(value, "]")) { try { JSONArray jsonArray = new JSONArray(value); String[] values = new String[jsonArray.length()]; for (int i = 0; i < jsonArray.length(); i++) { values[i] = jsonArray.optString(i); } pResourceProps.put(property, values); } catch (JSONException ex) { // ignore } } else { // decode if required value = decodeIfEncoded(value); pResourceProps.put(property, value); } foundAny = true; } } } return foundAny; }
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 w w. j a va2s . c o m*/ 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 {/*from ww w.j ava2 s .c o m*/ 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:neon.core.GameLoader.java
License:Open Source License
private void loadPlayer(Element playerData, Atlas atlas) { // player aanmaken RCreature species = (RCreature) Engine.getResources().getResource(playerData.getAttributeValue("race")); Player player = new Player(new RCreature(species.toElement()), playerData.getAttributeValue("name"), Gender.valueOf(playerData.getAttributeValue("gender").toUpperCase()), Player.Specialisation.valueOf(playerData.getAttributeValue("spec")), playerData.getAttributeValue("prof")); engine.startGame(/*from ww w . j a v a 2s . com*/ new Game(player, engine.getFileSystem(), engine.getScriptEngine(), engine.getPhysicsEngine())); Rectangle bounds = player.getShapeComponent(); bounds.setLocation(Integer.parseInt(playerData.getAttributeValue("x")), Integer.parseInt(playerData.getAttributeValue("y"))); player.setSign(playerData.getAttributeValue("sign")); player.species.text = "@"; // start map int mapUID = Integer.parseInt(playerData.getAttributeValue("map")); atlas.setMap(atlas.getMap(mapUID)); int level = Integer.parseInt(playerData.getAttributeValue("l")); atlas.setCurrentZone(level); // stats Stats stats = player.getStatsComponent(); stats.addStr(Integer.parseInt(playerData.getChild("stats").getAttributeValue("str")) - stats.getStr()); stats.addCon(Integer.parseInt(playerData.getChild("stats").getAttributeValue("con")) - stats.getCon()); stats.addDex(Integer.parseInt(playerData.getChild("stats").getAttributeValue("dex")) - stats.getDex()); stats.addInt(Integer.parseInt(playerData.getChild("stats").getAttributeValue("int")) - stats.getInt()); stats.addWis(Integer.parseInt(playerData.getChild("stats").getAttributeValue("wis")) - stats.getWis()); stats.addCha(Integer.parseInt(playerData.getChild("stats").getAttributeValue("cha")) - stats.getCha()); // skills for (Attribute skill : (List<Attribute>) playerData.getChild("skills").getAttributes()) { player.setSkill(Skill.valueOf(skill.getName()), Integer.parseInt(skill.getValue())); } // items for (Element e : playerData.getChildren("item")) { long uid = Long.parseLong(e.getAttributeValue("uid")); player.getInventoryComponent().addItem(uid); } // spells for (Element e : playerData.getChildren("spell")) { player.getMagicComponent().addSpell(SpellFactory.getSpell(e.getText())); } // feats for (Element e : playerData.getChildren("feat")) { player.getCharacteristicsComponent().addFeat(Feat.valueOf(e.getText())); } // geld player.getInventoryComponent().addMoney(Integer.parseInt(playerData.getChildText("money"))); }
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"); }/* w w w. ja v a2s . c om*/ 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.core.dataop.downloadable.XMLSupport.java
License:Open Source License
private static void addAttribute(final MetadataElement root, final Element domElem) { final Attribute nameAttrib = domElem.getAttribute("name"); final Attribute valueAttrib = domElem.getAttribute("value"); final Attribute typeAttrib = domElem.getAttribute("type"); final Attribute unitAttrib = domElem.getAttribute("unit"); final Attribute descAttrib = domElem.getAttribute("desc"); if (nameAttrib == null || valueAttrib == null) return;//from w w w. ja v a 2s . c o m final MetadataAttribute attribute = new MetadataAttribute(nameAttrib.getName(), ProductData.TYPE_ASCII, 1); attribute.getData().setElems(valueAttrib.getValue()); if (unitAttrib != null) attribute.setUnit(unitAttrib.getValue()); if (descAttrib != null) attribute.setDescription(descAttrib.getValue()); root.addAttribute(attribute); }
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 ww w. j av a 2 s . 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 *//*from w w w . j a v a 2 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.fnppl.opensdx.xml.Element.java
License:Open Source License
public Vector<String[]> getAttributes() { Vector<String[]> atts = new Vector<String[]>(); List<Attribute> l = (List<Attribute>) base.getAttributes(); if (l != null) { for (Attribute a : l) { atts.add(new String[] { a.getName(), a.getValue() }); }//ww w . j a va2s .c o m } return atts; }