| java.lang.Object org.apache.cocoon.xml.NamespacesTable
NamespacesTable | public class NamespacesTable (Code) | | Keeps track of namespaces declarations and resolve namespaces names.
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()
}
version: $Id: NamespacesTable.java 433543 2006-08-22 06:22:54Z crossley $ |
Inner Class :public interface Name | |
Inner Class :public interface Declaration | |
Constructor Summary | |
public | NamespacesTable() Construct a new NamespacesTable instance. |
Method Summary | |
public Declaration | addDeclaration(String prefix, String uri) Declare a new namespace prefix-uri mapping. | public void | clear() Clear and reinitialize this namespace table before reuse. | public void | enterScope() Enter a new scope. | public void | enterScope(ContentHandler handler) Start all declared mappings of the current scope and enter a new scope. | public Declaration[] | getCurrentScopeDeclarations() Get the declarations that were declared within the current scope. | public String | getPrefix(String uri) Return one of the prefixes currently mapped to the specified URI or
null. | public String[] | getPrefixes(String uri) Return an array with all prefixes currently mapped to the specified URI. | public String | getUri(String prefix) Return the URI associated with the given prefix or null if the
prefix was not mapped. | public void | leaveScope() Leave a scope. | public void | leaveScope(ContentHandler handler) Leave a scope. | public Declaration | removeDeclaration(String prefix) Undeclare a namespace prefix-uri mapping. | public Name | resolve(String uri, String raw, String prefix, String local) Resolve a namespace-aware name against the current namespaces
declarations.
Parameters: uri - The namespace URI or null if not known. Parameters: raw - The raw (complete) name or null if not known. Parameters: prefix - The namespace prefix or null if not known. Parameters: local - The local name or null if not known. |
NamespacesTable | public NamespacesTable()(Code) | | Construct a new NamespacesTable instance.
|
addDeclaration | public Declaration addDeclaration(String prefix, String uri)(Code) | | Declare a new namespace prefix-uri mapping.
The newly added Declaration . |
clear | public void clear()(Code) | | Clear and reinitialize this namespace table before reuse.
since: 2.1.8 |
enterScope | public void enterScope()(Code) | | 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 | public void enterScope(ContentHandler handler) throws SAXException(Code) | | 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 |
getCurrentScopeDeclarations | public Declaration[] getCurrentScopeDeclarations()(Code) | | Get the declarations that were declared within the current scope.
the declarations (possibly empty, but never null) since: 2.1.8 |
getPrefix | public String getPrefix(String uri)(Code) | | Return one of the prefixes currently mapped to the specified URI or
null.
|
getPrefixes | public String[] getPrefixes(String uri)(Code) | | 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.
A non-null String array. |
getUri | public String getUri(String prefix)(Code) | | Return the URI associated with the given prefix or null if the
prefix was not mapped.
|
resolve | public Name resolve(String uri, String raw, String prefix, String local) throws SAXException(Code) | | Resolve a namespace-aware name against the current namespaces
declarations.
Parameters: uri - The namespace URI or null if not known. Parameters: raw - The raw (complete) name or null if not known. Parameters: prefix - The namespace prefix or null if not known. Parameters: local - The local name or null if not known. A non-null Name . exception: SAXException - If the name cannot be resolved. |
|
|