StructuredDocumentHandler.h 3.18 KB
Newer Older
Francois Gygi committed
1 2
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
3 4 5 6
// Copyright (c) 2008 The Regents of the University of California
//
// This file is part of Qbox
//
Francois Gygi committed
7 8
// Qbox is distributed under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 2 of
Francois Gygi committed
9 10 11 12 13 14
// the License, or (at your option) any later version.
// See the file COPYING in the root directory of this distribution
// or <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
// StructuredDocumentHandler.h
//
////////////////////////////////////////////////////////////////////////////////

#ifndef STRUCTUREDDOCUMENTHANDLER_H
#define STRUCTUREDDOCUMENTHANDLER_H

#include <xercesc/sax2/DefaultHandler.hpp>
#include "StrX.h"

#include "StructureHandler.h"

#include <stack>
#include <string>

class StructuredDocumentHandler : public DefaultHandler
{
  struct HandlerContext
  {
    int depth;
    StructureHandler* handler;
    HandlerContext(StructureHandler* handler_, int depth_) :
      handler(handler_), depth(depth_) {}
  };

  protected:
41

42
  std::stack<HandlerContext> contextStack;
Francois Gygi committed
43 44 45
  int nestingDepth;
  int contextDepth;
  StructureHandler* activeHandler;
46
  std::string buffer;
Francois Gygi committed
47 48 49 50 51

  public:

  StructuredDocumentHandler(StructureHandler* handler) :
    activeHandler(handler), contextDepth(0), nestingDepth(0) {}
52

Francois Gygi committed
53
  ~StructuredDocumentHandler() {}
54

Francois Gygi committed
55 56 57 58 59 60 61 62
  // -----------------------------------------------------------------------
  //  Implementations of the SAX DocumentHandler interface
  // -----------------------------------------------------------------------
  void startDocument();
  void endDocument();

  void startElement(const XMLCh* const uri,const XMLCh* const localname,
    const XMLCh* const qname, const Attributes& attributes);
63 64 65 66
#ifndef XERCES_VERSION_MAJOR
#error "XERCES_VERSION_MAJOR not defined"
#endif
#if XERCES_VERSION_MAJOR > 2
67 68
  void characters(const XMLCh* const chars, const XMLSize_t length);
#else
Francois Gygi committed
69
  void characters(const XMLCh* const chars, const unsigned int length);
70
#endif
Francois Gygi committed
71 72 73 74 75 76 77 78 79 80 81 82 83
  void endElement(const XMLCh* const uri, const XMLCh* const localname,
                  const XMLCh* const qname);
  void ignorableWhitespace(const XMLCh* const chars,
    const unsigned int length);
  void processingInstruction(const XMLCh* const target,
       const XMLCh* const data);

  // -----------------------------------------------------------------------
  //  Implementations of the SAX ErrorHandler interface
  // -----------------------------------------------------------------------
  void warning(const SAXParseException& exception);
  void error(const SAXParseException& exception);
  void fatalError(const SAXParseException& exception);
84

Francois Gygi committed
85 86 87 88 89 90 91 92 93 94 95 96
  // -----------------------------------------------------------------------
  //  Implementation of the SAX DTDHandler interface
  // -----------------------------------------------------------------------
  void notationDecl(const XMLCh* const name, const XMLCh* const publicId,
       const XMLCh* const systemId);

  void unparsedEntityDecl(const XMLCh* const name,
    const XMLCh* const publicId, const XMLCh* const systemId,
    const XMLCh* const notationName);

};
#endif