001: /*
002: * $Id: StartDocumentEvent.java,v 1.2 2006/04/01 06:01:35 jeffsuttor Exp $
003: */
004:
005: /*
006: * The contents of this file are subject to the terms
007: * of the Common Development and Distribution License
008: * (the License). You may not use this file except in
009: * compliance with the License.
010: *
011: * You can obtain a copy of the license at
012: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
013: * See the License for the specific language governing
014: * permissions and limitations under the License.
015: *
016: * When distributing Covered Code, include this CDDL
017: * Header Notice in each file and include the License file
018: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
019: * If applicable, add the following below the CDDL Header,
020: * with the fields enclosed by brackets [] replaced by
021: * you own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * [Name of File] [ver.__] [Date]
025: *
026: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
027: */
028:
029: package com.sun.xml.stream.events;
030:
031: import javax.xml.stream.events.StartDocument;
032: import javax.xml.stream.Location;
033: import javax.xml.stream.XMLStreamConstants;
034:
035: /** Implementation of StartDocumentEvent.
036: *
037: * @author Neeraj Bajaj Sun Microsystems,Inc.
038: * @author K.Venugopal Sun Microsystems,Inc.
039: *
040: */
041:
042: public class StartDocumentEvent extends DummyEvent implements
043: StartDocument {
044:
045: protected String fSystemId;
046: protected String fEncodingScheam;
047: protected boolean fStandalone;
048: protected String fVersion;
049: private boolean fEncodingSchemeSet;
050: private boolean fStandaloneSet;
051:
052: public StartDocumentEvent() {
053: this ("UTF-8", "1.0", true, null);
054: }
055:
056: public StartDocumentEvent(String encoding) {
057: this (encoding, "1.0", true, null);
058: }
059:
060: public StartDocumentEvent(String encoding, String version) {
061: this (encoding, version, true, null);
062: }
063:
064: public StartDocumentEvent(String encoding, String version,
065: boolean standalone) {
066: this (encoding, version, standalone, null);
067: }
068:
069: public StartDocumentEvent(String encoding, String version,
070: boolean standalone, Location loc) {
071: init();
072: this .fEncodingScheam = encoding;
073: this .fVersion = version;
074: this .fStandalone = standalone;
075: this .fEncodingSchemeSet = false;
076: this .fStandaloneSet = false;
077: this .fLocation = loc;
078: }
079:
080: protected void init() {
081: setEventType(XMLStreamConstants.START_DOCUMENT);
082: }
083:
084: public String getSystemId() {
085: if (fLocation == null)
086: return "";
087: else
088: return fLocation.getSystemId();
089: }
090:
091: public String getCharacterEncodingScheme() {
092: return fEncodingScheam;
093: }
094:
095: public boolean isStandalone() {
096: return fStandalone;
097: }
098:
099: public String getVersion() {
100: return fVersion;
101: }
102:
103: public void setStandalone(boolean flag) {
104: fStandaloneSet = true;
105: fStandalone = flag;
106: }
107:
108: public void setStandalone(String s) {
109: fStandaloneSet = true;
110: if (s == null) {
111: fStandalone = true;
112: return;
113: }
114: if (s.equals("yes"))
115: fStandalone = true;
116: else
117: fStandalone = false;
118: }
119:
120: public boolean encodingSet() {
121: return fEncodingSchemeSet;
122: }
123:
124: public boolean standaloneSet() {
125: return fStandaloneSet;
126: }
127:
128: public void setEncoding(String encoding) {
129: fEncodingScheam = encoding;
130: }
131:
132: void setDeclaredEncoding(boolean value) {
133: fEncodingSchemeSet = value;
134: }
135:
136: public void setVersion(String s) {
137: fVersion = s;
138: }
139:
140: void clear() {
141: fEncodingScheam = "UTF-8";
142: fStandalone = true;
143: fVersion = "1.0";
144: fEncodingSchemeSet = false;
145: fStandaloneSet = false;
146: }
147:
148: public String toString() {
149: String s = "<?xml version=\"" + fVersion + "\"";
150: s = s + " encoding='" + fEncodingScheam + "'";
151: if (fStandaloneSet) {
152: if (fStandalone)
153: s = s + " standalone='yes'?>";
154: else
155: s = s + " standalone='no'?>";
156: } else {
157: s = s + "?>";
158: }
159: return s;
160: }
161:
162: public boolean isStartDocument() {
163: return true;
164: }
165: }
|