List of usage examples for org.jdom2 Element getName
public String getName()
From source file:egovframework.rte.fdl.xml.AbstractXMLUtility.java
License:Apache License
/** * Node //from ww w . ja v a 2s .c o m * * @param element - ? Element * @param addNDName - ? * @param list - add TextNode */ public void addNode(Element element, String addNDName, List<?> list) { List<?> childList = element.getChildren(); if (childList.size() != 0) { for (int yy = 0; yy < childList.size(); yy++) { Element tmp = (Element) childList.get(yy); if (tmp.getName().equals(addNDName)) { for (int tt = 0; tt < list.size(); tt++) { SharedObject sobj = (SharedObject) list.get(tt); Element enew = new Element((String) sobj.getKey()); enew.setText((String) sobj.getValue()); tmp.addContent(enew); } } addNode(tmp, addNDName, list); } } else { if (element.getName().equals(addNDName)) { for (int tt = 0; tt < list.size(); tt++) { SharedObject sobj = (SharedObject) list.get(tt); Element enew = new Element((String) sobj.getKey()); enew.setText((String) sobj.getValue()); element.addContent(enew); } } } }
From source file:egovframework.rte.fdl.xml.AbstractXMLUtility.java
License:Apache License
/** * //from w ww .j a va 2 s. c o m * * @param element - ? Element * @param name - */ public void removeNode(Element element, String name) { List<?> list = element.getChildren(); if (list.size() != 0) { for (int i = 0; i < list.size(); i++) { Element tmp = (Element) list.get(i); if (tmp.getName().equals(name)) { tmp.getParentElement().removeChild(name); } else { removeNode(tmp, name); } } } else { // Visit the children // logger.debug("element Name :"+element.getName()); if (element.getName().equals(name)) { element.getParentElement().removeChild(name); } } }
From source file:egovframework.rte.fdl.xml.AbstractXMLUtility.java
License:Apache License
/** * //from ww w . j a va2 s.c om * * @param element - ? Element * @param oldNode - * @param newNodename - */ public void chgNode(Element element, String oldNode, String newNodename) { List<?> list = element.getChildren(); if (list.size() != 0) { for (int i = 0; i < list.size(); i++) { Element tmp = (Element) list.get(i); if (element.getName().equals(oldNode)) { element.setName(newNodename); } else { chgNode(tmp, oldNode, newNodename); } } } else { // Visit the children // logger.debug("element Name:"+element.getName()); if (element.getName().equals(oldNode)) { element.setName(newNodename); } } }
From source file:engine.Engine.java
License:Open Source License
public void loadLevel(String filePath) throws JDOMException, IOException { SAXBuilder sax = new SAXBuilder(); Document doc;/* w w w . ja v a 2s.co m*/ doc = sax.build(new File(filePath)); Element root = doc.getRootElement(); List<Element> listElem = root.getChildren(); for (Element elem : listElem) { Entity entity = null; switch (elem.getName()) { case "BreakableBlock": entity = new BreakableBlock(this); break; case "SolidBlock": entity = new SolidBlock(this); break; case "Bomb": entity = new Bomb(this); break; case "Fire": entity = new Fire(this); break; case "Bomberman": entity = new Bomberman(this); break; case "Bonus": Bonus bonus = new Bonus(this); bonus.setBomb(elem.getAttribute("bomb").getIntValue()); bonus.setPower(elem.getAttribute("power").getIntValue()); bonus.setSpeed(elem.getAttribute("speed").getIntValue()); entity = bonus; break; case "SpeedBonus": entity = new SpeedBonus(this); break; case "PowerBonus": entity = new PowerBonus(this); break; case "BombBonus": entity = new BombBonus(this); break; case "KickBonus": entity = new KickBonus(this); break; case "FutureBonus": futureBonus(elem); continue; default: this.log.warn("loadLevel: unknown type object -> " + elem.getName()); continue; } Vector2f position = new Vector2f(); position.x = elem.getAttribute("x").getIntValue() * 1000; position.y = elem.getAttribute("y").getIntValue() * 1000; entity.setPosition(position); entity.setDirection(elem.getAttribute("dir").getIntValue()); addEntity(entity); } this.collisionManager.addHandler(new BombermanBlockCH(this.collisionManager)); this.collisionManager.addHandler(new BombermanBonusCH()); this.collisionManager.addHandler(new BombermanFireCH()); this.collisionManager.addHandler(new BombFireCH()); this.collisionManager.addHandler(new BonusFireCH()); this.collisionManager.addHandler(new BlockFireCH()); this.collisionManager.addHandler(new BombBlockCH()); BombermanBombCH han = new BombermanBombCH(this.collisionManager); addListener(han); this.collisionManager.addHandler(han); this.loaded = true; }
From source file:es.ucm.fdi.clover.gui.CloverSave.java
License:Open Source License
/** * Restores the CloverSave to a different XML file; totally changes the * 'views' (it is basically recreated) output array; *///from w w w . j ava 2 s .c om public static ArrayList<ClusterView> restore(BaseGraph base, ClusterViewFactory vf, File f) throws IOException { if (vf == null) { vf = new DefaultClusterViewFactory(); } ArrayList<ClusterView> views = new ArrayList<ClusterView>(); HashMap<String, Filter> filters = new HashMap<String, Filter>(); HashMap<String, ClusterHierarchy> hierarchies = new HashMap<String, ClusterHierarchy>(); SAXBuilder builder = new SAXBuilder(); ClassLoader loader = base.getClass().getClassLoader(); try { Document doc = builder.build(f.getAbsolutePath()); Element root = doc.getRootElement(); Element sharedElems = (Element) root.getChildren().get(0); for (Element e : (List<Element>) sharedElems.getChildren()) { if (e.getName().equals("filter")) { String className = e.getAttributeValue("filterClass"); Filter filter = (Filter) loader.loadClass(className).newInstance(); filter.restore(e); filters.put(e.getAttributeValue("id"), filter); } else if (e.getName().equals("hierarchy")) { Element cluster = (Element) e.getChildren().get(0); Element clusterer = (Element) e.getChildren().get(1); String className = clusterer.getAttributeValue("engineClass"); ClusteringEngine engine = (ClusteringEngine) loader.loadClass(className).newInstance(); engine.restore(clusterer); BaseGraph hb = base; if (e.getAttribute("filterId") != null) { Filter filter = filters.get(e.getAttributeValue("filterId")); hb = new FilteredGraph(base, filter); } ClusterHierarchy h = new ClusterHierarchy(e, hb, engine); hierarchies.put(e.getAttributeValue("id"), h); } } for (Element e : (List<Element>) root.getChildren()) { if (!e.getName().equals("view")) continue; // build view String hid = e.getAttributeValue("hierarchyId"); ClusterView view = vf.createClusterView(hierarchies.get(hid), e); view.restore(e); Element layoutCache = (Element) e.getChildren().get(0); view.getAnimator().getLayoutCache().restore(layoutCache, view.getBase()); Element animatorProps = (Element) e.getChildren().get(1); view.getAnimator().restore(animatorProps); views.add(view); } } // indicates a well-formedness error catch (JDOMException jde) { log.warn("Document is not well-formed XML"); jde.printStackTrace(); } catch (IOException ioe) { System.out.println(ioe); ioe.printStackTrace(); } catch (Exception e) { System.out.println(e); e.printStackTrace(); } return views; }
From source file:es.ucm.fdi.clover.model.ClusterHierarchy.java
License:Open Source License
/** * Restores the current hierarchy from an XML representation (the one * that is generated by 'save')//ww w.ja v a2s . c o m */ public void restore(Element e) { Element first = (Element) e.getChildren().get(0); HashMap<String, Object> map = new HashMap<String, Object>(); for (Object v : base.vertexSet()) { map.put(base.getId(v), v); } if (first.getName().equals("vertex")) { root = new Cluster(base, map.get(first.getAttributeValue("id"))); } else { root = new Cluster(); if (first.getAttribute("name") != null) { root.setName(first.getAttributeValue("name")); } for (Element child : (List<Element>) first.getChildren()) { restore(child, root, map); } } }
From source file:es.ucm.fdi.clover.model.ClusterHierarchy.java
License:Open Source License
private void restore(Element e, Cluster parent, HashMap<String, Object> map) { if (e.getName().equals("vertex")) { Cluster c = new Cluster(base, map.get(e.getAttributeValue("id"))); parent.add(c);// w w w .j ava 2 s . com } else { Cluster c = new Cluster(); if (e.getAttribute("name") != null) { c.setName(e.getAttributeValue("name")); } for (Element child : (List<Element>) e.getChildren()) { restore(child, c, map); } parent.add(c); } }
From source file:es.upm.dit.xsdinferencer.extraction.extractorImpl.JSONTypesExtractorImpl.java
License:Apache License
/** * This method sets a given namespace to the given element and any of its descendants whose * name is a provided one and have no namespace. * @param name the name of the searched elements * @param rootElement the root element to begin the search at * @param namespace the namespace to set */// www. java 2 s.c o m private void setNamespaceToElementsByName(String name, Element rootElement, Namespace namespace) { IteratorIterable<Element> descendants = rootElement .getDescendants(Filters.element(name, Namespace.NO_NAMESPACE)); for (Element descendant : descendants) { descendant.setNamespace(namespace); } if (rootElement.getName().equals(name) && rootElement.getNamespace().equals(Namespace.NO_NAMESPACE)) { rootElement.setNamespace(namespace); } }
From source file:es.upm.dit.xsdinferencer.extraction.extractorImpl.JSONTypesExtractorImpl.java
License:Apache License
/** * This method undoes what addPrefixToJSONKeysEndingsRecursive method did at the original JSON: It looks * for elements whose name ends at a desired key ending preceeded by a prefix to remove and removes it. * @param rootElement the root element.// w w w .j av a 2s. co m * @param desiredKeyEnding the desired ending. * @param prefixToRemove the prefix to remove. */ private void removePrefixToElementNameEndings(Element rootElement, String desiredKeyEnding, String prefixToRemove) { String keyToSearch = prefixToRemove + desiredKeyEnding; for (Element element : rootElement.getDescendants(Filters.element())) { if (!(element.getName().endsWith(keyToSearch) && element.getNamespace().equals(Namespace.NO_NAMESPACE))) { continue; } String name = element.getName(); String newName = name.replaceAll(Pattern.quote(keyToSearch) + "$", desiredKeyEnding); element.setName(newName); } }
From source file:es.upm.dit.xsdinferencer.extraction.extractorImpl.TypesExtractorImpl.java
License:Apache License
/** * Returns a path of the element made of the name of the elements and their prefixes (or namespace URIs). * Prefixes (or URIs) are separated from element names by :, so THEY MUST BE REPLACED BY _ if they are * going to be used to build type names. * Note that the : WILL always appear, although there is not any namespace prefix. * If a solved namespace-prefix mapping is given, the prefix mapped to the namespace of the element will be used instead of the prefix of the element. * @param element the element/*ww w. j a v a 2 s.co m*/ * @param config current inference configuration * @param useURI if true, the URI is used to build the path, if false, the prefix is used * @param solvedNamespaceToPrefixMapping the solved mappings between the namespace URIs and prefixes * @return a list that represents the path. Each element of the list is a path element. * @throws NullPointerException if any argument is null */ public static List<String> getRealPathOfElementUnfiltered(Element element, XSDInferenceConfiguration config, boolean useURI, Map<String, String> solvedNamespaceToPrefixMapping) { checkNotNull(element, "'element' must not be null"); checkNotNull(config, "'config' must not be null"); LinkedList<String> path = new LinkedList<String>(); Element currentElement = element; do { String e; if (useURI) { e = currentElement.getNamespaceURI() + ":" + currentElement.getName(); } else { String effectivePrefix = solvedNamespaceToPrefixMapping != null ? solvedNamespaceToPrefixMapping.get(currentElement.getNamespaceURI()) : currentElement.getNamespacePrefix(); e = effectivePrefix + ":" + currentElement.getName(); } path.addFirst(e); } while ((currentElement = currentElement.getParentElement()) != null); return path; }