Search in sources :

Example 1 with XpathPrefixResolver

use of com.sun.enterprise.tools.verifier.XpathPrefixResolver in project Payara by payara.

the class VerifierTest method getXPathValueForNonRuntime.

/*
     *getXPathValueForNonRuntime(String xpath)
     *   return String - is the value of the element specified in the xpath.
     */
public String getXPathValueForNonRuntime(String xpath) {
    try {
        String value = null;
        Document d = getVerifierContext().getDocument();
        if (d == null)
            return null;
        XObject result = XPathAPI.eval(d, xpath, (PrefixResolver) new XpathPrefixResolver(d));
        NodeList nl = result.nodelist();
        for (int i = 0; i < nl.getLength(); i++) {
            Node n = ((Node) nl.item(i)).getFirstChild();
            if (n == null)
                return null;
            value = n.getNodeValue();
        }
        return value;
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}
Also used : XpathPrefixResolver(com.sun.enterprise.tools.verifier.XpathPrefixResolver) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) XObject(com.sun.org.apache.xpath.internal.objects.XObject)

Example 2 with XpathPrefixResolver

use of com.sun.enterprise.tools.verifier.XpathPrefixResolver in project Payara by payara.

the class VerifierTest method getNonRuntimeCountNodeSet.

public int getNonRuntimeCountNodeSet(String xpath) {
    try {
        // int value = -1;
        Document d = getVerifierContext().getDocument();
        if (d == null)
            return -1;
        XObject result = XPathAPI.eval(d, xpath, (PrefixResolver) new XpathPrefixResolver(d));
        NodeList nl = result.nodelist();
        NodeSet ns = new NodeSet(nl);
        return ns.getLength();
    } catch (Exception ex) {
        ex.printStackTrace();
        return -1;
    }
}
Also used : NodeSet(com.sun.org.apache.xpath.internal.NodeSet) XpathPrefixResolver(com.sun.enterprise.tools.verifier.XpathPrefixResolver) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) XObject(com.sun.org.apache.xpath.internal.objects.XObject)

Aggregations

XpathPrefixResolver (com.sun.enterprise.tools.verifier.XpathPrefixResolver)2 XObject (com.sun.org.apache.xpath.internal.objects.XObject)2 Document (org.w3c.dom.Document)2 NodeList (org.w3c.dom.NodeList)2 NodeSet (com.sun.org.apache.xpath.internal.NodeSet)1 Node (org.w3c.dom.Node)1