1 16 19 package com.sun.org.apache.xml.internal.dtm.ref.dom2dtm; 20 21 import com.sun.org.apache.xml.internal.dtm.DTMException; 22 23 import org.w3c.dom.Attr ; 24 import org.w3c.dom.Document ; 25 import org.w3c.dom.Element ; 26 import org.w3c.dom.NamedNodeMap ; 27 import org.w3c.dom.Node ; 28 import org.w3c.dom.NodeList ; 29 import org.w3c.dom.TypeInfo ; 30 import org.w3c.dom.UserDataHandler ; 31 import org.w3c.dom.DOMException ; 32 33 50 public class DOM2DTMdefaultNamespaceDeclarationNode implements Attr ,TypeInfo 51 { 52 final String NOT_SUPPORTED_ERR="Unsupported operation on pseudonode"; 53 54 Element pseudoparent; 55 String prefix,uri,nodename; 56 int handle; 57 DOM2DTMdefaultNamespaceDeclarationNode(Element pseudoparent,String prefix,String uri,int handle) 58 { 59 this.pseudoparent=pseudoparent; 60 this.prefix=prefix; 61 this.uri=uri; 62 this.handle=handle; 63 this.nodename="xmlns:"+prefix; 64 } 65 public String getNodeName() {return nodename;} 66 public String getName() {return nodename;} 67 public String getNamespaceURI() {return "http://www.w3.org/2000/xmlns/";} 68 public String getPrefix() {return prefix;} 69 public String getLocalName() {return prefix;} 70 public String getNodeValue() {return uri;} 71 public String getValue() {return uri;} 72 public Element getOwnerElement() {return pseudoparent;} 73 74 public boolean isSupported(String feature, String version) {return false;} 75 public boolean hasChildNodes() {return false;} 76 public boolean hasAttributes() {return false;} 77 public Node getParentNode() {return null;} 78 public Node getFirstChild() {return null;} 79 public Node getLastChild() {return null;} 80 public Node getPreviousSibling() {return null;} 81 public Node getNextSibling() {return null;} 82 public boolean getSpecified() {return false;} 83 public void normalize() {return;} 84 public NodeList getChildNodes() {return null;} 85 public NamedNodeMap getAttributes() {return null;} 86 public short getNodeType() {return Node.ATTRIBUTE_NODE;} 87 public void setNodeValue(String value) {throw new DTMException(NOT_SUPPORTED_ERR);} 88 public void setValue(String value) {throw new DTMException(NOT_SUPPORTED_ERR);} 89 public void setPrefix(String value) {throw new DTMException(NOT_SUPPORTED_ERR);} 90 public Node insertBefore(Node a, Node b) {throw new DTMException(NOT_SUPPORTED_ERR);} 91 public Node replaceChild(Node a, Node b) {throw new DTMException(NOT_SUPPORTED_ERR);} 92 public Node appendChild(Node a) {throw new DTMException(NOT_SUPPORTED_ERR);} 93 public Node removeChild(Node a) {throw new DTMException(NOT_SUPPORTED_ERR);} 94 public Document getOwnerDocument() {return pseudoparent.getOwnerDocument();} 95 public Node cloneNode(boolean deep) {throw new DTMException(NOT_SUPPORTED_ERR);} 96 97 102 public int getHandleOfNode() 103 { 104 return handle; 105 } 106 108 111 public String getTypeName() {return null; } 112 115 public String getTypeNamespace() { return null;} 116 119 public boolean isDerivedFrom( String ns, String localName, int derivationMethod ) { 120 return false; 121 } 122 123 public TypeInfo getSchemaTypeInfo() { return this; } 124 public boolean isId( ) { return false; } 125 126 139 public Object setUserData(String key, 140 Object data, 141 UserDataHandler handler) { 142 return getOwnerDocument().setUserData( key, data, handler); 143 } 144 145 154 public Object getUserData(String key) { 155 return getOwnerDocument().getUserData( key); 156 } 157 158 178 public Object getFeature(String feature, String version) { 179 return isSupported(feature, version) ? this : null; 182 } 183 184 226 public boolean isEqualNode(Node arg) { 227 if (arg == this) { 228 return true; 229 } 230 if (arg.getNodeType() != getNodeType()) { 231 return false; 232 } 233 if (getNodeName() == null) { 236 if (arg.getNodeName() != null) { 237 return false; 238 } 239 } 240 else if (!getNodeName().equals(arg.getNodeName())) { 241 return false; 242 } 243 244 if (getLocalName() == null) { 245 if (arg.getLocalName() != null) { 246 return false; 247 } 248 } 249 else if (!getLocalName().equals(arg.getLocalName())) { 250 return false; 251 } 252 253 if (getNamespaceURI() == null) { 254 if (arg.getNamespaceURI() != null) { 255 return false; 256 } 257 } 258 else if (!getNamespaceURI().equals(arg.getNamespaceURI())) { 259 return false; 260 } 261 262 if (getPrefix() == null) { 263 if (arg.getPrefix() != null) { 264 return false; 265 } 266 } 267 else if (!getPrefix().equals(arg.getPrefix())) { 268 return false; 269 } 270 271 if (getNodeValue() == null) { 272 if (arg.getNodeValue() != null) { 273 return false; 274 } 275 } 276 else if (!getNodeValue().equals(arg.getNodeValue())) { 277 return false; 278 } 279 289 290 return true; 291 } 292 293 302 public String lookupNamespaceURI(String specifiedPrefix) { 303 short type = this.getNodeType(); 304 switch (type) { 305 case Node.ELEMENT_NODE : { 306 307 String namespace = this.getNamespaceURI(); 308 String prefix = this.getPrefix(); 309 if (namespace !=null) { 310 if (specifiedPrefix== null && prefix==specifiedPrefix) { 312 return namespace; 314 } else if (prefix != null && prefix.equals(specifiedPrefix)) { 315 return namespace; 317 } 318 } 319 if (this.hasAttributes()) { 320 NamedNodeMap map = this.getAttributes(); 321 int length = map.getLength(); 322 for (int i=0;i<length;i++) { 323 Node attr = map.item(i); 324 String attrPrefix = attr.getPrefix(); 325 String value = attr.getNodeValue(); 326 namespace = attr.getNamespaceURI(); 327 if (namespace !=null && namespace.equals("http://www.w3.org/2000/xmlns/")) { 328 if (specifiedPrefix == null && 330 attr.getNodeName().equals("xmlns")) { 331 return value; 333 } else if (attrPrefix !=null && 334 attrPrefix.equals("xmlns") && 335 attr.getLocalName().equals(specifiedPrefix)) { 336 return value; 338 } 339 } 340 } 341 } 342 348 349 return null; 350 351 352 } 353 358 case Node.ENTITY_NODE : 359 case Node.NOTATION_NODE: 360 case Node.DOCUMENT_FRAGMENT_NODE: 361 case Node.DOCUMENT_TYPE_NODE: 362 return null; 364 case Node.ATTRIBUTE_NODE:{ 365 if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) { 366 return getOwnerElement().lookupNamespaceURI(specifiedPrefix); 367 368 } 369 return null; 370 } 371 default:{ 372 378 return null; 379 } 380 381 } 382 } 383 384 385 394 public boolean isDefaultNamespace(String namespaceURI){ 395 455 return false; 456 457 458 } 459 460 468 public String lookupPrefix(String namespaceURI){ 469 470 if (namespaceURI == null) { 473 return null; 474 } 475 476 short type = this.getNodeType(); 477 478 switch (type) { 479 490 case Node.ENTITY_NODE : 491 case Node.NOTATION_NODE: 492 case Node.DOCUMENT_FRAGMENT_NODE: 493 case Node.DOCUMENT_TYPE_NODE: 494 return null; 496 case Node.ATTRIBUTE_NODE:{ 497 if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) { 498 return getOwnerElement().lookupPrefix(namespaceURI); 499 500 } 501 return null; 502 } 503 default:{ 504 510 return null; 511 } 512 } 513 } 514 515 529 public boolean isSameNode(Node other) { 530 return this == other; 532 } 533 534 579 public void setTextContent(String textContent) 580 throws DOMException { 581 setNodeValue(textContent); 582 } 583 628 public String getTextContent() throws DOMException { 629 return getNodeValue(); } 631 632 640 public short compareDocumentPosition(Node other) throws DOMException { 641 return 0; 642 } 643 644 668 public String getBaseURI() { 669 return null; 670 } 671 672 673 674 } 675 676 | Popular Tags |