1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*
  17. * $Id: DTMNodeProxy.java,v
  18. */
  19. package com.sun.org.apache.xml.internal.dtm.ref;
  20. import com.sun.org.apache.xml.internal.dtm.DTM;
  21. import com.sun.org.apache.xml.internal.dtm.DTMDOMException;
  22. import org.w3c.dom.Attr;
  23. import org.w3c.dom.CDATASection;
  24. import org.w3c.dom.Comment;
  25. import org.w3c.dom.DOMException;
  26. import org.w3c.dom.DOMImplementation;
  27. import org.w3c.dom.Document;
  28. import org.w3c.dom.DocumentFragment;
  29. import org.w3c.dom.DocumentType;
  30. import org.w3c.dom.Element;
  31. import org.w3c.dom.EntityReference;
  32. import org.w3c.dom.NamedNodeMap;
  33. import org.w3c.dom.Node;
  34. import org.w3c.dom.NodeList;
  35. import org.w3c.dom.ProcessingInstruction;
  36. import org.w3c.dom.Text;
  37. import org.w3c.dom.UserDataHandler;
  38. import org.w3c.dom.DOMConfiguration;
  39. import org.w3c.dom.TypeInfo;
  40. /**
  41. * <meta name="usage" content="internal"/>
  42. * <code>DTMNodeProxy</code> presents a DOM Node API front-end to the DTM model.
  43. * <p>
  44. * It does _not_ attempt to address the "node identity" question; no effort
  45. * is made to prevent the creation of multiple proxies referring to a single
  46. * DTM node. Users can create a mechanism for managing this, or relinquish the
  47. * use of "==" and use the .sameNodeAs() mechanism, which is under
  48. * consideration for future versions of the DOM.
  49. * <p>
  50. * DTMNodeProxy may be subclassed further to present specific DOM node types.
  51. *
  52. * @see org.w3c.dom
  53. */
  54. public class DTMNodeProxy
  55. implements Node, Document, Text, Element, Attr,
  56. ProcessingInstruction, Comment, DocumentFragment
  57. {
  58. /** The DTM for this node. */
  59. public DTM dtm;
  60. /** The DTM node handle. */
  61. int node;
  62. /** The DOMImplementation object */
  63. static final DOMImplementation implementation=new DTMNodeProxyImplementation();
  64. /**
  65. * Create a DTMNodeProxy Node representing a specific Node in a DTM
  66. *
  67. * @param dtm The DTM Reference, must be non-null.
  68. * @param node The DTM node handle.
  69. */
  70. public DTMNodeProxy(DTM dtm, int node)
  71. {
  72. this.dtm = dtm;
  73. this.node = node;
  74. }
  75. /**
  76. * NON-DOM: Return the DTM model
  77. *
  78. * @return The DTM that this proxy is a representative for.
  79. */
  80. public final DTM getDTM()
  81. {
  82. return dtm;
  83. }
  84. /**
  85. * NON-DOM: Return the DTM node number
  86. *
  87. * @return The DTM node handle.
  88. */
  89. public final int getDTMNodeNumber()
  90. {
  91. return node;
  92. }
  93. /**
  94. * Test for equality based on node number.
  95. *
  96. * @param node A DTM node proxy reference.
  97. *
  98. * @return true if the given node has the same handle as this node.
  99. */
  100. public final boolean equals(Node node)
  101. {
  102. try
  103. {
  104. DTMNodeProxy dtmp = (DTMNodeProxy) node;
  105. // return (dtmp.node == this.node);
  106. // Patch attributed to Gary L Peskin <garyp@firstech.com>
  107. return (dtmp.node == this.node) && (dtmp.dtm == this.dtm);
  108. }
  109. catch (ClassCastException cce)
  110. {
  111. return false;
  112. }
  113. }
  114. /**
  115. * Test for equality based on node number.
  116. *
  117. * @param node A DTM node proxy reference.
  118. *
  119. * @return true if the given node has the same handle as this node.
  120. */
  121. public final boolean equals(Object node)
  122. {
  123. try
  124. {
  125. // DTMNodeProxy dtmp = (DTMNodeProxy)node;
  126. // return (dtmp.node == this.node);
  127. // Patch attributed to Gary L Peskin <garyp@firstech.com>
  128. return equals((Node) node);
  129. }
  130. catch (ClassCastException cce)
  131. {
  132. return false;
  133. }
  134. }
  135. /**
  136. * FUTURE DOM: Test node identity, in lieu of Node==Node
  137. *
  138. * @param other
  139. *
  140. * @return true if the given node has the same handle as this node.
  141. */
  142. public final boolean sameNodeAs(Node other)
  143. {
  144. if (!(other instanceof DTMNodeProxy))
  145. return false;
  146. DTMNodeProxy that = (DTMNodeProxy) other;
  147. return this.dtm == that.dtm && this.node == that.node;
  148. }
  149. /**
  150. *
  151. * @return
  152. * @see org.w3c.dom.Node
  153. */
  154. public final String getNodeName()
  155. {
  156. return dtm.getNodeName(node);
  157. }
  158. /**
  159. * A PI's "target" states what processor channel the PI's data
  160. * should be directed to. It is defined differently in HTML and XML.
  161. * <p>
  162. * In XML, a PI's "target" is the first (whitespace-delimited) token
  163. * following the "<?" token that begins the PI.
  164. * <p>
  165. * In HTML, target is always null.
  166. * <p>
  167. * Note that getNodeName is aliased to getTarget.
  168. *
  169. * @return
  170. */
  171. public final String getTarget()
  172. {
  173. return dtm.getNodeName(node);
  174. } // getTarget():String
  175. /**
  176. *
  177. * @return
  178. * @see org.w3c.dom.Node as of DOM Level 2
  179. */
  180. public final String getLocalName()
  181. {
  182. return dtm.getLocalName(node);
  183. }
  184. /**
  185. * @return The prefix for this node.
  186. * @see org.w3c.dom.Node as of DOM Level 2
  187. */
  188. public final String getPrefix()
  189. {
  190. return dtm.getPrefix(node);
  191. }
  192. /**
  193. *
  194. * @param prefix
  195. *
  196. * @throws DOMException
  197. * @see org.w3c.dom.Node as of DOM Level 2 -- DTMNodeProxy is read-only
  198. */
  199. public final void setPrefix(String prefix) throws DOMException
  200. {
  201. throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
  202. }
  203. /**
  204. *
  205. * @return
  206. * @see org.w3c.dom.Node as of DOM Level 2
  207. */
  208. public final String getNamespaceURI()
  209. {
  210. return dtm.getNamespaceURI(node);
  211. }
  212. /** Ask whether we support a given DOM feature.
  213. * In fact, we do not _fully_ support any DOM feature -- we're a
  214. * read-only subset -- so arguably we should always return false.
  215. * Or we could say that we support DOM Core Level 2 but all nodes
  216. * are read-only. Unclear which answer is least misleading.
  217. *
  218. * NON-DOM method. This was present in early drafts of DOM Level 2,
  219. * but was renamed isSupported. It's present here only because it's
  220. * cheap, harmless, and might help some poor fool who is still trying
  221. * to use an early Working Draft of the DOM.
  222. *
  223. * @param feature
  224. * @param version
  225. *
  226. * @return false
  227. */
  228. public final boolean supports(String feature, String version)
  229. {
  230. return implementation.hasFeature(feature,version);
  231. //throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  232. }
  233. /** Ask whether we support a given DOM feature.
  234. * In fact, we do not _fully_ support any DOM feature -- we're a
  235. * read-only subset -- so arguably we should always return false.
  236. *
  237. * @param feature
  238. * @param version
  239. *
  240. * @return false
  241. * @see org.w3c.dom.Node as of DOM Level 2
  242. */
  243. public final boolean isSupported(String feature, String version)
  244. {
  245. return implementation.hasFeature(feature,version);
  246. // throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  247. }
  248. /**
  249. *
  250. * @return
  251. *
  252. * @throws DOMException
  253. * @see org.w3c.dom.Node
  254. */
  255. public final String getNodeValue() throws DOMException
  256. {
  257. return dtm.getNodeValue(node);
  258. }
  259. /**
  260. * @return The string value of the node
  261. *
  262. * @throws DOMException
  263. */
  264. public final String getStringValue() throws DOMException
  265. {
  266. return dtm.getStringValue(node).toString();
  267. }
  268. /**
  269. *
  270. * @param nodeValue
  271. *
  272. * @throws DOMException
  273. * @see org.w3c.dom.Node -- DTMNodeProxy is read-only
  274. */
  275. public final void setNodeValue(String nodeValue) throws DOMException
  276. {
  277. throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
  278. }
  279. /**
  280. *
  281. * @return
  282. * @see org.w3c.dom.Node
  283. */
  284. public final short getNodeType()
  285. {
  286. return (short) dtm.getNodeType(node);
  287. }
  288. /**
  289. *
  290. * @return
  291. * @see org.w3c.dom.Node
  292. */
  293. public final Node getParentNode()
  294. {
  295. if (getNodeType() == Node.ATTRIBUTE_NODE)
  296. return null;
  297. int newnode = dtm.getParent(node);
  298. return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
  299. }
  300. /**
  301. *
  302. * @return
  303. * @see org.w3c.dom.Node
  304. */
  305. public final Node getOwnerNode()
  306. {
  307. int newnode = dtm.getParent(node);
  308. return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
  309. }
  310. /**
  311. *
  312. * @return
  313. * @see org.w3c.dom.Node
  314. */
  315. public final NodeList getChildNodes()
  316. {
  317. // Annoyingly, AxisIterators do not currently implement DTMIterator, so
  318. // we can't just wap DTMNodeList around an Axis.CHILD iterator.
  319. // Instead, we've created a special-case operating mode for that object.
  320. return new DTMChildIterNodeList(dtm,node);
  321. // throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  322. }
  323. /**
  324. *
  325. * @return
  326. * @see org.w3c.dom.Node
  327. */
  328. public final Node getFirstChild()
  329. {
  330. int newnode = dtm.getFirstChild(node);
  331. return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
  332. }
  333. /**
  334. *
  335. * @return
  336. * @see org.w3c.dom.Node
  337. */
  338. public final Node getLastChild()
  339. {
  340. int newnode = dtm.getLastChild(node);
  341. return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
  342. }
  343. /**
  344. *
  345. * @return
  346. * @see org.w3c.dom.Node
  347. */
  348. public final Node getPreviousSibling()
  349. {
  350. int newnode = dtm.getPreviousSibling(node);
  351. return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
  352. }
  353. /**
  354. *
  355. * @return
  356. * @see org.w3c.dom.Node
  357. */
  358. public final Node getNextSibling()
  359. {
  360. // Attr's Next is defined at DTM level, but not at DOM level.
  361. if (dtm.getNodeType(node) == Node.ATTRIBUTE_NODE)
  362. return null;
  363. int newnode = dtm.getNextSibling(node);
  364. return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
  365. }
  366. // DTMNamedNodeMap m_attrs;
  367. /**
  368. *
  369. * @return
  370. * @see org.w3c.dom.Node
  371. */
  372. public final NamedNodeMap getAttributes()
  373. {
  374. return new DTMNamedNodeMap(dtm, node);
  375. }
  376. /**
  377. * Method hasAttribute
  378. *
  379. *
  380. * @param name
  381. *
  382. * (hasAttribute) @return
  383. */
  384. public boolean hasAttribute(String name)
  385. {
  386. return DTM.NULL != dtm.getAttributeNode(node,null,name);
  387. }
  388. /**
  389. * Method hasAttributeNS
  390. *
  391. *
  392. * @param name
  393. * @param x
  394. *
  395. * (hasAttributeNS) @return
  396. */
  397. public boolean hasAttributeNS(String name, String x)
  398. {
  399. return DTM.NULL != dtm.getAttributeNode(node,x,name);
  400. }
  401. /**
  402. *
  403. * @return
  404. * @see org.w3c.dom.Node
  405. */
  406. public final Document getOwnerDocument()
  407. {
  408. // Note that this uses the DOM-compatable version of the call
  409. return (Document)(dtm.getNode(dtm.getOwnerDocument(node)));
  410. }
  411. /**
  412. *
  413. * @param newChild
  414. * @param refChild
  415. *
  416. * @return
  417. *
  418. * @throws DOMException
  419. * @see org.w3c.dom.Node -- DTMNodeProxy is read-only
  420. */
  421. public final Node insertBefore(Node newChild, Node refChild)
  422. throws DOMException
  423. {
  424. throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
  425. }
  426. /**
  427. *
  428. * @param newChild
  429. * @param oldChild
  430. *
  431. * @return
  432. *
  433. * @throws DOMException
  434. * @see org.w3c.dom.Node -- DTMNodeProxy is read-only
  435. */
  436. public final Node replaceChild(Node newChild, Node oldChild)
  437. throws DOMException
  438. {
  439. throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
  440. }
  441. /**
  442. *
  443. * @param oldChild
  444. *
  445. * @return
  446. *
  447. * @throws DOMException
  448. * @see org.w3c.dom.Node -- DTMNodeProxy is read-only
  449. */
  450. public final Node removeChild(Node oldChild) throws DOMException
  451. {
  452. throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
  453. }
  454. /**
  455. *
  456. * @param newChild
  457. *
  458. * @return
  459. *
  460. * @throws DOMException
  461. * @see org.w3c.dom.Node -- DTMNodeProxy is read-only
  462. */
  463. public final Node appendChild(Node newChild) throws DOMException
  464. {
  465. throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
  466. }
  467. /**
  468. *
  469. * @return
  470. * @see org.w3c.dom.Node
  471. */
  472. public final boolean hasChildNodes()
  473. {
  474. return (DTM.NULL != dtm.getFirstChild(node));
  475. }
  476. /**
  477. *
  478. * @param deep
  479. *
  480. * @return
  481. * @see org.w3c.dom.Node -- DTMNodeProxy is read-only
  482. */
  483. public final Node cloneNode(boolean deep)
  484. {
  485. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  486. }
  487. /**
  488. *
  489. * @return
  490. * @see org.w3c.dom.Document
  491. */
  492. public final DocumentType getDoctype()
  493. {
  494. return null;
  495. }
  496. /**
  497. *
  498. * @return
  499. * @see org.w3c.dom.Document
  500. */
  501. public final DOMImplementation getImplementation()
  502. {
  503. return implementation;
  504. }
  505. /** This is a bit of a problem in DTM, since a DTM may be a Document
  506. * Fragment and hence not have a clear-cut Document Element. We can
  507. * make it work in the well-formed cases but would that be confusing for others?
  508. *
  509. * @return
  510. * @see org.w3c.dom.Document
  511. */
  512. public final Element getDocumentElement()
  513. {
  514. int dochandle=dtm.getDocument();
  515. int elementhandle=DTM.NULL;
  516. for(int kidhandle=dtm.getFirstChild(dochandle);
  517. kidhandle!=DTM.NULL;
  518. kidhandle=dtm.getNextSibling(kidhandle))
  519. {
  520. switch(dtm.getNodeType(kidhandle))
  521. {
  522. case Node.ELEMENT_NODE:
  523. if(elementhandle!=DTM.NULL)
  524. {
  525. elementhandle=DTM.NULL; // More than one; ill-formed.
  526. kidhandle=dtm.getLastChild(dochandle); // End loop
  527. }
  528. else
  529. elementhandle=kidhandle;
  530. break;
  531. // These are harmless; document is still wellformed
  532. case Node.COMMENT_NODE:
  533. case Node.PROCESSING_INSTRUCTION_NODE:
  534. case Node.DOCUMENT_TYPE_NODE:
  535. break;
  536. default:
  537. elementhandle=DTM.NULL; // ill-formed
  538. kidhandle=dtm.getLastChild(dochandle); // End loop
  539. break;
  540. }
  541. }
  542. if(elementhandle==DTM.NULL)
  543. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  544. else
  545. return (Element)(dtm.getNode(elementhandle));
  546. }
  547. /**
  548. *
  549. * @param tagName
  550. *
  551. * @return
  552. *
  553. * @throws DOMException
  554. * @see org.w3c.dom.Document
  555. */
  556. public final Element createElement(String tagName) throws DOMException
  557. {
  558. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  559. }
  560. /**
  561. *
  562. * @return
  563. * @see org.w3c.dom.Document
  564. */
  565. public final DocumentFragment createDocumentFragment()
  566. {
  567. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  568. }
  569. /**
  570. *
  571. * @param data
  572. *
  573. * @return
  574. * @see org.w3c.dom.Document
  575. */
  576. public final Text createTextNode(String data)
  577. {
  578. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  579. }
  580. /**
  581. *
  582. * @param data
  583. *
  584. * @return
  585. * @see org.w3c.dom.Document
  586. */
  587. public final Comment createComment(String data)
  588. {
  589. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  590. }
  591. /**
  592. *
  593. * @param data
  594. *
  595. * @return
  596. *
  597. * @throws DOMException
  598. * @see org.w3c.dom.Document
  599. */
  600. public final CDATASection createCDATASection(String data)
  601. throws DOMException
  602. {
  603. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  604. }
  605. /**
  606. *
  607. * @param target
  608. * @param data
  609. *
  610. * @return
  611. *
  612. * @throws DOMException
  613. * @see org.w3c.dom.Document
  614. */
  615. public final ProcessingInstruction createProcessingInstruction(
  616. String target, String data) throws DOMException
  617. {
  618. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  619. }
  620. /**
  621. *
  622. * @param name
  623. *
  624. * @return
  625. *
  626. * @throws DOMException
  627. * @see org.w3c.dom.Document
  628. */
  629. public final Attr createAttribute(String name) throws DOMException
  630. {
  631. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  632. }
  633. /**
  634. *
  635. * @param name
  636. *
  637. * @return
  638. *
  639. * @throws DOMException
  640. * @see org.w3c.dom.Document
  641. */
  642. public final EntityReference createEntityReference(String name)
  643. throws DOMException
  644. {
  645. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  646. }
  647. /**
  648. *
  649. * @param tagname
  650. *
  651. * @return
  652. * @see org.w3c.dom.Document
  653. */
  654. public final NodeList getElementsByTagName(String tagname)
  655. {
  656. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  657. }
  658. /**
  659. *
  660. * @param importedNode
  661. * @param deep
  662. *
  663. * @return
  664. *
  665. * @throws DOMException
  666. * @see org.w3c.dom.Document as of DOM Level 2 -- DTMNodeProxy is read-only
  667. */
  668. public final Node importNode(Node importedNode, boolean deep)
  669. throws DOMException
  670. {
  671. throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
  672. }
  673. /**
  674. *
  675. * @param namespaceURI
  676. * @param qualifiedName
  677. *
  678. * @return
  679. *
  680. * @throws DOMException
  681. * @see org.w3c.dom.Document as of DOM Level 2
  682. */
  683. public final Element createElementNS(
  684. String namespaceURI, String qualifiedName) throws DOMException
  685. {
  686. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  687. }
  688. /**
  689. *
  690. * @param namespaceURI
  691. * @param qualifiedName
  692. *
  693. * @return
  694. *
  695. * @throws DOMException
  696. * @see org.w3c.dom.Document as of DOM Level 2
  697. */
  698. public final Attr createAttributeNS(
  699. String namespaceURI, String qualifiedName) throws DOMException
  700. {
  701. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  702. }
  703. /**
  704. *
  705. * @param namespaceURI
  706. * @param localName
  707. *
  708. * @return
  709. * @see org.w3c.dom.Document as of DOM Level 2
  710. */
  711. public final NodeList getElementsByTagNameNS(String namespaceURI,
  712. String localName)
  713. {
  714. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  715. }
  716. /**
  717. *
  718. * @param elementId
  719. *
  720. * @return
  721. * @see org.w3c.dom.Document as of DOM Level 2
  722. */
  723. public final Element getElementById(String elementId)
  724. {
  725. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  726. }
  727. /**
  728. *
  729. * @param offset
  730. *
  731. * @return
  732. *
  733. * @throws DOMException
  734. * @see org.w3c.dom.Text
  735. */
  736. public final Text splitText(int offset) throws DOMException
  737. {
  738. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  739. }
  740. /**
  741. *
  742. * @return
  743. *
  744. * @throws DOMException
  745. * @see org.w3c.dom.CharacterData
  746. */
  747. public final String getData() throws DOMException
  748. {
  749. return dtm.getNodeValue(node);
  750. }
  751. /**
  752. *
  753. * @param data
  754. *
  755. * @throws DOMException
  756. * @see org.w3c.dom.CharacterData
  757. */
  758. public final void setData(String data) throws DOMException
  759. {
  760. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  761. }
  762. /**
  763. *
  764. * @return
  765. * @see org.w3c.dom.CharacterData
  766. */
  767. public final int getLength()
  768. {
  769. // %OPT% This should do something smarter?
  770. return dtm.getNodeValue(node).length();
  771. }
  772. /**
  773. *
  774. * @param offset
  775. * @param count
  776. *
  777. * @return
  778. *
  779. * @throws DOMException
  780. * @see org.w3c.dom.CharacterData
  781. */
  782. public final String substringData(int offset, int count) throws DOMException
  783. {
  784. return getData().substring(offset,offset+count);
  785. }
  786. /**
  787. *
  788. * @param arg
  789. *
  790. * @throws DOMException
  791. * @see org.w3c.dom.CharacterData
  792. */
  793. public final void appendData(String arg) throws DOMException
  794. {
  795. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  796. }
  797. /**
  798. *
  799. * @param offset
  800. * @param arg
  801. *
  802. * @throws DOMException
  803. * @see org.w3c.dom.CharacterData
  804. */
  805. public final void insertData(int offset, String arg) throws DOMException
  806. {
  807. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  808. }
  809. /**
  810. *
  811. * @param offset
  812. * @param count
  813. *
  814. * @throws DOMException
  815. * @see org.w3c.dom.CharacterData
  816. */
  817. public final void deleteData(int offset, int count) throws DOMException
  818. {
  819. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  820. }
  821. /**
  822. *
  823. * @param offset
  824. * @param count
  825. * @param arg
  826. *
  827. * @throws DOMException
  828. * @see org.w3c.dom.CharacterData
  829. */
  830. public final void replaceData(int offset, int count, String arg)
  831. throws DOMException
  832. {
  833. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  834. }
  835. /**
  836. *
  837. * @return
  838. * @see org.w3c.dom.Element
  839. */
  840. public final String getTagName()
  841. {
  842. return dtm.getNodeName(node);
  843. }
  844. /**
  845. *
  846. * @param name
  847. *
  848. * @return
  849. * @see org.w3c.dom.Element
  850. */
  851. public final String getAttribute(String name)
  852. {
  853. DTMNamedNodeMap map = new DTMNamedNodeMap(dtm, node);
  854. Node node = map.getNamedItem(name);
  855. return (null == node) ? null : node.getNodeValue();
  856. }
  857. /**
  858. *
  859. * @param name
  860. * @param value
  861. *
  862. * @throws DOMException
  863. * @see org.w3c.dom.Element
  864. */
  865. public final void setAttribute(String name, String value)
  866. throws DOMException
  867. {
  868. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  869. }
  870. /**
  871. *
  872. * @param name
  873. *
  874. * @throws DOMException
  875. * @see org.w3c.dom.Element
  876. */
  877. public final void removeAttribute(String name) throws DOMException
  878. {
  879. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  880. }
  881. /**
  882. *
  883. * @param name
  884. *
  885. * @return
  886. * @see org.w3c.dom.Element
  887. */
  888. public final Attr getAttributeNode(String name)
  889. {
  890. DTMNamedNodeMap map = new DTMNamedNodeMap(dtm, node);
  891. return (Attr)map.getNamedItem(name);
  892. }
  893. /**
  894. *
  895. * @param newAttr
  896. *
  897. * @return
  898. *
  899. * @throws DOMException
  900. * @see org.w3c.dom.Element
  901. */
  902. public final Attr setAttributeNode(Attr newAttr) throws DOMException
  903. {
  904. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  905. }
  906. /**
  907. *
  908. * @param oldAttr
  909. *
  910. * @return
  911. *
  912. * @throws DOMException
  913. * @see org.w3c.dom.Element
  914. */
  915. public final Attr removeAttributeNode(Attr oldAttr) throws DOMException
  916. {
  917. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  918. }
  919. /**
  920. * Introduced in DOM Level 2.
  921. *
  922. * @return
  923. */
  924. public boolean hasAttributes()
  925. {
  926. return DTM.NULL != dtm.getFirstAttribute(node);
  927. }
  928. /** @see org.w3c.dom.Element */
  929. public final void normalize()
  930. {
  931. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  932. }
  933. /**
  934. *
  935. * @param namespaceURI
  936. * @param localName
  937. *
  938. * @return
  939. * @see org.w3c.dom.Element
  940. */
  941. public final String getAttributeNS(String namespaceURI, String localName)
  942. {
  943. DTMNamedNodeMap map = new DTMNamedNodeMap(dtm, node);
  944. Node node = map.getNamedItemNS(namespaceURI,localName);
  945. return (null == node) ? null : node.getNodeValue();
  946. }
  947. /**
  948. *
  949. * @param namespaceURI
  950. * @param qualifiedName
  951. * @param value
  952. *
  953. * @throws DOMException
  954. * @see org.w3c.dom.Element
  955. */
  956. public final void setAttributeNS(
  957. String namespaceURI, String qualifiedName, String value)
  958. throws DOMException
  959. {
  960. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  961. }
  962. /**
  963. *
  964. * @param namespaceURI
  965. * @param localName
  966. *
  967. * @throws DOMException
  968. * @see org.w3c.dom.Element
  969. */
  970. public final void removeAttributeNS(String namespaceURI, String localName)
  971. throws DOMException
  972. {
  973. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  974. }
  975. /**
  976. *
  977. * @param namespaceURI
  978. * @param localName
  979. *
  980. * @return
  981. * @see org.w3c.dom.Element
  982. */
  983. public final Attr getAttributeNodeNS(String namespaceURI, String localName)
  984. {
  985. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  986. }
  987. /**
  988. *
  989. * @param newAttr
  990. *
  991. * @return
  992. *
  993. * @throws DOMException
  994. * @see org.w3c.dom.Element
  995. */
  996. public final Attr setAttributeNodeNS(Attr newAttr) throws DOMException
  997. {
  998. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  999. }
  1000. /**
  1001. *
  1002. * @return
  1003. * @see org.w3c.dom.Attr
  1004. */
  1005. public final String getName()
  1006. {
  1007. return dtm.getNodeName(node);
  1008. }
  1009. /**
  1010. *
  1011. * @return
  1012. * @see org.w3c.dom.Attr
  1013. */
  1014. public final boolean getSpecified()
  1015. {
  1016. // We really don't know which attributes might have come from the
  1017. // source document versus from the DTD. Treat them all as having
  1018. // been provided by the user.
  1019. // %REVIEW% if/when we become aware of DTDs/schemae.
  1020. return true;
  1021. }
  1022. /**
  1023. *
  1024. * @return
  1025. * @see org.w3c.dom.Attr
  1026. */
  1027. public final String getValue()
  1028. {
  1029. return dtm.getNodeValue(node);
  1030. }
  1031. /**
  1032. *
  1033. * @param value
  1034. * @see org.w3c.dom.Attr
  1035. */
  1036. public final void setValue(String value)
  1037. {
  1038. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1039. }
  1040. /**
  1041. * Get the owner element of an attribute.
  1042. *
  1043. * @return
  1044. * @see org.w3c.dom.Attr as of DOM Level 2
  1045. */
  1046. public final Element getOwnerElement()
  1047. {
  1048. if (getNodeType() != Node.ATTRIBUTE_NODE)
  1049. return null;
  1050. // In XPath and DTM data models, unlike DOM, an Attr's parent is its
  1051. // owner element.
  1052. int newnode = dtm.getParent(node);
  1053. return (newnode == DTM.NULL) ? null : (Element)(dtm.getNode(newnode));
  1054. }
  1055. /**
  1056. * NEEDSDOC Method adoptNode
  1057. *
  1058. *
  1059. * NEEDSDOC @param source
  1060. *
  1061. * NEEDSDOC (adoptNode) @return
  1062. *
  1063. * @throws DOMException
  1064. */
  1065. public Node adoptNode(Node source) throws DOMException
  1066. {
  1067. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1068. }
  1069. /**
  1070. * <p>EXPERIMENTAL! Based on the <a
  1071. * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
  1072. * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
  1073. * <p>
  1074. * An attribute specifying, as part of the XML declaration, the encoding
  1075. * of this document. This is <code>null</code> when unspecified.
  1076. * @since DOM Level 3
  1077. *
  1078. * NEEDSDOC ($objectName$) @return
  1079. */
  1080. public String getInputEncoding()
  1081. {
  1082. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1083. }
  1084. /**
  1085. * <p>EXPERIMENTAL! Based on the <a
  1086. * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
  1087. * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
  1088. * <p>
  1089. * An attribute specifying, as part of the XML declaration, the encoding
  1090. * of this document. This is <code>null</code> when unspecified.
  1091. * @since DOM Level 3
  1092. *
  1093. * NEEDSDOC @param encoding
  1094. */
  1095. public void setEncoding(String encoding)
  1096. {
  1097. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1098. }
  1099. /**
  1100. * <p>EXPERIMENTAL! Based on the <a
  1101. * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
  1102. * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
  1103. * <p>
  1104. * An attribute specifying, as part of the XML declaration, whether this
  1105. * document is standalone.
  1106. * @since DOM Level 3
  1107. *
  1108. * NEEDSDOC ($objectName$) @return
  1109. */
  1110. public boolean getStandalone()
  1111. {
  1112. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1113. }
  1114. /**
  1115. * <p>EXPERIMENTAL! Based on the <a
  1116. * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
  1117. * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
  1118. * <p>
  1119. * An attribute specifying, as part of the XML declaration, whether this
  1120. * document is standalone.
  1121. * @since DOM Level 3
  1122. *
  1123. * NEEDSDOC @param standalone
  1124. */
  1125. public void setStandalone(boolean standalone)
  1126. {
  1127. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1128. }
  1129. /**
  1130. * <p>EXPERIMENTAL! Based on the <a
  1131. * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
  1132. * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
  1133. * <p>
  1134. * An attribute specifying whether errors checking is enforced or not.
  1135. * When set to <code>false</code>, the implementation is free to not
  1136. * test every possible error case normally defined on DOM operations,
  1137. * and not raise any <code>DOMException</code>. In case of error, the
  1138. * behavior is undefined. This attribute is <code>true</code> by
  1139. * defaults.
  1140. * @since DOM Level 3
  1141. *
  1142. * NEEDSDOC ($objectName$) @return
  1143. */
  1144. public boolean getStrictErrorChecking()
  1145. {
  1146. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1147. }
  1148. /**
  1149. * <p>EXPERIMENTAL! Based on the <a
  1150. * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
  1151. * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
  1152. * <p>
  1153. * An attribute specifying whether errors checking is enforced or not.
  1154. * When set to <code>false</code>, the implementation is free to not
  1155. * test every possible error case normally defined on DOM operations,
  1156. * and not raise any <code>DOMException</code>. In case of error, the
  1157. * behavior is undefined. This attribute is <code>true</code> by
  1158. * defaults.
  1159. * @since DOM Level 3
  1160. *
  1161. * NEEDSDOC @param strictErrorChecking
  1162. */
  1163. public void setStrictErrorChecking(boolean strictErrorChecking)
  1164. {
  1165. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1166. }
  1167. /**
  1168. * <p>EXPERIMENTAL! Based on the <a
  1169. * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
  1170. * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
  1171. * <p>
  1172. * An attribute specifying, as part of the XML declaration, the version
  1173. * number of this document. This is <code>null</code> when unspecified.
  1174. * @since DOM Level 3
  1175. *
  1176. * NEEDSDOC ($objectName$) @return
  1177. */
  1178. public String getVersion()
  1179. {
  1180. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1181. }
  1182. /**
  1183. * <p>EXPERIMENTAL! Based on the <a
  1184. * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
  1185. * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
  1186. * <p>
  1187. * An attribute specifying, as part of the XML declaration, the version
  1188. * number of this document. This is <code>null</code> when unspecified.
  1189. * @since DOM Level 3
  1190. *
  1191. * NEEDSDOC @param version
  1192. */
  1193. public void setVersion(String version)
  1194. {
  1195. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1196. }
  1197. /** Inner class to support getDOMImplementation.
  1198. */
  1199. static class DTMNodeProxyImplementation implements DOMImplementation
  1200. {
  1201. public DocumentType createDocumentType(String qualifiedName,String publicId, String systemId)
  1202. {
  1203. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1204. }
  1205. public Document createDocument(String namespaceURI,String qualfiedName,DocumentType doctype)
  1206. {
  1207. // Could create a DTM... but why, when it'd have to be permanantly empty?
  1208. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1209. }
  1210. /** Ask whether we support a given DOM feature.
  1211. *
  1212. * In fact, we do not _fully_ support any DOM feature -- we're a
  1213. * read-only subset -- so arguably we should always return false.
  1214. * On the other hand, it may be more practically useful to return
  1215. * true and simply treat the whole DOM as read-only, failing on the
  1216. * methods we can't support. I'm not sure which would be more useful
  1217. * to the caller.
  1218. */
  1219. public boolean hasFeature(String feature,String version)
  1220. {
  1221. if( ("CORE".equals(feature.toUpperCase()) || "XML".equals(feature.toUpperCase()))
  1222. &&
  1223. ("1.0".equals(version) || "2.0".equals(version)))
  1224. return true;
  1225. return false;
  1226. }
  1227. /**
  1228. * This method returns a specialized object which implements the
  1229. * specialized APIs of the specified feature and version. The
  1230. * specialized object may also be obtained by using binding-specific
  1231. * casting methods but is not necessarily expected to, as discussed in Mixed DOM implementations
  1232. .
  1233. * @param feature The name of the feature requested (case-insensitive).
  1234. * @param version This is the version number of the feature to test. If
  1235. * the version is <code>null</code> or the empty string, supporting
  1236. * any version of the feature will cause the method to return an
  1237. * object that supports at least one version of the feature.
  1238. * @return Returns an object which implements the specialized APIs of
  1239. * the specified feature and version, if any, or <code>null</code> if
  1240. * there is no object which implements interfaces associated with that
  1241. * feature. If the <code>DOMObject</code> returned by this method
  1242. * implements the <code>Node</code> interface, it must delegate to the
  1243. * primary core <code>Node</code> and not return results inconsistent
  1244. * with the primary core <code>Node</code> such as attributes,
  1245. * childNodes, etc.
  1246. * @since DOM Level 3
  1247. */
  1248. public Object getFeature(String feature, String version) {
  1249. // we don't have any alternate node, either this node does the job
  1250. // or we don't have anything that does
  1251. //return hasFeature(feature, version) ? this : null;
  1252. return null; //PENDING
  1253. }
  1254. }
  1255. //RAMESH : Pending proper implementation of DOM Level 3
  1256. public Object setUserData(String key,
  1257. Object data,
  1258. UserDataHandler handler) {
  1259. return getOwnerDocument().setUserData( key, data, handler);
  1260. }
  1261. /**
  1262. * Retrieves the object associated to a key on a this node. The object
  1263. * must first have been set to this node by calling
  1264. * <code>setUserData</code> with the same key.
  1265. * @param key The key the object is associated to.
  1266. * @return Returns the <code>DOMObject</code> associated to the given key
  1267. * on this node, or <code>null</code> if there was none.
  1268. * @since DOM Level 3
  1269. */
  1270. public Object getUserData(String key) {
  1271. return getOwnerDocument().getUserData( key);
  1272. }
  1273. /**
  1274. * This method returns a specialized object which implements the
  1275. * specialized APIs of the specified feature and version. The
  1276. * specialized object may also be obtained by using binding-specific
  1277. * casting methods but is not necessarily expected to, as discussed in Mixed DOM implementations.
  1278. * @param feature The name of the feature requested (case-insensitive).
  1279. * @param version This is the version number of the feature to test. If
  1280. * the version is <code>null</code> or the empty string, supporting
  1281. * any version of the feature will cause the method to return an
  1282. * object that supports at least one version of the feature.
  1283. * @return Returns an object which implements the specialized APIs of
  1284. * the specified feature and version, if any, or <code>null</code> if
  1285. * there is no object which implements interfaces associated with that
  1286. * feature. If the <code>DOMObject</code> returned by this method
  1287. * implements the <code>Node</code> interface, it must delegate to the
  1288. * primary core <code>Node</code> and not return results inconsistent
  1289. * with the primary core <code>Node</code> such as attributes,
  1290. * childNodes, etc.
  1291. * @since DOM Level 3
  1292. */
  1293. public Object getFeature(String feature, String version) {
  1294. // we don't have any alternate node, either this node does the job
  1295. // or we don't have anything that does
  1296. return isSupported(feature, version) ? this : null;
  1297. }
  1298. /**
  1299. * Tests whether two nodes are equal.
  1300. * <br>This method tests for equality of nodes, not sameness (i.e.,
  1301. * whether the two nodes are references to the same object) which can be
  1302. * tested with <code>Node.isSameNode</code>. All nodes that are the same
  1303. * will also be equal, though the reverse may not be true.
  1304. * <br>Two nodes are equal if and only if the following conditions are
  1305. * satisfied: The two nodes are of the same type.The following string
  1306. * attributes are equal: <code>nodeName</code>, <code>localName</code>,
  1307. * <code>namespaceURI</code>, <code>prefix</code>, <code>nodeValue</code>
  1308. * , <code>baseURI</code>. This is: they are both <code>null</code>, or
  1309. * they have the same length and are character for character identical.
  1310. * The <code>attributes</code> <code>NamedNodeMaps</code> are equal.
  1311. * This is: they are both <code>null</code>, or they have the same
  1312. * length and for each node that exists in one map there is a node that
  1313. * exists in the other map and is equal, although not necessarily at the
  1314. * same index.The <code>childNodes</code> <code>NodeLists</code> are
  1315. * equal. This is: they are both <code>null</code>, or they have the
  1316. * same length and contain equal nodes at the same index. This is true
  1317. * for <code>Attr</code> nodes as for any other type of node. Note that
  1318. * normalization can affect equality; to avoid this, nodes should be
  1319. * normalized before being compared.
  1320. * <br>For two <code>DocumentType</code> nodes to be equal, the following
  1321. * conditions must also be satisfied: The following string attributes
  1322. * are equal: <code>publicId</code>, <code>systemId</code>,
  1323. * <code>internalSubset</code>.The <code>entities</code>
  1324. * <code>NamedNodeMaps</code> are equal.The <code>notations</code>
  1325. * <code>NamedNodeMaps</code> are equal.
  1326. * <br>On the other hand, the following do not affect equality: the
  1327. * <code>ownerDocument</code> attribute, the <code>specified</code>
  1328. * attribute for <code>Attr</code> nodes, the
  1329. * <code>isWhitespaceInElementContent</code> attribute for
  1330. * <code>Text</code> nodes, as well as any user data or event listeners
  1331. * registered on the nodes.
  1332. * @param arg The node to compare equality with.
  1333. * @param deep If <code>true</code>, recursively compare the subtrees; if
  1334. * <code>false</code>, compare only the nodes themselves (and its
  1335. * attributes, if it is an <code>Element</code>).
  1336. * @return If the nodes, and possibly subtrees are equal,
  1337. * <code>true</code> otherwise <code>false</code>.
  1338. * @since DOM Level 3
  1339. */
  1340. public boolean isEqualNode(Node arg) {
  1341. if (arg == this) {
  1342. return true;
  1343. }
  1344. if (arg.getNodeType() != getNodeType()) {
  1345. return false;
  1346. }
  1347. // in theory nodeName can't be null but better be careful
  1348. // who knows what other implementations may be doing?...
  1349. if (getNodeName() == null) {
  1350. if (arg.getNodeName() != null) {
  1351. return false;
  1352. }
  1353. }
  1354. else if (!getNodeName().equals(arg.getNodeName())) {
  1355. return false;
  1356. }
  1357. if (getLocalName() == null) {
  1358. if (arg.getLocalName() != null) {
  1359. return false;
  1360. }
  1361. }
  1362. else if (!getLocalName().equals(arg.getLocalName())) {
  1363. return false;
  1364. }
  1365. if (getNamespaceURI() == null) {
  1366. if (arg.getNamespaceURI() != null) {
  1367. return false;
  1368. }
  1369. }
  1370. else if (!getNamespaceURI().equals(arg.getNamespaceURI())) {
  1371. return false;
  1372. }
  1373. if (getPrefix() == null) {
  1374. if (arg.getPrefix() != null) {
  1375. return false;
  1376. }
  1377. }
  1378. else if (!getPrefix().equals(arg.getPrefix())) {
  1379. return false;
  1380. }
  1381. if (getNodeValue() == null) {
  1382. if (arg.getNodeValue() != null) {
  1383. return false;
  1384. }
  1385. }
  1386. else if (!getNodeValue().equals(arg.getNodeValue())) {
  1387. return false;
  1388. }
  1389. /*
  1390. if (getBaseURI() == null) {
  1391. if (((NodeImpl) arg).getBaseURI() != null) {
  1392. return false;
  1393. }
  1394. }
  1395. else if (!getBaseURI().equals(((NodeImpl) arg).getBaseURI())) {
  1396. return false;
  1397. }
  1398. */
  1399. return true;
  1400. }
  1401. /**
  1402. * DOM Level 3 - Experimental:
  1403. * Look up the namespace URI associated to the given prefix, starting from this node.
  1404. * Use lookupNamespaceURI(null) to lookup the default namespace
  1405. *
  1406. * @param namespaceURI
  1407. * @return th URI for the namespace
  1408. * @since DOM Level 3
  1409. */
  1410. public String lookupNamespaceURI(String specifiedPrefix) {
  1411. short type = this.getNodeType();
  1412. switch (type) {
  1413. case Node.ELEMENT_NODE : {
  1414. String namespace = this.getNamespaceURI();
  1415. String prefix = this.getPrefix();
  1416. if (namespace !=null) {
  1417. // REVISIT: is it possible that prefix is empty string?
  1418. if (specifiedPrefix== null && prefix==specifiedPrefix) {
  1419. // looking for default namespace
  1420. return namespace;
  1421. } else if (prefix != null && prefix.equals(specifiedPrefix)) {
  1422. // non default namespace
  1423. return namespace;
  1424. }
  1425. }
  1426. if (this.hasAttributes()) {
  1427. NamedNodeMap map = this.getAttributes();
  1428. int length = map.getLength();
  1429. for (int i=0;i<length;i++) {
  1430. Node attr = map.item(i);
  1431. String attrPrefix = attr.getPrefix();
  1432. String value = attr.getNodeValue();
  1433. namespace = attr.getNamespaceURI();
  1434. if (namespace !=null && namespace.equals("http://www.w3.org/2000/xmlns/")) {
  1435. // at this point we are dealing with DOM Level 2 nodes only
  1436. if (specifiedPrefix == null &&
  1437. attr.getNodeName().equals("xmlns")) {
  1438. // default namespace
  1439. return value;
  1440. } else if (attrPrefix !=null &&
  1441. attrPrefix.equals("xmlns") &&
  1442. attr.getLocalName().equals(specifiedPrefix)) {
  1443. // non default namespace
  1444. return value;
  1445. }
  1446. }
  1447. }
  1448. }
  1449. /*
  1450. NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
  1451. if (ancestor != null) {
  1452. return ancestor.lookupNamespaceURI(specifiedPrefix);
  1453. }
  1454. */
  1455. return null;
  1456. }
  1457. /*
  1458. case Node.DOCUMENT_NODE : {
  1459. return((NodeImpl)((Document)this).getDocumentElement()).lookupNamespaceURI(specifiedPrefix) ;
  1460. }
  1461. */
  1462. case Node.ENTITY_NODE :
  1463. case Node.NOTATION_NODE:
  1464. case Node.DOCUMENT_FRAGMENT_NODE:
  1465. case Node.DOCUMENT_TYPE_NODE:
  1466. // type is unknown
  1467. return null;
  1468. case Node.ATTRIBUTE_NODE:{
  1469. if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) {
  1470. return getOwnerElement().lookupNamespaceURI(specifiedPrefix);
  1471. }
  1472. return null;
  1473. }
  1474. default:{
  1475. /*
  1476. NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
  1477. if (ancestor != null) {
  1478. return ancestor.lookupNamespaceURI(specifiedPrefix);
  1479. }
  1480. */
  1481. return null;
  1482. }
  1483. }
  1484. }
  1485. /**
  1486. * DOM Level 3: Experimental
  1487. * This method checks if the specified <code>namespaceURI</code> is the
  1488. * default namespace or not.
  1489. * @param namespaceURI The namespace URI to look for.
  1490. * @return <code>true</code> if the specified <code>namespaceURI</code>
  1491. * is the default namespace, <code>false</code> otherwise.
  1492. * @since DOM Level 3
  1493. */
  1494. public boolean isDefaultNamespace(String namespaceURI){
  1495. /*
  1496. // REVISIT: remove casts when DOM L3 becomes REC.
  1497. short type = this.getNodeType();
  1498. switch (type) {
  1499. case Node.ELEMENT_NODE: {
  1500. String namespace = this.getNamespaceURI();
  1501. String prefix = this.getPrefix();
  1502. // REVISIT: is it possible that prefix is empty string?
  1503. if (prefix == null || prefix.length() == 0) {
  1504. if (namespaceURI == null) {
  1505. return (namespace == namespaceURI);
  1506. }
  1507. return namespaceURI.equals(namespace);
  1508. }
  1509. if (this.hasAttributes()) {
  1510. ElementImpl elem = (ElementImpl)this;
  1511. NodeImpl attr = (NodeImpl)elem.getAttributeNodeNS("http://www.w3.org/2000/xmlns/", "xmlns");
  1512. if (attr != null) {
  1513. String value = attr.getNodeValue();
  1514. if (namespaceURI == null) {
  1515. return (namespace == value);
  1516. }
  1517. return namespaceURI.equals(value);
  1518. }
  1519. }
  1520. NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
  1521. if (ancestor != null) {
  1522. return ancestor.isDefaultNamespace(namespaceURI);
  1523. }
  1524. return false;
  1525. }
  1526. case Node.DOCUMENT_NODE:{
  1527. return((NodeImpl)((Document)this).getDocumentElement()).isDefaultNamespace(namespaceURI);
  1528. }
  1529. case Node.ENTITY_NODE :
  1530. case Node.NOTATION_NODE:
  1531. case Node.DOCUMENT_FRAGMENT_NODE:
  1532. case Node.DOCUMENT_TYPE_NODE:
  1533. // type is unknown
  1534. return false;
  1535. case Node.ATTRIBUTE_NODE:{
  1536. if (this.ownerNode.getNodeType() == Node.ELEMENT_NODE) {
  1537. return ownerNode.isDefaultNamespace(namespaceURI);
  1538. }
  1539. return false;
  1540. }
  1541. default:{
  1542. NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
  1543. if (ancestor != null) {
  1544. return ancestor.isDefaultNamespace(namespaceURI);
  1545. }
  1546. return false;
  1547. }
  1548. }
  1549. */
  1550. return false;
  1551. }
  1552. /**
  1553. *
  1554. * DOM Level 3 - Experimental:
  1555. * Look up the prefix associated to the given namespace URI, starting from this node.
  1556. *
  1557. * @param namespaceURI
  1558. * @return the prefix for the namespace
  1559. */
  1560. public String lookupPrefix(String namespaceURI){
  1561. // REVISIT: When Namespaces 1.1 comes out this may not be true
  1562. // Prefix can't be bound to null namespace
  1563. if (namespaceURI == null) {
  1564. return null;
  1565. }
  1566. short type = this.getNodeType();
  1567. switch (type) {
  1568. /*
  1569. case Node.ELEMENT_NODE: {
  1570. String namespace = this.getNamespaceURI(); // to flip out children
  1571. return lookupNamespacePrefix(namespaceURI, (ElementImpl)this);
  1572. }
  1573. case Node.DOCUMENT_NODE:{
  1574. return((NodeImpl)((Document)this).getDocumentElement()).lookupPrefix(namespaceURI);
  1575. }
  1576. */
  1577. case Node.ENTITY_NODE :
  1578. case Node.NOTATION_NODE:
  1579. case Node.DOCUMENT_FRAGMENT_NODE:
  1580. case Node.DOCUMENT_TYPE_NODE:
  1581. // type is unknown
  1582. return null;
  1583. case Node.ATTRIBUTE_NODE:{
  1584. if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) {
  1585. return getOwnerElement().lookupPrefix(namespaceURI);
  1586. }
  1587. return null;
  1588. }
  1589. default:{
  1590. /*
  1591. NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
  1592. if (ancestor != null) {
  1593. return ancestor.lookupPrefix(namespaceURI);
  1594. }
  1595. */
  1596. return null;
  1597. }
  1598. }
  1599. }
  1600. /**
  1601. * Returns whether this node is the same node as the given one.
  1602. * <br>This method provides a way to determine whether two
  1603. * <code>Node</code> references returned by the implementation reference
  1604. * the same object. When two <code>Node</code> references are references
  1605. * to the same object, even if through a proxy, the references may be
  1606. * used completely interchangably, such that all attributes have the
  1607. * same values and calling the same DOM method on either reference
  1608. * always has exactly the same effect.
  1609. * @param other The node to test against.
  1610. * @return Returns <code>true</code> if the nodes are the same,
  1611. * <code>false</code> otherwise.
  1612. * @since DOM Level 3
  1613. */
  1614. public boolean isSameNode(Node other) {
  1615. // we do not use any wrapper so the answer is obvious
  1616. return this == other;
  1617. }
  1618. /**
  1619. * This attribute returns the text content of this node and its
  1620. * descendants. When it is defined to be null, setting it has no effect.
  1621. * When set, any possible children this node may have are removed and
  1622. * replaced by a single <code>Text</code> node containing the string
  1623. * this attribute is set to. On getting, no serialization is performed,
  1624. * the returned string does not contain any markup. No whitespace
  1625. * normalization is performed, the returned string does not contain the
  1626. * element content whitespaces . Similarly, on setting, no parsing is
  1627. * performed either, the input string is taken as pure textual content.
  1628. * <br>The string returned is made of the text content of this node
  1629. * depending on its type, as defined below:
  1630. * <table border='1'>
  1631. * <tr>
  1632. * <th>Node type</th>
  1633. * <th>Content</th>
  1634. * </tr>
  1635. * <tr>
  1636. * <td valign='top' rowspan='1' colspan='1'>
  1637. * ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE,
  1638. * DOCUMENT_FRAGMENT_NODE</td>
  1639. * <td valign='top' rowspan='1' colspan='1'>concatenation of the <code>textContent</code>
  1640. * attribute value of every child node, excluding COMMENT_NODE and
  1641. * PROCESSING_INSTRUCTION_NODE nodes</td>
  1642. * </tr>
  1643. * <tr>
  1644. * <td valign='top' rowspan='1' colspan='1'>ATTRIBUTE_NODE, TEXT_NODE,
  1645. * CDATA_SECTION_NODE, COMMENT_NODE, PROCESSING_INSTRUCTION_NODE</td>
  1646. * <td valign='top' rowspan='1' colspan='1'>
  1647. * <code>nodeValue</code></td>
  1648. * </tr>
  1649. * <tr>
  1650. * <td valign='top' rowspan='1' colspan='1'>DOCUMENT_NODE, DOCUMENT_TYPE_NODE, NOTATION_NODE</td>
  1651. * <td valign='top' rowspan='1' colspan='1'>
  1652. * null</td>
  1653. * </tr>
  1654. * </table>
  1655. * @exception DOMException
  1656. * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
  1657. * @exception DOMException
  1658. * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
  1659. * fit in a <code>DOMString</code> variable on the implementation
  1660. * platform.
  1661. * @since DOM Level 3
  1662. */
  1663. public void setTextContent(String textContent)
  1664. throws DOMException {
  1665. setNodeValue(textContent);
  1666. }
  1667. /**
  1668. * This attribute returns the text content of this node and its
  1669. * descendants. When it is defined to be null, setting it has no effect.
  1670. * When set, any possible children this node may have are removed and
  1671. * replaced by a single <code>Text</code> node containing the string
  1672. * this attribute is set to. On getting, no serialization is performed,
  1673. * the returned string does not contain any markup. No whitespace
  1674. * normalization is performed, the returned string does not contain the
  1675. * element content whitespaces . Similarly, on setting, no parsing is
  1676. * performed either, the input string is taken as pure textual content.
  1677. * <br>The string returned is made of the text content of this node
  1678. * depending on its type, as defined below:
  1679. * <table border='1'>
  1680. * <tr>
  1681. * <th>Node type</th>
  1682. * <th>Content</th>
  1683. * </tr>
  1684. * <tr>
  1685. * <td valign='top' rowspan='1' colspan='1'>
  1686. * ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE,
  1687. * DOCUMENT_FRAGMENT_NODE</td>
  1688. * <td valign='top' rowspan='1' colspan='1'>concatenation of the <code>textContent</code>
  1689. * attribute value of every child node, excluding COMMENT_NODE and
  1690. * PROCESSING_INSTRUCTION_NODE nodes</td>
  1691. * </tr>
  1692. * <tr>
  1693. * <td valign='top' rowspan='1' colspan='1'>ATTRIBUTE_NODE, TEXT_NODE,
  1694. * CDATA_SECTION_NODE, COMMENT_NODE, PROCESSING_INSTRUCTION_NODE</td>
  1695. * <td valign='top' rowspan='1' colspan='1'>
  1696. * <code>nodeValue</code></td>
  1697. * </tr>
  1698. * <tr>
  1699. * <td valign='top' rowspan='1' colspan='1'>DOCUMENT_NODE, DOCUMENT_TYPE_NODE, NOTATION_NODE</td>
  1700. * <td valign='top' rowspan='1' colspan='1'>
  1701. * null</td>
  1702. * </tr>
  1703. * </table>
  1704. * @exception DOMException
  1705. * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
  1706. * @exception DOMException
  1707. * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
  1708. * fit in a <code>DOMString</code> variable on the implementation
  1709. * platform.
  1710. * @since DOM Level 3
  1711. */
  1712. public String getTextContent() throws DOMException {
  1713. return getNodeValue(); // overriden in some subclasses
  1714. }
  1715. /**
  1716. * Compares a node with this node with regard to their position in the
  1717. * document.
  1718. * @param other The node to compare against this node.
  1719. * @return Returns how the given node is positioned relatively to this
  1720. * node.
  1721. * @since DOM Level 3
  1722. */
  1723. public short compareDocumentPosition(Node other) throws DOMException {
  1724. return 0;
  1725. }
  1726. /**
  1727. * The absolute base URI of this node or <code>null</code> if undefined.
  1728. * This value is computed according to . However, when the
  1729. * <code>Document</code> supports the feature "HTML" , the base URI is
  1730. * computed using first the value of the href attribute of the HTML BASE
  1731. * element if any, and the value of the <code>documentURI</code>
  1732. * attribute from the <code>Document</code> interface otherwise.
  1733. * <br> When the node is an <code>Element</code>, a <code>Document</code>
  1734. * or a a <code>ProcessingInstruction</code>, this attribute represents
  1735. * the properties [base URI] defined in . When the node is a
  1736. * <code>Notation</code>, an <code>Entity</code>, or an
  1737. * <code>EntityReference</code>, this attribute represents the
  1738. * properties [declaration base URI] in the . How will this be affected
  1739. * by resolution of relative namespace URIs issue?It's not.Should this
  1740. * only be on Document, Element, ProcessingInstruction, Entity, and
  1741. * Notation nodes, according to the infoset? If not, what is it equal to
  1742. * on other nodes? Null? An empty string? I think it should be the
  1743. * parent's.No.Should this be read-only and computed or and actual
  1744. * read-write attribute?Read-only and computed (F2F 19 Jun 2000 and
  1745. * teleconference 30 May 2001).If the base HTML element is not yet
  1746. * attached to a document, does the insert change the Document.baseURI?
  1747. * Yes. (F2F 26 Sep 2001)
  1748. * @since DOM Level 3
  1749. */
  1750. public String getBaseURI() {
  1751. return null;
  1752. }
  1753. /**
  1754. * DOM Level 3 WD - Experimental.
  1755. * Renaming node
  1756. */
  1757. public Node renameNode(Node n,
  1758. String namespaceURI,
  1759. String name)
  1760. throws DOMException{
  1761. return n;
  1762. }
  1763. /**
  1764. * DOM Level 3 WD - Experimental
  1765. * Normalize document.
  1766. */
  1767. public void normalizeDocument(){
  1768. }
  1769. /**
  1770. * The configuration used when <code>Document.normalizeDocument</code> is
  1771. * invoked.
  1772. * @since DOM Level 3
  1773. */
  1774. public DOMConfiguration getDomConfig(){
  1775. return null;
  1776. }
  1777. /**Experimental DOM Level 3 feature: documentURI */
  1778. protected String fDocumentURI;
  1779. /**
  1780. * DOM Level 3 WD - Experimental.
  1781. */
  1782. public void setDocumentURI(String documentURI){
  1783. fDocumentURI= documentURI;
  1784. }
  1785. /**
  1786. * DOM Level 3 WD - Experimental.
  1787. * The location of the document or <code>null</code> if undefined.
  1788. * <br>Beware that when the <code>Document</code> supports the feature
  1789. * "HTML" , the href attribute of the HTML BASE element takes precedence
  1790. * over this attribute.
  1791. * @since DOM Level 3
  1792. */
  1793. public String getDocumentURI(){
  1794. return fDocumentURI;
  1795. }
  1796. /**Experimental DOM Level 3 feature: Document actualEncoding */
  1797. protected String actualEncoding;
  1798. /**
  1799. * DOM Level 3 WD - Experimental.
  1800. * An attribute specifying the actual encoding of this document. This is
  1801. * <code>null</code> otherwise.
  1802. * <br> This attribute represents the property [character encoding scheme]
  1803. * defined in .
  1804. * @since DOM Level 3
  1805. */
  1806. public String getActualEncoding() {
  1807. return actualEncoding;
  1808. }
  1809. /**
  1810. * DOM Level 3 WD - Experimental.
  1811. * An attribute specifying the actual encoding of this document. This is
  1812. * <code>null</code> otherwise.
  1813. * <br> This attribute represents the property [character encoding scheme]
  1814. * defined in .
  1815. * @since DOM Level 3
  1816. */
  1817. public void setActualEncoding(String value) {
  1818. actualEncoding = value;
  1819. }
  1820. /**
  1821. * DOM Level 3 WD - Experimental.
  1822. */
  1823. public Text replaceWholeText(String content)
  1824. throws DOMException{
  1825. /*
  1826. if (needsSyncData()) {
  1827. synchronizeData();
  1828. }
  1829. // make sure we can make the replacement
  1830. if (!canModify(nextSibling)) {
  1831. throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
  1832. DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null));
  1833. }
  1834. Node parent = this.getParentNode();
  1835. if (content == null || content.length() == 0) {
  1836. // remove current node
  1837. if (parent !=null) { // check if node in the tree
  1838. parent.removeChild(this);
  1839. return null;
  1840. }
  1841. }
  1842. Text currentNode = null;
  1843. if (isReadOnly()){
  1844. Text newNode = this.ownerDocument().createTextNode(content);
  1845. if (parent !=null) { // check if node in the tree
  1846. parent.insertBefore(newNode, this);
  1847. parent.removeChild(this);
  1848. currentNode = newNode;
  1849. } else {
  1850. return newNode;
  1851. }
  1852. } else {
  1853. this.setData(content);
  1854. currentNode = this;
  1855. }
  1856. Node sibling = currentNode.getNextSibling();
  1857. while ( sibling !=null) {
  1858. parent.removeChild(sibling);
  1859. sibling = currentNode.getNextSibling();
  1860. }
  1861. return currentNode;
  1862. */
  1863. return null; //Pending
  1864. }
  1865. /**
  1866. * DOM Level 3 WD - Experimental.
  1867. * Returns all text of <code>Text</code> nodes logically-adjacent text
  1868. * nodes to this node, concatenated in document order.
  1869. * @since DOM Level 3
  1870. */
  1871. public String getWholeText(){
  1872. /*
  1873. if (needsSyncData()) {
  1874. synchronizeData();
  1875. }
  1876. if (nextSibling == null) {
  1877. return data;
  1878. }
  1879. StringBuffer buffer = new StringBuffer();
  1880. if (data != null && data.length() != 0) {
  1881. buffer.append(data);
  1882. }
  1883. getWholeText(nextSibling, buffer);
  1884. return buffer.toString();
  1885. */
  1886. return null; // PENDING
  1887. }
  1888. /**
  1889. * DOM Level 3 WD - Experimental.
  1890. * Returns whether this text node contains whitespace in element content,
  1891. * often abusively called "ignorable whitespace".
  1892. */
  1893. public boolean isElementContentWhitespace(){
  1894. return false;
  1895. }
  1896. /**
  1897. * NON-DOM: set the type of this attribute to be ID type.
  1898. *
  1899. * @param id
  1900. */
  1901. public void setIdAttribute(boolean id){
  1902. //PENDING
  1903. }
  1904. /**
  1905. * DOM Level 3: register the given attribute node as an ID attribute
  1906. */
  1907. public void setIdAttribute(String name, boolean makeId) {
  1908. //PENDING
  1909. }
  1910. /**
  1911. * DOM Level 3: register the given attribute node as an ID attribute
  1912. */
  1913. public void setIdAttributeNode(Attr at, boolean makeId) {
  1914. //PENDING
  1915. }
  1916. /**
  1917. * DOM Level 3: register the given attribute node as an ID attribute
  1918. */
  1919. public void setIdAttributeNS(String namespaceURI, String localName,
  1920. boolean makeId) {
  1921. //PENDING
  1922. }
  1923. /**
  1924. * Method getSchemaTypeInfo.
  1925. * @return TypeInfo
  1926. */
  1927. public TypeInfo getSchemaTypeInfo(){
  1928. return null; //PENDING
  1929. }
  1930. public boolean isId() {
  1931. return false; //PENDING
  1932. }
  1933. private String xmlEncoding;
  1934. public String getXmlEncoding( ) {
  1935. return xmlEncoding;
  1936. }
  1937. public void setXmlEncoding( String xmlEncoding ) {
  1938. this.xmlEncoding = xmlEncoding;
  1939. }
  1940. private boolean xmlStandalone;
  1941. public boolean getXmlStandalone() {
  1942. return xmlStandalone;
  1943. }
  1944. public void setXmlStandalone(boolean xmlStandalone) throws DOMException {
  1945. this.xmlStandalone = xmlStandalone;
  1946. }
  1947. private String xmlVersion;
  1948. public String getXmlVersion() {
  1949. return xmlVersion;
  1950. }
  1951. public void setXmlVersion(String xmlVersion) throws DOMException {
  1952. this.xmlVersion = xmlVersion;
  1953. }
  1954. }