if (isOutputElement) {
visiblyUtilized = (Set) this._inclusiveNSSet.clone();
}
for (int i = 0; i < attrsLength; i++) {
Attr N = (Attr) attrs.item(i);
String NName=N.getLocalName();
String NNodeValue=N.getNodeValue();
if ( !isVisible(N) ) {
//The node is not in the nodeset(if there is a nodeset)
continue;
}
if (!XMLNS_URI.equals(N.getNamespaceURI())) {
//Not a namespace definition.
if (isOutputElement) {
//The Element is output element, add his prefix(if used) to visibyUtilized
String prefix = N.getPrefix();
if ((prefix != null) && (!prefix.equals(XML) && !prefix.equals(XMLNS)) ){
visiblyUtilized.add(prefix);
}
//Add to the result.
result.add(N);
}
continue;
}
if (ns.addMapping(NName, NNodeValue,N)) {
//New definiton check if it is relative
if (C14nHelper.namespaceIsRelative(NNodeValue)) {
Object exArgs[] = {E.getTagName(), NName,
N.getNodeValue()};
throw new CanonicalizationException(
"c14n.Canonicalizer.RelativeNamespace", exArgs);
}
}
}
if (isOutputElement) {
//The element is visible, handle the xmlns definition
Attr xmlns = E.getAttributeNodeNS(XMLNS_URI, XMLNS);
if ((xmlns!=null) && (!isVisible(xmlns))) {
//There is a definition but the xmlns is not selected by the xpath.
//then xmlns=""
ns.addMapping(XMLNS,"",nullNode);
}
if (E.getNamespaceURI() != null) {
String prefix = E.getPrefix();
if ((prefix == null) || (prefix.length() == 0)) {
visiblyUtilized.add(XMLNS);
} else {
visiblyUtilized.add( prefix);
}
} else {
visiblyUtilized.add(XMLNS);
}
//This can be optimezed by I don't have time
//visiblyUtilized.addAll(this._inclusiveNSSet);
Iterator it=visiblyUtilized.iterator();
while (it.hasNext()) {
String s=(String)it.next();
Attr key=ns.getMapping(s);
if (key==null) {
continue;
}
result.add(key);
}
} else /*if (_circunvented)*/ {
Iterator it=this._inclusiveNSSet.iterator();
while (it.hasNext()) {
String s=(String)it.next();
Attr key=ns.getMappingWithoutRendered(s);
if (key==null) {
continue;
}
result.add(key);
}