001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.xml;
030:
031: import org.w3c.dom.Entity;
032: import org.w3c.dom.Node;
033:
034: import java.io.IOException;
035:
036: class QEntity extends QNode implements Entity {
037: String _name;
038: String _value;
039: String _publicId;
040: String _systemId;
041: String _ndata;
042: boolean _isPe;
043: boolean _isSpecial;
044:
045: QEntity(String name, String value) {
046: _name = name;
047: _value = value;
048: _isSpecial = true;
049: if (value != null)
050: _firstChild = new QText(value);
051: }
052:
053: QEntity(String name, String value, String publicId, String systemId) {
054: _name = name;
055: _value = value;
056: _systemId = systemId;
057: _publicId = publicId;
058: if (value != null)
059: _firstChild = new QText(value);
060: }
061:
062: public String getNodeName() {
063: return _name;
064: }
065:
066: public String getTagName() {
067: return _name;
068: }
069:
070: public short getNodeType() {
071: return Node.ENTITY_NODE;
072: }
073:
074: public String getPublicId() {
075: return _publicId;
076: }
077:
078: public void setPublicId(String arg) {
079: _publicId = arg;
080: }
081:
082: public String getSystemId() {
083: return _systemId;
084: }
085:
086: public void setSystemId(String arg) {
087: _systemId = arg;
088: }
089:
090: public String getValue() {
091: return _value;
092: }
093:
094: public void setValue(String arg) {
095: _value = arg;
096: }
097:
098: public String getNotationName() {
099: return _ndata;
100: }
101:
102: public void setNotationName(String arg) {
103: _ndata = arg;
104: }
105:
106: Node importNode(QDocument owner, boolean deep) {
107: QEntity entity = new QEntity(_name, _value, _publicId,
108: _systemId);
109:
110: return entity;
111: }
112:
113: // DOM LEVEL 3
114:
115: public String getActualEncoding() {
116: throw new UnsupportedOperationException();
117: }
118:
119: public void setActualEncoding(String actualEncoding) {
120: throw new UnsupportedOperationException();
121: }
122:
123: public String getEncoding() {
124: throw new UnsupportedOperationException();
125: }
126:
127: public void setEncoding(String encoding) {
128: throw new UnsupportedOperationException();
129: }
130:
131: public String getVersion() {
132: throw new UnsupportedOperationException();
133: }
134:
135: public String getXmlVersion() {
136: throw new UnsupportedOperationException();
137: }
138:
139: public String getXmlEncoding() {
140: throw new UnsupportedOperationException();
141: }
142:
143: public String getInputEncoding() {
144: throw new UnsupportedOperationException();
145: }
146:
147: public void setVersion(String version) {
148: throw new UnsupportedOperationException();
149: }
150:
151: void print(XmlPrinter out) throws IOException {
152: out.print("<!ENTITY ");
153: if (_isPe)
154: out.print("% ");
155: out.print(_name);
156: if (_publicId != null) {
157: out.print(" PUBLIC \"");
158: out.printDecl(_publicId);
159: out.print("\"");
160: if (_systemId != null) {
161: out.print(" \"");
162: out.printDecl(_systemId);
163: out.print("\"");
164: }
165:
166: if (_ndata != null) {
167: out.print(" NDATA ");
168: out.printDecl(_ndata);
169: }
170: } else if (_systemId != null) {
171: out.print(" SYSTEM \"");
172: out.printDecl(_systemId);
173: out.print("\"");
174:
175: if (_ndata != null) {
176: out.print(" NDATA ");
177: out.printDecl(_ndata);
178: }
179: } else if (_value != null) {
180: out.print(" \"");
181: out.printDecl(_value);
182: out.print("\"");
183: }
184: out.println(">");
185: }
186:
187: public String toString() {
188: if (_systemId != null)
189: return "QEntity[" + _name + " SYSTEM \"" + _systemId
190: + "\"]";
191: else
192: return "QEntity[" + _name + " \"" + _value + "\"]";
193: }
194: }
|