Example usage for org.apache.commons.jxpath.ri.model NodePointer getNamespaceURI

List of usage examples for org.apache.commons.jxpath.ri.model NodePointer getNamespaceURI

Introduction

In this page you can find the example usage for org.apache.commons.jxpath.ri.model NodePointer getNamespaceURI.

Prototype

public String getNamespaceURI(String prefix) 

Source Link

Document

Decodes a namespace prefix to the corresponding URI.

Usage

From source file:org.firesoa.common.jxpath.model.dom4j.Dom4JNodePointer.java

/**
 * Execute test against node on behalf of pointer.
 * @param pointer Pointer/*from   w  w  w .  j  a  v a2 s . co  m*/
 * @param node to test
 * @param test to execute
 * @return true if node passes test
 */
public static boolean testNode(NodePointer pointer, Object node, NodeTest test) {
    if (test == null) {
        return true;
    }
    if (test instanceof NodeNameTest) {
        if (!(node instanceof Element)) {
            return false;
        }

        NodeNameTest nodeNameTest = (NodeNameTest) test;
        QName testName = nodeNameTest.getNodeName();
        String namespaceURI = nodeNameTest.getNamespaceURI();
        boolean wildcard = nodeNameTest.isWildcard();
        String testPrefix = testName.getPrefix();

        //testPrefixnull??
        if (testPrefix == null && namespaceURI == null) {
            namespaceURI = pointer.getNamespaceURI(Constants.DEFAULT_NS_PREFIX);
        }

        if (wildcard && testPrefix == null) {
            return true;
        }
        if (wildcard || testName.getName().equals(Dom4JNodePointer.getLocalName(node))) {
            String nodeNS = Dom4JNodePointer.getNamespaceURI((Node) node);
            return equalStrings(namespaceURI, nodeNS)
                    || nodeNS == null && equalStrings(testPrefix, Dom4JNodePointer.getPrefix((Node) node));
        }
        return false;
    }
    if (test instanceof NodeTypeTest) {
        switch (((NodeTypeTest) test).getNodeType()) {
        case Compiler.NODE_TYPE_NODE:
            return true;
        case Compiler.NODE_TYPE_TEXT:
            return (node instanceof Text) || (node instanceof CDATA);
        case Compiler.NODE_TYPE_COMMENT:
            return node instanceof Comment;
        case Compiler.NODE_TYPE_PI:
            return node instanceof ProcessingInstruction;
        default:
            return false;
        }
    }
    if (test instanceof ProcessingInstructionTest && node instanceof ProcessingInstruction) {
        String testPI = ((ProcessingInstructionTest) test).getTarget();
        String nodePI = ((ProcessingInstruction) node).getTarget();
        return testPI.equals(nodePI);
    }
    return false;
}