1 | /* |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
3 | * contributor license agreements. See the NOTICE file distributed with |
---|
4 | * this work for additional information regarding copyright ownership. |
---|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
6 | * (the "License"); you may not use this file except in compliance with |
---|
7 | * the License. You may obtain a copy of the License at |
---|
8 | * |
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | * |
---|
11 | * Unless required by applicable law or agreed to in writing, software |
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | * See the License for the specific language governing permissions and |
---|
15 | * limitations under the License. |
---|
16 | */ |
---|
17 | |
---|
18 | /* |
---|
19 | * $Id: HandlerBase.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
20 | */ |
---|
21 | |
---|
22 | |
---|
23 | #ifndef HANDLERBASE_HPP |
---|
24 | #define HANDLERBASE_HPP |
---|
25 | |
---|
26 | #include <xercesc/sax/DocumentHandler.hpp> |
---|
27 | #include <xercesc/sax/DTDHandler.hpp> |
---|
28 | #include <xercesc/sax/EntityResolver.hpp> |
---|
29 | #include <xercesc/sax/ErrorHandler.hpp> |
---|
30 | #include <xercesc/sax/SAXParseException.hpp> |
---|
31 | |
---|
32 | XERCES_CPP_NAMESPACE_BEGIN |
---|
33 | |
---|
34 | class Locator; |
---|
35 | class AttributeList; |
---|
36 | |
---|
37 | /** |
---|
38 | * Default base class for handlers. |
---|
39 | * |
---|
40 | * <p>This class implements the default behaviour for four SAX |
---|
41 | * interfaces: EntityResolver, DTDHandler, DocumentHandler, |
---|
42 | * and ErrorHandler.</p> |
---|
43 | * |
---|
44 | * <p>Application writers can extend this class when they need to |
---|
45 | * implement only part of an interface; parser writers can |
---|
46 | * instantiate this class to provide default handlers when the |
---|
47 | * application has not supplied its own.</p> |
---|
48 | * |
---|
49 | * <p>Note that the use of this class is optional.</p> |
---|
50 | * |
---|
51 | * @see EntityResolver#EntityResolver |
---|
52 | * @see DTDHandler#DTDHandler |
---|
53 | * @see DocumentHandler#DocumentHandler |
---|
54 | * @see ErrorHandler#ErrorHandler |
---|
55 | */ |
---|
56 | |
---|
57 | class SAX_EXPORT HandlerBase : |
---|
58 | |
---|
59 | public EntityResolver, public DTDHandler, public DocumentHandler |
---|
60 | , public ErrorHandler |
---|
61 | { |
---|
62 | public: |
---|
63 | /** @name Default handlers for the DocumentHandler interface */ |
---|
64 | //@{ |
---|
65 | /** |
---|
66 | * Receive notification of character data inside an element. |
---|
67 | * |
---|
68 | * <p>By default, do nothing. Application writers may override this |
---|
69 | * method to take specific actions for each chunk of character data |
---|
70 | * (such as adding the data to a node or buffer, or printing it to |
---|
71 | * a file).</p> |
---|
72 | * |
---|
73 | * @param chars The characters. |
---|
74 | * @param length The number of characters to use from the |
---|
75 | * character array. |
---|
76 | * @exception SAXException Any SAX exception, possibly |
---|
77 | * wrapping another exception. |
---|
78 | * @see DocumentHandler#characters |
---|
79 | */ |
---|
80 | virtual void characters |
---|
81 | ( |
---|
82 | const XMLCh* const chars |
---|
83 | , const unsigned int length |
---|
84 | ); |
---|
85 | |
---|
86 | /** |
---|
87 | * Receive notification of the end of the document. |
---|
88 | * |
---|
89 | * <p>By default, do nothing. Application writers may override this |
---|
90 | * method in a subclass to take specific actions at the beginning |
---|
91 | * of a document (such as finalising a tree or closing an output |
---|
92 | * file).</p> |
---|
93 | * |
---|
94 | * @exception SAXException Any SAX exception, possibly |
---|
95 | * wrapping another exception. |
---|
96 | * @see DocumentHandler#endDocument |
---|
97 | */ |
---|
98 | virtual void endDocument(); |
---|
99 | |
---|
100 | /** |
---|
101 | * Receive notification of the end of an element. |
---|
102 | * |
---|
103 | * <p>By default, do nothing. Application writers may override this |
---|
104 | * method in a subclass to take specific actions at the end of |
---|
105 | * each element (such as finalising a tree node or writing |
---|
106 | * output to a file).</p> |
---|
107 | * |
---|
108 | * @param name The element type name. |
---|
109 | * @exception SAXException Any SAX exception, possibly |
---|
110 | * wrapping another exception. |
---|
111 | * @see DocumentHandler#endElement |
---|
112 | */ |
---|
113 | virtual void endElement(const XMLCh* const name); |
---|
114 | |
---|
115 | /** |
---|
116 | * Receive notification of ignorable whitespace in element content. |
---|
117 | * |
---|
118 | * <p>By default, do nothing. Application writers may override this |
---|
119 | * method to take specific actions for each chunk of ignorable |
---|
120 | * whitespace (such as adding data to a node or buffer, or printing |
---|
121 | * it to a file).</p> |
---|
122 | * |
---|
123 | * @param chars The whitespace characters. |
---|
124 | * @param length The number of characters to use from the |
---|
125 | * character array. |
---|
126 | * @exception SAXException Any SAX exception, possibly |
---|
127 | * wrapping another exception. |
---|
128 | * @see DocumentHandler#ignorableWhitespace |
---|
129 | */ |
---|
130 | virtual void ignorableWhitespace |
---|
131 | ( |
---|
132 | const XMLCh* const chars |
---|
133 | , const unsigned int length |
---|
134 | ); |
---|
135 | |
---|
136 | /** |
---|
137 | * Receive notification of a processing instruction. |
---|
138 | * |
---|
139 | * <p>By default, do nothing. Application writers may override this |
---|
140 | * method in a subclass to take specific actions for each |
---|
141 | * processing instruction, such as setting status variables or |
---|
142 | * invoking other methods.</p> |
---|
143 | * |
---|
144 | * @param target The processing instruction target. |
---|
145 | * @param data The processing instruction data, or null if |
---|
146 | * none is supplied. |
---|
147 | * @exception SAXException Any SAX exception, possibly |
---|
148 | * wrapping another exception. |
---|
149 | * @see DocumentHandler#processingInstruction |
---|
150 | */ |
---|
151 | virtual void processingInstruction |
---|
152 | ( |
---|
153 | const XMLCh* const target |
---|
154 | , const XMLCh* const data |
---|
155 | ); |
---|
156 | |
---|
157 | /** |
---|
158 | * Reset the Docuemnt object on its reuse |
---|
159 | * |
---|
160 | * @see DocumentHandler#resetDocument |
---|
161 | */ |
---|
162 | virtual void resetDocument(); |
---|
163 | //@} |
---|
164 | |
---|
165 | /** @name Default implementation of DocumentHandler interface */ |
---|
166 | |
---|
167 | //@{ |
---|
168 | /** |
---|
169 | * Receive a Locator object for document events. |
---|
170 | * |
---|
171 | * <p>By default, do nothing. Application writers may override this |
---|
172 | * method in a subclass if they wish to store the locator for use |
---|
173 | * with other document events.</p> |
---|
174 | * |
---|
175 | * @param locator A locator for all SAX document events. |
---|
176 | * @see DocumentHandler#setDocumentLocator |
---|
177 | * @see Locator |
---|
178 | */ |
---|
179 | virtual void setDocumentLocator(const Locator* const locator); |
---|
180 | |
---|
181 | /** |
---|
182 | * Receive notification of the beginning of the document. |
---|
183 | * |
---|
184 | * <p>By default, do nothing. Application writers may override this |
---|
185 | * method in a subclass to take specific actions at the beginning |
---|
186 | * of a document (such as allocating the root node of a tree or |
---|
187 | * creating an output file).</p> |
---|
188 | * |
---|
189 | * @exception SAXException Any SAX exception, possibly |
---|
190 | * wrapping another exception. |
---|
191 | * @see DocumentHandler#startDocument |
---|
192 | */ |
---|
193 | virtual void startDocument(); |
---|
194 | |
---|
195 | /** |
---|
196 | * Receive notification of the start of an element. |
---|
197 | * |
---|
198 | * <p>By default, do nothing. Application writers may override this |
---|
199 | * method in a subclass to take specific actions at the start of |
---|
200 | * each element (such as allocating a new tree node or writing |
---|
201 | * output to a file).</p> |
---|
202 | * |
---|
203 | * @param name The element type name. |
---|
204 | * @param attributes The specified or defaulted attributes. |
---|
205 | * @exception SAXException Any SAX exception, possibly |
---|
206 | * wrapping another exception. |
---|
207 | * @see DocumentHandler#startElement |
---|
208 | */ |
---|
209 | virtual void startElement |
---|
210 | ( |
---|
211 | const XMLCh* const name |
---|
212 | , AttributeList& attributes |
---|
213 | ); |
---|
214 | |
---|
215 | //@} |
---|
216 | |
---|
217 | /** @name Default implementation of the EntityResolver interface. */ |
---|
218 | |
---|
219 | //@{ |
---|
220 | /** |
---|
221 | * Resolve an external entity. |
---|
222 | * |
---|
223 | * <p>Always return null, so that the parser will use the system |
---|
224 | * identifier provided in the XML document. This method implements |
---|
225 | * the SAX default behaviour: application writers can override it |
---|
226 | * in a subclass to do special translations such as catalog lookups |
---|
227 | * or URI redirection.</p> |
---|
228 | * |
---|
229 | * @param publicId The public identifer, or null if none is |
---|
230 | * available. |
---|
231 | * @param systemId The system identifier provided in the XML |
---|
232 | * document. |
---|
233 | * @return The new input source, or null to require the |
---|
234 | * default behaviour. |
---|
235 | * The returned InputSource is owned by the parser which is |
---|
236 | * responsible to clean up the memory. |
---|
237 | * @exception SAXException Any SAX exception, possibly |
---|
238 | * wrapping another exception. |
---|
239 | * @see EntityResolver#resolveEntity |
---|
240 | */ |
---|
241 | virtual InputSource* resolveEntity |
---|
242 | ( |
---|
243 | const XMLCh* const publicId |
---|
244 | , const XMLCh* const systemId |
---|
245 | ); |
---|
246 | |
---|
247 | //@} |
---|
248 | |
---|
249 | /** @name Default implementation of the ErrorHandler interface */ |
---|
250 | //@{ |
---|
251 | /** |
---|
252 | * Receive notification of a recoverable parser error. |
---|
253 | * |
---|
254 | * <p>The default implementation does nothing. Application writers |
---|
255 | * may override this method in a subclass to take specific actions |
---|
256 | * for each error, such as inserting the message in a log file or |
---|
257 | * printing it to the console.</p> |
---|
258 | * |
---|
259 | * @param exc The warning information encoded as an exception. |
---|
260 | * @exception SAXException Any SAX exception, possibly |
---|
261 | * wrapping another exception. |
---|
262 | * @see ErrorHandler#warning |
---|
263 | * @see SAXParseException#SAXParseException |
---|
264 | */ |
---|
265 | virtual void error(const SAXParseException& exc); |
---|
266 | |
---|
267 | /** |
---|
268 | * Report a fatal XML parsing error. |
---|
269 | * |
---|
270 | * <p>The default implementation throws a SAXParseException. |
---|
271 | * Application writers may override this method in a subclass if |
---|
272 | * they need to take specific actions for each fatal error (such as |
---|
273 | * collecting all of the errors into a single report): in any case, |
---|
274 | * the application must stop all regular processing when this |
---|
275 | * method is invoked, since the document is no longer reliable, and |
---|
276 | * the parser may no longer report parsing events.</p> |
---|
277 | * |
---|
278 | * @param exc The error information encoded as an exception. |
---|
279 | * @exception SAXException Any SAX exception, possibly |
---|
280 | * wrapping another exception. |
---|
281 | * @see ErrorHandler#fatalError |
---|
282 | * @see SAXParseException#SAXParseException |
---|
283 | */ |
---|
284 | virtual void fatalError(const SAXParseException& exc); |
---|
285 | |
---|
286 | /** |
---|
287 | * Receive notification of a parser warning. |
---|
288 | * |
---|
289 | * <p>The default implementation does nothing. Application writers |
---|
290 | * may override this method in a subclass to take specific actions |
---|
291 | * for each warning, such as inserting the message in a log file or |
---|
292 | * printing it to the console.</p> |
---|
293 | * |
---|
294 | * @param exc The warning information encoded as an exception. |
---|
295 | * @exception SAXException Any SAX exception, possibly |
---|
296 | * wrapping another exception. |
---|
297 | * @see ErrorHandler#warning |
---|
298 | * @see SAXParseException#SAXParseException |
---|
299 | */ |
---|
300 | virtual void warning(const SAXParseException& exc); |
---|
301 | |
---|
302 | /** |
---|
303 | * Reset the Error handler object on its reuse |
---|
304 | * |
---|
305 | * @see ErrorHandler#resetErrors |
---|
306 | */ |
---|
307 | virtual void resetErrors(); |
---|
308 | |
---|
309 | //@} |
---|
310 | |
---|
311 | |
---|
312 | /** @name Default implementation of DTDHandler interface. */ |
---|
313 | //@{ |
---|
314 | |
---|
315 | /** |
---|
316 | * Receive notification of a notation declaration. |
---|
317 | * |
---|
318 | * <p>By default, do nothing. Application writers may override this |
---|
319 | * method in a subclass if they wish to keep track of the notations |
---|
320 | * declared in a document.</p> |
---|
321 | * |
---|
322 | * @param name The notation name. |
---|
323 | * @param publicId The notation public identifier, or null if not |
---|
324 | * available. |
---|
325 | * @param systemId The notation system identifier. |
---|
326 | * @see DTDHandler#notationDecl |
---|
327 | */ |
---|
328 | virtual void notationDecl |
---|
329 | ( |
---|
330 | const XMLCh* const name |
---|
331 | , const XMLCh* const publicId |
---|
332 | , const XMLCh* const systemId |
---|
333 | ); |
---|
334 | |
---|
335 | /** |
---|
336 | * Reset the DTD object on its reuse |
---|
337 | * |
---|
338 | * @see DTDHandler#resetDocType |
---|
339 | */ |
---|
340 | virtual void resetDocType(); |
---|
341 | |
---|
342 | /** |
---|
343 | * Receive notification of an unparsed entity declaration. |
---|
344 | * |
---|
345 | * <p>By default, do nothing. Application writers may override this |
---|
346 | * method in a subclass to keep track of the unparsed entities |
---|
347 | * declared in a document.</p> |
---|
348 | * |
---|
349 | * @param name The entity name. |
---|
350 | * @param publicId The entity public identifier, or null if not |
---|
351 | * available. |
---|
352 | * @param systemId The entity system identifier. |
---|
353 | * @param notationName The name of the associated notation. |
---|
354 | * @see DTDHandler#unparsedEntityDecl |
---|
355 | */ |
---|
356 | virtual void unparsedEntityDecl |
---|
357 | ( |
---|
358 | const XMLCh* const name |
---|
359 | , const XMLCh* const publicId |
---|
360 | , const XMLCh* const systemId |
---|
361 | , const XMLCh* const notationName |
---|
362 | ); |
---|
363 | //@} |
---|
364 | |
---|
365 | HandlerBase() {}; |
---|
366 | virtual ~HandlerBase() {}; |
---|
367 | |
---|
368 | private: |
---|
369 | // ----------------------------------------------------------------------- |
---|
370 | // Unimplemented constructors and operators |
---|
371 | // ----------------------------------------------------------------------- |
---|
372 | HandlerBase(const HandlerBase&); |
---|
373 | HandlerBase& operator=(const HandlerBase&); |
---|
374 | }; |
---|
375 | |
---|
376 | |
---|
377 | // --------------------------------------------------------------------------- |
---|
378 | // HandlerBase: Inline default implementations |
---|
379 | // --------------------------------------------------------------------------- |
---|
380 | inline void HandlerBase::characters(const XMLCh* const |
---|
381 | , const unsigned int) |
---|
382 | { |
---|
383 | } |
---|
384 | |
---|
385 | inline void HandlerBase::endDocument() |
---|
386 | { |
---|
387 | } |
---|
388 | |
---|
389 | inline void HandlerBase::endElement(const XMLCh* const) |
---|
390 | { |
---|
391 | } |
---|
392 | |
---|
393 | inline void HandlerBase::error(const SAXParseException&) |
---|
394 | { |
---|
395 | } |
---|
396 | |
---|
397 | inline void HandlerBase::fatalError(const SAXParseException& exc) |
---|
398 | { |
---|
399 | throw exc; |
---|
400 | } |
---|
401 | |
---|
402 | inline void |
---|
403 | HandlerBase::ignorableWhitespace( const XMLCh* const |
---|
404 | , const unsigned int) |
---|
405 | { |
---|
406 | } |
---|
407 | |
---|
408 | inline void HandlerBase::notationDecl( const XMLCh* const |
---|
409 | , const XMLCh* const |
---|
410 | , const XMLCh* const) |
---|
411 | { |
---|
412 | } |
---|
413 | |
---|
414 | inline void |
---|
415 | HandlerBase::processingInstruction( const XMLCh* const |
---|
416 | , const XMLCh* const) |
---|
417 | { |
---|
418 | } |
---|
419 | |
---|
420 | inline void HandlerBase::resetErrors() |
---|
421 | { |
---|
422 | } |
---|
423 | |
---|
424 | inline void HandlerBase::resetDocument() |
---|
425 | { |
---|
426 | } |
---|
427 | |
---|
428 | inline void HandlerBase::resetDocType() |
---|
429 | { |
---|
430 | } |
---|
431 | |
---|
432 | inline InputSource* |
---|
433 | HandlerBase::resolveEntity( const XMLCh* const |
---|
434 | , const XMLCh* const) |
---|
435 | { |
---|
436 | return 0; |
---|
437 | } |
---|
438 | |
---|
439 | inline void |
---|
440 | HandlerBase::unparsedEntityDecl(const XMLCh* const |
---|
441 | , const XMLCh* const |
---|
442 | , const XMLCh* const |
---|
443 | , const XMLCh* const) |
---|
444 | { |
---|
445 | } |
---|
446 | |
---|
447 | inline void HandlerBase::setDocumentLocator(const Locator* const) |
---|
448 | { |
---|
449 | } |
---|
450 | |
---|
451 | inline void HandlerBase::startDocument() |
---|
452 | { |
---|
453 | } |
---|
454 | |
---|
455 | inline void |
---|
456 | HandlerBase::startElement( const XMLCh* const |
---|
457 | , AttributeList&) |
---|
458 | { |
---|
459 | } |
---|
460 | |
---|
461 | inline void HandlerBase::warning(const SAXParseException&) |
---|
462 | { |
---|
463 | } |
---|
464 | |
---|
465 | XERCES_CPP_NAMESPACE_END |
---|
466 | |
---|
467 | #endif |
---|