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: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Emil Ong
028: */
029:
030: package com.caucho.xml.stream.events;
031:
032: import javax.xml.stream.XMLStreamException;
033: import javax.xml.stream.events.StartDocument;
034: import java.io.IOException;
035: import java.io.Writer;
036:
037: public class StartDocumentImpl extends XMLEventImpl implements
038: StartDocument {
039: private final boolean _encodingSet;
040: private final String _characterEncodingScheme;
041: private final String _systemId;
042: private final String _version;
043: private final boolean _isStandalone;
044: private final boolean _standaloneSet;
045:
046: public StartDocumentImpl() {
047: this (false, null, null, "1.0", false, false);
048: }
049:
050: public StartDocumentImpl(boolean encodingSet,
051: String characterEncodingScheme, String systemId,
052: String version, boolean isStandalone, boolean standaloneSet) {
053: _encodingSet = encodingSet;
054: _characterEncodingScheme = characterEncodingScheme;
055: _systemId = systemId;
056: _version = version;
057: _isStandalone = isStandalone;
058: _standaloneSet = standaloneSet;
059: }
060:
061: public boolean encodingSet() {
062: return _encodingSet;
063: }
064:
065: public String getCharacterEncodingScheme() {
066: return _characterEncodingScheme;
067: }
068:
069: public String getSystemId() {
070: return _systemId;
071: }
072:
073: public String getVersion() {
074: return _version;
075: }
076:
077: public boolean isStandalone() {
078: return _isStandalone;
079: }
080:
081: public boolean standaloneSet() {
082: return _standaloneSet;
083: }
084:
085: public int getEventType() {
086: return START_DOCUMENT;
087: }
088:
089: public void writeAsEncodedUnicode(Writer writer)
090: throws XMLStreamException {
091: try {
092: writer.write("<?xml version=\"" + _version + "\"");
093:
094: if (_encodingSet)
095: writer.write(" encoding=\"" + _characterEncodingScheme
096: + "\"");
097:
098: if (_standaloneSet)
099: writer.write(" standalone=\"" + _standaloneSet + "\"");
100:
101: writer.write("?>");
102:
103: // XXX system id?
104: } catch (IOException e) {
105: throw new XMLStreamException(e);
106: }
107: }
108:
109: public String toString() {
110: StringBuilder sb = new StringBuilder();
111:
112: sb.append("<?xml version=\"" + _version + "\"");
113:
114: if (_encodingSet)
115: sb.append(" encoding=\"" + _characterEncodingScheme + "\"");
116:
117: if (_standaloneSet)
118: sb.append(" standalone=\"" + _standaloneSet + "\"");
119:
120: sb.append("?>");
121:
122: return sb.toString();
123: }
124:
125: public boolean equals(Object o) {
126: if (!(o instanceof StartDocument))
127: return false;
128: if (o == null)
129: return false;
130: if (this == o)
131: return true;
132:
133: StartDocument start = (StartDocument) o;
134:
135: if (getCharacterEncodingScheme() != null) {
136: if (!getCharacterEncodingScheme().equals(
137: start.getCharacterEncodingScheme()))
138: return false;
139: } else if (start.getCharacterEncodingScheme() != null)
140: return false;
141:
142: if (getSystemId() != null) {
143: if (!getSystemId().equals(start.getSystemId()))
144: return false;
145: } else if (start.getSystemId() != null)
146: return false;
147:
148: if (getVersion() != null) {
149: if (!getVersion().equals(start.getVersion()))
150: return false;
151: } else if (start.getVersion() != null)
152: return false;
153:
154: return encodingSet() == start.encodingSet()
155: && isStandalone() == start.isStandalone()
156: && standaloneSet() == start.standaloneSet();
157: }
158: }
|