1 16 17 package org.apache.xerces.dom; 18 19 import org.w3c.dom.DOMException ; 20 import org.w3c.dom.DocumentType ; 21 import org.w3c.dom.Node ; 22 import org.w3c.dom.NamedNodeMap ; 23 import java.util.Hashtable ; 24 import org.w3c.dom.UserDataHandler ; 25 26 51 public class DocumentTypeImpl 52 extends ParentNode 53 implements DocumentType { 54 55 59 60 static final long serialVersionUID = 7751299192316526485L; 61 62 66 67 protected String name; 68 69 70 protected NamedNodeMapImpl entities; 71 72 73 protected NamedNodeMapImpl notations; 74 75 77 78 protected NamedNodeMapImpl elements; 79 80 protected String publicID; 82 83 protected String systemID; 85 86 protected String internalSubset; 88 89 91 private int doctypeNumber=0; 94 95 private Hashtable userData = null; 99 100 public DocumentTypeImpl(CoreDocumentImpl ownerDocument, String name) { 101 super(ownerDocument); 102 103 this.name = name; 104 entities = new NamedNodeMapImpl(this); 106 notations = new NamedNodeMapImpl(this); 107 108 elements = new NamedNodeMapImpl(this); 110 111 } 113 114 public DocumentTypeImpl(CoreDocumentImpl ownerDocument, 115 String qualifiedName, 116 String publicID, String systemID) { 117 this(ownerDocument, qualifiedName); 118 this.publicID = publicID; 119 this.systemID = systemID; 120 121 } 123 127 133 public String getPublicId() { 134 if (needsSyncData()) { 135 synchronizeData(); 136 } 137 return publicID; 138 } 139 145 public String getSystemId() { 146 if (needsSyncData()) { 147 synchronizeData(); 148 } 149 return systemID; 150 } 151 152 157 public void setInternalSubset(String internalSubset) { 158 if (needsSyncData()) { 159 synchronizeData(); 160 } 161 this.internalSubset = internalSubset; 162 } 163 164 170 public String getInternalSubset() { 171 if (needsSyncData()) { 172 synchronizeData(); 173 } 174 return internalSubset; 175 } 176 177 181 185 public short getNodeType() { 186 return Node.DOCUMENT_TYPE_NODE; 187 } 188 189 192 public String getNodeName() { 193 if (needsSyncData()) { 194 synchronizeData(); 195 } 196 return name; 197 } 198 199 200 public Node cloneNode(boolean deep) { 201 202 DocumentTypeImpl newnode = (DocumentTypeImpl)super.cloneNode(deep); 203 newnode.entities = entities.cloneMap(newnode); 205 newnode.notations = notations.cloneMap(newnode); 206 newnode.elements = elements.cloneMap(newnode); 207 208 return newnode; 209 210 } 212 216 public String getTextContent() throws DOMException { 217 return null; 218 } 219 220 224 public void setTextContent(String textContent) 225 throws DOMException { 226 } 228 229 233 public boolean isEqualNode(Node arg) { 234 235 if (!super.isEqualNode(arg)) { 236 return false; 237 } 238 239 if (needsSyncData()) { 240 synchronizeData(); 241 } 242 DocumentTypeImpl argDocType = (DocumentTypeImpl) arg; 243 244 if ((getPublicId() == null && argDocType.getPublicId() != null) 247 || (getPublicId() != null && argDocType.getPublicId() == null) 248 || (getSystemId() == null && argDocType.getSystemId() != null) 249 || (getSystemId() != null && argDocType.getSystemId() == null) 250 || (getInternalSubset() == null 251 && argDocType.getInternalSubset() != null) 252 || (getInternalSubset() != null 253 && argDocType.getInternalSubset() == null)) { 254 return false; 255 } 256 257 if (getPublicId() != null) { 258 if (!getPublicId().equals(argDocType.getPublicId())) { 259 return false; 260 } 261 } 262 263 if (getSystemId() != null) { 264 if (!getSystemId().equals(argDocType.getSystemId())) { 265 return false; 266 } 267 } 268 269 if (getInternalSubset() != null) { 270 if (!getInternalSubset().equals(argDocType.getInternalSubset())) { 271 return false; 272 } 273 } 274 275 NamedNodeMapImpl argEntities = argDocType.entities; 277 278 if ((entities == null && argEntities != null) 279 || (entities != null && argEntities == null)) 280 return false; 281 282 if (entities != null && argEntities != null) { 283 if (entities.getLength() != argEntities.getLength()) 284 return false; 285 286 for (int index = 0; entities.item(index) != null; index++) { 287 Node entNode1 = entities.item(index); 288 Node entNode2 = 289 argEntities.getNamedItem(entNode1.getNodeName()); 290 291 if (!((NodeImpl) entNode1).isEqualNode((NodeImpl) entNode2)) 292 return false; 293 } 294 } 295 296 NamedNodeMapImpl argNotations = argDocType.notations; 297 298 if ((notations == null && argNotations != null) 299 || (notations != null && argNotations == null)) 300 return false; 301 302 if (notations != null && argNotations != null) { 303 if (notations.getLength() != argNotations.getLength()) 304 return false; 305 306 for (int index = 0; notations.item(index) != null; index++) { 307 Node noteNode1 = notations.item(index); 308 Node noteNode2 = 309 argNotations.getNamedItem(noteNode1.getNodeName()); 310 311 if (!((NodeImpl) noteNode1).isEqualNode((NodeImpl) noteNode2)) 312 return false; 313 } 314 } 315 316 return true; 317 } 319 320 324 void setOwnerDocument(CoreDocumentImpl doc) { 325 super.setOwnerDocument(doc); 326 entities.setOwnerDocument(doc); 327 notations.setOwnerDocument(doc); 328 elements.setOwnerDocument(doc); 329 } 330 331 334 protected int getNodeNumber() { 335 if (getOwnerDocument()!=null) 338 return super.getNodeNumber(); 339 340 if (doctypeNumber==0) { 343 344 CoreDOMImplementationImpl cd = (CoreDOMImplementationImpl)CoreDOMImplementationImpl.getDOMImplementation(); 345 doctypeNumber = cd.assignDocTypeNumber(); 346 } 347 return doctypeNumber; 348 } 349 350 354 358 public String getName() { 359 360 if (needsSyncData()) { 361 synchronizeData(); 362 } 363 return name; 364 365 } 367 389 public NamedNodeMap getEntities() { 390 if (needsSyncChildren()) { 391 synchronizeChildren(); 392 } 393 return entities; 394 } 395 396 401 public NamedNodeMap getNotations() { 402 if (needsSyncChildren()) { 403 synchronizeChildren(); 404 } 405 return notations; 406 } 407 408 412 417 public void setReadOnly(boolean readOnly, boolean deep) { 418 419 if (needsSyncChildren()) { 420 synchronizeChildren(); 421 } 422 super.setReadOnly(readOnly, deep); 423 424 elements.setReadOnly(readOnly, true); 426 entities.setReadOnly(readOnly, true); 427 notations.setReadOnly(readOnly, true); 428 429 } 431 435 public NamedNodeMap getElements() { 436 if (needsSyncChildren()) { 437 synchronizeChildren(); 438 } 439 return elements; 440 } 441 442 public Object setUserData(String key, 443 Object data, UserDataHandler handler) { 444 if(userData == null) 445 userData = new Hashtable (); 446 if (data == null) { 447 if (userData != null) { 448 Object o = userData.remove(key); 449 if (o != null) { 450 UserDataRecord r = (UserDataRecord) o; 451 return r.fData; 452 } 453 } 454 return null; 455 } 456 else { 457 Object o = userData.put(key, new UserDataRecord(data, handler)); 458 if (o != null) { 459 UserDataRecord r = (UserDataRecord) o; 460 return r.fData; 461 } 462 } 463 return null; 464 } 465 466 public Object getUserData(String key) { 467 if (userData == null) { 468 return null; 469 } 470 Object o = userData.get(key); 471 if (o != null) { 472 UserDataRecord r = (UserDataRecord) o; 473 return r.fData; 474 } 475 return null; 476 } 477 478 protected Hashtable getUserDataRecord(){ 479 return userData; 480 } 481 482 } | Popular Tags |