Methods Summary |
---|
public java.lang.Object | clone()This method makes a clone of this object.
NamespaceMappings clone = new NamespaceMappings();
clone.m_nodeStack = (Stack) m_nodeStack.clone();
clone.m_namespaces = (Hashtable) m_namespaces.clone();
clone.count = count;
return clone;
|
public java.lang.String | generateNextPrefix()Generate a new namespace prefix ( ns0, ns1 ...) not used before
return "ns" + (count++);
|
com.sun.org.apache.xml.internal.serializer.NamespaceMappings$MappingRecord | getMappingFromPrefix(java.lang.String prefix)
final Stack stack = (Stack) m_namespaces.get(prefix);
return stack != null && !stack.isEmpty() ?
((MappingRecord) stack.peek()) : null;
|
com.sun.org.apache.xml.internal.serializer.NamespaceMappings$MappingRecord | getMappingFromURI(java.lang.String uri)
MappingRecord foundMap = null;
Enumeration prefixes = m_namespaces.keys();
while (prefixes.hasMoreElements())
{
String prefix = (String) prefixes.nextElement();
MappingRecord map2 = getMappingFromPrefix(prefix);
if (map2 != null && (map2.m_uri).equals(uri))
{
foundMap = map2;
break;
}
}
return foundMap;
|
private void | initNamespaces()This method initializes the namespace object with appropriate stacks
and predefines a few prefix/uri pairs which always exist.
// Define the default namespace (initially maps to "" uri)
Stack stack;
m_namespaces.put(EMPTYSTRING, stack = new Stack());
stack.push(new MappingRecord(EMPTYSTRING,EMPTYSTRING,0));
m_namespaces.put(XML_PREFIX, stack = new Stack());
stack.push(new MappingRecord( XML_PREFIX,
"http://www.w3.org/XML/1998/namespace",0));
m_nodeStack.push(new MappingRecord(null,null,-1));
|
public java.lang.String | lookupNamespace(java.lang.String prefix)Use a namespace prefix to lookup a namespace URI.
final Stack stack = (Stack) m_namespaces.get(prefix);
return stack != null && !stack.isEmpty() ?
((MappingRecord) stack.peek()).m_uri : null;
|
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.
String foundPrefix = null;
Enumeration prefixes = m_namespaces.keys();
while (prefixes.hasMoreElements())
{
String prefix = (String) prefixes.nextElement();
String uri2 = lookupNamespace(prefix);
if (uri2 != null && uri2.equals(uri))
{
foundPrefix = prefix;
break;
}
}
return foundPrefix;
|
boolean | popNamespace(java.lang.String prefix)Undeclare the namespace that is currently pointed to by a given prefix
// Prefixes "xml" and "xmlns" cannot be redefined
if (prefix.startsWith(XML_PREFIX))
{
return false;
}
Stack stack;
if ((stack = (Stack) m_namespaces.get(prefix)) != null)
{
stack.pop();
return true;
}
return false;
|
void | popNamespaces(int elemDepth, org.xml.sax.ContentHandler saxHandler)Pop, or undeclare all namespace definitions that are currently
declared at the given element depth, or deepter.
while (true)
{
if (m_nodeStack.isEmpty())
return;
MappingRecord map = (MappingRecord)(m_nodeStack.peek());
int depth = map.m_declarationDepth;
if (depth < elemDepth)
return;
/* the depth of the declared mapping is elemDepth or deeper
* so get rid of it
*/
map = (MappingRecord) m_nodeStack.pop();
final String prefix = map.m_prefix;
popNamespace(prefix);
if (saxHandler != null)
{
try
{
saxHandler.endPrefixMapping(prefix);
}
catch (SAXException e)
{
// not much we can do if they aren't willing to listen
}
}
}
|
boolean | pushNamespace(java.lang.String prefix, java.lang.String uri, int elemDepth)Declare a mapping of a prefix to namespace URI at the given element depth.
// Prefixes "xml" and "xmlns" cannot be redefined
if (prefix.startsWith(XML_PREFIX))
{
return false;
}
Stack stack;
// Get the stack that contains URIs for the specified prefix
if ((stack = (Stack) m_namespaces.get(prefix)) == null)
{
m_namespaces.put(prefix, stack = new Stack());
}
if (!stack.empty() && uri.equals(((MappingRecord)stack.peek()).m_uri))
{
return false;
}
MappingRecord map = new MappingRecord(prefix,uri,elemDepth);
stack.push(map);
m_nodeStack.push(map);
return true;
|
final void | reset()
this.count = 0;
this.m_namespaces.clear();
this.m_nodeStack.clear();
initNamespaces();
|