001: /* DocType.java
002:
003: {{IS_NOTE
004:
005: Purpose:
006: Description:
007: History:
008: 2001/10/22 16:12:44, Create, Tom M. Yeh.
009: }}IS_NOTE
010:
011: Copyright (C) 2001 Potix Corporation. All Rights Reserved.
012:
013: {{IS_RIGHT
014: This program is distributed under GPL Version 2.0 in the hope that
015: it will be useful, but WITHOUT ANY WARRANTY.
016: }}IS_RIGHT
017: */
018: package org.zkoss.idom;
019:
020: import org.w3c.dom.NamedNodeMap;
021: import org.w3c.dom.DocumentType;
022:
023: import org.zkoss.lang.Objects;
024: import org.zkoss.idom.impl.*;
025:
026: /**
027: * The iDOM DocType.
028: *
029: * @author tomyeh
030: * @see Document
031: */
032: public class DocType extends AbstractItem implements DocumentType {
033: /** The element being constrained */
034: protected String _name;
035: /** The public ID of the DOCTYPE */
036: protected String _pubId;
037: /** The system ID of the DOCTYPE */
038: protected String _sysId;
039: /** The internal subset of the DOCTYPE */
040: protected String _intSubset;
041:
042: /** Constructor.
043: *
044: * @param publicId the public Id; null or empty if not availabl
045: * @param systemId the system Id; null or empty if not availabl
046: */
047: public DocType(String elementName, String publicId, String systemId) {
048: setName(elementName);
049: setPublicId(publicId);
050: setSystemId(systemId);
051: }
052:
053: /** Constructor.
054: */
055: public DocType(String elementName, String systemId) {
056: setName(elementName);
057: _pubId = "";
058: setSystemId(systemId);
059: }
060:
061: /** Constructor.
062: */
063: public DocType(String elementName) {
064: this ();
065: setName(elementName);
066: _pubId = _sysId = "";
067: }
068:
069: /** Constructor.
070: */
071: protected DocType() {
072: _pubId = _sysId = "";
073: }
074:
075: //-- DocType extrs --//
076: /**
077: * Gets the public ID of an externally referenced DTD, or an empty
078: * String if none is referenced.
079: *
080: * @return the public ID of referenced DTD; never null
081: */
082: public final String getPublicId() {
083: return _pubId;
084: }
085:
086: /**
087: * Sets the public ID of an externally referenced DTD, or an empty
088: * String if none is referenced.
089: *
090: * @param publicId the public Id; null or empty if not availabl
091: */
092: public final void setPublicId(String publicId) {
093: checkWritable();
094:
095: if (publicId == null)
096: publicId = "";
097:
098: if (!Objects.equals(_pubId, publicId)) {
099: _pubId = publicId;
100: setModified();
101: }
102: }
103:
104: /**
105: * Gets the system ID of an externally referenced DTD, or an empty
106: * String if none is referenced.
107: *
108: * @return the system ID of referenced DTD; never null
109: */
110: public final String getSystemId() {
111: return _sysId;
112: }
113:
114: /**
115: * Sets the system ID of an externally referenced DTD, or an empty
116: * String if none is referenced.
117: *
118: * @param systemId the system Id; null or empty if not availabl
119: */
120: public final void setSystemId(String systemId) {
121: checkWritable();
122:
123: if (systemId == null)
124: systemId = "";
125:
126: if (!Objects.equals(_sysId, systemId)) {
127: _sysId = systemId;
128: setModified();
129: }
130: }
131:
132: /**
133: * Gets the data for the internal subset.
134: */
135: public final String getInternalSubset() {
136: return _intSubset;
137: }
138:
139: /**
140: * Sets the data for the internal subset.
141: */
142: public final void setInternalSubset(String newData) {
143: checkWritable();
144: if (!Objects.equals(_intSubset, newData)) {
145: _intSubset = newData;
146: setModified();
147: }
148: }
149:
150: //-- Item --//
151: /**
152: * Gets the element name being constrained. Never null.
153: */
154: public final String getName() {
155: return _name;
156: }
157:
158: public final void setName(String elementName) {
159: checkWritable();
160:
161: if (elementName == null)
162: elementName = "";
163:
164: if (!Objects.equals(_name, elementName)) {
165: //TY: we don't verify it here because it might contain colon
166: //Verifier.checkElementName(elementName, getLocator());
167: _name = elementName;
168: setModified();
169: }
170: }
171:
172: //-- Node --//
173: public final short getNodeType() {
174: return DOCUMENT_TYPE_NODE;
175: }
176:
177: //-- DocumentType --//
178: public final NamedNodeMap getEntities() {
179: throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
180: getLocator()); //NOT YET
181: }
182:
183: public final NamedNodeMap getNotations() {
184: throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
185: getLocator()); //NOT YET
186: }
187:
188: //-- Object --//
189: public String toString() {
190: StringBuffer sb = new StringBuffer(64).append("[DocType: ")
191: .append(_name);
192: if (_pubId.length() > 0)
193: sb.append(" PUBLIC ").append(_pubId);
194: if (_sysId.length() > 0)
195: sb.append(" SYSTEM ").append(_sysId);
196: return sb.append(']').toString();
197: }
198: }
|