1 13 package org.ccil.cowan.tagsoup; 14 15 22 public class Element { 23 24 25 private ElementType theType; private AttributesImpl theAtts; private Element theNext; private boolean preclosed; 30 35 36 public Element(ElementType type, boolean defaultAttributes) { 37 theType = type; 38 if (defaultAttributes) theAtts = new AttributesImpl(type.atts()); 39 else theAtts = new AttributesImpl(); 40 theNext = null; 41 preclosed = false; 42 } 43 44 48 49 public ElementType type() { return theType; } 50 51 57 public AttributesImpl atts() { return theAtts; } 58 59 63 64 public Element next() { return theNext; } 65 66 70 71 public void setNext(Element next) { theNext = next; } 72 73 78 79 public String name() { return theType.name(); } 80 81 86 87 public String namespace() { return theType.namespace(); } 88 89 94 95 public String localName() { return theType.localName(); } 96 97 102 103 public int model() { return theType.model(); } 104 105 110 111 public int memberOf() { return theType.memberOf(); } 112 113 118 119 public int flags() { return theType.flags(); } 120 121 126 127 public ElementType parent() { return theType.parent(); } 128 129 135 136 public boolean canContain(Element other) { 137 return theType.canContain(other.theType); 138 } 139 140 141 147 148 public void setAttribute(String name, String type, String value) { 149 theType.setAttribute(theAtts, name, type, value); 150 } 151 152 157 158 public void anonymize() { 159 for (int i = theAtts.getLength() - 1; i >= 0; i--) { 160 if (theAtts.getType(i).equals("ID") || 161 theAtts.getQName(i).equals("name")) { 162 theAtts.removeAttribute(i); 163 } 164 } 165 } 166 167 174 175 public void clean() { 176 for (int i = theAtts.getLength() - 1; i >= 0; i--) { 177 String name = theAtts.getLocalName(i); 178 if (theAtts.getValue(i) == null || name == null || 179 name.length() == 0) { 180 theAtts.removeAttribute(i); 181 continue; 182 } 183 if (theAtts.getType(i).equals("BOOLEAN")) { 184 theAtts.setType(i, "NMTOKEN"); 185 } 186 } 187 } 188 189 193 194 public void preclose() { 195 preclosed = true; 196 } 197 198 201 202 public boolean isPreclosed() { 203 return preclosed; 204 } 205 206 } 207 | Popular Tags |