in core/src/main/java/org/apache/commons/jelly/XMLOutput.java [115:170]
public void pushNamespace(String prefix, String uri) throws SAXException {
Map prefixUriMap;
if (prefix == null) {
prefix = "";
}
if (uri == null) {
uri = "";
}
if ("xml".equals(prefix)) {
// We should ignore setting 'xml' prefix
// As declared in java of ContentHandler#startPrefixMapping
return;
}
// Lets find out if we already declared this same prefix,
// if not declare in current depth map (the first of list)
// and call contentHandler.startPrefixMapping(prefix, uri);
boolean isNew = true;
for (Iterator iter = nsStack.iterator(); iter.hasNext();) {
prefixUriMap = (Map) iter.next();
if (prefixUriMap.containsKey(prefix)) {
if (uri.equals(prefixUriMap.get(prefix))) {
// Its an active namespace already
// System.out.println(">>>"+XMLOutput.this.hashCode()+">NamespaceStack.pushNamespace() IS NOT NEW prefix="+prefix+",uri="+uri);
isNew = false;
}
// We found it in stack
// If it was exactly the same, we won't bother
break;
}
}
if (isNew) {
// not declared sometime before
prefixUriMap = (Map) nsStack.get(0); // Current depth map
// Sanity check: Don't let two prefixes for different uris in
// same depth
if (prefixUriMap.containsKey(prefix)) {
if (!uri.equals(prefixUriMap.get(prefix))) {
throw new SAXException("Cannot set same prefix to different URI in same node: trying to add prefix \""
+ prefix + "\" for uri \""+uri+"\" whereas the declared ones are " + prefixUriMap);
}
} else {
prefixUriMap.put(prefix, uri);
// To avoid setting xmlns="" for top node (not very nice :D)
// We need to specifically check this condition
if (!isRootNodeDefaultNs(prefix, uri)) {
// System.out.println(">>>"+XMLOutput.this.hashCode()+">NamespaceStack.pushNamespace() prefix="+prefix+",uri="+uri);
contentHandler.startPrefixMapping(prefix, uri);
}
}
}
}