Class NamespacesTable
This class also provides a very convenient and safe way of handling namespace declarations in SAX pipes. It also allows to filter duplicate namespace declarations that too often clutter up XML documents that went through several transformations, and avoid useless namespace declarations that aren't followed by element events.
Usage example in a SAX pipe:
NamespacesTable namespaces = new NamespacesTable(); ContentHandler nextHandler; public void startPrefixMapping(String prefix, String uri) throws SAXException { namespaces.addDeclaration(prefix, uri); } public void startElement(...) throws SAXException { // automatically start mappings for this scope namespaces.enterScope(nextHandler); nextHandler.startElement(...); } public void endElement(...) throws SAXException { nextHandler.endElement(...); // automatically end mappings for this scope namespaces.leaveScope(nextHandler); } public void endPrefixMapping(String prefix) throws SAXException { // Ignore, it is handled by leaveScope() }
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Deprecated.This API is deprecated, migrate code to the XML APIs provided by the JDK.static interface
Deprecated.This API is deprecated, migrate code to the XML APIs provided by the JDK. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddDeclaration
(String prefix, String uri) Deprecated.Declare a new namespace prefix-uri mapping.void
clear()
Deprecated.Clear and reinitialize this namespace table before reuse.void
Deprecated.Enter a new scope.void
enterScope
(ContentHandler handler) Deprecated.Start all declared mappings of the current scope and enter a new scope.Deprecated.Get the declarations that were declared within the current scope.Deprecated.Return one of the prefixes currently mapped to the specified URI or null.String[]
getPrefixes
(String uri) Deprecated.Return an array with all prefixes currently mapped to the specified URI.Deprecated.Return the URI associated with the given prefix or null if the prefix was not mapped.void
Deprecated.Leave a scope.void
leaveScope
(ContentHandler handler) Deprecated.Leave a scope.removeDeclaration
(String prefix) Deprecated.Undeclare a namespace prefix-uri mapping.Deprecated.Resolve a namespace-aware name against the current namespaces declarations.
-
Constructor Details
-
NamespacesTable
public NamespacesTable()Deprecated.Construct a newNamespacesTable
instance.
-
-
Method Details
-
clear
public void clear()Deprecated.Clear and reinitialize this namespace table before reuse.- Since:
- 2.1.8
-
addDeclaration
Deprecated.Declare a new namespace prefix-uri mapping.- Returns:
- The newly added
Declaration
.
-
removeDeclaration
Deprecated.Undeclare a namespace prefix-uri mapping. If the prefix was previously declared mapping another URI, its value is restored.When using
enterScope()
/leaveScope()
, this method does nothing and always returnsnull
, as declaration removal is handled inleaveScope()
.- Returns:
- the removed
Declaration
or null.
-
enterScope
public void enterScope()Deprecated.Enter a new scope. This starts a new, empty list of declarations for the new scope.Typically called in a SAX handler before sending a
startElement()
event.- Since:
- 2.1.8
-
enterScope
Deprecated.Start all declared mappings of the current scope and enter a new scope. This starts a new, empty list of declarations for the new scope.Typically called in a SAX handler before sending a
startElement()
event.- Parameters:
handler
- the handler that will receive startPrefixMapping events.- Throws:
SAXException
- Since:
- 2.1.8
-
leaveScope
public void leaveScope()Deprecated.Leave a scope. The namespace declarations that occured before the correspondingenterScope()
are no more visible using the resolution methods, but still available usinggetCurrentScopeDeclarations()
until the next call toaddDeclaration(String, String)
orenterScope()
.Typically called in a SAX handler after sending a
endElement()
event.- Since:
- 2.1.8
-
leaveScope
Deprecated.Leave a scope. The namespace declarations that occured before the correspondingenterScope()
are no more visible using the resolution methods, but still available usinggetCurrentScopeDeclarations()
until the next call toaddDeclaration(String, String)
orenterScope()
.Typically called in a SAX handler after sending a
endElement()
event.- Parameters:
handler
- the handler that will receive endPrefixMapping events.- Throws:
SAXException
- Since:
- 2.1.8
-
getCurrentScopeDeclarations
Deprecated.Get the declarations that were declared within the current scope.- Returns:
- the declarations (possibly empty, but never null)
- Since:
- 2.1.8
-
getUri
Deprecated.Return the URI associated with the given prefix or null if the prefix was not mapped. -
getPrefixes
Deprecated.Return an array with all prefixes currently mapped to the specified URI.
The array length might be zero if no prefixes are associated with the specified uri.- Returns:
- A non-null
String
array.
-
getPrefix
Deprecated.Return one of the prefixes currently mapped to the specified URI or null. -
resolve
public NamespacesTable.Name resolve(String uri, String raw, String prefix, String local) throws SAXException Deprecated.Resolve a namespace-aware name against the current namespaces declarations.- Parameters:
uri
- The namespace URI or null if not known.raw
- The raw (complete) name or null if not known.prefix
- The namespace prefix or null if not known.local
- The local name or null if not known.- Returns:
- A non-null
Name
. - Throws:
SAXException
- If the name cannot be resolved.
-