org.apache.xml.serializer
Class NamespaceMappings

java.lang.Object
  |
  +--org.apache.xml.serializer.NamespaceMappings

public class NamespaceMappings
extends java.lang.Object

This class keeps track of the currently defined namespaces. Conceptually the prefix/uri/depth triplets are pushed on a stack pushed on a stack. The depth indicates the nesting depth of the element for which the mapping was made.

For example:

 
   
      
      
    
    
    
 
 
When the element is encounted the prefix "p1" associated with uri "def" is pushed on the stack with depth 1. When the first is encountered "p2" and "ghi" are pushed with depth 2. When the is encountered "p3" and "jkl" are pushed with depth 3. When occurs the popNamespaces(3) will pop "p3"/"jkl" off the stack. Of course popNamespaces(2) would pop anything with depth 2 or greater. So prefix/uri pairs are pushed and poped off the stack as elements are processed. At any given moment of processing the currently visible prefixes are on the stack and a prefix can be found given a uri, or a uri can be found given a prefix.


Constructor Summary
NamespaceMappings()
          Default constructor
 
Method Summary
 java.lang.Object clone()
          This method makes a clone of this object.
 java.lang.String generateNextPrefix()
          Generate a new namespace prefix ( ns0, ns1 ...) not used before
 java.lang.String lookupNamespace(java.lang.String prefix)
          Use a namespace prefix to lookup a namespace URI.
 java.lang.String lookupPrefix(java.lang.String uri)
          Given a namespace uri, and the namespaces mappings for the current element, return the current prefix for that uri.
 boolean popNamespace(java.lang.String prefix)
          Undeclare the namespace that is currently pointed to by a given prefix
 void popNamespaces(int elemDepth, ContentHandler saxHandler)
          Pop, or undeclare all namespace definitions that are currently declared at the given element depth, or deepter.
 boolean pushNamespace(java.lang.String prefix, java.lang.String uri, int elemDepth)
          Declare a prefix to point to a namespace URI
 void reset()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NamespaceMappings

public NamespaceMappings()
Default constructor
See Also:
Object.Object()
Method Detail

lookupNamespace

public java.lang.String lookupNamespace(java.lang.String prefix)
Use a namespace prefix to lookup a namespace URI.
Parameters:
prefix - String the prefix of the namespace
Returns:
the URI corresponding to the prefix

lookupPrefix

public java.lang.String lookupPrefix(java.lang.String uri)
Given a namespace uri, and the namespaces mappings for the current element, return the current prefix for that uri.
Parameters:
uri - the namespace URI to be search for
Returns:
an existing prefix that maps to the given URI, null if no prefix maps to the given namespace URI.

popNamespace

public boolean popNamespace(java.lang.String prefix)
Undeclare the namespace that is currently pointed to by a given prefix

pushNamespace

public boolean pushNamespace(java.lang.String prefix,
                             java.lang.String uri,
                             int elemDepth)
Declare a prefix to point to a namespace URI
Parameters:
prefix - a String with the prefix for a qualified name
uri - a String with the uri to which the prefix is to map
elemDepth - the depth of current declaration

popNamespaces

public void popNamespaces(int elemDepth,
                          ContentHandler saxHandler)
Pop, or undeclare all namespace definitions that are currently declared at the given element depth, or deepter.
Parameters:
elemDepth - the element depth for which mappings declared at this depth or deeper will no longer be valid
saxHandler - The ContentHandler to notify of any endPrefixMapping() calls. This parameter can be null.

generateNextPrefix

public java.lang.String generateNextPrefix()
Generate a new namespace prefix ( ns0, ns1 ...) not used before
Returns:
String a new namespace prefix ( ns0, ns1, ns2 ...)

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
This method makes a clone of this object.

reset

public final void reset()


Copyright © 2004 Apache XML Project. All Rights Reserved.