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