1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2008 The Regents of the University of California
4 //
5 // This file is part of Qbox
6 //
7 // Qbox is distributed under the terms of the GNU General Public License
8 // as published by the Free Software Foundation, either version 2 of
9 // the License, or (at your option) any later version.
10 // See the file COPYING in the root directory of this distribution
11 // or <http://www.gnu.org/licenses/>.
12 //
13 ////////////////////////////////////////////////////////////////////////////////
14 //
15 // StructuredDocumentHandler.h
16 //
17 ////////////////////////////////////////////////////////////////////////////////
18 
19 #ifndef STRUCTUREDDOCUMENTHANDLER_H
20 #define STRUCTUREDDOCUMENTHANDLER_H
21 
22 #include <xercesc/sax2/DefaultHandler.hpp>
23 #include "StrX.h"
24 
25 #include "StructureHandler.h"
26 
27 #include <stack>
28 #include <string>
29 
30 class StructuredDocumentHandler : public DefaultHandler
31 {
32   struct HandlerContext
33   {
34     int depth;
35     StructureHandler* handler;
HandlerContextHandlerContext36     HandlerContext(StructureHandler* handler_, int depth_) :
37       handler(handler_), depth(depth_) {}
38   };
39 
40   protected:
41 
42   std::stack<HandlerContext> contextStack;
43   int nestingDepth;
44   int contextDepth;
45   StructureHandler* activeHandler;
46   std::string buffer;
47 
48   public:
49 
StructuredDocumentHandler(StructureHandler * handler)50   StructuredDocumentHandler(StructureHandler* handler) :
51     activeHandler(handler), contextDepth(0), nestingDepth(0) {}
52 
~StructuredDocumentHandler()53   ~StructuredDocumentHandler() {}
54 
55   // -----------------------------------------------------------------------
56   //  Implementations of the SAX DocumentHandler interface
57   // -----------------------------------------------------------------------
58   void startDocument();
59   void endDocument();
60 
61   void startElement(const XMLCh* const uri,const XMLCh* const localname,
62     const XMLCh* const qname, const Attributes& attributes);
63 #ifndef XERCES_VERSION_MAJOR
64 #error "XERCES_VERSION_MAJOR not defined"
65 #endif
66 #if XERCES_VERSION_MAJOR > 2
67   void characters(const XMLCh* const chars, const XMLSize_t length);
68 #else
69   void characters(const XMLCh* const chars, const unsigned int length);
70 #endif
71   void endElement(const XMLCh* const uri, const XMLCh* const localname,
72                   const XMLCh* const qname);
73   void ignorableWhitespace(const XMLCh* const chars,
74     const unsigned int length);
75   void processingInstruction(const XMLCh* const target,
76        const XMLCh* const data);
77 
78   // -----------------------------------------------------------------------
79   //  Implementations of the SAX ErrorHandler interface
80   // -----------------------------------------------------------------------
81   void warning(const SAXParseException& exception);
82   void error(const SAXParseException& exception);
83   void fatalError(const SAXParseException& exception);
84 
85   // -----------------------------------------------------------------------
86   //  Implementation of the SAX DTDHandler interface
87   // -----------------------------------------------------------------------
88   void notationDecl(const XMLCh* const name, const XMLCh* const publicId,
89        const XMLCh* const systemId);
90 
91   void unparsedEntityDecl(const XMLCh* const name,
92     const XMLCh* const publicId, const XMLCh* const systemId,
93     const XMLCh* const notationName);
94 
95 };
96 #endif
97