in nbxml/src/main/java/org/apache/vysper/xml/fragment/ResolverNamespaceResolver.java [46:87]
public Map<String, String> getNamespaceDeclarations() {
Map<String, String> ns = new LinkedHashMap<String, String>();
if (!elements.isEmpty()) {
XMLElement topElm = elements.peek();
for (Entry<String, String> entry : topElm.getDeclaredNamespaces().entrySet()) {
ns.put(entry.getKey(), entry.getValue());
}
// look for any generated prefixes for attributes
for (Attribute attribute : topElm.getAttributes()) {
String attrNs = attribute.getNamespaceUri();
if (attrNs.length() > 0 && resolvePrefix(attrNs, false) == null) {
// attribute is in a namespace, and that namespace is not declared
ns.put(resolvePrefix(attrNs), attrNs);
}
}
// add the element declaration as well, if not already defined
if (topElm.getNamespaceURI().length() > 0) {
// declared in a namespace
if (!ns.containsValue(topElm.getNamespaceURI())) {
// the namespace is not declared as an attribute on topElm
// is it declared on a parent?
// pop the element to test for declaration on the parent
pop();
if (resolvePrefix(topElm.getNamespaceURI(), false) == null) {
ns.put(topElm.getNamespacePrefix(), topElm.getNamespaceURI());
}
// restore stack
push(topElm);
}
} else {
// is there a parent in a namespace? if so, we need to reset the default namespace
if (elements.size() > 1 && elements.get(elements.size() - 2).getNamespaceURI().length() > 0
&& !ns.containsKey("")) {
ns.put("", "");
}
}
}
return ns;
}