Example usage for org.apache.commons.jxpath.ri NamespaceResolver getNamespaceURI

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

Introduction

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

Prototype

public synchronized String getNamespaceURI(String prefix) 

Source Link

Document

Given a prefix, returns a registered namespace URI.

Usage

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

/**
 * ??nameattribute/* ww  w.  jav  a2 s  .  c o 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();
}