public class NamespaceSupport extends java.lang.Object implements NamespaceContext
Similar to org.xml.sax.NamespaceSupport, but for marshalling and not for parsing XML.
Constructor and Description |
---|
NamespaceSupport()
Creates a new instance of NamespaceSupport.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
checkContext(int i)
This method is used to restore the namespace state
after an element is created.
|
void |
declarePrefix(java.lang.String pPrefix,
java.lang.String pURI)
Declares a new prefix.
|
java.lang.String |
getAttributePrefix(java.lang.String pURI)
Returns a non-empty prefix currently mapped to the given
URL or null, if there is no such mapping.
|
int |
getContext()
Returns the current number of assigned prefixes.
|
java.lang.String |
getNamespaceURI(java.lang.String pPrefix)
Given a prefix, returns the URI to which the prefix is
currently mapped or null, if there is no such mapping.
|
java.lang.String |
getPrefix(java.lang.String pURI)
Returns a prefix currently mapped to the given URI or
null, if there is no such mapping.
|
java.util.Iterator |
getPrefixes(java.lang.String pURI)
Returns a collection to all prefixes bound to the given
namespace URI.
|
boolean |
isPrefixDeclared(java.lang.String pPrefix)
Returns whether a given prefix is currently declared.
|
void |
reset()
Resets the NamespaceSupport's state for reuse.
|
void |
undeclarePrefix(java.lang.String pPrefix)
Removes a prefix declaration.
|
public NamespaceSupport()
Creates a new instance of NamespaceSupport.
public void reset()
Resets the NamespaceSupport's state for reuse.
public void declarePrefix(java.lang.String pPrefix, java.lang.String pURI)
Declares a new prefix.
public void undeclarePrefix(java.lang.String pPrefix)
Removes a prefix declaration. Assumes that the prefix is the current prefix. If not, throws a IllegalStateException.
public java.lang.String getNamespaceURI(java.lang.String pPrefix)
Given a prefix, returns the URI to which the prefix is currently mapped or null, if there is no such mapping.
Note: This methods behaviour is precisely
defined by NamespaceContext.getNamespaceURI(java.lang.String)
.
getNamespaceURI
in interface NamespaceContext
pPrefix
- The prefix in questionpublic java.lang.String getPrefix(java.lang.String pURI)
Returns a prefix currently mapped to the given URI or
null, if there is no such mapping. This method may be used
to find a possible prefix for an elements namespace URI. For
attributes you should use getAttributePrefix(String)
.
Note: This methods behaviour is precisely
defined by NamespaceContext.getPrefix(java.lang.String)
.
getPrefix
in interface NamespaceContext
pURI
- The namespace URI in questionjava.lang.IllegalArgumentException
- The namespace URI is null.public java.lang.String getAttributePrefix(java.lang.String pURI)
Returns a non-empty prefix currently mapped to the given
URL or null, if there is no such mapping. This method may be
used to find a possible prefix for an attributes namespace
URI. For elements you should use getPrefix(String)
.
pURI
- Thhe namespace URI in questionjava.lang.IllegalArgumentException
- The namespace URI is null.public java.util.Iterator getPrefixes(java.lang.String pURI)
Returns a collection to all prefixes bound to the given namespace URI.
Note: This methods behaviour is precisely
defined by NamespaceContext.getPrefixes(java.lang.String)
.
getPrefixes
in interface NamespaceContext
pURI
- The namespace prefix in questionIterator
: Using it's
Iterator.remove()
method throws an
UnsupportedOperationException
.public boolean isPrefixDeclared(java.lang.String pPrefix)
Returns whether a given prefix is currently declared.
public int getContext()
ContentHandler.startElement(String, String, String, org.xml.sax.Attributes)
.
The return value is used as a saveable state. After
invoking
ContentHandler.endElement(String, String, String)
,
the state is restored by calling checkContext(int)
.public java.lang.String checkContext(int i)
getContext()
.NamespaceSupport nss; ContentHandler h; int context = nss.getContext(); h.startElement("foo", "bar", "f:bar", new AttributesImpl()); ... h.endElement("foo", "bar", "f:bar"); for (;;) { String prefix = nss.checkContext(context); if (prefix == null) { break; } h.endPrefixMapping(prefix); }