Save This Page
Home » cocoon-2.1.11-src » org.apache » cocoon » xml » [javadoc | source]
org.apache.cocoon.xml
public class: NamespacesTable [javadoc | source]
java.lang.Object
   org.apache.cocoon.xml.NamespacesTable
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()
}
Nested Class Summary:
public interface  NamespacesTable.Name  A namespace-aware name. (This interface is used in conjunction with NamespacesTable). 
public interface  NamespacesTable.Declaration  A namespace declaration. (This interface is used in conjunction with NamespacesTable). 
Constructor:
 public NamespacesTable() 
Method from org.apache.cocoon.xml.NamespacesTable Summary:
addDeclaration,   clear,   enterScope,   enterScope,   getCurrentScopeDeclarations,   getPrefix,   getPrefixes,   getUri,   leaveScope,   leaveScope,   removeDeclaration,   resolve
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.cocoon.xml.NamespacesTable Detail:
 public NamespacesTable.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. This starts a new, empty list of declarations for the new scope.

    Typically called in a SAX handler before sending a startElement() event.

 public  void enterScope(ContentHandler handler) throws SAXException 
    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.

 public NamespacesTable.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.
    The array length might be zero if no prefixes are associated with 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() 
 public  void leaveScope(ContentHandler handler) throws SAXException 
 public NamespacesTable.Declaration removeDeclaration(String prefix) 
    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 returns null, as declaration removal is handled in #leaveScope() .

 public NamespacesTable.Name resolve(String uri,
    String raw,
    String prefix,
    String local) throws SAXException 
    Resolve a namespace-aware name against the current namespaces declarations.