1 package net.sf.saxon.dom; 2 3 import net.sf.saxon.om.*; 4 import net.sf.saxon.pattern.NameTest; 5 import net.sf.saxon.type.Type; 6 import org.w3c.dom.*; 7 8 12 13 public class ElementOverNodeInfo extends NodeOverNodeInfo implements Element { 14 15 18 19 public String getTagName() { 20 return node.getDisplayName(); 21 } 22 23 31 public NodeList getElementsByTagName(String name) { 32 return DocumentOverNodeInfo.getElementsByTagName(node, name); 33 } 34 35 51 public NodeList getElementsByTagNameNS(String namespaceURI, String localName) throws DOMException { 52 return DocumentOverNodeInfo.getElementsByTagNameNS(node, namespaceURI, localName); 53 } 54 55 62 63 public String getAttribute(String name) { 64 AxisIterator atts = node.iterateAxis(Axis.ATTRIBUTE); 65 while (true) { 66 NodeInfo att = (NodeInfo)atts.next(); 67 if (att == null) { 68 return ""; 69 } 70 if (att.getDisplayName().equals(name)) { 71 String val = att.getStringValue(); 72 if (val==null) return ""; 73 return val; 74 } 75 } 76 } 77 78 89 90 public Attr getAttributeNode(String name) { 91 AxisIterator atts = node.iterateAxis(Axis.ATTRIBUTE); 92 while (true) { 93 NodeInfo att = (NodeInfo)atts.next(); 94 if (att == null) { 95 return null; 96 } 97 if (att.getDisplayName().equals(name)) { 98 return (Attr)att; 99 } 100 } 101 } 102 103 108 109 public Attr setAttributeNode(Attr newAttr) throws DOMException { 110 disallowUpdate(); 111 return null; 112 } 113 114 119 120 public void removeAttribute(String oldAttr) throws DOMException { 121 disallowUpdate(); 122 } 123 124 129 130 public Attr removeAttributeNode(Attr oldAttr) throws DOMException { 131 disallowUpdate(); 132 return null; 133 } 134 135 136 145 146 public String getAttributeNS(String namespaceURI, String localName) { 147 String val = Navigator.getAttributeValue(node, namespaceURI, localName); 148 if (val==null) return ""; 149 return val; 150 } 151 152 162 public void setAttribute(String name, String value) throws DOMException { 163 disallowUpdate(); 164 } 165 166 176 177 public void setAttributeNS(String namespaceURI, 178 String qualifiedName, 179 String value) 180 throws DOMException { 181 disallowUpdate(); 182 } 183 184 190 191 public void removeAttributeNS(String namespaceURI, 192 String localName) 193 throws DOMException{ 194 disallowUpdate(); 195 } 196 197 207 208 public Attr getAttributeNodeNS(String namespaceURI, String localName) { 209 DocumentInfo doc = node.getDocumentRoot(); 210 if (doc==null) { 211 throw new UnsupportedOperationException ("getAttributeNodeNS is not supported on a tree with no document node"); 212 } 213 int fingerprint = doc.getNamePool().getFingerprint(namespaceURI, localName); 214 if (fingerprint==-1) return null; 215 NameTest test = new NameTest(Type.ATTRIBUTE, fingerprint, node.getNamePool()); 216 AxisIterator atts = node.iterateAxis(Axis.ATTRIBUTE, test); 217 return (Attr)wrap((NodeInfo)atts.next()); 218 } 219 220 231 232 public Attr setAttributeNodeNS(Attr newAttr) 233 throws DOMException{ 234 disallowUpdate(); 235 return null; 236 } 237 238 249 250 public boolean hasAttribute(String name) { 251 AxisIterator atts = node.iterateAxis(Axis.ATTRIBUTE); 252 while (true) { 253 NodeInfo att = (NodeInfo)atts.next(); 254 if (att == null) { 255 return false; 256 } 257 if (att.getDisplayName().equals(name)) { 258 return true; 259 } 260 } 261 } 262 263 275 276 public boolean hasAttributeNS(String namespaceURI, String localName) { 277 return (Navigator.getAttributeValue(node, namespaceURI, localName) != null); 278 } 279 280 282 public void setIdAttribute(String name, 283 boolean isId) 284 throws DOMException{ 285 disallowUpdate(); 286 } 287 288 public void setIdAttributeNS(String namespaceURI, 289 String localName, 290 boolean isId) 291 throws DOMException{ 292 disallowUpdate(); 293 } 294 295 public void setIdAttributeNode(Attr idAttr, 296 boolean isId) 297 throws DOMException{ 298 disallowUpdate(); 299 } 300 301 302 305 306 public TypeInfo getSchemaTypeInfo() { 307 int annotation = node.getTypeAnnotation(); 308 if (annotation == -1) { 309 return null; 310 } 311 return new TypeInfoImpl(node.getConfiguration(), 312 node.getConfiguration().getSchemaType(annotation)); 313 } 314 315 } 316 317 | Popular Tags |