1 28 29 package com.caucho.xml2; 30 31 import com.caucho.util.L10N; 32 import com.caucho.vfs.Depend; 33 import com.caucho.vfs.WriteStream; 34 35 import org.w3c.dom.DOMException ; 36 import org.w3c.dom.Document ; 37 import org.w3c.dom.NamedNodeMap ; 38 import org.w3c.dom.Node ; 39 import org.w3c.dom.NodeList ; 40 import org.w3c.dom.UserDataHandler ; 41 42 import javax.xml.namespace.QName ; 43 import java.io.IOException ; 44 import java.util.ArrayList ; 45 46 49 public abstract class QAbstractNode implements CauchoNode, java.io.Serializable { 50 protected static L10N L = new L10N(QAbstractNode.class); 51 52 QDocument _owner; 53 54 QNode _parent; 55 56 QAbstractNode _next; 57 QAbstractNode _previous; 58 59 String _systemId; 60 String _filename; 61 int _line; 62 63 protected QAbstractNode() 64 { 65 } 66 67 protected QAbstractNode(QDocument owner) 68 { 69 _owner = owner; 70 } 71 72 public void setLocation(String systemId, String filename, 73 int line, int column) 74 { 75 _systemId = systemId; 76 _filename = filename; 77 _line = line; 78 } 79 80 83 public String getFilename() 84 { 85 if (_filename != null) 86 return _filename; 87 else if (_previous != null) 88 return _previous.getFilename(); 89 else if (_parent != null) 90 return _parent.getFilename(); 91 else 92 return null; 93 } 94 95 98 public String getBaseURI() 99 { 100 if (_systemId != null) 101 return _systemId; 102 else if (_previous != null) 103 return _previous.getBaseURI(); 104 else if (_parent != null) 105 return _parent.getBaseURI(); 106 else 107 return getFilename(); 108 } 109 110 113 public static String baseURI(Node node) 114 { 115 if (node instanceof QAbstractNode) 116 return ((QAbstractNode) node).getBaseURI(); 117 else 118 return null; 119 } 120 121 124 public int getLine() 125 { 126 if (_filename != null) 127 return _line; 128 else if (_previous != null) 129 return _previous.getLine(); 130 else if (_parent != null) 131 return _parent.getLine(); 132 else 133 return 0; 134 } 135 136 public int getColumn() 137 { 138 return 0; 139 } 140 141 144 public Document getOwnerDocument() 145 { 146 return _owner; 147 } 148 149 public boolean isSupported(String feature, String version) 150 { 151 return _owner.getImplementation().hasFeature(feature, version); 152 } 153 154 157 public Object getFeature(String feature, String version) 158 { 159 return null; 160 } 161 162 165 public void setFeature(String feature, boolean value) 166 { 167 } 168 169 172 public short compareDocumentPosition(Node node) 173 { 174 return 0; 175 } 176 177 180 public String lookupPrefix(String feature) 181 { 182 return null; 183 } 184 185 188 public boolean hasAttributes() 189 { 190 return false; 191 } 192 193 public String getPrefix() 194 { 195 return ""; 196 } 197 198 public void setPrefix(String prefix) 199 { 200 } 201 202 public Object setUserData(String key, Object value, UserDataHandler userData) 203 { 204 return null; 205 } 206 207 public Object getUserData(String data) 208 { 209 return null; 210 } 211 212 public String getCanonicalName() 213 { 214 return getNodeName(); 215 } 216 217 public String getLocalName() 218 { 219 return getNodeName(); 220 } 221 222 public String getNamespaceURI() 223 { 224 return ""; 225 } 226 227 public QName getQName() 228 { 229 return new QName (getNodeName(), getNamespaceURI()); 230 } 231 232 public String getNodeValue() { return null; } 233 234 public void setNodeValue(String value) {} 235 236 public Node getParentNode() { return _parent; } 237 238 public NodeList getChildNodes() 239 { 240 return new QEmptyNodeList(); 241 } 242 243 public Node getFirstChild() { return null; } 244 245 public Node getLastChild() { return null; } 246 247 public Node getPreviousSibling() { return _previous; } 248 249 public Node getNextSibling() { return _next; } 250 251 public NamedNodeMap getAttributes() { return null; } 252 253 public Node insertBefore(Node newChild, Node refChild) 254 throws DOMException  255 { 256 throw new QDOMException(DOMException.HIERARCHY_REQUEST_ERR, ""); 257 } 258 259 public Node replaceChild(Node newChild, Node refChild) 260 throws DOMException  261 { 262 throw new QDOMException(DOMException.HIERARCHY_REQUEST_ERR, ""); 263 } 264 265 public Node removeChild(Node oldChild) throws DOMException  266 { 267 throw new QDOMException(DOMException.HIERARCHY_REQUEST_ERR, ""); 268 } 269 270 public Node appendChild(Node newNode) throws DOMException  271 { 272 throw new QDOMException(DOMException.HIERARCHY_REQUEST_ERR, ""); 273 } 274 275 public boolean hasChildNodes() { return false; } 276 277 public boolean equals(Node arg, boolean deep) 278 { 279 return this == arg; 280 } 281 282 void remove() 283 { 284 if (_owner != null) 285 _owner._changeCount++; 286 287 if (_previous != null) 288 _previous._next = _next; 289 else if (_parent != null) 290 _parent._firstChild = _next; 291 292 if (_next != null) 293 _next._previous = _previous; 294 else if (_parent != null) 295 _parent._lastChild = _previous; 296 297 _previous = null; 298 _next = null; 299 _parent = null; 300 } 301 302 public QAbstractNode getNextPreorder() 303 { 304 if (_next != null) 305 return _next; 306 307 for (QNode ptr = _parent; ptr != null; ptr = ptr._parent) { 308 if (ptr._next != null) 309 return ptr._next; 310 } 311 312 return null; 313 } 314 315 public boolean hasContent() { return false; } 316 317 public QAbstractNode getNextContent() 318 { 319 for (QAbstractNode node = _next; node != null; node = node._next) { 320 if (node.hasContent()) 321 return node; 322 } 323 324 return null; 325 } 326 327 public QAbstractNode getPreviousContent() 328 { 329 for (QAbstractNode node = _previous; node != null; node = node._previous) { 330 if (node.hasContent()) 331 return node; 332 } 333 334 return null; 335 } 336 337 public String getTextValue() 338 { 339 return getNodeValue(); 340 } 341 342 345 public boolean supports(String feature, String version) 346 { 347 return _owner._implementation.hasFeature(feature, version); 348 } 349 350 public void normalize() 351 { 352 353 } 354 355 public Node cloneNode(boolean deep) 356 { 357 return _owner.importNode(this, deep); 358 } 359 360 362 public short compareTreePosition(Node other) 363 { 364 throw new UnsupportedOperationException (); 365 } 366 367 public String getTextContent() 368 throws DOMException  369 { 370 return XmlUtil.textValue(this); 371 } 372 373 public void setTextContent(String textContent) 374 throws DOMException  375 { 376 throw new UnsupportedOperationException (); 377 } 378 379 public boolean isSameNode(Node other) 380 { 381 return this == other; 382 } 383 384 public String lookupNamespacePrefix(String namespaceURI, 385 boolean useDefault) 386 { 387 throw new UnsupportedOperationException (); 388 } 389 390 public boolean isDefaultNamespace(String namespaceURI) 391 { 392 throw new UnsupportedOperationException (); 393 } 394 395 public String lookupNamespaceURI(String prefix) 396 { 397 throw new UnsupportedOperationException (); 398 } 399 400 public boolean isEqualNode(Node arg) 401 { 402 return equals(arg); 403 } 404 405 public Node getInterface(String feature) 406 { 407 throw new UnsupportedOperationException (); 408 } 409 410 423 424 426 public ArrayList <Depend> getDependencyList() 427 { 428 if (_owner != null) 429 return _owner.getDependencyList(); 430 else 431 return null; 432 } 433 434 boolean isNameValid(String name) 435 { 436 if (name == null || name.length() == 0) 437 return false; 438 439 if (! XmlChar.isNameStart(name.charAt(0))) 440 return false; 441 442 for (int i = 1; i < name.length(); i++) { 443 char ch = name.charAt(i); 444 if (! XmlChar.isNameChar(ch)) 445 return false; 446 } 447 448 return true; 449 } 450 451 public boolean checkValid() 452 throws Exception  453 { 454 if (_parent == null) { 455 if (_next != null || _previous != null) 456 throw new Exception ("null bad: " + this); 457 else 458 return true; 459 } 460 461 if (_parent._owner != _owner && _owner != _parent) 462 throw new Exception ("owner bad: " + this); 463 464 QAbstractNode ptr = _parent._firstChild; 465 for (; ptr != null && ptr != this; ptr = ptr._next) { 466 } 467 if (ptr == null) 468 throw new Exception ("not in parent: " + this); 469 470 ptr = _parent._lastChild; 471 for (; ptr != null && ptr != this; ptr = ptr._previous) { 472 } 473 if (ptr == null) 474 throw new Exception ("not in parent: " + this); 475 476 if (_next == null && _parent._lastChild != this) 477 throw new Exception ("bad tail: " + this); 478 479 else if (_next != null && _next._previous != this) 480 throw new Exception ("bad link: " + this); 481 482 if (_previous == null && _parent._firstChild != this) 483 throw new Exception ("bad head: " + this); 484 else if (_previous != null && _previous._next != this) 485 throw new Exception ("bad link: " + this); 486 487 return true; 488 } 489 490 void print(XmlPrinter out) throws IOException  491 { 492 } 493 494 public void print(WriteStream out) throws IOException  495 { 496 new XmlPrinter(out).printXml(this); 497 } 498 499 public void printPretty(WriteStream out) throws IOException  500 { 501 new XmlPrinter(out).printPrettyXml(this); 502 } 503 504 public void printHtml(WriteStream out) throws IOException  505 { 506 new XmlPrinter(out).printHtml(this); 507 } 508 509 private Object writeReplace() 510 { 511 return new SerializedXml(this); 512 } 513 } 514
| Popular Tags
|