Search in sources :

Example 16 with XPath

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);
    }
}
Also used : XPath(org.dom4j.XPath) Node(org.dom4j.Node) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) List(java.util.List)

Example 17 with XPath

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;
}
Also used : XPath(org.dom4j.XPath)

Example 18 with XPath

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);
    }
}
Also used : XPath(org.dom4j.XPath) Element(org.dom4j.Element)

Example 19 with XPath

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);
}
Also used : XPath(org.dom4j.XPath)

Example 20 with XPath

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);
}
Also used : XPath(org.dom4j.XPath)

Aggregations

XPath (org.dom4j.XPath)27 Element (org.dom4j.Element)18 List (java.util.List)9 Iterator (java.util.Iterator)8 HashMap (java.util.HashMap)7 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)6 Node (org.dom4j.Node)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 FileSystemException (org.apache.commons.vfs2.FileSystemException)3 KettleException (org.pentaho.di.core.exception.KettleException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Date (java.util.Date)2 Set (java.util.Set)2 FileObject (org.apache.commons.vfs2.FileObject)2 Attribute (org.dom4j.Attribute)2 Document (org.dom4j.Document)2 DocumentFactory (org.dom4j.DocumentFactory)2 Namespace (org.dom4j.Namespace)2