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