PrefixResolverDefaultpublic class PrefixResolverDefault extends Object implements PrefixResolverThis class implements a generic PrefixResolver that
can be used to perform prefix-to-namespace lookup
for the XPath object. |
Fields Summary |
---|
Node | m_contextThe context to resolve the prefix from, if the context
is not given. |
Constructors Summary |
---|
public PrefixResolverDefault(Node xpathExpressionContext)Construct a PrefixResolverDefault object.
m_context = xpathExpressionContext;
|
Methods Summary |
---|
public java.lang.String | getBaseIdentifier()Return the base identifier.
return null;
| public java.lang.String | getNamespaceForPrefix(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.
return getNamespaceForPrefix(prefix, m_context);
| public java.lang.String | getNamespaceForPrefix(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.
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 boolean | handlesNullPrefixes()
return false;
|
|