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:#Parser |
|
6 |
instanceVariableNames:'stream reader domImplementation' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
9 |
category:'XML Suite-Parser' |
|
10 |
! |
|
11 |
||
12 |
||
13 |
!Parser class methodsFor:'instance creation'! |
|
14 |
||
15 |
forDOM1 |
|
16 |
||
17 |
^self withDOMFeatures:'XML 1.0' |
|
18 |
||
19 |
"Created: / 04-08-2005 / 13:36:05 / janfrog" |
|
20 |
! |
|
21 |
||
22 |
forDOM3 |
|
23 |
||
24 |
^self withDOMFeatures:'XML 3.0' |
|
25 |
||
26 |
"Created: / 04-08-2005 / 13:36:01 / janfrog" |
|
27 |
! |
|
28 |
||
29 |
forXSLTFO |
|
30 |
||
31 |
^self withDOMFeatures:'XML 3.0 XSLT-FO 1.0' |
|
32 |
||
33 |
"Created: / 07-04-2007 / 14:51:29 / janfrog" |
|
34 |
! |
|
35 |
||
36 |
new |
|
37 |
^self withDOMFeatures:'XML 1.0' |
|
38 |
||
39 |
"Modified: / 04-08-2005 / 12:47:38 / janfrog" |
|
40 |
! |
|
41 |
||
42 |
withDOMFeatures:featureString |
|
43 |
||
44 |
^self basicNew initializeWithFeatures:featureString |
|
45 |
||
46 |
"Created: / 04-08-2005 / 12:47:23 / janfrog" |
|
47 |
! ! |
|
48 |
||
49 |
!Parser methodsFor:'initialization'! |
|
50 |
||
51 |
initializeWithFeatures:featureString |
|
52 |
||
53 |
domImplementation := |
|
54 |
DOMImplementationRegistry |
|
55 |
getDOMImplementation:featureString. |
|
56 |
domImplementation ifNil:[ |
|
57 |
DOMException raiseErrorString:'No implementation found' |
|
58 |
]. |
|
59 |
reader := XMLReader new. |
|
60 |
||
61 |
"Created: / 04-08-2005 / 12:50:05 / janfrog" |
|
62 |
! |
|
63 |
||
64 |
on:aStream |
|
65 |
||
66 |
stream := aStream binary |
|
67 |
||
68 |
"Created: / 23-04-2005 / 12:33:06 / janfrog" |
|
69 |
! ! |
|
70 |
||
71 |
!Parser methodsFor:'settings'! |
|
72 |
||
73 |
isEncodeChecking:aBoolean |
|
74 |
||
75 |
"Created: / 23-04-2005 / 13:04:19 / janfrog" |
|
76 |
! |
|
77 |
||
78 |
validate:aBoolean |
|
79 |
||
80 |
"Created: / 23-04-2005 / 13:03:58 / janfrog" |
|
81 |
! ! |
|
82 |
||
83 |
!Parser methodsFor:'utilities - parsing'! |
|
84 |
||
85 |
ensureStreamIsBinary |
|
86 |
||
87 |
||
88 |
stream isBinary ifFalse: |
|
89 |
[stream isExternalStream |
|
90 |
ifTrue: |
|
91 |
[stream binary] |
|
92 |
ifFalse: |
|
93 |
[stream := stream collection asByteArray readStream]] |
|
94 |
||
95 |
"Created: / 02-10-2006 / 17:32:27 / janfrog" |
|
96 |
"Modified: / 06-10-2006 / 09:42:08 / janfrog" |
|
97 |
! |
|
98 |
||
99 |
parse: aString |
|
100 |
||
101 |
^self processDocumentString: aString beforeScanDo: [:p | p isEncodeChecking: false. p validate: false.] |
|
102 |
||
103 |
"Modified: / 23-04-2005 / 13:03:31 / janfrog" |
|
104 |
! |
|
105 |
||
106 |
processDocumentInFilename: aFilename |
|
107 |
||
108 |
^self processDocumentInFilename: aFilename beforeScanDo: [:parser | ] |
|
109 |
||
110 |
"Created: / 23-04-2005 / 13:02:46 / janfrog" |
|
111 |
! |
|
112 |
||
113 |
processDocumentInFilename: aFilename beforeScanDo: aBlock |
|
114 |
||
115 |
| str | |
|
116 |
str := (aFilename asFilename withEncoding: #UTF_8) readStream. |
|
117 |
^self processDocumentInStream: str beforeScanDo: aBlock |
|
118 |
||
119 |
"Created: / 23-04-2005 / 13:02:46 / janfrog" |
|
120 |
"Modified: / 11-11-2006 / 10:01:26 / janfrog" |
|
121 |
! |
|
122 |
||
123 |
processDocumentInStream: aStream |
|
124 |
||
125 |
^self processDocumentInStream: aStream beforeScanDo: [:parser | ] |
|
126 |
||
127 |
"Created: / 11-11-2006 / 10:00:40 / janfrog" |
|
128 |
! |
|
129 |
||
130 |
processDocumentInStream: aStream beforeScanDo: aBlock |
|
131 |
||
132 |
| p | |
|
133 |
stream := aStream. |
|
134 |
stream lineEndTransparent. |
|
135 |
p := self on: stream. |
|
136 |
aBlock value: p. |
|
137 |
^p scanDocument |
|
138 |
||
139 |
"Created: / 11-11-2006 / 10:00:45 / janfrog" |
|
140 |
! |
|
141 |
||
142 |
processDocumentString: aString |
|
143 |
||
144 |
^self processDocumentString: aString beforeScanDo: [:parser | ] |
|
145 |
||
146 |
"Created: / 23-04-2005 / 13:02:46 / janfrog" |
|
147 |
! |
|
148 |
||
149 |
processDocumentString: aString beforeScanDo: aBlock |
|
150 |
||
151 |
| p | |
|
152 |
p := self on: aString "asByteArray" readStream. |
|
153 |
aBlock value: p. |
|
154 |
^p scanDocument |
|
155 |
||
156 |
"Created: / 23-04-2005 / 13:02:46 / janfrog" |
|
157 |
"Modified: / 15-05-2005 / 20:49:38 / janfrog" |
|
158 |
"Modified: / 18-05-2005 / 10:57:19 / masca" |
|
159 |
! |
|
160 |
||
161 |
scanDocument |
|
162 |
"Returns parsed document, i.e. it's Document node" |
|
163 |
||
164 |
| contentHandler | |
|
165 |
||
166 |
stream ifNil:[ParseError raiseErrorString:'No stream'. ^nil]. |
|
167 |
self ensureStreamIsBinary. |
|
168 |
contentHandler := domImplementation saxContentHandler. |
|
169 |
reader setContentHandler:contentHandler. |
|
170 |
[ |
|
171 |
reader parseInputSource:(XMLv2::InputSource onStream:stream) |
|
172 |
] on: SAXError do:[:ex| |
|
173 |
ParseError raiseErrorString:ex errorString. |
|
174 |
^nil. |
|
175 |
]. |
|
176 |
^contentHandler document |
|
177 |
||
178 |
"Created: / 23-04-2005 / 12:39:18 / janfrog" |
|
179 |
"Modified: / 06-10-2006 / 09:42:08 / janfrog" |
|
180 |
! ! |
|
181 |
||
182 |
!Parser class methodsFor:'documentation'! |
|
183 |
||
184 |
version |
|
185 |
^ '$Header: /opt/data/cvs/stx/goodies/xmlsuite/XMLv2__Parser.st,v 1.7 2007-04-10 08:33:15 vranyj1 Exp $' |
|
186 |
! ! |