author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Thu, 10 Apr 2008 09:14:47 +0000 | |
changeset 3 | 7909b6680107 |
parent 2 | 06f508a6f55c |
child 174 | 76f50ac2e6a0 |
permissions | -rw-r--r-- |
3
7909b6680107
Loaded into & commited from 5.3.6
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
1 |
"{ Package: 'stx:goodies/xmlsuite/core' }" |
0 | 2 |
|
3 |
"{ NameSpace: XMLv2 }" |
|
4 |
||
5 |
Object subclass:#InputSource |
|
6 |
instanceVariableNames:'stream encoding systemId publicId' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
9 |
category:'XML Suite-SAX2' |
|
10 |
! |
|
11 |
||
12 |
||
13 |
!InputSource class methodsFor:'instance creation'! |
|
14 |
||
15 |
onFile:aStringOrFilename |
|
16 |
^ self onStream:aStringOrFilename asFilename readStream |
|
17 |
||
18 |
"Created: / 30-05-2005 / 16:26:40 / masca" |
|
19 |
! |
|
20 |
||
21 |
onStream:byteStream |
|
22 |
||
23 |
"From SAX2 specification: |
|
24 |
public InputSource(java.io.InputStream byteStream) |
|
25 |
||
26 |
Create a new input source with a byte stream. |
|
27 |
||
28 |
Application writers should use setSystemId() to provide a base for |
|
29 |
resolving relative URIs, may use setPublicId to include a public |
|
30 |
identifier, and may use setEncoding to specify the object's character |
|
31 |
encoding. |
|
32 |
||
33 |
Parameters: |
|
34 |
byteStream - The raw byte stream containing the document." |
|
35 |
||
36 |
byteStream binary. |
|
37 |
byteStream isBinary |
|
38 |
ifFalse:[SAXError raiseErrorString:'Binary stream required']. |
|
39 |
||
40 |
^self new setByteStream:byteStream |
|
41 |
||
42 |
"Created: / 15-05-2005 / 20:35:23 / janfrog" |
|
43 |
"Modified: / 06-10-2006 / 09:42:13 / janfrog" |
|
44 |
! |
|
45 |
||
46 |
onString:aString |
|
47 |
||
48 |
^self onStream:aString asByteArray readStream |
|
49 |
||
50 |
"Created: / 15-05-2005 / 21:55:21 / janfrog" |
|
51 |
"Modified: / 18-10-2005 / 09:53:53 / janfrog" |
|
52 |
! ! |
|
53 |
||
54 |
!InputSource methodsFor:'SAX2 interface'! |
|
55 |
||
56 |
getByteStream |
|
57 |
||
58 |
||
59 |
"getByteStream |
|
60 |
||
61 |
public java.io.InputStream getByteStream() |
|
62 |
||
63 |
Get the byte stream for this input source. |
|
64 |
||
65 |
The getEncoding method will return the character encoding for this |
|
66 |
byte stream, or null if unknown. |
|
67 |
||
68 |
Returns: |
|
69 |
The byte stream, or null if none was supplied. |
|
70 |
See Also: |
|
71 |
getEncoding(), setByteStream(java.io.InputStream)" |
|
72 |
||
73 |
^stream |
|
74 |
||
75 |
"Created: / 15-05-2005 / 20:41:08 / janfrog" |
|
76 |
! |
|
77 |
||
78 |
getCharacterStream |
|
79 |
||
80 |
"public java.io.Reader getCharacterStream() |
|
81 |
||
82 |
Get the character stream for this input source. |
|
83 |
||
84 |
Returns: |
|
85 |
The character stream, or null if none was supplied. |
|
86 |
See Also: |
|
87 |
setCharacterStream(java.io.Reader)" |
|
88 |
||
89 |
self error:'not supported until reader will be implemented' |
|
90 |
||
91 |
"Created: / 15-05-2005 / 20:57:41 / janfrog" |
|
92 |
! |
|
93 |
||
94 |
getEncoding |
|
95 |
||
96 |
"public java.lang.String getEncoding() |
|
97 |
||
98 |
Get the character encoding for a byte stream or URI. This value will |
|
99 |
be ignored when the application provides a character stream. |
|
100 |
||
101 |
Returns: |
|
102 |
The encoding, or null if none was supplied. |
|
103 |
See Also: |
|
104 |
setByteStream(java.io.InputStream), getSystemId(), getByteStream()" |
|
105 |
||
106 |
self error:'not yet supported'. |
|
107 |
^encoding |
|
108 |
||
109 |
"Created: / 15-05-2005 / 20:52:50 / janfrog" |
|
110 |
! |
|
111 |
||
112 |
getPublicId |
|
113 |
||
114 |
"getPublicId |
|
115 |
||
116 |
public java.lang.String getPublicId() |
|
117 |
||
118 |
Get the public identifier for this input source. |
|
119 |
||
120 |
Returns: |
|
121 |
The public identifier, or null if none was supplied. |
|
122 |
See Also: |
|
123 |
setPublicId(java.lang.String)" |
|
124 |
||
125 |
^publicId |
|
126 |
||
127 |
"Created: / 15-05-2005 / 20:37:26 / janfrog" |
|
128 |
! |
|
129 |
||
130 |
getSystemId |
|
131 |
||
132 |
"public java.lang.String getSystemId() |
|
133 |
||
134 |
Get the system identifier for this input source. |
|
135 |
||
136 |
If the system ID is a URL, it will be fully resolved. |
|
137 |
||
138 |
Returns: |
|
139 |
The system identifier, or null if none was supplied. |
|
140 |
See Also: |
|
141 |
setSystemId(java.lang.String), getEncoding()" |
|
142 |
||
143 |
systemId ifNotNil:[^systemId]. |
|
144 |
||
145 |
"now, try to guess system id" |
|
146 |
(stream notNil and:[stream isFileStream]) |
|
147 |
ifTrue:[^systemId := URI fromString:'file://', stream pathName asFilename asAbsoluteFilename asString]. |
|
148 |
||
149 |
^nil |
|
150 |
||
151 |
"Created: / 15-05-2005 / 20:39:15 / janfrog" |
|
152 |
"Modified: / 07-06-2005 / 11:24:15 / masca" |
|
153 |
! |
|
154 |
||
155 |
setByteStream:byteStream |
|
156 |
||
157 |
"public void setByteStream(java.io.InputStream byteStream) |
|
158 |
||
159 |
Set the byte stream for this input source. |
|
160 |
||
161 |
The SAX parser will ignore this if there is also a character stream |
|
162 |
specified, but it will use a byte stream in preference to opening |
|
163 |
a URI connection itself. |
|
164 |
||
165 |
If the application knows the character encoding of the byte stream, it should set it with the setEncoding method. |
|
166 |
||
167 |
Parameters: |
|
168 |
byteStream - A byte stream containing an XML document or other entity. |
|
169 |
See Also: |
|
170 |
setEncoding(java.lang.String), getByteStream(), getEncoding(), InputStream" |
|
171 |
||
172 |
stream := byteStream |
|
173 |
||
174 |
"Created: / 15-05-2005 / 20:40:31 / janfrog" |
|
175 |
! |
|
176 |
||
177 |
setCharacterStream:aCharacterStream |
|
178 |
||
179 |
"public void setCharacterStream(java.io.Reader characterStream) |
|
180 |
||
181 |
Set the character stream for this input source. |
|
182 |
||
183 |
If there is a character stream specified, the SAX parser will |
|
184 |
ignore any byte stream and will not attempt to open a URI connection |
|
185 |
to the system identifier. |
|
186 |
||
187 |
Parameters: |
|
188 |
characterStream - The character stream containing the XML document |
|
189 |
or other entity. |
|
190 |
See Also: |
|
191 |
getCharacterStream(), Reader" |
|
192 |
||
193 |
self error:'not supported until readers will be implemented' |
|
194 |
||
195 |
"Created: / 15-05-2005 / 20:55:11 / janfrog" |
|
196 |
! |
|
197 |
||
198 |
setEncoding:aString |
|
199 |
||
200 |
"public void setEncoding(java.lang.String encoding) |
|
201 |
||
202 |
Set the character encoding, if known. |
|
203 |
||
204 |
The encoding must be a string acceptable for an XML encoding |
|
205 |
declaration (see section 4.3.3 of the XML 1.0 recommendation). |
|
206 |
||
207 |
This method has no effect when the application provides a character stream. |
|
208 |
||
209 |
Parameters: |
|
210 |
encoding - A string describing the character encoding. |
|
211 |
See Also: |
|
212 |
setSystemId(java.lang.String), setByteStream(java.io.InputStream), |
|
213 |
getEncoding()" |
|
214 |
||
215 |
self error:'Not supported yet'. |
|
216 |
encoding := aString |
|
217 |
||
218 |
"Created: / 15-05-2005 / 20:51:56 / janfrog" |
|
219 |
! |
|
220 |
||
221 |
setPublicId:aString |
|
222 |
||
223 |
" |
|
224 |
public void setPublicId(java.lang.String publicId) |
|
225 |
||
226 |
Set the public identifier for this input source. |
|
227 |
||
228 |
The public identifier is always optional: if the application writer |
|
229 |
includes one, it will be provided as part of the location information. |
|
230 |
||
231 |
Parameters: |
|
232 |
publicId - The public identifier as a string. |
|
233 |
See Also: |
|
234 |
getPublicId(), Locator.getPublicId(), SAXParseException.getPublicId()" |
|
235 |
||
236 |
publicId := aString |
|
237 |
||
238 |
"Created: / 15-05-2005 / 20:36:46 / janfrog" |
|
239 |
! |
|
240 |
||
241 |
setSystemId:aString |
|
242 |
||
243 |
" |
|
244 |
public void setSystemId(java.lang.String systemId) |
|
245 |
||
246 |
Set the system identifier for this input source. |
|
247 |
||
248 |
The system identifier is optional if there is a byte stream or |
|
249 |
a character stream, but it is still useful to provide one, since |
|
250 |
the application can use it to resolve relative URIs and can |
|
251 |
include it in error messages and warnings (the parser will attempt |
|
252 |
to open a connection to the URI only if there is no byte stream |
|
253 |
or character stream specified). |
|
254 |
||
255 |
If the application knows the character encoding of the object pointed |
|
256 |
to by the system identifier, it can register the encoding using the |
|
257 |
setEncoding method. |
|
258 |
||
259 |
If the system identifier is a URL, it must be fully resolved |
|
260 |
(it may not be a relative URL). |
|
261 |
||
262 |
Parameters: |
|
263 |
systemId - The system identifier as a string. |
|
264 |
See Also: |
|
265 |
setEncoding(java.lang.String), getSystemId(), Locator.getSystemId(), |
|
266 |
SAXParseException.getSystemId()" |
|
267 |
||
268 |
systemId := aString |
|
269 |
||
270 |
"Created: / 15-05-2005 / 20:38:20 / janfrog" |
|
271 |
! ! |
|
272 |
||
273 |
!InputSource methodsFor:'utilities'! |
|
274 |
||
275 |
streamPosition |
|
276 |
||
277 |
^stream position |
|
278 |
||
279 |
"Created: / 11-07-2005 / 12:06:57 / masca" |
|
280 |
! ! |
|
281 |
||
282 |
!InputSource class methodsFor:'documentation'! |
|
283 |
||
284 |
version |
|
285 |
^ '$Header: /opt/data/cvs/stx/goodies/xmlsuite/XMLv2__InputSource.st,v 1.2 2006-10-06 11:09:12 vranyj1 Exp $' |
|
286 |
! ! |