Package org.apache.xml.serializer
Class NamespaceMappings
java.lang.Object
org.apache.xml.serializer.NamespaceMappings
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.
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.
This class is intended for internal use only. However, it is made public because
other packages require it.
For example:
invalid input: '<'chapter xmlns:p1="def"> invalid input: '<'paragraph xmlns:p2="ghi"> invalid input: '<'sentance xmlns:p3="jkl"> invalid input: '<'paragraph xlmns:p4="mno">When the
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()
This method makes a clone of this object.Generate a new namespace prefix ( ns0, ns1 ...) not used beforeString[]
lookupAllPrefixes
(String uri) Given a namespace uri, get all prefixes bound to the Namespace URI in the current scope.lookupNamespace
(String prefix) Use a namespace prefix to lookup a namespace URI.lookupPrefix
(String uri) Given a namespace uri, and the namespaces mappings for the current element, return the current prefix for that uri.boolean
pushNamespace
(String prefix, String uri, int elemDepth) Declare a mapping of a prefix to namespace URI at the given element depth.
-
Constructor Details
-
NamespaceMappings
public NamespaceMappings()Default constructor- See Also:
-
-
Method Details
-
lookupNamespace
Use a namespace prefix to lookup a namespace URI.- Parameters:
prefix
- String the prefix of the namespace- Returns:
- the URI corresponding to the prefix, returns "" if there is no visible mapping.
-
lookupPrefix
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.
-
pushNamespace
Declare a mapping of a prefix to namespace URI at the given element depth.- Parameters:
prefix
- a String with the prefix for a qualified nameuri
- a String with the uri to which the prefix is to mapelemDepth
- the depth of current declaration
-
generateNextPrefix
Generate a new namespace prefix ( ns0, ns1 ...) not used before- Returns:
- String a new namespace prefix ( ns0, ns1, ns2 ...)
-
clone
This method makes a clone of this object.- Throws:
CloneNotSupportedException
-
lookupAllPrefixes
Given a namespace uri, get all prefixes bound to the Namespace URI in the current scope.- Parameters:
uri
- the namespace URI to be search for- Returns:
- An array of Strings which are all prefixes bound to the namespace URI in the current scope. An array of zero elements is returned if no prefixes map to the given namespace URI.
-