use of org.dom4j.XPath in project archiva by apache.
the class XMLReader method getElementList.
@SuppressWarnings("unchecked")
public List<Element> getElementList(String xpathExpr) throws XMLException {
XPath xpath = createXPath(xpathExpr);
Object evaluated = xpath.evaluate(document);
if (evaluated == null) {
return null;
}
if (evaluated instanceof List) {
return (List<Element>) evaluated;
} else if (evaluated instanceof Node) {
List<Element> ret = new ArrayList<>();
ret.add((Element) evaluated);
return ret;
} else {
// Unknown evaluated type.
throw new XMLException(".getElementList( Expr: " + xpathExpr + " ) resulted in non-List type -> (" + evaluated.getClass().getName() + ") " + evaluated);
}
}
use of org.dom4j.XPath in project archiva by apache.
the class XMLReader method hasElement.
public boolean hasElement(String xpathExpr) throws XMLException {
XPath xpath = createXPath(xpathExpr);
Object evaluated = xpath.selectSingleNode(document);
if (evaluated == null) {
return false;
}
return true;
}
use of org.dom4j.XPath in project archiva by apache.
the class XMLReader method getElementText.
public String getElementText(Node context, String xpathExpr) throws XMLException {
XPath xpath = createXPath(xpathExpr);
Object evaluated = xpath.selectSingleNode(context);
if (evaluated == null) {
return null;
}
if (evaluated instanceof Element) {
Element evalElem = (Element) evaluated;
return evalElem.getTextTrim();
} else {
// Unknown evaluated type.
throw new XMLException(".getElementText( Node, Expr: " + xpathExpr + " ) resulted in non-Element type -> (" + evaluated.getClass().getName() + ") " + evaluated);
}
}
use of org.dom4j.XPath in project core by craftercms.
the class XmlUtils method selectNodes.
/**
* Executes the specified namespace aware XPath query as a multiple node query, returning the resulting list of nodes.
*/
@SuppressWarnings("unchecked")
public static List<Node> selectNodes(Node node, String xpathQuery, Map<String, String> namespaceUris) {
XPath xpath = DocumentHelper.createXPath(xpathQuery);
xpath.setNamespaceURIs(namespaceUris);
return xpath.selectNodes(node);
}
use of org.dom4j.XPath in project core by craftercms.
the class XmlUtils method selectSingleNode.
/**
* Executes the specified namespace aware XPath query as a single node query, returning the resulting single node.
*/
public static Node selectSingleNode(Node node, String xpathQuery, Map<String, String> namespaceUris) {
XPath xpath = DocumentHelper.createXPath(xpathQuery);
xpath.setNamespaceURIs(namespaceUris);
return xpath.selectSingleNode(node);
}
Aggregations