use of org.w3c.dom.NamedNodeMap in project gocd by gocd.
the class XmlDocument method createAndCacheNamespaces.
private void createAndCacheNamespaces(Ruby ruby, Node node) {
if (node == null)
return;
if (node.hasAttributes()) {
NamedNodeMap nodeMap = node.getAttributes();
for (int i = 0; i < nodeMap.getLength(); i++) {
Node n = nodeMap.item(i);
if (n instanceof Attr) {
Attr attr = (Attr) n;
String attrName = attr.getName();
// not sure, but need to get value always before document is referred.
// or lose attribute value
// don't delete this line
String attrValue = attr.getValue();
if (isNamespace(attrName)) {
// create and cache
XmlNamespace.createFromAttr(ruby, attr);
}
}
}
}
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
createAndCacheNamespaces(ruby, children.item(i));
}
}
use of org.w3c.dom.NamedNodeMap in project gocd by gocd.
the class Canonicalizer11 method handleParent.
@Override
protected void handleParent(Element e, NameSpaceSymbTable ns) {
if (!e.hasAttributes() && e.getNamespaceURI() == null) {
return;
}
xmlattrStack.push(-1);
NamedNodeMap attrs = e.getAttributes();
int attrsLength = attrs.getLength();
for (int i = 0; i < attrsLength; i++) {
Attr attribute = (Attr) attrs.item(i);
String NName = attribute.getLocalName();
String NValue = attribute.getNodeValue();
if (Constants.NamespaceSpecNS.equals(attribute.getNamespaceURI())) {
if (!XML.equals(NName) || !Constants.XML_LANG_SPACE_SpecNS.equals(NValue)) {
ns.addMapping(NName, NValue, attribute);
}
} else if (!"id".equals(NName) && XML_LANG_URI.equals(attribute.getNamespaceURI())) {
xmlattrStack.addXmlnsAttr(attribute);
}
}
if (e.getNamespaceURI() != null) {
String NName = e.getPrefix();
String NValue = e.getNamespaceURI();
String Name;
if (NName == null || NName.equals("")) {
NName = "xmlns";
Name = "xmlns";
} else {
Name = "xmlns:" + NName;
}
Attr n = e.getOwnerDocument().createAttributeNS("http://www.w3.org/2000/xmlns/", Name);
n.setValue(NValue);
ns.addMapping(NName, NValue, n);
}
}
use of org.w3c.dom.NamedNodeMap in project gocd by gocd.
the class Canonicalizer20010315 method handleParent.
@Override
protected void handleParent(Element e, NameSpaceSymbTable ns) {
if (!e.hasAttributes() && e.getNamespaceURI() == null) {
return;
}
xmlattrStack.push(-1);
NamedNodeMap attrs = e.getAttributes();
int attrsLength = attrs.getLength();
for (int i = 0; i < attrsLength; i++) {
Attr attribute = (Attr) attrs.item(i);
String NName = attribute.getLocalName();
String NValue = attribute.getNodeValue();
if (Constants.NamespaceSpecNS.equals(attribute.getNamespaceURI())) {
if (!XML.equals(NName) || !Constants.XML_LANG_SPACE_SpecNS.equals(NValue)) {
ns.addMapping(NName, NValue, attribute);
}
} else if (XML_LANG_URI.equals(attribute.getNamespaceURI())) {
xmlattrStack.addXmlnsAttr(attribute);
}
}
if (e.getNamespaceURI() != null) {
String NName = e.getPrefix();
String NValue = e.getNamespaceURI();
String Name;
if (NName == null || NName.equals("")) {
NName = "xmlns";
Name = "xmlns";
} else {
Name = "xmlns:" + NName;
}
Attr n = e.getOwnerDocument().createAttributeNS("http://www.w3.org/2000/xmlns/", Name);
n.setValue(NValue);
ns.addMapping(NName, NValue, n);
}
}
use of org.w3c.dom.NamedNodeMap in project gocd by gocd.
the class CanonicalizerBase method handleParent.
protected void handleParent(Element e, NameSpaceSymbTable ns) {
if (!e.hasAttributes() && e.getNamespaceURI() == null) {
return;
}
NamedNodeMap attrs = e.getAttributes();
int attrsLength = attrs.getLength();
for (int i = 0; i < attrsLength; i++) {
Attr attribute = (Attr) attrs.item(i);
String NName = attribute.getLocalName();
String NValue = attribute.getNodeValue();
if (Constants.NamespaceSpecNS.equals(attribute.getNamespaceURI()) && (!XML.equals(NName) || !Constants.XML_LANG_SPACE_SpecNS.equals(NValue))) {
ns.addMapping(NName, NValue, attribute);
}
}
if (e.getNamespaceURI() != null) {
String NName = e.getPrefix();
String NValue = e.getNamespaceURI();
String Name;
if (NName == null || NName.equals("")) {
NName = XMLNS;
Name = XMLNS;
} else {
Name = XMLNS + ":" + NName;
}
Attr n = e.getOwnerDocument().createAttributeNS("http://www.w3.org/2000/xmlns/", Name);
n.setValue(NValue);
ns.addMapping(NName, NValue, n);
}
}
use of org.w3c.dom.NamedNodeMap in project buck by facebook.
the class XmlPrettyPrinter method printOpenElementTag.
private void printOpenElementTag(int depth, Node node) {
Element element = (Element) node;
if (newlineBeforeElementOpen(element, depth)) {
mOut.append(mLineSeparator);
}
if (indentBeforeElementOpen(element, depth)) {
indent(depth);
}
mOut.append('<').append(element.getTagName());
NamedNodeMap attributes = element.getAttributes();
int attributeCount = attributes.getLength();
if (attributeCount > 0) {
// Sort the attributes
List<Attr> attributeList = new ArrayList<Attr>();
for (int i = 0; i < attributeCount; i++) {
attributeList.add((Attr) attributes.item(i));
}
Comparator<Attr> comparator = mPrefs.getAttributeComparator();
if (comparator != null) {
Collections.sort(attributeList, comparator);
}
// Put the single attribute on the same line as the element tag?
boolean singleLine = mPrefs.oneAttributeOnFirstLine && attributeCount == 1 || // usually just zero, one or two) on the same line
mStyle == XmlFormatStyle.RESOURCE;
// We also place the namespace declaration on the same line as the root element,
// but this doesn't also imply singleLine handling; subsequent attributes end up
// on their own lines
boolean indentNextAttribute;
if (singleLine || (depth == 0 && XMLNS.equals(attributeList.get(0).getPrefix()))) {
mOut.append(' ');
indentNextAttribute = false;
} else {
mOut.append(mLineSeparator);
indentNextAttribute = true;
}
Attr last = attributeList.get(attributeCount - 1);
for (Attr attribute : attributeList) {
if (indentNextAttribute) {
indent(depth + 1);
}
mOut.append(attribute.getName());
mOut.append('=').append('"');
XmlUtils.appendXmlAttributeValue(mOut, attribute.getValue());
mOut.append('"');
// immediately follow the last attribute
if (attribute != last) {
//$NON-NLS-1$
mOut.append(singleLine ? " " : mLineSeparator);
indentNextAttribute = !singleLine;
}
}
}
boolean isClosed = isEmptyTag(element);
// element
if (mPrefs.spaceBeforeClose && (mStyle != XmlFormatStyle.RESOURCE || isClosed) && // in <selector> files etc still treat the <item> entries as in resource files
!TAG_ITEM.equals(element.getTagName()) && (isClosed || element.getAttributes().getLength() > 0)) {
mOut.append(' ');
}
if (isClosed) {
mOut.append('/');
}
mOut.append('>');
if (newlineAfterElementOpen(element, depth, isClosed)) {
mOut.append(mLineSeparator);
}
}
Aggregations