1 | // |
---|
2 | // XMLFilterImpl.cpp |
---|
3 | // |
---|
4 | // $Id: //poco/1.3/XML/src/XMLFilterImpl.cpp#2 $ |
---|
5 | // |
---|
6 | // Library: XML |
---|
7 | // Package: SAX |
---|
8 | // Module: SAXFilters |
---|
9 | // |
---|
10 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
---|
11 | // and Contributors. |
---|
12 | // |
---|
13 | // Permission is hereby granted, free of charge, to any person or organization |
---|
14 | // obtaining a copy of the software and accompanying documentation covered by |
---|
15 | // this license (the "Software") to use, reproduce, display, distribute, |
---|
16 | // execute, and transmit the Software, and to prepare derivative works of the |
---|
17 | // Software, and to permit third-parties to whom the Software is furnished to |
---|
18 | // do so, all subject to the following: |
---|
19 | // |
---|
20 | // The copyright notices in the Software and this entire statement, including |
---|
21 | // the above license grant, this restriction and the following disclaimer, |
---|
22 | // must be included in all copies of the Software, in whole or in part, and |
---|
23 | // all derivative works of the Software, unless such copies or derivative |
---|
24 | // works are solely in the form of machine-executable object code generated by |
---|
25 | // a source language processor. |
---|
26 | // |
---|
27 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
28 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
29 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT |
---|
30 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE |
---|
31 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, |
---|
32 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
33 | // DEALINGS IN THE SOFTWARE. |
---|
34 | // |
---|
35 | |
---|
36 | |
---|
37 | #include <Poco/SAX/XMLFilterImpl.h> |
---|
38 | #include <Poco/SAX/SAXException.h> |
---|
39 | |
---|
40 | |
---|
41 | namespace Poco { |
---|
42 | namespace XML { |
---|
43 | |
---|
44 | |
---|
45 | XMLFilterImpl::XMLFilterImpl(): |
---|
46 | _pParent(0), |
---|
47 | _pEntityResolver(0), |
---|
48 | _pDTDHandler(0), |
---|
49 | _pContentHandler(0), |
---|
50 | _pErrorHandler(0) |
---|
51 | { |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | XMLFilterImpl::XMLFilterImpl(XMLReader* pParent): |
---|
56 | _pParent(pParent), |
---|
57 | _pEntityResolver(0), |
---|
58 | _pDTDHandler(0), |
---|
59 | _pContentHandler(0), |
---|
60 | _pErrorHandler(0) |
---|
61 | { |
---|
62 | } |
---|
63 | |
---|
64 | |
---|
65 | XMLFilterImpl::~XMLFilterImpl() |
---|
66 | { |
---|
67 | } |
---|
68 | |
---|
69 | |
---|
70 | XMLReader* XMLFilterImpl::getParent() const |
---|
71 | { |
---|
72 | return _pParent; |
---|
73 | } |
---|
74 | |
---|
75 | |
---|
76 | void XMLFilterImpl::setParent(XMLReader* pParent) |
---|
77 | { |
---|
78 | _pParent = pParent; |
---|
79 | } |
---|
80 | |
---|
81 | |
---|
82 | void XMLFilterImpl::setEntityResolver(EntityResolver* pResolver) |
---|
83 | { |
---|
84 | _pEntityResolver = pResolver; |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | EntityResolver* XMLFilterImpl::getEntityResolver() const |
---|
89 | { |
---|
90 | return _pEntityResolver; |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | void XMLFilterImpl::setDTDHandler(DTDHandler* pDTDHandler) |
---|
95 | { |
---|
96 | _pDTDHandler = pDTDHandler; |
---|
97 | } |
---|
98 | |
---|
99 | |
---|
100 | DTDHandler* XMLFilterImpl::getDTDHandler() const |
---|
101 | { |
---|
102 | return _pDTDHandler; |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | void XMLFilterImpl::setContentHandler(ContentHandler* pContentHandler) |
---|
107 | { |
---|
108 | _pContentHandler = pContentHandler; |
---|
109 | } |
---|
110 | |
---|
111 | |
---|
112 | ContentHandler* XMLFilterImpl::getContentHandler() const |
---|
113 | { |
---|
114 | return _pContentHandler; |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | void XMLFilterImpl::setErrorHandler(ErrorHandler* pErrorHandler) |
---|
119 | { |
---|
120 | _pErrorHandler = pErrorHandler; |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | ErrorHandler* XMLFilterImpl::getErrorHandler() const |
---|
125 | { |
---|
126 | return _pErrorHandler; |
---|
127 | } |
---|
128 | |
---|
129 | |
---|
130 | void XMLFilterImpl::setFeature(const XMLString& featureId, bool state) |
---|
131 | { |
---|
132 | if (_pParent) |
---|
133 | _pParent->setFeature(featureId, state); |
---|
134 | else |
---|
135 | throw SAXNotRecognizedException(fromXMLString(featureId)); |
---|
136 | } |
---|
137 | |
---|
138 | |
---|
139 | bool XMLFilterImpl::getFeature(const XMLString& featureId) const |
---|
140 | { |
---|
141 | if (_pParent) |
---|
142 | return _pParent->getFeature(featureId); |
---|
143 | else |
---|
144 | throw SAXNotRecognizedException(fromXMLString(featureId)); |
---|
145 | } |
---|
146 | |
---|
147 | |
---|
148 | void XMLFilterImpl::setProperty(const XMLString& propertyId, const XMLString& value) |
---|
149 | { |
---|
150 | if (_pParent) |
---|
151 | _pParent->setProperty(propertyId, value); |
---|
152 | else |
---|
153 | throw SAXNotRecognizedException(fromXMLString(propertyId)); |
---|
154 | } |
---|
155 | |
---|
156 | |
---|
157 | void XMLFilterImpl::setProperty(const XMLString& propertyId, void* value) |
---|
158 | { |
---|
159 | if (_pParent) |
---|
160 | _pParent->setProperty(propertyId, value); |
---|
161 | else |
---|
162 | throw SAXNotRecognizedException(fromXMLString(propertyId)); |
---|
163 | } |
---|
164 | |
---|
165 | |
---|
166 | void* XMLFilterImpl::getProperty(const XMLString& propertyId) const |
---|
167 | { |
---|
168 | if (_pParent) |
---|
169 | return _pParent->getProperty(propertyId); |
---|
170 | else |
---|
171 | throw SAXNotRecognizedException(fromXMLString(propertyId)); |
---|
172 | } |
---|
173 | |
---|
174 | |
---|
175 | void XMLFilterImpl::parse(InputSource* pSource) |
---|
176 | { |
---|
177 | setupParse(); |
---|
178 | _pParent->parse(pSource); |
---|
179 | } |
---|
180 | |
---|
181 | |
---|
182 | void XMLFilterImpl::parse(const XMLString& systemId) |
---|
183 | { |
---|
184 | setupParse(); |
---|
185 | _pParent->parse(systemId); |
---|
186 | } |
---|
187 | |
---|
188 | |
---|
189 | void XMLFilterImpl::parseMemoryNP(const char* xml, std::size_t size) |
---|
190 | { |
---|
191 | setupParse(); |
---|
192 | _pParent->parseMemoryNP(xml, size); |
---|
193 | } |
---|
194 | |
---|
195 | |
---|
196 | InputSource* XMLFilterImpl::resolveEntity(const XMLString* publicId, const XMLString& systemId) |
---|
197 | { |
---|
198 | if (_pEntityResolver) |
---|
199 | return _pEntityResolver->resolveEntity(publicId, systemId); |
---|
200 | else |
---|
201 | return 0; |
---|
202 | } |
---|
203 | |
---|
204 | |
---|
205 | void XMLFilterImpl::releaseInputSource(InputSource* pSource) |
---|
206 | { |
---|
207 | if (_pEntityResolver) |
---|
208 | _pEntityResolver->releaseInputSource(pSource); |
---|
209 | } |
---|
210 | |
---|
211 | |
---|
212 | void XMLFilterImpl::notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId) |
---|
213 | { |
---|
214 | if (_pDTDHandler) |
---|
215 | _pDTDHandler->notationDecl(name, publicId, systemId); |
---|
216 | } |
---|
217 | |
---|
218 | |
---|
219 | void XMLFilterImpl::unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName) |
---|
220 | { |
---|
221 | if (_pDTDHandler) |
---|
222 | _pDTDHandler->unparsedEntityDecl(name, publicId, systemId, notationName); |
---|
223 | } |
---|
224 | |
---|
225 | |
---|
226 | void XMLFilterImpl::setDocumentLocator(const Locator* loc) |
---|
227 | { |
---|
228 | if (_pContentHandler) |
---|
229 | _pContentHandler->setDocumentLocator(loc); |
---|
230 | } |
---|
231 | |
---|
232 | |
---|
233 | void XMLFilterImpl::startDocument() |
---|
234 | { |
---|
235 | if (_pContentHandler) |
---|
236 | _pContentHandler->startDocument(); |
---|
237 | } |
---|
238 | |
---|
239 | |
---|
240 | void XMLFilterImpl::endDocument() |
---|
241 | { |
---|
242 | if (_pContentHandler) |
---|
243 | _pContentHandler->endDocument(); |
---|
244 | } |
---|
245 | |
---|
246 | |
---|
247 | void XMLFilterImpl::startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attrList) |
---|
248 | { |
---|
249 | if (_pContentHandler) |
---|
250 | _pContentHandler->startElement(uri, localName, qname, attrList); |
---|
251 | } |
---|
252 | |
---|
253 | |
---|
254 | void XMLFilterImpl::endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname) |
---|
255 | { |
---|
256 | if (_pContentHandler) |
---|
257 | _pContentHandler->endElement(uri, localName, qname); |
---|
258 | } |
---|
259 | |
---|
260 | |
---|
261 | void XMLFilterImpl::characters(const XMLChar ch[], int start, int length) |
---|
262 | { |
---|
263 | if (_pContentHandler) |
---|
264 | _pContentHandler->characters(ch, start, length); |
---|
265 | } |
---|
266 | |
---|
267 | |
---|
268 | void XMLFilterImpl::ignorableWhitespace(const XMLChar ch[], int start, int length) |
---|
269 | { |
---|
270 | if (_pContentHandler) |
---|
271 | _pContentHandler->ignorableWhitespace(ch, start, length); |
---|
272 | } |
---|
273 | |
---|
274 | |
---|
275 | void XMLFilterImpl::processingInstruction(const XMLString& target, const XMLString& data) |
---|
276 | { |
---|
277 | if (_pContentHandler) |
---|
278 | _pContentHandler->processingInstruction(target, data); |
---|
279 | } |
---|
280 | |
---|
281 | |
---|
282 | void XMLFilterImpl::startPrefixMapping(const XMLString& prefix, const XMLString& uri) |
---|
283 | { |
---|
284 | if (_pContentHandler) |
---|
285 | _pContentHandler->startPrefixMapping(prefix, uri); |
---|
286 | } |
---|
287 | |
---|
288 | |
---|
289 | void XMLFilterImpl::endPrefixMapping(const XMLString& prefix) |
---|
290 | { |
---|
291 | if (_pContentHandler) |
---|
292 | _pContentHandler->endPrefixMapping(prefix); |
---|
293 | } |
---|
294 | |
---|
295 | |
---|
296 | void XMLFilterImpl::skippedEntity(const XMLString& prefix) |
---|
297 | { |
---|
298 | if (_pContentHandler) |
---|
299 | _pContentHandler->skippedEntity(prefix); |
---|
300 | } |
---|
301 | |
---|
302 | |
---|
303 | void XMLFilterImpl::warning(const SAXException& e) |
---|
304 | { |
---|
305 | if (_pErrorHandler) |
---|
306 | _pErrorHandler->warning(e); |
---|
307 | } |
---|
308 | |
---|
309 | |
---|
310 | void XMLFilterImpl::error(const SAXException& e) |
---|
311 | { |
---|
312 | if (_pErrorHandler) |
---|
313 | _pErrorHandler->error(e); |
---|
314 | } |
---|
315 | |
---|
316 | |
---|
317 | void XMLFilterImpl::fatalError(const SAXException& e) |
---|
318 | { |
---|
319 | if (_pErrorHandler) |
---|
320 | _pErrorHandler->fatalError(e); |
---|
321 | } |
---|
322 | |
---|
323 | |
---|
324 | void XMLFilterImpl::setupParse() |
---|
325 | { |
---|
326 | poco_check_ptr (_pParent); |
---|
327 | |
---|
328 | _pParent->setEntityResolver(this); |
---|
329 | _pParent->setDTDHandler(this); |
---|
330 | _pParent->setContentHandler(this); |
---|
331 | _pParent->setErrorHandler(this); |
---|
332 | } |
---|
333 | |
---|
334 | |
---|
335 | } } // namespace Poco::XML |
---|