List of usage examples for org.jdom2 Element getChildren
public List<Element> getChildren()
List
of all the child elements nested directly (one level deep) within this element, as Element
objects. From source file:de.knowwe.visualization.dot.DOTRenderer.java
License:Open Source License
/** * Iterates through all the children of root to find all a-tag elements. * * @created 21.12.2013/*from www . j ava 2s . c om*/ */ private static void findAndAugmentElements(Element root) { List<?> children = root.getChildren(); Iterator<?> iter = children.iterator(); //noinspection WhileLoopReplaceableByForEach while (iter.hasNext()) { Element childElement = (Element) iter.next(); if (childElement.getName().equals("a")) { addTargetAttribute(childElement); } else { findAndAugmentElements(childElement); } } }
From source file:de.mud.flash.FlashTerminal.java
License:Open Source License
/** * Handle XML Commands sent by the remote host. * /*www . j a va2 s.c o m*/ * @param xml * string containing the xml commands */ private void handleXMLCommand(String xml) { log.error("handleXMLCommand(" + xml + ")"); StringReader src = new StringReader("<root>" + xml.replace('\0', ' ') + "</root>"); try { Element root = builder.build(src).getRootElement(); Iterator<?> cmds = root.getChildren().iterator(); while (cmds.hasNext()) { Element command = (Element) cmds.next(); String name = command.getName(); if ("mode".equals(name)) { simpleMode = "true".equals(command.getAttribute("simple").getValue().toLowerCase()); } else if ("timestamp".equals(name)) { perf(command.getAttribute("msg").getValue()); } else if ("start".equals(name)) { terminalReady = true; buffer.update[0] = true; redraw(); } } } catch (JDOMException e) { log.error("error reading command: " + e); } catch (IOException e) { log.error(e.getMessage()); } }
From source file:de.nava.informa.utils.ParserUtils.java
License:Open Source License
/** * Converts names of child-tags mentioned in <code>childrenNames</code> list * to that given case./*from www . j av a 2s . c om*/ * * @param root root element. * @param childrenNames names of child tags to convert. */ public static void matchCaseOfChildren(Element root, String[] childrenNames) { if (root == null || childrenNames.length == 0) return; // Prepare list of names int namesCount = childrenNames.length; Map<String, String> names = new HashMap<>(namesCount); for (String childName : childrenNames) { if (childName != null) { String lower = childName.toLowerCase(); if (!names.containsKey(lower)) names.put(lower, childName); } } // Walk through the children elements List elements = root.getChildren(); for (Object element : elements) { Element child = (Element) element; String childName = child.getName().toLowerCase(); if (names.containsKey(childName)) child.setName(names.get(childName)); } }
From source file:de.nava.informa.utils.ParserUtils.java
License:Open Source License
/** * Converts names of child-tags mentioned in <code>childName</code> list * to that given case.//from www .j a v a2 s .com * * @param root root element. * @param childName name of child tags to convert. */ public static void matchCaseOfChildren(Element root, String childName) { if (root == null || childName == null) return; // Walk through the children elements List elements = root.getChildren(); for (Object element : elements) { Element child = (Element) element; String name = child.getName().toLowerCase(); if (name.equalsIgnoreCase(childName)) child.setName(childName); } }
From source file:de.relaunch64.popelganda.database.Settings.java
License:Open Source License
public ArrayList<Object[]> getReopenFiles() { // get reopen files Element el = root.getChild(SETTING_REOPEN_FILES); // check if we have any if (null == el) return null; // create return value ArrayList<Object[]> rofiles = new ArrayList<>(); // retrieve all children, each element representing one // file that should be re-opened List<Element> children = el.getChildren(); // iterate all children for (Element e : children) { // get file path File f = new File(e.getText()); // check if exists if (f.exists()) { // get compiler value String attr_c = e.getAttributeValue(ATTR_ASM); String attr_s = e.getAttributeValue(ATTR_SCRIPT); // init defaults Assembler assembler = Assemblers.ASM_KICKASSEMBLER; int script = -1; // check if we have compiler value try { if (attr_c != null) assembler = Assemblers.byID(Integer.parseInt(attr_c)); if (attr_s != null) script = Integer.parseInt(attr_s); } catch (NumberFormatException ex) { assembler = Assemblers.ASM_KICKASSEMBLER; script = -1;// w w w . jav a 2 s. c o m } // add compiler and filepath to return value rofiles.add(new Object[] { f, assembler, script }); } } return rofiles; }
From source file:de.smartics.maven.plugin.jboss.modules.parser.ModulesDescriptorBuilder.java
License:Apache License
private void adjustNamespaces(final Element element) { element.setNamespace(null);/*w ww .j av a2 s . com*/ final List<Namespace> namespaces = new ArrayList<Namespace>(element.getAdditionalNamespaces()); for (final Namespace namespace : namespaces) { element.removeNamespaceDeclaration(namespace); } element.setNamespace(ModuleXmlBuilder.NS); for (final Element child : element.getChildren()) { adjustNamespaces(child); } }
From source file:de.smartics.maven.plugin.jboss.modules.parser.ModulesDescriptorBuilder.java
License:Apache License
private void parseApplyToModule(final Element applyToModuleElement) { if (applyToModuleElement == null) { return;/*from w w w .jav a 2 s .com*/ } final ApplyToModule.Builder mBuilder = new ApplyToModule.Builder(); adjustNamespaces(applyToModuleElement); final XMLOutputter outputter = new XMLOutputter(Format.getCompactFormat()); for (final Element child : applyToModuleElement.getChildren()) { handleChild(mBuilder, outputter, child); } builder.with(mBuilder.build()); }
From source file:de.smartics.maven.plugin.jboss.modules.parser.ModulesDescriptorBuilder.java
License:Apache License
private void handleDependencies(final ApplyToModule.Builder mBuilder, final XMLOutputter outputter, final Element child) { int nonModuleCounter = 0; for (final Element childElement : child.getChildren()) { final String childElementName = childElement.getName(); final String name; if ("module".equals(childElementName)) { name = childElement.getAttributeValue("name"); } else {/*w w w . j a va2s.c o m*/ // i.e. system, maybe others. nonModuleCounter++; name = "non-module@" + nonModuleCounter; } final String fragment = outputter.outputString(childElement); mBuilder.addDependencyXml(name, fragment); } }
From source file:de.smartics.maven.plugin.jboss.modules.util.XmlUtils.java
License:Apache License
public static void adjustNamespaces(final Element element, Namespace ns) { element.setNamespace(null);/* w ww .ja v a 2 s . com*/ final List<Namespace> namespaces = new ArrayList<Namespace>(element.getAdditionalNamespaces()); for (final Namespace namespace : namespaces) { element.removeNamespaceDeclaration(namespace); } element.setNamespace(ns); for (final Element child : element.getChildren()) { adjustNamespaces(child, ns); } }
From source file:de.smartics.maven.plugin.jboss.modules.xml.ModuleXmlBuilder.java
License:Apache License
private void addResources(ModuleDescriptor module, final Collection<Dependency> dependencies) { final Element resources = new Element("resources", NS); List<String> resourceRootsXml = module.getApplyToModule().getResourceRootsXml(); for (final String xml : resourceRootsXml) { final Element element = xmlFragmentParser.parse(xml); resources.addContent(element);//w w w . j av a 2 s . com } if (!dependencies.isEmpty()) { final List<SortElement> sorted = createSortedResources(dependencies); for (final SortElement element : sorted) { final Element resource = new Element("resource-root", NS); final String fileName = element.key; resource.setAttribute("path", fileName); resources.addContent(resource); } } if (!resources.getChildren().isEmpty()) { root.addContent(resources); } }