FileDocCategorySizeDatePackage
JAXPPrefixResolver.javaAPI DocJava SE 5 API3937Fri Aug 26 14:56:10 BST 2005com.sun.org.apache.xpath.internal.jaxp

JAXPPrefixResolver

public class JAXPPrefixResolver extends Object implements PrefixResolver
This class implements a Default PrefixResolver which can be used to perform prefix-to-namespace lookup for the XPath object. This class delegates the resolution to the passed NamespaceContext

Fields Summary
private NamespaceContext
namespaceContext
public static final String
S_XMLNAMESPACEURI
The URI for the XML namespace. (Duplicate of that found in com.sun.org.apache.xpath.internal.XPathContext).
Constructors Summary
public JAXPPrefixResolver(NamespaceContext nsContext)

        this.namespaceContext = nsContext;
    
Methods Summary
public java.lang.StringgetBaseIdentifier()
Return the base identifier.

return
null

        return null;
    
public java.lang.StringgetNamespaceForPrefix(java.lang.String prefix)

        return namespaceContext.getNamespaceURI( prefix );
    
public java.lang.StringgetNamespaceForPrefix(java.lang.String prefix, org.w3c.dom.Node namespaceContext)
Given a prefix and a Context Node, get the corresponding namespace. Warning: This will not work correctly if namespaceContext is an attribute node.

param
prefix Prefix to resolve.
param
namespaceContext Node from which to start searching for a xmlns attribute that binds a prefix to a namespace.
return
Namespace that prefix resolves to, or null if prefix is not bound.



                                                                     
       
                                        
        Node parent = namespaceContext;
        String namespace = null;

        if (prefix.equals("xml")) {
            namespace = S_XMLNAMESPACEURI;
        } else {
            int type;

            while ((null != parent) && (null == namespace)
                && (((type = parent.getNodeType()) == Node.ELEMENT_NODE)
                    || (type == Node.ENTITY_REFERENCE_NODE))) {

                if (type == Node.ELEMENT_NODE) {
                    NamedNodeMap nnm = parent.getAttributes();

                    for (int i = 0; i < nnm.getLength(); i++) {
                        Node attr = nnm.item(i);
                        String aname = attr.getNodeName();
                        boolean isPrefix = aname.startsWith("xmlns:");

                        if (isPrefix || aname.equals("xmlns")) {
                            int index = aname.indexOf(':");
                            String p =isPrefix ?aname.substring(index + 1) :"";

                            if (p.equals(prefix)) {
                                namespace = attr.getNodeValue();
                                break;
                            }
                        }
                    }
                }

                parent = parent.getParentNode();
            }
        }
        return namespace;
    
public booleanhandlesNullPrefixes()

see
PrefixResolver#handlesNullPrefixes()

        return false;