public class NamespaceResolver extends Object implements NamespaceContext
Usage note: NamespaceContext
allows multiple prefixes per URI,
in keeping with the Namespace spec. This implementation supports that, but
it's a bad idea to actually use this feature when writing an XPath. You'll
be much happier if you limit yourself to a 1:1 mapping.
If you have a single namespace mapping, this implementation is overkill.
Instead, use SimpleNamespaceResolver
.
Constructor and Description |
---|
NamespaceResolver() |
Modifier and Type | Method and Description |
---|---|
NamespaceResolver |
addNamespace(String prefix,
String nsURI)
Adds a namespace to this resolver.
|
protected NamespaceResolver |
clone()
Returns a deep clone of this object, that can then be independently
manipulated.
|
boolean |
equals(Object obj)
Two instances are considered equal if they have the same mappings,
including default namespace.
|
List<String> |
getAllPrefixes()
Returns a list of all prefixes known to this resolver, in alphabetical
order.
|
String |
getDefaultNamespace()
Returns the default namespace, an empty string if one has not yet
been set.
|
String |
getNamespaceURI(String prefix)
Returns the namespace URI bound to a given prefix,
null
if no URI is bound to the specified prefix. |
String |
getPrefix(String nsURI)
Returns the first prefix in alphabetical order bound to this namespace
URI,
null if there is no binding for the namespace. |
Iterator<String> |
getPrefixes(String nsURI)
Returns an iterator over all prefixes bound to this namespace URI, in
alphabetical order, an empty iterator if there are no bindings.
|
int |
hashCode() |
NamespaceResolver |
setDefaultNamespace(String nsURI)
Sets the default namespace -- the namespace that will be returned
when an empty string is passed to the resolver.
|
String |
toString()
Returns a string containing the the
xmlns attribute
specifications that would result from this resolver. |
public NamespaceResolver addNamespace(String prefix, String nsURI)
IllegalArgumentException
- if either prefix
or nsURI
is null
.public NamespaceResolver setDefaultNamespace(String nsURI)
IllegalArgumentException
- if nsURI
is
null
.public String getDefaultNamespace()
public List<String> getAllPrefixes()
public String getNamespaceURI(String prefix)
null
if no URI is bound to the specified prefix. See interface doc for
default bindings.getNamespaceURI
in interface NamespaceContext
public String getPrefix(String nsURI)
null
if there is no binding for the namespace. See
interface doc for default bindings.getPrefix
in interface NamespaceContext
public Iterator<String> getPrefixes(String nsURI)
getPrefixes
in interface NamespaceContext
public final boolean equals(Object obj)
public String toString()
xmlns
attribute
specifications that would result from this resolver.protected NamespaceResolver clone()