X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=support%2Fsrc%2Forg%2Fwamblee%2Fxml%2FDOMUtility.java;h=581704447d3c2c1f8cd8c92c36c47c83c94b5351;hb=250f2d46f13720ba3bbbb82c2c6b5142dd9d6b2e;hp=6a7a5af75e6a4174a0a5f41b21adc9d82355c042;hpb=39d918dff4a7a36f68e3ef9d810884fad6a1c08b;p=utils diff --git a/support/src/org/wamblee/xml/DOMUtility.java b/support/src/org/wamblee/xml/DOMUtility.java index 6a7a5af7..58170444 100644 --- a/support/src/org/wamblee/xml/DOMUtility.java +++ b/support/src/org/wamblee/xml/DOMUtility.java @@ -12,58 +12,63 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** - * Utility class for performing various operations on DOM trees. + * Utility class for performing various operations on DOM trees. */ public final class DOMUtility { - - /** - * Disabled constructor. - * - */ - private DOMUtility() { - // Empty - } - - /** - * Removes duplicate attributes from a DOM tree. - * @param aNode Node to remove duplicate attributes from (recursively). - * Attributes of the node itself are not dealt with. Only the child - * nodes are dealt with. - */ - public static void removeDuplicateAttributes(Node aNode) { - NodeList list = aNode.getChildNodes(); - for (int i = 0; i < list.getLength(); i++) { - Node node = list.item(i); - if ( node instanceof Element ) { - removeDuplicateAttributes((Element)node); + + /** + * Disabled constructor. + * + */ + private DOMUtility() { + // Empty + } + + /** + * Removes duplicate attributes from a DOM tree. + * + * @param aNode + * Node to remove duplicate attributes from (recursively). + * Attributes of the node itself are not dealt with. Only the + * child nodes are dealt with. + */ + public static void removeDuplicateAttributes(Node aNode) { + NodeList list = aNode.getChildNodes(); + for (int i = 0; i < list.getLength(); i++) { + Node node = list.item(i); + if (node instanceof Element) { + removeDuplicateAttributes((Element) node); removeDuplicateAttributes(node); - } - } - } - - /** - * Removes duplicate attributes from an element. - * @param aElement Element. - */ - private static void removeDuplicateAttributes(Element aElement) { - NamedNodeMap attributes = aElement.getAttributes(); - Map uniqueAttributes = new TreeMap(); - List attlist = new ArrayList(); - for (int i = 0; i < attributes.getLength(); i++) { - Attr attribute = (Attr)attributes.item(i); - if ( uniqueAttributes.containsKey(attribute.getNodeName())) { - System.out.println("Detected duplicate attribute '" + attribute.getNodeName() + "'"); - } - uniqueAttributes.put(attribute.getNodeName(), attribute); - attlist.add(attribute); - } - // Remove all attributes from the element. - for (Attr att: attlist) { - aElement.removeAttributeNode(att); - } - // Add the unique attributes back to the element. - for (Attr att: uniqueAttributes.values()) { - aElement.setAttributeNode(att); - } - } + } + } + } + + /** + * Removes duplicate attributes from an element. + * + * @param aElement + * Element. + */ + private static void removeDuplicateAttributes(Element aElement) { + NamedNodeMap attributes = aElement.getAttributes(); + Map uniqueAttributes = new TreeMap(); + List attlist = new ArrayList(); + for (int i = 0; i < attributes.getLength(); i++) { + Attr attribute = (Attr) attributes.item(i); + if (uniqueAttributes.containsKey(attribute.getNodeName())) { + System.out.println("Detected duplicate attribute '" + + attribute.getNodeName() + "'"); + } + uniqueAttributes.put(attribute.getNodeName(), attribute); + attlist.add(attribute); + } + // Remove all attributes from the element. + for (Attr att : attlist) { + aElement.removeAttributeNode(att); + } + // Add the unique attributes back to the element. + for (Attr att : uniqueAttributes.values()) { + aElement.setAttributeNode(att); + } + } }