1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xalan" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, Lotus
  53. * Development Corporation., http://www.lotus.com. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package org.apache.xml.dtm.ref;
  58. import org.w3c.dom.*;
  59. import org.apache.xml.dtm.*;
  60. import org.apache.xml.dtm.Axis;
  61. /**
  62. * <meta name="usage" content="internal"/>
  63. * <code>DTMNodeProxy</code> presents a DOM Node API front-end to the DTM model.
  64. * <p>
  65. * It does _not_ attempt to address the "node identity" question; no effort
  66. * is made to prevent the creation of multiple proxies referring to a single
  67. * DTM node. Users can create a mechanism for managing this, or relinquish the
  68. * use of "==" and use the .sameNodeAs() mechanism, which is under
  69. * consideration for future versions of the DOM.
  70. * <p>
  71. * DTMNodeProxy may be subclassed further to present specific DOM node types.
  72. *
  73. * @see org.w3c.dom
  74. */
  75. public class DTMNodeProxy
  76. implements Node, Document, Text, Element, Attr,
  77. ProcessingInstruction, Comment, DocumentFragment
  78. {
  79. /** The DTM for this node. */
  80. public DTM dtm;
  81. /** The DTM node handle. */
  82. int node;
  83. /** The DOMImplementation object */
  84. static final DOMImplementation implementation=new DTMNodeProxyImplementation();
  85. /**
  86. * Create a DTMNodeProxy Node representing a specific Node in a DTM
  87. *
  88. * @param dtm The DTM Reference, must be non-null.
  89. * @param node The DTM node handle.
  90. */
  91. DTMNodeProxy(DTM dtm, int node)
  92. {
  93. this.dtm = dtm;
  94. this.node = node;
  95. }
  96. /**
  97. * NON-DOM: Return the DTM model
  98. *
  99. * @return The DTM that this proxy is a representative for.
  100. */
  101. public final DTM getDTM()
  102. {
  103. return dtm;
  104. }
  105. /**
  106. * NON-DOM: Return the DTM node number
  107. *
  108. * @return The DTM node handle.
  109. */
  110. public final int getDTMNodeNumber()
  111. {
  112. return node;
  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(Node 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 (dtmp.node == this.node) && (dtmp.dtm == this.dtm);
  129. }
  130. catch (ClassCastException cce)
  131. {
  132. return false;
  133. }
  134. }
  135. /**
  136. * Test for equality based on node number.
  137. *
  138. * @param node A DTM node proxy reference.
  139. *
  140. * @return true if the given node has the same handle as this node.
  141. */
  142. public final boolean equals(Object node)
  143. {
  144. try
  145. {
  146. // DTMNodeProxy dtmp = (DTMNodeProxy)node;
  147. // return (dtmp.node == this.node);
  148. // Patch attributed to Gary L Peskin <garyp@firstech.com>
  149. return equals((Node) node);
  150. }
  151. catch (ClassCastException cce)
  152. {
  153. return false;
  154. }
  155. }
  156. /**
  157. * FUTURE DOM: Test node identity, in lieu of Node==Node
  158. *
  159. * @param other
  160. *
  161. * @return true if the given node has the same handle as this node.
  162. */
  163. public final boolean sameNodeAs(Node other)
  164. {
  165. if (!(other instanceof DTMNodeProxy))
  166. return false;
  167. DTMNodeProxy that = (DTMNodeProxy) other;
  168. return this.dtm == that.dtm && this.node == that.node;
  169. }
  170. /**
  171. *
  172. * @return
  173. * @see org.w3c.dom.Node
  174. */
  175. public final String getNodeName()
  176. {
  177. return dtm.getNodeName(node);
  178. }
  179. /**
  180. * A PI's "target" states what processor channel the PI's data
  181. * should be directed to. It is defined differently in HTML and XML.
  182. * <p>
  183. * In XML, a PI's "target" is the first (whitespace-delimited) token
  184. * following the "<?" token that begins the PI.
  185. * <p>
  186. * In HTML, target is always null.
  187. * <p>
  188. * Note that getNodeName is aliased to getTarget.
  189. *
  190. * @return
  191. */
  192. public final String getTarget()
  193. {
  194. return dtm.getNodeName(node);
  195. } // getTarget():String
  196. /**
  197. *
  198. * @return
  199. * @see org.w3c.dom.Node as of DOM Level 2
  200. */
  201. public final String getLocalName()
  202. {
  203. return dtm.getLocalName(node);
  204. }
  205. /**
  206. * @return The prefix for this node.
  207. * @see org.w3c.dom.Node as of DOM Level 2
  208. */
  209. public final String getPrefix()
  210. {
  211. return dtm.getPrefix(node);
  212. }
  213. /**
  214. *
  215. * @param prefix
  216. *
  217. * @throws DOMException
  218. * @see org.w3c.dom.Node as of DOM Level 2 -- DTMNodeProxy is read-only
  219. */
  220. public final void setPrefix(String prefix) throws DOMException
  221. {
  222. throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
  223. }
  224. /**
  225. *
  226. * @return
  227. * @see org.w3c.dom.Node as of DOM Level 2
  228. */
  229. public final String getNamespaceURI()
  230. {
  231. return dtm.getNamespaceURI(node);
  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. * Or we could say that we support DOM Core Level 2 but all nodes
  237. * are read-only. Unclear which answer is least misleading.
  238. *
  239. * NON-DOM method. This was present in early drafts of DOM Level 2,
  240. * but was renamed isSupported. It's present here only because it's
  241. * cheap, harmless, and might help some poor fool who is still trying
  242. * to use an early Working Draft of the DOM.
  243. *
  244. * @param feature
  245. * @param version
  246. *
  247. * @return false
  248. */
  249. public final boolean supports(String feature, String version)
  250. {
  251. return implementation.hasFeature(feature,version);
  252. //throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  253. }
  254. /** Ask whether we support a given DOM feature.
  255. * In fact, we do not _fully_ support any DOM feature -- we're a
  256. * read-only subset -- so arguably we should always return false.
  257. *
  258. * @param feature
  259. * @param version
  260. *
  261. * @return false
  262. * @see org.w3c.dom.Node as of DOM Level 2
  263. */
  264. public final boolean isSupported(String feature, String version)
  265. {
  266. return implementation.hasFeature(feature,version);
  267. // throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  268. }
  269. /**
  270. *
  271. * @return
  272. *
  273. * @throws DOMException
  274. * @see org.w3c.dom.Node
  275. */
  276. public final String getNodeValue() throws DOMException
  277. {
  278. return dtm.getNodeValue(node);
  279. }
  280. /**
  281. * @return The string value of the node
  282. *
  283. * @throws DOMException
  284. */
  285. public final String getStringValue() throws DOMException
  286. {
  287. return dtm.getStringValue(node).toString();
  288. }
  289. /**
  290. *
  291. * @param nodeValue
  292. *
  293. * @throws DOMException
  294. * @see org.w3c.dom.Node -- DTMNodeProxy is read-only
  295. */
  296. public final void setNodeValue(String nodeValue) throws DOMException
  297. {
  298. throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
  299. }
  300. /**
  301. *
  302. * @return
  303. * @see org.w3c.dom.Node
  304. */
  305. public final short getNodeType()
  306. {
  307. return (short) dtm.getNodeType(node);
  308. }
  309. /**
  310. *
  311. * @return
  312. * @see org.w3c.dom.Node
  313. */
  314. public final Node getParentNode()
  315. {
  316. if (getNodeType() == Node.ATTRIBUTE_NODE)
  317. return null;
  318. int newnode = dtm.getParent(node);
  319. return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
  320. }
  321. /**
  322. *
  323. * @return
  324. * @see org.w3c.dom.Node
  325. */
  326. public final Node getOwnerNode()
  327. {
  328. int newnode = dtm.getParent(node);
  329. return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
  330. }
  331. /**
  332. *
  333. * @return
  334. * @see org.w3c.dom.Node
  335. */
  336. public final NodeList getChildNodes()
  337. {
  338. // Annoyingly, AxisIterators do not currently implement DTMIterator, so
  339. // we can't just wap DTMNodeList around an Axis.CHILD iterator.
  340. // Instead, we've created a special-case operating mode for that object.
  341. return new DTMNodeList(dtm,node);
  342. // throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  343. }
  344. /**
  345. *
  346. * @return
  347. * @see org.w3c.dom.Node
  348. */
  349. public final Node getFirstChild()
  350. {
  351. int newnode = dtm.getFirstChild(node);
  352. return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
  353. }
  354. /**
  355. *
  356. * @return
  357. * @see org.w3c.dom.Node
  358. */
  359. public final Node getLastChild()
  360. {
  361. int newnode = dtm.getLastChild(node);
  362. return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
  363. }
  364. /**
  365. *
  366. * @return
  367. * @see org.w3c.dom.Node
  368. */
  369. public final Node getPreviousSibling()
  370. {
  371. int newnode = dtm.getPreviousSibling(node);
  372. return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
  373. }
  374. /**
  375. *
  376. * @return
  377. * @see org.w3c.dom.Node
  378. */
  379. public final Node getNextSibling()
  380. {
  381. // Attr's Next is defined at DTM level, but not at DOM level.
  382. if (dtm.getNodeType(node) == Node.ATTRIBUTE_NODE)
  383. return null;
  384. int newnode = dtm.getNextSibling(node);
  385. return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
  386. }
  387. // DTMNamedNodeMap m_attrs;
  388. /**
  389. *
  390. * @return
  391. * @see org.w3c.dom.Node
  392. */
  393. public final NamedNodeMap getAttributes()
  394. {
  395. return new DTMNamedNodeMap(dtm, node);
  396. }
  397. /**
  398. * Method hasAttribute
  399. *
  400. *
  401. * @param name
  402. *
  403. * (hasAttribute) @return
  404. */
  405. public boolean hasAttribute(String name)
  406. {
  407. return DTM.NULL != dtm.getAttributeNode(node,null,name);
  408. }
  409. /**
  410. * Method hasAttributeNS
  411. *
  412. *
  413. * @param name
  414. * @param x
  415. *
  416. * (hasAttributeNS) @return
  417. */
  418. public boolean hasAttributeNS(String name, String x)
  419. {
  420. return DTM.NULL != dtm.getAttributeNode(node,x,name);
  421. }
  422. /**
  423. *
  424. * @return
  425. * @see org.w3c.dom.Node
  426. */
  427. public final Document getOwnerDocument()
  428. {
  429. // Note that this uses the DOM-compatable version of the call
  430. return (Document)(dtm.getNode(dtm.getOwnerDocument(node)));
  431. }
  432. /**
  433. *
  434. * @param newChild
  435. * @param refChild
  436. *
  437. * @return
  438. *
  439. * @throws DOMException
  440. * @see org.w3c.dom.Node -- DTMNodeProxy is read-only
  441. */
  442. public final Node insertBefore(Node newChild, Node refChild)
  443. throws DOMException
  444. {
  445. throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
  446. }
  447. /**
  448. *
  449. * @param newChild
  450. * @param oldChild
  451. *
  452. * @return
  453. *
  454. * @throws DOMException
  455. * @see org.w3c.dom.Node -- DTMNodeProxy is read-only
  456. */
  457. public final Node replaceChild(Node newChild, Node oldChild)
  458. throws DOMException
  459. {
  460. throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
  461. }
  462. /**
  463. *
  464. * @param oldChild
  465. *
  466. * @return
  467. *
  468. * @throws DOMException
  469. * @see org.w3c.dom.Node -- DTMNodeProxy is read-only
  470. */
  471. public final Node removeChild(Node oldChild) throws DOMException
  472. {
  473. throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
  474. }
  475. /**
  476. *
  477. * @param newChild
  478. *
  479. * @return
  480. *
  481. * @throws DOMException
  482. * @see org.w3c.dom.Node -- DTMNodeProxy is read-only
  483. */
  484. public final Node appendChild(Node newChild) throws DOMException
  485. {
  486. throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
  487. }
  488. /**
  489. *
  490. * @return
  491. * @see org.w3c.dom.Node
  492. */
  493. public final boolean hasChildNodes()
  494. {
  495. return (DTM.NULL != dtm.getFirstChild(node));
  496. }
  497. /**
  498. *
  499. * @param deep
  500. *
  501. * @return
  502. * @see org.w3c.dom.Node -- DTMNodeProxy is read-only
  503. */
  504. public final Node cloneNode(boolean deep)
  505. {
  506. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  507. }
  508. /**
  509. *
  510. * @return
  511. * @see org.w3c.dom.Document
  512. */
  513. public final DocumentType getDoctype()
  514. {
  515. return null;
  516. }
  517. /**
  518. *
  519. * @return
  520. * @see org.w3c.dom.Document
  521. */
  522. public final DOMImplementation getImplementation()
  523. {
  524. return implementation;
  525. }
  526. /** This is a bit of a problem in DTM, since a DTM may be a Document
  527. * Fragment and hence not have a clear-cut Document Element. We can
  528. * make it work in the well-formed cases but would that be confusing for others?
  529. *
  530. * @return
  531. * @see org.w3c.dom.Document
  532. */
  533. public final Element getDocumentElement()
  534. {
  535. int dochandle=dtm.getDocument();
  536. int elementhandle=dtm.NULL;
  537. for(int kidhandle=dtm.getFirstChild(dochandle);
  538. kidhandle!=dtm.NULL;
  539. kidhandle=dtm.getNextSibling(kidhandle))
  540. {
  541. switch(dtm.getNodeType(kidhandle))
  542. {
  543. case Node.ELEMENT_NODE:
  544. if(elementhandle!=dtm.NULL)
  545. {
  546. elementhandle=dtm.NULL; // More than one; ill-formed.
  547. kidhandle=dtm.getLastChild(dochandle); // End loop
  548. }
  549. else
  550. elementhandle=kidhandle;
  551. break;
  552. // These are harmless; document is still wellformed
  553. case Node.COMMENT_NODE:
  554. case Node.PROCESSING_INSTRUCTION_NODE:
  555. case Node.DOCUMENT_TYPE_NODE:
  556. break;
  557. default:
  558. elementhandle=dtm.NULL; // ill-formed
  559. kidhandle=dtm.getLastChild(dochandle); // End loop
  560. break;
  561. }
  562. }
  563. if(elementhandle==dtm.NULL)
  564. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  565. else
  566. return (Element)(dtm.getNode(elementhandle));
  567. }
  568. /**
  569. *
  570. * @param tagName
  571. *
  572. * @return
  573. *
  574. * @throws DOMException
  575. * @see org.w3c.dom.Document
  576. */
  577. public final Element createElement(String tagName) throws DOMException
  578. {
  579. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  580. }
  581. /**
  582. *
  583. * @return
  584. * @see org.w3c.dom.Document
  585. */
  586. public final DocumentFragment createDocumentFragment()
  587. {
  588. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  589. }
  590. /**
  591. *
  592. * @param data
  593. *
  594. * @return
  595. * @see org.w3c.dom.Document
  596. */
  597. public final Text createTextNode(String data)
  598. {
  599. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  600. }
  601. /**
  602. *
  603. * @param data
  604. *
  605. * @return
  606. * @see org.w3c.dom.Document
  607. */
  608. public final Comment createComment(String data)
  609. {
  610. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  611. }
  612. /**
  613. *
  614. * @param data
  615. *
  616. * @return
  617. *
  618. * @throws DOMException
  619. * @see org.w3c.dom.Document
  620. */
  621. public final CDATASection createCDATASection(String data)
  622. throws DOMException
  623. {
  624. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  625. }
  626. /**
  627. *
  628. * @param target
  629. * @param data
  630. *
  631. * @return
  632. *
  633. * @throws DOMException
  634. * @see org.w3c.dom.Document
  635. */
  636. public final ProcessingInstruction createProcessingInstruction(
  637. String target, String data) throws DOMException
  638. {
  639. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  640. }
  641. /**
  642. *
  643. * @param name
  644. *
  645. * @return
  646. *
  647. * @throws DOMException
  648. * @see org.w3c.dom.Document
  649. */
  650. public final Attr createAttribute(String name) throws DOMException
  651. {
  652. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  653. }
  654. /**
  655. *
  656. * @param name
  657. *
  658. * @return
  659. *
  660. * @throws DOMException
  661. * @see org.w3c.dom.Document
  662. */
  663. public final EntityReference createEntityReference(String name)
  664. throws DOMException
  665. {
  666. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  667. }
  668. /**
  669. *
  670. * @param tagname
  671. *
  672. * @return
  673. * @see org.w3c.dom.Document
  674. */
  675. public final NodeList getElementsByTagName(String tagname)
  676. {
  677. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  678. }
  679. /**
  680. *
  681. * @param importedNode
  682. * @param deep
  683. *
  684. * @return
  685. *
  686. * @throws DOMException
  687. * @see org.w3c.dom.Document as of DOM Level 2 -- DTMNodeProxy is read-only
  688. */
  689. public final Node importNode(Node importedNode, boolean deep)
  690. throws DOMException
  691. {
  692. throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
  693. }
  694. /**
  695. *
  696. * @param namespaceURI
  697. * @param qualifiedName
  698. *
  699. * @return
  700. *
  701. * @throws DOMException
  702. * @see org.w3c.dom.Document as of DOM Level 2
  703. */
  704. public final Element createElementNS(
  705. String namespaceURI, String qualifiedName) throws DOMException
  706. {
  707. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  708. }
  709. /**
  710. *
  711. * @param namespaceURI
  712. * @param qualifiedName
  713. *
  714. * @return
  715. *
  716. * @throws DOMException
  717. * @see org.w3c.dom.Document as of DOM Level 2
  718. */
  719. public final Attr createAttributeNS(
  720. String namespaceURI, String qualifiedName) throws DOMException
  721. {
  722. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  723. }
  724. /**
  725. *
  726. * @param namespaceURI
  727. * @param localName
  728. *
  729. * @return
  730. * @see org.w3c.dom.Document as of DOM Level 2
  731. */
  732. public final NodeList getElementsByTagNameNS(String namespaceURI,
  733. String localName)
  734. {
  735. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  736. }
  737. /**
  738. *
  739. * @param elementId
  740. *
  741. * @return
  742. * @see org.w3c.dom.Document as of DOM Level 2
  743. */
  744. public final Element getElementById(String elementId)
  745. {
  746. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  747. }
  748. /**
  749. *
  750. * @param offset
  751. *
  752. * @return
  753. *
  754. * @throws DOMException
  755. * @see org.w3c.dom.Text
  756. */
  757. public final Text splitText(int offset) throws DOMException
  758. {
  759. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  760. }
  761. /**
  762. *
  763. * @return
  764. *
  765. * @throws DOMException
  766. * @see org.w3c.dom.CharacterData
  767. */
  768. public final String getData() throws DOMException
  769. {
  770. return dtm.getNodeValue(node);
  771. }
  772. /**
  773. *
  774. * @param data
  775. *
  776. * @throws DOMException
  777. * @see org.w3c.dom.CharacterData
  778. */
  779. public final void setData(String data) throws DOMException
  780. {
  781. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  782. }
  783. /**
  784. *
  785. * @return
  786. * @see org.w3c.dom.CharacterData
  787. */
  788. public final int getLength()
  789. {
  790. // %OPT% This should do something smarter?
  791. return dtm.getNodeValue(node).length();
  792. }
  793. /**
  794. *
  795. * @param offset
  796. * @param count
  797. *
  798. * @return
  799. *
  800. * @throws DOMException
  801. * @see org.w3c.dom.CharacterData
  802. */
  803. public final String substringData(int offset, int count) throws DOMException
  804. {
  805. return getData().substring(offset,offset+count);
  806. }
  807. /**
  808. *
  809. * @param arg
  810. *
  811. * @throws DOMException
  812. * @see org.w3c.dom.CharacterData
  813. */
  814. public final void appendData(String arg) throws DOMException
  815. {
  816. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  817. }
  818. /**
  819. *
  820. * @param offset
  821. * @param arg
  822. *
  823. * @throws DOMException
  824. * @see org.w3c.dom.CharacterData
  825. */
  826. public final void insertData(int offset, String arg) throws DOMException
  827. {
  828. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  829. }
  830. /**
  831. *
  832. * @param offset
  833. * @param count
  834. *
  835. * @throws DOMException
  836. * @see org.w3c.dom.CharacterData
  837. */
  838. public final void deleteData(int offset, int count) throws DOMException
  839. {
  840. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  841. }
  842. /**
  843. *
  844. * @param offset
  845. * @param count
  846. * @param arg
  847. *
  848. * @throws DOMException
  849. * @see org.w3c.dom.CharacterData
  850. */
  851. public final void replaceData(int offset, int count, String arg)
  852. throws DOMException
  853. {
  854. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  855. }
  856. /**
  857. *
  858. * @return
  859. * @see org.w3c.dom.Element
  860. */
  861. public final String getTagName()
  862. {
  863. return dtm.getNodeName(node);
  864. }
  865. /**
  866. *
  867. * @param name
  868. *
  869. * @return
  870. * @see org.w3c.dom.Element
  871. */
  872. public final String getAttribute(String name)
  873. {
  874. DTMNamedNodeMap map = new DTMNamedNodeMap(dtm, node);
  875. Node node = map.getNamedItem(name);
  876. return (null == node) ? null : node.getNodeValue();
  877. }
  878. /**
  879. *
  880. * @param name
  881. * @param value
  882. *
  883. * @throws DOMException
  884. * @see org.w3c.dom.Element
  885. */
  886. public final void setAttribute(String name, String value)
  887. throws DOMException
  888. {
  889. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  890. }
  891. /**
  892. *
  893. * @param name
  894. *
  895. * @throws DOMException
  896. * @see org.w3c.dom.Element
  897. */
  898. public final void removeAttribute(String name) throws DOMException
  899. {
  900. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  901. }
  902. /**
  903. *
  904. * @param name
  905. *
  906. * @return
  907. * @see org.w3c.dom.Element
  908. */
  909. public final Attr getAttributeNode(String name)
  910. {
  911. DTMNamedNodeMap map = new DTMNamedNodeMap(dtm, node);
  912. return (Attr)map.getNamedItem(name);
  913. }
  914. /**
  915. *
  916. * @param newAttr
  917. *
  918. * @return
  919. *
  920. * @throws DOMException
  921. * @see org.w3c.dom.Element
  922. */
  923. public final Attr setAttributeNode(Attr newAttr) throws DOMException
  924. {
  925. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  926. }
  927. /**
  928. *
  929. * @param oldAttr
  930. *
  931. * @return
  932. *
  933. * @throws DOMException
  934. * @see org.w3c.dom.Element
  935. */
  936. public final Attr removeAttributeNode(Attr oldAttr) throws DOMException
  937. {
  938. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  939. }
  940. /**
  941. * Introduced in DOM Level 2.
  942. *
  943. * @return
  944. */
  945. public boolean hasAttributes()
  946. {
  947. return DTM.NULL != dtm.getFirstAttribute(node);
  948. }
  949. /** @see org.w3c.dom.Element */
  950. public final void normalize()
  951. {
  952. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  953. }
  954. /**
  955. *
  956. * @param namespaceURI
  957. * @param localName
  958. *
  959. * @return
  960. * @see org.w3c.dom.Element
  961. */
  962. public final String getAttributeNS(String namespaceURI, String localName)
  963. {
  964. DTMNamedNodeMap map = new DTMNamedNodeMap(dtm, node);
  965. Node node = map.getNamedItemNS(namespaceURI,localName);
  966. return (null == node) ? null : node.getNodeValue();
  967. }
  968. /**
  969. *
  970. * @param namespaceURI
  971. * @param qualifiedName
  972. * @param value
  973. *
  974. * @throws DOMException
  975. * @see org.w3c.dom.Element
  976. */
  977. public final void setAttributeNS(
  978. String namespaceURI, String qualifiedName, String value)
  979. throws DOMException
  980. {
  981. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  982. }
  983. /**
  984. *
  985. * @param namespaceURI
  986. * @param localName
  987. *
  988. * @throws DOMException
  989. * @see org.w3c.dom.Element
  990. */
  991. public final void removeAttributeNS(String namespaceURI, String localName)
  992. throws DOMException
  993. {
  994. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  995. }
  996. /**
  997. *
  998. * @param namespaceURI
  999. * @param localName
  1000. *
  1001. * @return
  1002. * @see org.w3c.dom.Element
  1003. */
  1004. public final Attr getAttributeNodeNS(String namespaceURI, String localName)
  1005. {
  1006. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1007. }
  1008. /**
  1009. *
  1010. * @param newAttr
  1011. *
  1012. * @return
  1013. *
  1014. * @throws DOMException
  1015. * @see org.w3c.dom.Element
  1016. */
  1017. public final Attr setAttributeNodeNS(Attr newAttr) throws DOMException
  1018. {
  1019. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1020. }
  1021. /**
  1022. *
  1023. * @return
  1024. * @see org.w3c.dom.Attr
  1025. */
  1026. public final String getName()
  1027. {
  1028. return dtm.getNodeName(node);
  1029. }
  1030. /**
  1031. *
  1032. * @return
  1033. * @see org.w3c.dom.Attr
  1034. */
  1035. public final boolean getSpecified()
  1036. {
  1037. // We really don't know which attributes might have come from the
  1038. // source document versus from the DTD. Treat them all as having
  1039. // been provided by the user.
  1040. // %REVIEW% if/when we become aware of DTDs/schemae.
  1041. return true;
  1042. }
  1043. /**
  1044. *
  1045. * @return
  1046. * @see org.w3c.dom.Attr
  1047. */
  1048. public final String getValue()
  1049. {
  1050. return dtm.getNodeValue(node);
  1051. }
  1052. /**
  1053. *
  1054. * @param value
  1055. * @see org.w3c.dom.Attr
  1056. */
  1057. public final void setValue(String value)
  1058. {
  1059. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1060. }
  1061. /**
  1062. * Get the owner element of an attribute.
  1063. *
  1064. * @return
  1065. * @see org.w3c.dom.Attr as of DOM Level 2
  1066. */
  1067. public final Element getOwnerElement()
  1068. {
  1069. if (getNodeType() != Node.ATTRIBUTE_NODE)
  1070. return null;
  1071. // In XPath and DTM data models, unlike DOM, an Attr's parent is its
  1072. // owner element.
  1073. int newnode = dtm.getParent(node);
  1074. return (newnode == DTM.NULL) ? null : (Element)(dtm.getNode(newnode));
  1075. }
  1076. /**
  1077. * NEEDSDOC Method adoptNode
  1078. *
  1079. *
  1080. * NEEDSDOC @param source
  1081. *
  1082. * NEEDSDOC (adoptNode) @return
  1083. *
  1084. * @throws DOMException
  1085. */
  1086. public Node adoptNode(Node source) throws DOMException
  1087. {
  1088. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1089. }
  1090. /**
  1091. * <p>EXPERIMENTAL! Based on the <a
  1092. * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
  1093. * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
  1094. * <p>
  1095. * An attribute specifying, as part of the XML declaration, the encoding
  1096. * of this document. This is <code>null</code> when unspecified.
  1097. * @since DOM Level 3
  1098. *
  1099. * NEEDSDOC ($objectName$) @return
  1100. */
  1101. public String getEncoding()
  1102. {
  1103. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1104. }
  1105. /**
  1106. * <p>EXPERIMENTAL! Based on the <a
  1107. * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
  1108. * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
  1109. * <p>
  1110. * An attribute specifying, as part of the XML declaration, the encoding
  1111. * of this document. This is <code>null</code> when unspecified.
  1112. * @since DOM Level 3
  1113. *
  1114. * NEEDSDOC @param encoding
  1115. */
  1116. public void setEncoding(String encoding)
  1117. {
  1118. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1119. }
  1120. /**
  1121. * <p>EXPERIMENTAL! Based on the <a
  1122. * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
  1123. * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
  1124. * <p>
  1125. * An attribute specifying, as part of the XML declaration, whether this
  1126. * document is standalone.
  1127. * @since DOM Level 3
  1128. *
  1129. * NEEDSDOC ($objectName$) @return
  1130. */
  1131. public boolean getStandalone()
  1132. {
  1133. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1134. }
  1135. /**
  1136. * <p>EXPERIMENTAL! Based on the <a
  1137. * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
  1138. * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
  1139. * <p>
  1140. * An attribute specifying, as part of the XML declaration, whether this
  1141. * document is standalone.
  1142. * @since DOM Level 3
  1143. *
  1144. * NEEDSDOC @param standalone
  1145. */
  1146. public void setStandalone(boolean standalone)
  1147. {
  1148. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1149. }
  1150. /**
  1151. * <p>EXPERIMENTAL! Based on the <a
  1152. * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
  1153. * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
  1154. * <p>
  1155. * An attribute specifying whether errors checking is enforced or not.
  1156. * When set to <code>false</code>, the implementation is free to not
  1157. * test every possible error case normally defined on DOM operations,
  1158. * and not raise any <code>DOMException</code>. In case of error, the
  1159. * behavior is undefined. This attribute is <code>true</code> by
  1160. * defaults.
  1161. * @since DOM Level 3
  1162. *
  1163. * NEEDSDOC ($objectName$) @return
  1164. */
  1165. public boolean getStrictErrorChecking()
  1166. {
  1167. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1168. }
  1169. /**
  1170. * <p>EXPERIMENTAL! Based on the <a
  1171. * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
  1172. * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
  1173. * <p>
  1174. * An attribute specifying whether errors checking is enforced or not.
  1175. * When set to <code>false</code>, the implementation is free to not
  1176. * test every possible error case normally defined on DOM operations,
  1177. * and not raise any <code>DOMException</code>. In case of error, the
  1178. * behavior is undefined. This attribute is <code>true</code> by
  1179. * defaults.
  1180. * @since DOM Level 3
  1181. *
  1182. * NEEDSDOC @param strictErrorChecking
  1183. */
  1184. public void setStrictErrorChecking(boolean strictErrorChecking)
  1185. {
  1186. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1187. }
  1188. /**
  1189. * <p>EXPERIMENTAL! Based on the <a
  1190. * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
  1191. * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
  1192. * <p>
  1193. * An attribute specifying, as part of the XML declaration, the version
  1194. * number of this document. This is <code>null</code> when unspecified.
  1195. * @since DOM Level 3
  1196. *
  1197. * NEEDSDOC ($objectName$) @return
  1198. */
  1199. public String getVersion()
  1200. {
  1201. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1202. }
  1203. /**
  1204. * <p>EXPERIMENTAL! Based on the <a
  1205. * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
  1206. * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
  1207. * <p>
  1208. * An attribute specifying, as part of the XML declaration, the version
  1209. * number of this document. This is <code>null</code> when unspecified.
  1210. * @since DOM Level 3
  1211. *
  1212. * NEEDSDOC @param version
  1213. */
  1214. public void setVersion(String version)
  1215. {
  1216. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1217. }
  1218. /** Inner class to support getDOMImplementation.
  1219. */
  1220. static class DTMNodeProxyImplementation implements DOMImplementation
  1221. {
  1222. public DocumentType createDocumentType(String qualifiedName,String publicId, String systemId)
  1223. {
  1224. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1225. }
  1226. public Document createDocument(String namespaceURI,String qualfiedName,DocumentType doctype)
  1227. {
  1228. // Could create a DTM... but why, when it'd have to be permanantly empty?
  1229. throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
  1230. }
  1231. /** Ask whether we support a given DOM feature.
  1232. *
  1233. * In fact, we do not _fully_ support any DOM feature -- we're a
  1234. * read-only subset -- so arguably we should always return false.
  1235. * On the other hand, it may be more practically useful to return
  1236. * true and simply treat the whole DOM as read-only, failing on the
  1237. * methods we can't support. I'm not sure which would be more useful
  1238. * to the caller.
  1239. */
  1240. public boolean hasFeature(String feature,String version)
  1241. {
  1242. if( ("CORE".equals(feature.toUpperCase()) || "XML".equals(feature.toUpperCase()))
  1243. &&
  1244. ("1.0".equals(version) || "2.0".equals(version))
  1245. )
  1246. return true;
  1247. return false;
  1248. }
  1249. }
  1250. }