List of usage examples for org.jdom2 Element getDescendants
@Override public <F extends Content> IteratorIterable<F> getDescendants(final Filter<F> filter)
From source file:org.mycore.frontend.editor.postprocessor.MCREditorPostProcessorXSL.java
License:Open Source License
public MCRJDOMContent transform(MCRContent source) throws IOException { try {/*from www . j a va 2 s .c o m*/ Element root = source.asXML().getRootElement().clone(); for (Iterator<Text> iter = root.getDescendants(Filters.text()).iterator(); iter.hasNext();) { Text text = iter.next(); text.setText(MCRXMLFunctions.normalizeUnicode(text.getText())); } return new MCRJDOMContent(root); } catch (JDOMException ex) { throw new IOException(ex); } catch (SAXException ex) { throw new IOException(ex); } }
From source file:org.openecomp.sdc.asdctool.impl.GraphMLDataAnalyzer.java
License:Open Source License
private List<ComponentRow> getComponents(Document document) { List<ComponentRow> res = new ArrayList<>(); Element root = document.getRootElement(); ElementFilter filter = new ElementFilter("graph"); Element graph = root.getDescendants(filter).next(); filter = new ElementFilter("edge"); IteratorIterable<Element> edges = graph.getDescendants(filter); Set<String> componentsHavingReqOrCap = new HashSet<>(); filter = new ElementFilter("data"); for (Element edge : edges) { IteratorIterable<Element> dataNodes = edge.getDescendants(filter); for (Element data : dataNodes) { String attributeValue = data.getAttributeValue("key"); switch (attributeValue) { case "labelE": String edgeLabel = data.getText(); if (edgeLabel.equals("REQUIREMENT") || edgeLabel.equals("CAPABILITY")) { componentsHavingReqOrCap.add(edge.getAttributeValue("source")); }/*from w w w. jav a2 s . c o m*/ break; } } } filter = new ElementFilter("node"); IteratorIterable<Element> nodes = graph.getDescendants(filter); filter = new ElementFilter("data"); for (Element element : nodes) { IteratorIterable<Element> dataNodes = element.getDescendants(filter); ComponentRow componentRow = new ComponentRow(); boolean isComponent = false; for (Element data : dataNodes) { String attributeValue = data.getAttributeValue("key"); switch (attributeValue) { case "nodeLabel": String nodeLabel = data.getText(); if (nodeLabel.equals("resource") || nodeLabel.equals("service")) { isComponent = true; componentRow.setType(nodeLabel); String componentId = element.getAttributeValue("id"); componentRow.setHasNonCalculatedReqCap(componentsHavingReqOrCap.contains(componentId)); } break; case "uid": componentRow.setUniqueId(data.getText()); break; case "name": componentRow.setName(data.getText()); break; case "toscaResourceName": componentRow.setToscaResourceName(data.getText()); break; case "resourceType": componentRow.setResourceType(data.getText()); break; case "version": componentRow.setVersion(data.getText()); break; case "deleted": componentRow.setIsDeleted(Boolean.parseBoolean(data.getText())); break; default: break; } } if (isComponent) { res.add(componentRow); } } return res; }
From source file:org.openecomp.sdc.asdctool.impl.GraphMLDataAnalyzer.java
License:Open Source License
private List<ComponentInstanceRow> getComponentInstances(Document document) { List<ComponentInstanceRow> res = new ArrayList<>(); Element root = document.getRootElement(); ElementFilter filter = new ElementFilter("graph"); Element graph = root.getDescendants(filter).next(); filter = new ElementFilter("node"); IteratorIterable<Element> nodes = graph.getDescendants(filter); filter = new ElementFilter("data"); for (Element element : nodes) { IteratorIterable<Element> dataNodes = element.getDescendants(filter); ComponentInstanceRow componentInstRow = new ComponentInstanceRow(); boolean isComponentInst = false; for (Element data : dataNodes) { String attributeValue = data.getAttributeValue("key"); switch (attributeValue) { case "nodeLabel": String nodeLabel = data.getText(); if (nodeLabel.equals("resourceInstance")) { isComponentInst = true; }//from w ww. j av a2s . com break; case "uid": componentInstRow.setUniqueId(data.getText()); break; case "name": componentInstRow.setName(data.getText()); break; case "originType": componentInstRow.setOriginType(data.getText()); break; default: break; } } if (isComponentInst) { // Assuming the uid is in standard form of // <container>.<origin>.<name> String uniqueId = componentInstRow.getUniqueId(); if (uniqueId != null) { String[] split = uniqueId.split("\\."); if (split.length == 3) { componentInstRow.setContainerUid(split[0]); componentInstRow.setOriginUid(split[1]); } } res.add(componentInstRow); } } return res; }
From source file:org.openflexo.foundation.ontology.owl.OWLOntology.java
License:Open Source License
private static Element getElement(Element from, String name) { Iterator it = from.getDescendants(new ElementFilter(name)); if (it.hasNext()) { return (Element) it.next(); } else {//from w w w. j ava 2 s. co m return null; } }
From source file:org.slc.sli.ingestion.parser.impl.XsdTypeProvider.java
License:Apache License
@Override public RecordMeta getTypeFromParentType(RecordMeta parentMeta, String eventName) { Element parentElement = getComplexElement(parentMeta.getType()); while (parentElement != null && eventName != null) { IteratorIterable<Element> res = parentElement.getDescendants(Filters.element(ELEMENT, XS_NAMESPACE)); for (Element e : res) { if (e.getAttributeValue(NAME).equals(eventName)) { String elementType = e.getAttributeValue(TYPE); if (elementType == null) { Element simple = e.getChild(SIMPLETYPE, XS_NAMESPACE); elementType = getSimpleTypeRestrictionBase(simple); }// w ww . j a v a2s .c o m return new RecordMetaImpl(eventName, elementType, shouldBeList(e, parentElement), parentMeta.getAction()); } } IteratorIterable<Element> extensions = parentElement .getDescendants(Filters.element(EXTENSION, XS_NAMESPACE)); if (extensions.hasNext()) { parentElement = getComplexElement(extensions.next().getAttributeValue(BASE)); } else { parentElement = null; } } return null; }
From source file:org.xcri.types.DescriptiveTextType.java
License:Open Source License
private void processXhtml(Element element) throws InvalidElementException { try {// ww w .j ava 2 s . c om // // Check for potentially dangerous elements // @SuppressWarnings("rawtypes") Iterator i = element.getDescendants(new ContentSecurityFilter()); ArrayList<Element> toRemove = new ArrayList<Element>(); while (i.hasNext()) { Element dangerousElement = (Element) i.next(); toRemove.add(dangerousElement); log.warn("description : content contains potentially dangerous XHTML :" + dangerousElement.getName()); } // // If configured to do so, remove elements // if (ParserConfiguration.getInstance().sanitizeXHTML()) { for (Element dangerousElement : toRemove) { log.warn("description : removing XHTML element :" + dangerousElement.getName()); dangerousElement.getParentElement().removeContent(dangerousElement); } } xhtml = element; isXhtml = true; // // Set value to text output of XML // this.setValue(new XMLOutputter().outputString(xhtml)); } catch (Exception e) { throw new InvalidElementException("Error reading content of description element"); } }
From source file:unidue.ub.statistics.resolver.JOPResolver.java
/** Remove all @ contained in "Title" elements that seem to separate to non-sort part of the title from the rest */ private void fixAtInTitles(Element root) { List<Element> candidates = new ArrayList<Element>(); Iterator<Element> titles = root.getDescendants(new ElementFilter("Title")); while (titles.hasNext()) { Element title = titles.next(); String text = title.getText(); if ((text != null) && text.contains("@")) candidates.add(title);// w ww . ja v a 2 s. co m } for (Element title : candidates) title.setText(title.getText().replaceAll("\\s@(\\S)", " $1")); }