6
|
1 |
/*
|
|
2 |
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package com.sun.xml.internal.stream.events ;
|
|
27 |
|
|
28 |
import javax.xml.stream.events.StartDocument;
|
|
29 |
import javax.xml.stream.Location;
|
|
30 |
import javax.xml.stream.XMLStreamConstants;
|
|
31 |
|
|
32 |
/** Implementation of StartDocumentEvent.
|
|
33 |
*
|
|
34 |
* @author Neeraj Bajaj Sun Microsystems,Inc.
|
|
35 |
* @author K.Venugopal Sun Microsystems,Inc.
|
|
36 |
*
|
|
37 |
*/
|
|
38 |
|
|
39 |
public class StartDocumentEvent extends DummyEvent
|
|
40 |
implements StartDocument {
|
|
41 |
|
|
42 |
protected String fSystemId;
|
|
43 |
protected String fEncodingScheam;
|
|
44 |
protected boolean fStandalone;
|
|
45 |
protected String fVersion;
|
|
46 |
private boolean fEncodingSchemeSet;
|
|
47 |
private boolean fStandaloneSet;
|
|
48 |
|
|
49 |
public StartDocumentEvent() {
|
|
50 |
this("UTF-8","1.0",true,null);
|
|
51 |
}
|
|
52 |
|
|
53 |
public StartDocumentEvent(String encoding){
|
|
54 |
this(encoding,"1.0",true,null);
|
|
55 |
}
|
|
56 |
|
|
57 |
public StartDocumentEvent(String encoding, String version){
|
|
58 |
this(encoding,version,true,null);
|
|
59 |
}
|
|
60 |
|
|
61 |
public StartDocumentEvent(String encoding, String version, boolean standalone){
|
|
62 |
this(encoding,version,standalone,null);
|
|
63 |
}
|
|
64 |
|
|
65 |
public StartDocumentEvent(String encoding, String version, boolean standalone,Location loc){
|
|
66 |
init();
|
|
67 |
this.fEncodingScheam = encoding;
|
|
68 |
this.fVersion = version;
|
|
69 |
this.fStandalone = standalone;
|
|
70 |
this.fEncodingSchemeSet = false;
|
|
71 |
this.fStandaloneSet = false;
|
|
72 |
if (loc != null) {
|
|
73 |
this.fLocation = loc;
|
|
74 |
}
|
|
75 |
}
|
|
76 |
protected void init() {
|
|
77 |
setEventType(XMLStreamConstants.START_DOCUMENT);
|
|
78 |
}
|
|
79 |
|
|
80 |
public String getSystemId() {
|
|
81 |
if(fLocation == null )
|
|
82 |
return "";
|
|
83 |
else
|
|
84 |
return fLocation.getSystemId();
|
|
85 |
}
|
|
86 |
|
|
87 |
|
|
88 |
public String getCharacterEncodingScheme() {
|
|
89 |
return fEncodingScheam;
|
|
90 |
}
|
|
91 |
|
|
92 |
public boolean isStandalone() {
|
|
93 |
return fStandalone;
|
|
94 |
}
|
|
95 |
|
|
96 |
public String getVersion() {
|
|
97 |
return fVersion;
|
|
98 |
}
|
|
99 |
|
|
100 |
public void setStandalone(boolean flag) {
|
|
101 |
fStandaloneSet = true;
|
|
102 |
fStandalone = flag;
|
|
103 |
}
|
|
104 |
|
|
105 |
public void setStandalone(String s) {
|
|
106 |
fStandaloneSet = true;
|
|
107 |
if(s == null) {
|
|
108 |
fStandalone = true;
|
|
109 |
return;
|
|
110 |
}
|
|
111 |
if(s.equals("yes"))
|
|
112 |
fStandalone = true;
|
|
113 |
else
|
|
114 |
fStandalone = false;
|
|
115 |
}
|
|
116 |
|
|
117 |
public boolean encodingSet() {
|
|
118 |
return fEncodingSchemeSet;
|
|
119 |
}
|
|
120 |
|
|
121 |
public boolean standaloneSet() {
|
|
122 |
return fStandaloneSet;
|
|
123 |
}
|
|
124 |
|
|
125 |
public void setEncoding(String encoding) {
|
|
126 |
fEncodingScheam = encoding;
|
|
127 |
}
|
|
128 |
|
|
129 |
void setDeclaredEncoding(boolean value){
|
|
130 |
fEncodingSchemeSet = value;
|
|
131 |
}
|
|
132 |
|
|
133 |
public void setVersion(String s) {
|
|
134 |
fVersion = s;
|
|
135 |
}
|
|
136 |
|
|
137 |
void clear() {
|
|
138 |
fEncodingScheam = "UTF-8";
|
|
139 |
fStandalone = true;
|
|
140 |
fVersion = "1.0";
|
|
141 |
fEncodingSchemeSet = false;
|
|
142 |
fStandaloneSet = false;
|
|
143 |
}
|
|
144 |
|
|
145 |
public String toString() {
|
|
146 |
String s = "<?xml version=\"" + fVersion + "\"";
|
|
147 |
s = s + " encoding='" + fEncodingScheam + "'";
|
|
148 |
if(fStandaloneSet) {
|
|
149 |
if(fStandalone)
|
|
150 |
s = s + " standalone='yes'?>";
|
|
151 |
else
|
|
152 |
s = s + " standalone='no'?>";
|
|
153 |
} else {
|
|
154 |
s = s + "?>";
|
|
155 |
}
|
|
156 |
return s;
|
|
157 |
}
|
|
158 |
|
|
159 |
public boolean isStartDocument() {
|
|
160 |
return true;
|
|
161 |
}
|
|
162 |
}
|