001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.dom;
019:
020: import org.w3c.dom.Entity;
021: import org.w3c.dom.Node;
022:
023: /**
024: * Entity nodes hold the reference data for an XML Entity -- either
025: * parsed or unparsed. The nodeName (inherited from Node) will contain
026: * the name (if any) of the Entity. Its data will be contained in the
027: * Entity's children, in exactly the structure which an
028: * EntityReference to this name will present within the document's
029: * body.
030: * <P>
031: * Note that this object models the actual entity, _not_ the entity
032: * declaration or the entity reference.
033: * <P>
034: * An XML processor may choose to completely expand entities before
035: * the structure model is passed to the DOM; in this case, there will
036: * be no EntityReferences in the DOM tree.
037: * <P>
038: * Quoting the 10/01 DOM Proposal,
039: * <BLOCKQUOTE>
040: * "The DOM Level 1 does not support editing Entity nodes; if a user
041: * wants to make changes to the contents of an Entity, every related
042: * EntityReference node has to be replaced in the structure model by
043: * a clone of the Entity's contents, and then the desired changes
044: * must be made to each of those clones instead. All the
045: * descendants of an Entity node are readonly."
046: * </BLOCKQUOTE>
047: * I'm interpreting this as: It is the parser's responsibilty to call
048: * the non-DOM operation setReadOnly(true,true) after it constructs
049: * the Entity. Since the DOM explicitly decided not to deal with this,
050: * _any_ answer will involve a non-DOM operation, and this is the
051: * simplest solution.
052: *
053: * @xerces.internal
054: *
055: * @author Elena Litani, IBM
056: * @version $Id: EntityImpl.java 447266 2006-09-18 05:57:49Z mrglavas $
057: * @since PR-DOM-Level-1-19980818.
058: */
059: public class EntityImpl extends ParentNode implements Entity {
060:
061: //
062: // Constants
063: //
064:
065: /** Serialization version. */
066: static final long serialVersionUID = -3575760943444303423L;
067:
068: //
069: // Data
070: //
071:
072: /** Entity name. */
073: protected String name;
074:
075: /** Public identifier. */
076: protected String publicId;
077:
078: /** System identifier. */
079: protected String systemId;
080:
081: /** Encoding */
082: protected String encoding;
083:
084: /** Input Encoding */
085: protected String inputEncoding;
086:
087: /** Version */
088: protected String version;
089:
090: /** Notation name. */
091: protected String notationName;
092:
093: /** base uri*/
094: protected String baseURI;
095:
096: //
097: // Constructors
098: //
099:
100: /** Factory constructor. */
101: public EntityImpl(CoreDocumentImpl ownerDoc, String name) {
102: super (ownerDoc);
103: this .name = name;
104: isReadOnly(true);
105: }
106:
107: //
108: // Node methods
109: //
110:
111: /**
112: * A short integer indicating what type of node this is. The named
113: * constants for this value are defined in the org.w3c.dom.Node interface.
114: */
115: public short getNodeType() {
116: return Node.ENTITY_NODE;
117: }
118:
119: /**
120: * Returns the entity name
121: */
122: public String getNodeName() {
123: if (needsSyncData()) {
124: synchronizeData();
125: }
126: return name;
127: }
128:
129: /** Clone node. */
130: public Node cloneNode(boolean deep) {
131: EntityImpl newentity = (EntityImpl) super .cloneNode(deep);
132: newentity.setReadOnly(true, deep);
133: return newentity;
134: }
135:
136: //
137: // Entity methods
138: //
139:
140: /**
141: * The public identifier associated with the entity. If not specified,
142: * this will be null.
143: */
144: public String getPublicId() {
145:
146: if (needsSyncData()) {
147: synchronizeData();
148: }
149: return publicId;
150:
151: } // getPublicId():String
152:
153: /**
154: * The system identifier associated with the entity. If not specified,
155: * this will be null.
156: */
157: public String getSystemId() {
158:
159: if (needsSyncData()) {
160: synchronizeData();
161: }
162: return systemId;
163:
164: } // getSystemId():String
165:
166: /**
167: * DOM Level 3 WD - experimental
168: * the version number of this entity, when it is an external parsed entity.
169: */
170: public String getXmlVersion() {
171:
172: if (needsSyncData()) {
173: synchronizeData();
174: }
175: return version;
176:
177: } // getVersion():String
178:
179: /**
180: * DOM Level 3 WD - experimental
181: * the encoding of this entity, when it is an external parsed entity.
182: */
183: public String getXmlEncoding() {
184:
185: if (needsSyncData()) {
186: synchronizeData();
187: }
188:
189: return encoding;
190:
191: } // getVersion():String
192:
193: /**
194: * Unparsed entities -- which contain non-XML data -- have a
195: * "notation name" which tells applications how to deal with them.
196: * Parsed entities, which <em>are</em> in XML format, don't need this and
197: * set it to null.
198: */
199: public String getNotationName() {
200:
201: if (needsSyncData()) {
202: synchronizeData();
203: }
204: return notationName;
205:
206: } // getNotationName():String
207:
208: //
209: // Public methods
210: //
211:
212: /**
213: * DOM Level 2: The public identifier associated with the entity. If not specified,
214: * this will be null. */
215: public void setPublicId(String id) {
216:
217: if (needsSyncData()) {
218: synchronizeData();
219: }
220: publicId = id;
221:
222: } // setPublicId(String)
223:
224: /**
225: * NON-DOM
226: * encoding - An attribute specifying, as part of the text declaration,
227: * the encoding of this entity, when it is an external parsed entity.
228: * This is null otherwise
229: *
230: */
231: public void setXmlEncoding(String value) {
232: if (needsSyncData()) {
233: synchronizeData();
234: }
235: encoding = value;
236: } // setEncoding (String)
237:
238: /**
239: * An attribute specifying the encoding used for this entity at the tiome
240: * of parsing, when it is an external parsed entity. This is
241: * <code>null</code> if it an entity from the internal subset or if it
242: * is not known..
243: * @since DOM Level 3
244: */
245: public String getInputEncoding() {
246: if (needsSyncData()) {
247: synchronizeData();
248: }
249: return inputEncoding;
250: }
251:
252: /**
253: * NON-DOM, used to set the input encoding.
254: */
255: public void setInputEncoding(String inputEncoding) {
256: if (needsSyncData()) {
257: synchronizeData();
258: }
259: this .inputEncoding = inputEncoding;
260: }
261:
262: /**
263: * NON-DOM
264: * version - An attribute specifying, as part of the text declaration,
265: * the version number of this entity, when it is an external parsed entity.
266: * This is null otherwise
267: */
268: public void setXmlVersion(String value) {
269: if (needsSyncData()) {
270: synchronizeData();
271: }
272: version = value;
273: } // setVersion (String)
274:
275: /**
276: * DOM Level 2: The system identifier associated with the entity. If not
277: * specified, this will be null.
278: */
279: public void setSystemId(String id) {
280: if (needsSyncData()) {
281: synchronizeData();
282: }
283: systemId = id;
284:
285: } // setSystemId(String)
286:
287: /**
288: * DOM Level 2: Unparsed entities -- which contain non-XML data -- have a
289: * "notation name" which tells applications how to deal with them.
290: * Parsed entities, which <em>are</em> in XML format, don't need this and
291: * set it to null.
292: */
293: public void setNotationName(String name) {
294: if (needsSyncData()) {
295: synchronizeData();
296: }
297: notationName = name;
298:
299: } // setNotationName(String)
300:
301: /**
302: * Returns the absolute base URI of this node or null if the implementation
303: * wasn't able to obtain an absolute URI. Note: If the URI is malformed, a
304: * null is returned.
305: *
306: * @return The absolute base URI of this node or null.
307: * @since DOM Level 3
308: */
309: public String getBaseURI() {
310:
311: if (needsSyncData()) {
312: synchronizeData();
313: }
314: return (baseURI != null) ? baseURI
315: : ((CoreDocumentImpl) getOwnerDocument()).getBaseURI();
316: }
317:
318: /** NON-DOM: set base uri*/
319: public void setBaseURI(String uri) {
320: if (needsSyncData()) {
321: synchronizeData();
322: }
323: baseURI = uri;
324: }
325:
326: } // class EntityImpl
|