1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999-2002 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 "Xerces" 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, International
  53. * Business Machines, Inc., http://www.apache.org. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package com.sun.org.apache.xerces.internal.dom;
  58. import org.w3c.dom.Entity;
  59. import org.w3c.dom.Node;
  60. /**
  61. * Entity nodes hold the reference data for an XML Entity -- either
  62. * parsed or unparsed. The nodeName (inherited from Node) will contain
  63. * the name (if any) of the Entity. Its data will be contained in the
  64. * Entity's children, in exactly the structure which an
  65. * EntityReference to this name will present within the document's
  66. * body.
  67. * <P>
  68. * Note that this object models the actual entity, _not_ the entity
  69. * declaration or the entity reference.
  70. * <P>
  71. * An XML processor may choose to completely expand entities before
  72. * the structure model is passed to the DOM; in this case, there will
  73. * be no EntityReferences in the DOM tree.
  74. * <P>
  75. * Quoting the 10/01 DOM Proposal,
  76. * <BLOCKQUOTE>
  77. * "The DOM Level 1 does not support editing Entity nodes; if a user
  78. * wants to make changes to the contents of an Entity, every related
  79. * EntityReference node has to be replaced in the structure model by
  80. * a clone of the Entity's contents, and then the desired changes
  81. * must be made to each of those clones instead. All the
  82. * descendants of an Entity node are readonly."
  83. * </BLOCKQUOTE>
  84. * I'm interpreting this as: It is the parser's responsibilty to call
  85. * the non-DOM operation setReadOnly(true,true) after it constructs
  86. * the Entity. Since the DOM explicitly decided not to deal with this,
  87. * _any_ answer will involve a non-DOM operation, and this is the
  88. * simplest solution.
  89. *
  90. * @author Elena Litani, IBM
  91. * @version $Id: EntityImpl.java,v 1.23 2003/11/13 22:47:15 elena Exp $
  92. * @since PR-DOM-Level-1-19980818.
  93. */
  94. public class EntityImpl
  95. extends ParentNode
  96. implements Entity {
  97. //
  98. // Constants
  99. //
  100. /** Serialization version. */
  101. static final long serialVersionUID = -3575760943444303423L;
  102. //
  103. // Data
  104. //
  105. /** Entity name. */
  106. protected String name;
  107. /** Public identifier. */
  108. protected String publicId;
  109. /** System identifier. */
  110. protected String systemId;
  111. /** Encoding */
  112. protected String encoding;
  113. /** Input Encoding */
  114. protected String inputEncoding;
  115. /** Version */
  116. protected String version;
  117. /** Notation name. */
  118. protected String notationName;
  119. /** base uri*/
  120. protected String baseURI;
  121. //
  122. // Constructors
  123. //
  124. /** Factory constructor. */
  125. public EntityImpl(CoreDocumentImpl ownerDoc, String name) {
  126. super(ownerDoc);
  127. this.name = name;
  128. isReadOnly(true);
  129. }
  130. //
  131. // Node methods
  132. //
  133. /**
  134. * A short integer indicating what type of node this is. The named
  135. * constants for this value are defined in the org.w3c.dom.Node interface.
  136. */
  137. public short getNodeType() {
  138. return Node.ENTITY_NODE;
  139. }
  140. /**
  141. * Returns the entity name
  142. */
  143. public String getNodeName() {
  144. if (needsSyncData()) {
  145. synchronizeData();
  146. }
  147. return name;
  148. }
  149. /** Clone node. */
  150. public Node cloneNode(boolean deep) {
  151. EntityImpl newentity = (EntityImpl)super.cloneNode(deep);
  152. newentity.setReadOnly(true, deep);
  153. return newentity;
  154. }
  155. //
  156. // Entity methods
  157. //
  158. /**
  159. * The public identifier associated with the entity. If not specified,
  160. * this will be null.
  161. */
  162. public String getPublicId() {
  163. if (needsSyncData()) {
  164. synchronizeData();
  165. }
  166. return publicId;
  167. } // getPublicId():String
  168. /**
  169. * The system identifier associated with the entity. If not specified,
  170. * this will be null.
  171. */
  172. public String getSystemId() {
  173. if (needsSyncData()) {
  174. synchronizeData();
  175. }
  176. return systemId;
  177. } // getSystemId():String
  178. /**
  179. * DOM Level 3 WD - experimental
  180. * the version number of this entity, when it is an external parsed entity.
  181. */
  182. public String getXmlVersion() {
  183. if (needsSyncData()) {
  184. synchronizeData();
  185. }
  186. return version;
  187. } // getVersion():String
  188. /**
  189. * DOM Level 3 WD - experimental
  190. * the encoding of this entity, when it is an external parsed entity.
  191. */
  192. public String getXmlEncoding() {
  193. if (needsSyncData()) {
  194. synchronizeData();
  195. }
  196. return encoding;
  197. } // getVersion():String
  198. /**
  199. * Unparsed entities -- which contain non-XML data -- have a
  200. * "notation name" which tells applications how to deal with them.
  201. * Parsed entities, which <em>are</em> in XML format, don't need this and
  202. * set it to null.
  203. */
  204. public String getNotationName() {
  205. if (needsSyncData()) {
  206. synchronizeData();
  207. }
  208. return notationName;
  209. } // getNotationName():String
  210. //
  211. // Public methods
  212. //
  213. /**
  214. * DOM Level 2: The public identifier associated with the entity. If not specified,
  215. * this will be null. */
  216. public void setPublicId(String id) {
  217. if (needsSyncData()) {
  218. synchronizeData();
  219. }
  220. publicId = id;
  221. } // setPublicId(String)
  222. /**
  223. * NON-DOM
  224. * encoding - An attribute specifying, as part of the text declaration,
  225. * the encoding of this entity, when it is an external parsed entity.
  226. * This is null otherwise
  227. *
  228. */
  229. public void setXmlEncoding(String value) {
  230. if (needsSyncData()) {
  231. synchronizeData();
  232. }
  233. encoding = value;
  234. } // setEncoding (String)
  235. /**
  236. * An attribute specifying the encoding used for this entity at the tiome
  237. * of parsing, when it is an external parsed entity. This is
  238. * <code>null</code> if it an entity from the internal subset or if it
  239. * is not known..
  240. * @since DOM Level 3
  241. */
  242. public String getInputEncoding(){
  243. if (needsSyncData()) {
  244. synchronizeData();
  245. }
  246. return inputEncoding;
  247. }
  248. /**
  249. * NON-DOM, used to set the input encoding.
  250. */
  251. public void setInputEncoding(String inputEncoding){
  252. if (needsSyncData()) {
  253. synchronizeData();
  254. }
  255. this.inputEncoding = inputEncoding;
  256. }
  257. /**
  258. * NON-DOM
  259. * version - An attribute specifying, as part of the text declaration,
  260. * the version number of this entity, when it is an external parsed entity.
  261. * This is null otherwise
  262. */
  263. public void setXmlVersion(String value) {
  264. if (needsSyncData()) {
  265. synchronizeData();
  266. }
  267. version = value;
  268. } // setVersion (String)
  269. /**
  270. * DOM Level 2: The system identifier associated with the entity. If not
  271. * specified, this will be null.
  272. */
  273. public void setSystemId(String id) {
  274. if (needsSyncData()) {
  275. synchronizeData();
  276. }
  277. systemId = id;
  278. } // setSystemId(String)
  279. /**
  280. * DOM Level 2: Unparsed entities -- which contain non-XML data -- have a
  281. * "notation name" which tells applications how to deal with them.
  282. * Parsed entities, which <em>are</em> in XML format, don't need this and
  283. * set it to null.
  284. */
  285. public void setNotationName(String name) {
  286. if (needsSyncData()) {
  287. synchronizeData();
  288. }
  289. notationName = name;
  290. } // setNotationName(String)
  291. /**
  292. * DOM Level 3 WD - Experimental.
  293. * Retrieve baseURI
  294. */
  295. public String getBaseURI() {
  296. if (needsSyncData()) {
  297. synchronizeData();
  298. }
  299. return (baseURI!=null)?baseURI:((CoreDocumentImpl)getOwnerDocument()).getBaseURI();
  300. }
  301. /** NON-DOM: set base uri*/
  302. public void setBaseURI(String uri){
  303. if (needsSyncData()) {
  304. synchronizeData();
  305. }
  306. baseURI = uri;
  307. }
  308. } // class EntityImpl