1 57 58 package com.sun.org.apache.xerces.internal.dom; 59 60 import org.w3c.dom.DOMException ; 61 import org.w3c.dom.DocumentType ; 62 import org.w3c.dom.Node ; 63 import org.w3c.dom.NamedNodeMap ; 64 import java.util.Hashtable ; 65 import org.w3c.dom.UserDataHandler ; 66 67 90 public class DocumentTypeImpl 91 extends ParentNode 92 implements DocumentType { 93 94 98 99 static final long serialVersionUID = 7751299192316526485L; 100 101 105 106 protected String name; 107 108 109 protected NamedNodeMapImpl entities; 110 111 112 protected NamedNodeMapImpl notations; 113 114 116 117 protected NamedNodeMapImpl elements; 118 119 protected String publicID; 121 122 protected String systemID; 124 125 protected String internalSubset; 127 128 130 private int doctypeNumber=0; 133 134 private Hashtable userData = null; 138 139 140 public DocumentTypeImpl(CoreDocumentImpl ownerDocument, String name) { 141 super(ownerDocument); 142 143 this.name = name; 144 entities = new NamedNodeMapImpl(this); 146 notations = new NamedNodeMapImpl(this); 147 148 elements = new NamedNodeMapImpl(this); 150 151 } 153 154 public DocumentTypeImpl(CoreDocumentImpl ownerDocument, 155 String qualifiedName, 156 String publicID, String systemID) { 157 this(ownerDocument, qualifiedName); 158 this.publicID = publicID; 159 this.systemID = systemID; 160 161 } 163 167 173 public String getPublicId() { 174 if (needsSyncData()) { 175 synchronizeData(); 176 } 177 return publicID; 178 } 179 185 public String getSystemId() { 186 if (needsSyncData()) { 187 synchronizeData(); 188 } 189 return systemID; 190 } 191 192 197 public void setInternalSubset(String internalSubset) { 198 if (needsSyncData()) { 199 synchronizeData(); 200 } 201 this.internalSubset = internalSubset; 202 } 203 204 210 public String getInternalSubset() { 211 if (needsSyncData()) { 212 synchronizeData(); 213 } 214 return internalSubset; 215 } 216 217 221 225 public short getNodeType() { 226 return Node.DOCUMENT_TYPE_NODE; 227 } 228 229 232 public String getNodeName() { 233 if (needsSyncData()) { 234 synchronizeData(); 235 } 236 return name; 237 } 238 239 240 public Node cloneNode(boolean deep) { 241 242 DocumentTypeImpl newnode = (DocumentTypeImpl)super.cloneNode(deep); 243 newnode.entities = entities.cloneMap(newnode); 245 newnode.notations = notations.cloneMap(newnode); 246 newnode.elements = elements.cloneMap(newnode); 247 248 return newnode; 249 250 } 252 256 public String getTextContent() throws DOMException { 257 return null; 258 } 259 260 264 public void setTextContent(String textContent) 265 throws DOMException { 266 } 268 269 273 public boolean isEqualNode(Node arg) { 274 275 if (!super.isEqualNode(arg)) { 276 return false; 277 } 278 279 if (needsSyncData()) { 280 synchronizeData(); 281 } 282 DocumentTypeImpl argDocType = (DocumentTypeImpl) arg; 283 284 if ((getPublicId() == null && argDocType.getPublicId() != null) 287 || (getPublicId() != null && argDocType.getPublicId() == null) 288 || (getSystemId() == null && argDocType.getSystemId() != null) 289 || (getSystemId() != null && argDocType.getSystemId() == null) 290 || (getInternalSubset() == null 291 && argDocType.getInternalSubset() != null) 292 || (getInternalSubset() != null 293 && argDocType.getInternalSubset() == null)) { 294 return false; 295 } 296 297 if (getPublicId() != null) { 298 if (!getPublicId().equals(argDocType.getPublicId())) { 299 return false; 300 } 301 } 302 303 if (getSystemId() != null) { 304 if (!getSystemId().equals(argDocType.getSystemId())) { 305 return false; 306 } 307 } 308 309 if (getInternalSubset() != null) { 310 if (!getInternalSubset().equals(argDocType.getInternalSubset())) { 311 return false; 312 } 313 } 314 315 NamedNodeMapImpl argEntities = argDocType.entities; 317 318 if ((entities == null && argEntities != null) 319 || (entities != null && argEntities == null)) 320 return false; 321 322 if (entities != null && argEntities != null) { 323 if (entities.getLength() != argEntities.getLength()) 324 return false; 325 326 for (int index = 0; entities.item(index) != null; index++) { 327 Node entNode1 = entities.item(index); 328 Node entNode2 = 329 argEntities.getNamedItem(entNode1.getNodeName()); 330 331 if (!((NodeImpl) entNode1).isEqualNode((NodeImpl) entNode2)) 332 return false; 333 } 334 } 335 336 NamedNodeMapImpl argNotations = argDocType.notations; 337 338 if ((notations == null && argNotations != null) 339 || (notations != null && argNotations == null)) 340 return false; 341 342 if (notations != null && argNotations != null) { 343 if (notations.getLength() != argNotations.getLength()) 344 return false; 345 346 for (int index = 0; notations.item(index) != null; index++) { 347 Node noteNode1 = notations.item(index); 348 Node noteNode2 = 349 argNotations.getNamedItem(noteNode1.getNodeName()); 350 351 if (!((NodeImpl) noteNode1).isEqualNode((NodeImpl) noteNode2)) 352 return false; 353 } 354 } 355 356 return true; 357 } 359 360 364 void setOwnerDocument(CoreDocumentImpl doc) { 365 super.setOwnerDocument(doc); 366 entities.setOwnerDocument(doc); 367 notations.setOwnerDocument(doc); 368 elements.setOwnerDocument(doc); 369 } 370 371 374 protected int getNodeNumber() { 375 if (getOwnerDocument()!=null) 378 return super.getNodeNumber(); 379 380 if (doctypeNumber==0) { 383 384 CoreDOMImplementationImpl cd = (CoreDOMImplementationImpl)CoreDOMImplementationImpl.getDOMImplementation(); 385 doctypeNumber = cd.assignDocTypeNumber(); 386 } 387 return doctypeNumber; 388 } 389 390 394 398 public String getName() { 399 400 if (needsSyncData()) { 401 synchronizeData(); 402 } 403 return name; 404 405 } 407 429 public NamedNodeMap getEntities() { 430 if (needsSyncChildren()) { 431 synchronizeChildren(); 432 } 433 return entities; 434 } 435 436 441 public NamedNodeMap getNotations() { 442 if (needsSyncChildren()) { 443 synchronizeChildren(); 444 } 445 return notations; 446 } 447 448 452 457 public void setReadOnly(boolean readOnly, boolean deep) { 458 459 if (needsSyncChildren()) { 460 synchronizeChildren(); 461 } 462 super.setReadOnly(readOnly, deep); 463 464 elements.setReadOnly(readOnly, true); 466 entities.setReadOnly(readOnly, true); 467 notations.setReadOnly(readOnly, true); 468 469 } 471 475 public NamedNodeMap getElements() { 476 if (needsSyncChildren()) { 477 synchronizeChildren(); 478 } 479 return elements; 480 } 481 482 public Object setUserData(String key, 483 Object data, UserDataHandler handler) { 484 if(userData == null) 485 userData = new Hashtable (); 486 if (data == null) { 487 if (userData != null) { 488 Object o = userData.remove(key); 489 if (o != null) { 490 UserDataRecord r = (UserDataRecord) o; 491 return r.fData; 492 } 493 } 494 return null; 495 } 496 else { 497 Object o = userData.put(key, new UserDataRecord(data, handler)); 498 if (o != null) { 499 UserDataRecord r = (UserDataRecord) o; 500 return r.fData; 501 } 502 } 503 return null; 504 } 505 506 public Object getUserData(String key) { 507 if (userData == null) { 508 return null; 509 } 510 Object o = userData.get(key); 511 if (o != null) { 512 UserDataRecord r = (UserDataRecord) o; 513 return r.fData; 514 } 515 return null; 516 } 517 518 protected Hashtable getUserDataRecord(){ 519 return userData; 520 } 521 522 } | Popular Tags |