FileDocCategorySizeDatePackage
PrefixResolverDefault.javaAPI DocJava SE 6 API4004Tue Jun 10 00:23:10 BST 2008com.sun.org.apache.xml.internal.utils

PrefixResolverDefault

public class PrefixResolverDefault extends Object implements PrefixResolver
This class implements a generic PrefixResolver that can be used to perform prefix-to-namespace lookup for the XPath object.
xsl.usage
general

Fields Summary
Node
m_context
The context to resolve the prefix from, if the context is not given.
Constructors Summary
public PrefixResolverDefault(Node xpathExpressionContext)
Construct a PrefixResolverDefault object.

param
xpathExpressionContext The context from which XPath expression prefixes will be resolved. Warning: This will not work correctly if xpathExpressionContext is an attribute node.

    m_context = xpathExpressionContext;
  
Methods Summary
public java.lang.StringgetBaseIdentifier()
Return the base identifier.

return
null

    return null;
  
public java.lang.StringgetNamespaceForPrefix(java.lang.String prefix)
Given a namespace, get the corrisponding prefix. This assumes that the PrevixResolver hold's it's own namespace context, or is a namespace context itself.

param
prefix Prefix to resolve.
return
Namespace that prefix resolves to, or null if prefix is not bound.

    return getNamespaceForPrefix(prefix, m_context);
  
public java.lang.StringgetNamespaceForPrefix(java.lang.String prefix, org.w3c.dom.Node namespaceContext)
Given a namespace, get the corrisponding prefix. 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 = Constants.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)
        {
                if (parent.getNodeName().indexOf(prefix+":") == 0) 
                        return parent.getNamespaceURI();                
          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;