001: /*
002: * $Id: StartDocumentEvent.java,v 1.2 2004/07/15 02:11:01 cniles Exp $
003: *
004: * Copyright (c) 2004, Christian Niles, unit12.net
005: * All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions are met:
009: *
010: * * Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * * Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: *
017: * * Neither the name of Christian Niles, Unit12, nor the names of its
018: * contributors may be used to endorse or promote products derived from
019: * this software without specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
022: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
023: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
024: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
025: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
026: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
027: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
028: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
029: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
030: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
031: * POSSIBILITY OF SUCH DAMAGE.
032: *
033: */
034: package javanet.staxutils.events;
035:
036: import javax.xml.namespace.QName;
037: import javax.xml.stream.Location;
038: import javax.xml.stream.events.StartDocument;
039:
040: /**
041: * {@link StartDocument} implementation.
042: *
043: * @author Christian Niles
044: * @version $Revision: 1.2 $
045: */
046: public class StartDocumentEvent extends AbstractXMLEvent implements
047: StartDocument {
048:
049: /** Default XML version returned by {@link #getVersion()}. */
050: public static final String DEFAULT_VERSION = "1.0";
051:
052: /** Default system id returned by {@link #getSystemId()}. */
053: public static final String DEFAULT_SYSTEM_ID = "";
054:
055: /** Default encoding returned by {@link #getCharacterEncodingScheme()}. */
056: public static final String DEFAULT_ENCODING = "UTF-8";
057:
058: /** The document encoding, or <code>null</code> if none was specified. */
059: protected String encoding;
060:
061: /** The document standalone value, or <code>null</code> if none was specified. */
062: protected Boolean standalone;
063:
064: /** The XML version, or <code>null</code> if none was specified. */
065: protected String version;
066:
067: public StartDocumentEvent() {
068:
069: }
070:
071: public StartDocumentEvent(Location location) {
072:
073: super (location);
074:
075: }
076:
077: public StartDocumentEvent(String encoding, Location location) {
078:
079: super (location);
080: this .encoding = encoding;
081:
082: }
083:
084: public StartDocumentEvent(String encoding, Boolean standalone,
085: String version, Location location) {
086:
087: super (location);
088: this .encoding = encoding;
089: this .standalone = standalone;
090: this .version = version;
091:
092: }
093:
094: public StartDocumentEvent(String encoding, Boolean standalone,
095: String version, Location location, QName schemaType) {
096:
097: super (location, schemaType);
098: this .encoding = encoding;
099: this .standalone = standalone;
100: this .version = version;
101:
102: }
103:
104: /**
105: * Copy constructor.
106: *
107: * @param that The {@link StartDocument} event to copy.
108: */
109: public StartDocumentEvent(StartDocument that) {
110:
111: super (that);
112:
113: // copy encoding
114: if (that.encodingSet()) {
115:
116: this .encoding = that.getCharacterEncodingScheme();
117:
118: }
119:
120: // copy standalone
121: if (standaloneSet()) {
122:
123: this .standalone = that.isStandalone() ? Boolean.TRUE
124: : Boolean.FALSE;
125:
126: }
127:
128: this .version = DEFAULT_VERSION.equals(that.getVersion()) ? null
129: : that.getVersion();
130:
131: }
132:
133: /** Returns {@link #START_DOCUMENT}. */
134: public int getEventType() {
135:
136: return START_DOCUMENT;
137:
138: }
139:
140: public boolean encodingSet() {
141:
142: return encoding != null;
143:
144: }
145:
146: public String getCharacterEncodingScheme() {
147:
148: return (encoding == null ? DEFAULT_ENCODING : encoding);
149:
150: }
151:
152: public String getSystemId() {
153:
154: Location location = getLocation();
155: if (location != null) {
156:
157: String systemId = location.getSystemId();
158: if (systemId != null) {
159:
160: return systemId;
161:
162: }
163:
164: }
165:
166: return DEFAULT_SYSTEM_ID;
167:
168: }
169:
170: public String getVersion() {
171:
172: return (version == null ? DEFAULT_VERSION : version);
173:
174: }
175:
176: public boolean isStandalone() {
177:
178: return (standalone == null ? false : standalone.booleanValue());
179:
180: }
181:
182: public boolean standaloneSet() {
183:
184: return standalone != null;
185:
186: }
187:
188: }
|