KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > xml > fastinfoset > stax > events > StartDocumentEvent


1 /*
2  * Fast Infoset ver. 0.1 software ("Software")
3  *
4  * Copyright, 2004-2005 Sun Microsystems, Inc. All Rights Reserved.
5  *
6  * Software is licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License. You may
8  * obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations.
16  *
17  * Sun supports and benefits from the global community of open source
18  * developers, and thanks the community for its important contributions and
19  * open standards-based technology, which Sun has adopted into many of its
20  * products.
21  *
22  * Please note that portions of Software may be provided with notices and
23  * open source licenses from such communities and third parties that govern the
24  * use of those portions, and any licenses granted hereunder do not alter any
25  * rights and obligations you may have under such open source licenses,
26  * however, the disclaimer of warranty and limitation of liability provisions
27  * in this License will apply to all Software in this distribution.
28  *
29  * You acknowledge that the Software is not designed, licensed or intended
30  * for use in the design, construction, operation or maintenance of any nuclear
31  * facility.
32  *
33  * Apache License
34  * Version 2.0, January 2004
35  * http://www.apache.org/licenses/
36  *
37  */

38
39 package com.sun.xml.fastinfoset.stax.events ;
40
41 import javax.xml.stream.events.StartDocument;
42 import javax.xml.stream.Location;
43 import javax.xml.stream.XMLStreamConstants;
44 import com.sun.xml.fastinfoset.util.XMLConstants;
45
46 public class StartDocumentEvent extends EventBase implements StartDocument {
47     
48     protected String JavaDoc _systemId;
49     protected String JavaDoc _encoding = XMLConstants.ENCODING; //default
50
protected boolean _standalone = true;
51     protected String JavaDoc _version = XMLConstants.XMLVERSION;
52     private boolean _encodingSet = false;
53     private boolean _standaloneSet = false;
54     
55     public void reset() {
56         _encoding = XMLConstants.ENCODING;
57         _standalone = true;
58         _version = XMLConstants.XMLVERSION;
59         _encodingSet = false;
60         _standaloneSet=false;
61     }
62     public StartDocumentEvent() {
63         this(null ,null);
64     }
65     
66     public StartDocumentEvent(String JavaDoc encoding){
67         this(encoding, null);
68     }
69     
70     public StartDocumentEvent(String JavaDoc encoding, String JavaDoc version){
71         if (encoding != null) {
72             _encoding = encoding;
73             _encodingSet = true;
74         }
75         if (version != null)
76             _version = version;
77         setEventType(XMLStreamConstants.START_DOCUMENT);
78     }
79     
80     
81     // ------------------- methods defined in StartDocument -------------------------
82
/**
83     * Returns the system ID of the XML data
84     * @return the system ID, defaults to ""
85     */

86     public String JavaDoc getSystemId() {
87         return super.getSystemId();
88     }
89     
90     /**
91     * Returns the encoding style of the XML data
92     * @return the character encoding, defaults to "UTF-8"
93     */

94     public String JavaDoc getCharacterEncodingScheme() {
95         return _encoding;
96     }
97     /**
98     * Returns true if CharacterEncodingScheme was set in
99     * the encoding declaration of the document
100     */

101     public boolean encodingSet() {
102         return _encodingSet;
103     }
104     
105
106   /**
107    * Returns if this XML is standalone
108    * @return the standalone state of XML, defaults to "no"
109    */

110     public boolean isStandalone() {
111         return _standalone;
112     }
113     /**
114     * Returns true if the standalone attribute was set in
115     * the encoding declaration of the document.
116     */

117     public boolean standaloneSet() {
118         return _standaloneSet;
119     }
120     
121   /**
122    * Returns the version of XML of this XML stream
123    * @return the version of XML, defaults to "1.0"
124    */

125     public String JavaDoc getVersion() {
126         return _version;
127     }
128     // ------------------- end of methods defined in StartDocument -------------------------
129

130     public void setStandalone(boolean standalone) {
131         _standaloneSet = true;
132         _standalone = standalone;
133     }
134     
135     public void setStandalone(String JavaDoc s) {
136         _standaloneSet = true;
137         if(s == null) {
138             _standalone = true;
139             return;
140         }
141         if(s.equals("yes"))
142             _standalone = true;
143         else
144             _standalone = false;
145     }
146     
147         
148     public void setEncoding(String JavaDoc encoding) {
149         _encoding = encoding;
150         _encodingSet = true;
151     }
152     
153     void setDeclaredEncoding(boolean value){
154         _encodingSet = value;
155     }
156     
157     public void setVersion(String JavaDoc s) {
158         _version = s;
159     }
160     
161     void clear() {
162         _encoding = "UTF-8";
163         _standalone = true;
164         _version = "1.0";
165         _encodingSet = false;
166         _standaloneSet = false;
167     }
168     
169     public String JavaDoc toString() {
170         String JavaDoc s = "<?xml version=\"" + _version + "\"";
171         s = s + " encoding='" + _encoding + "'";
172         if(_standaloneSet) {
173             if(_standalone)
174                 s = s + " standalone='yes'?>";
175             else
176                 s = s + " standalone='no'?>";
177         } else {
178             s = s + "?>";
179         }
180         return s;
181     }
182     
183     public boolean isStartDocument() {
184         return true;
185     }
186 }
187
Popular Tags