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.apache.xerces.util.URI;
021: import org.w3c.dom.DOMException;
022: import org.w3c.dom.Node;
023: import org.w3c.dom.Notation;
024:
025: /**
026: * Notations are how the Document Type Description (DTD) records hints
027: * about the format of an XML "unparsed entity" -- in other words,
028: * non-XML data bound to this document type, which some applications
029: * may wish to consult when manipulating the document. A Notation
030: * represents a name-value pair, with its nodeName being set to the
031: * declared name of the notation.
032: * <P>
033: * Notations are also used to formally declare the "targets" of
034: * Processing Instructions.
035: * <P>
036: * Note that the Notation's data is non-DOM information; the DOM only
037: * records what and where it is.
038: * <P>
039: * See the XML 1.0 spec, sections 4.7 and 2.6, for more info.
040: * <P>
041: * Level 1 of the DOM does not support editing Notation contents.
042: *
043: * @xerces.internal
044: *
045: * @version $Id: NotationImpl.java 447266 2006-09-18 05:57:49Z mrglavas $
046: * @since PR-DOM-Level-1-19980818.
047: */
048: public class NotationImpl extends NodeImpl implements Notation {
049:
050: //
051: // Constants
052: //
053:
054: /** Serialization version. */
055: static final long serialVersionUID = -764632195890658402L;
056:
057: //
058: // Data
059: //
060:
061: /** Notation name. */
062: protected String name;
063:
064: /** Public identifier. */
065: protected String publicId;
066:
067: /** System identifier. */
068: protected String systemId;
069:
070: /** Base URI*/
071: protected String baseURI;
072:
073: //
074: // Constructors
075: //
076:
077: /** Factory constructor. */
078: public NotationImpl(CoreDocumentImpl ownerDoc, String name) {
079: super (ownerDoc);
080: this .name = name;
081: }
082:
083: //
084: // Node methods
085: //
086:
087: /**
088: * A short integer indicating what type of node this is. The named
089: * constants for this value are defined in the org.w3c.dom.Node interface.
090: */
091: public short getNodeType() {
092: return Node.NOTATION_NODE;
093: }
094:
095: /**
096: * Returns the notation name
097: */
098: public String getNodeName() {
099: if (needsSyncData()) {
100: synchronizeData();
101: }
102: return name;
103: }
104:
105: //
106: // Notation methods
107: //
108:
109: /**
110: * The Public Identifier for this Notation. If no public identifier
111: * was specified, this will be null.
112: */
113: public String getPublicId() {
114:
115: if (needsSyncData()) {
116: synchronizeData();
117: }
118: return publicId;
119:
120: } // getPublicId():String
121:
122: /**
123: * The System Identifier for this Notation. If no system identifier
124: * was specified, this will be null.
125: */
126: public String getSystemId() {
127:
128: if (needsSyncData()) {
129: synchronizeData();
130: }
131: return systemId;
132:
133: } // getSystemId():String
134:
135: //
136: // Public methods
137: //
138:
139: /**
140: * NON-DOM: The Public Identifier for this Notation. If no public
141: * identifier was specified, this will be null.
142: */
143: public void setPublicId(String id) {
144:
145: if (isReadOnly()) {
146: throw new DOMException(
147: DOMException.NO_MODIFICATION_ALLOWED_ERR,
148: DOMMessageFormatter.formatMessage(
149: DOMMessageFormatter.DOM_DOMAIN,
150: "NO_MODIFICATION_ALLOWED_ERR", null));
151: }
152: if (needsSyncData()) {
153: synchronizeData();
154: }
155: publicId = id;
156:
157: } // setPublicId(String)
158:
159: /**
160: * NON-DOM: The System Identifier for this Notation. If no system
161: * identifier was specified, this will be null.
162: */
163: public void setSystemId(String id) {
164:
165: if (isReadOnly()) {
166: throw new DOMException(
167: DOMException.NO_MODIFICATION_ALLOWED_ERR,
168: DOMMessageFormatter.formatMessage(
169: DOMMessageFormatter.DOM_DOMAIN,
170: "NO_MODIFICATION_ALLOWED_ERR", null));
171: }
172: if (needsSyncData()) {
173: synchronizeData();
174: }
175: systemId = id;
176:
177: } // setSystemId(String)
178:
179: /**
180: * Returns the absolute base URI of this node or null if the implementation
181: * wasn't able to obtain an absolute URI. Note: If the URI is malformed, a
182: * null is returned.
183: *
184: * @return The absolute base URI of this node or null.
185: * @since DOM Level 3
186: */
187: public String getBaseURI() {
188: if (needsSyncData()) {
189: synchronizeData();
190: }
191: if (baseURI != null && baseURI.length() != 0) {// attribute value is always empty string
192: try {
193: return new URI(baseURI).toString();
194: } catch (org.apache.xerces.util.URI.MalformedURIException e) {
195: // REVISIT: what should happen in this case?
196: return null;
197: }
198: }
199: return baseURI;
200: }
201:
202: /** NON-DOM: set base uri*/
203: public void setBaseURI(String uri) {
204: if (needsSyncData()) {
205: synchronizeData();
206: }
207: baseURI = uri;
208: }
209:
210: } // class NotationImpl
|