Example usage for org.apache.commons.jxpath.ri QName getPrefix

List of usage examples for org.apache.commons.jxpath.ri QName getPrefix

Introduction

In this page you can find the example usage for org.apache.commons.jxpath.ri QName getPrefix.

Prototype

public String getPrefix() 

Source Link

Document

Get the prefix of this QName.

Usage

From source file:org.eclipse.e4.emf.internal.xpath.EObjectAttributeIterator.java

/**
 * Create a new BeanAttributeIterator./*w  w  w  . j a v  a  2 s.  c o  m*/
 * @param parent parent pointer
 * @param name name of this bean
 */
public EObjectAttributeIterator(EStructuralFeatureOwnerPointer parent, QName name) {
    super(parent, (name.getPrefix() == null && (name.getName() == null || name.getName().equals("*"))) ? null
            : name.toString(), false, null);
    this.parent = parent;
    includeXmlLang = (name.getPrefix() != null && name.getPrefix().equals("xml"))
            && (name.getName().equals("lang") || name.getName().equals("*"));
}

From source file:org.eclipse.e4.emf.internal.xpath.EStructuralFeatureOwnerPointer.java

/**
 * Learn whether <code>name</code> is a valid child name for this PropertyOwnerPointer.
 * @param name the QName to test//from  ww  w  . j a va  2 s  . c om
 * @return <code>true</code> if <code>QName</code> is a valid property name.
 * @since JXPath 1.3
 */
public boolean isValidProperty(QName name) {
    return isDefaultNamespace(name.getPrefix());
}

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

public NodePointer createChild(JXPathContext context, QName name, int index) {
    if (index == WHOLE_COLLECTION) {
        index = 0;//w w  w. j  ava 2  s  .co m
    }
    boolean success = getAbstractFactory(context).createObject(context, this, node, name.toString(), index);
    if (success) {
        NodeTest nodeTest;
        String prefix = name.getPrefix();
        String namespaceURI = prefix == null ? null : context.getNamespaceURI(prefix);
        nodeTest = new NodeNameTest(name, namespaceURI);

        NodeIterator it = childIterator(nodeTest, false, null);
        if (it != null && it.setPosition(index + 1)) {
            return it.getNodePointer();
        }
    }
    throw new JXPathAbstractFactoryException("Factory could not create " + "a child node for path: " + asPath()
            + "/" + name + "[" + (index + 1) + "]");
}

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

/**
 * ??nameattribute/*from   www . ja v  a 2s .co  m*/
 */
public NodePointer createAttribute(JXPathContext context, QName name) {
    if (!(node instanceof Element)) {
        return super.createAttribute(context, name);
    }
    Element element = (Element) node;
    String prefix = name.getPrefix();
    if (prefix != null) {
        String nsUri = null;
        NamespaceResolver nsr = getNamespaceResolver();
        if (nsr != null) {
            nsUri = nsr.getNamespaceURI(prefix);
        }
        if (nsUri == null) {
            throw new JXPathException("Unknown namespace prefix: " + prefix);
        }
        Namespace dom4jNs = Namespace.get(prefix, nsUri);
        org.dom4j.QName attributeName = new org.dom4j.QName(name.getName(), dom4jNs);
        Attribute attr = element.attribute(attributeName);
        if (attr == null) {
            element.addAttribute(attributeName, "");
        }
    } else {
        Attribute attr = element.attribute(name.getName());
        if (attr == null) {
            element.addAttribute(name.getName(), "");
        }
    }
    NodeIterator it = attributeIterator(name);
    it.setPosition(1);
    return it.getNodePointer();
}

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

/**
 * Execute test against node on behalf of pointer.
 * @param pointer Pointer/*w  w w .j ava2 s. c  o 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;
}

From source file:org.geotools.feature.xpath.AttributeNodePointer.java

public NodeIterator attributeIterator(QName qname) {
    return new XmlAttributeNodeIterator(this,
            Types.typeName(getNamespaceResolver().getNamespaceURI(qname.getPrefix()), qname.getName()));
}

From source file:org.geotools.feature.xpath.FeatureTypeAttributePointer.java

public NodeIterator attributeIterator(QName qname) {
    return new DescriptorXmlAttributeNodeIterator(this,
            Types.typeName(getNamespaceResolver().getNamespaceURI(qname.getPrefix()), qname.getName()));
}

From source file:org.xchain.framework.jxpath.JXPathValidator.java

static void validateExtensionFunction(ExtensionFunction ef, NamespaceContext xmlns) {
    QName name = ef.getFunctionName();
    String prefix = name.getPrefix();

    // validate that the prefix is mapped.
    validatePrefix(prefix, xmlns);/*from  www.j a  v  a 2s .  c  om*/

    // if the prefix is mapped to an xchain namespace uri, then validate that a function is bound that might match the function.
    // TODO: add hooks for lifecycle based validation.
}

From source file:org.xchain.framework.jxpath.JXPathValidator.java

static void validateVariableReference(VariableReference variableReference, NamespaceContext xmlns) {
    QName name = variableReference.getVariableName();
    validatePrefix(name.getPrefix(), xmlns);
}

From source file:org.xchain.framework.jxpath.JXPathValidator.java

static void validateNodeNameTest(NodeNameTest nodeNameTest, NamespaceContext xmlns) {
    if (nodeNameTest.isWildcard()) {
        // TODO: we need to investigate wildcards with namespaces.
    } else {//w ww .  j a  va 2  s.  co m
        QName name = nodeNameTest.getNodeName();
        validatePrefix(name.getPrefix(), xmlns);
    }
}