1 2 18 package com.sun.org.apache.xml.internal.security.c14n.helper; 19 20 21 22 import com.sun.org.apache.xml.internal.security.utils.Constants; 23 import org.w3c.dom.Attr ; 24 25 26 42 public class AttrCompare implements java.util.Comparator { 43 44 private final int ATTR0_BEFORE_ATTR1 = -1; 45 private final int ATTR1_BEFORE_ATTR0 = 1; 46 47 private final static String XMLNS=Constants.NamespaceSpecNS; 48 66 public int compare(Object obj0, Object obj1) { 67 68 Attr attr0 = (Attr ) obj0; 69 Attr attr1 = (Attr ) obj1; 70 String namespaceURI0 = attr0.getNamespaceURI(); 71 String namespaceURI1 = attr1.getNamespaceURI(); 72 73 boolean isNamespaceAttr0 = 74 XMLNS.equals(namespaceURI0); 75 boolean isNamespaceAttr1 = 76 XMLNS.equals(namespaceURI1); 77 78 if (isNamespaceAttr0) { 79 if (isNamespaceAttr1) { 80 81 String localname0 = attr0.getLocalName(); 83 String localname1 = attr1.getLocalName(); 84 85 if (localname0.equals("xmlns")) { 86 localname0 = ""; 87 } 88 89 if (localname1.equals("xmlns")) { 90 localname1 = ""; 91 } 92 93 return localname0.compareTo(localname1); 94 } 95 return ATTR0_BEFORE_ATTR1; 97 98 } 99 if (isNamespaceAttr1) { 100 101 return ATTR1_BEFORE_ATTR0; 103 } 104 105 107 if (namespaceURI0 == null) { 108 if (namespaceURI1 == null) { 109 114 115 String name0 = attr0.getName(); 116 String name1 = attr1.getName(); 117 return name0.compareTo(name1); 118 } 119 return ATTR0_BEFORE_ATTR1; 120 121 } 122 if (namespaceURI1 == null) { 123 return ATTR1_BEFORE_ATTR0; 124 } 125 int a = namespaceURI0.compareTo(namespaceURI1); 126 127 if (a != 0) { 128 return a; 129 } 130 133 134 return (attr0.getLocalName()) 135 .compareTo( attr1.getLocalName()); 136 137 } 138 139 } 140 | Popular Tags |