Vaucanson  1.4.1
handlers_base.hh
1 // handlers_base.hh: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2007, 2008 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 
18 #ifndef VCSN_XML_HANDLERS_BASE_HH
19 # define VCSN_XML_HANDLERS_BASE_HH
20 
31 # include <map>
32 # include <string>
33 
34 # include <xercesc/sax2/SAX2XMLReader.hpp>
35 # include <xercesc/sax2/XMLReaderFactory.hpp>
36 # include <xercesc/sax2/DefaultHandler.hpp>
37 # include <xercesc/sax2/Attributes.hpp>
38 
39 # include <xercesc/sax/SAXException.hpp>
40 # include <xercesc/util/XMLString.hpp>
41 
42 # include <vaucanson/xml/xmleq.hh>
43 # include <vaucanson/xml/strings.hh>
44 
45 namespace vcsn
46 {
47  namespace xml
48  {
49  /*
50  * ErrHandler class, error handler.
51  */
52  class ErrHandler : public xercesc::DefaultHandler
53  {
54  public:
55  ErrHandler () : DefaultHandler() {}
56 
57  void
58  warning (const xercesc::SAXParseException& exc);
59  // Receive notification of a warning.
60  void
61  error (const xercesc::SAXParseException& exc);
62  // Receive notification of a recoverable error.
63  void
64  fatalError (const xercesc::SAXParseException& exc);
65  // Receive notification of a non-recoverable error.
66  void
67  resetErrors () {}
68  // Reset the Error handler object on its reuse.
69  };
70 
71  namespace error
72  {
73  void token(const XMLCh* const localname);
74  void attrs(const XMLCh* const localname,
75  const std::string& name,
76  const std::string& value);
77  void missattrs(const XMLCh* const localname,
78  const std::string& name);
79  void notletter(const std::string&);
80  } // !error
81  /*
82  * Handler class
83  */
84  class Handler : public xercesc::DefaultHandler
85  {
86  public:
87  Handler (xercesc::SAX2XMLReader* parser,
88  Handler& root);
89  Handler (xercesc::SAX2XMLReader* parser,
90  xercesc::DefaultHandler& root,
91  XMLEq& eq);
92 
93  void
94  startElement (const XMLCh* const uri,
95  const XMLCh* const localname,
96  const XMLCh* const qname,
97  const xercesc::Attributes& attrs);
98  void
99  endElement (const XMLCh* const uri,
100  const XMLCh* const localname,
101  const XMLCh* const qname);
102 
103  virtual void
104  start (const XMLCh* const uri,
105  const XMLCh* const localname,
106  const XMLCh* const qname,
107  const xercesc::Attributes& attrs) = 0;
108  virtual void
109  end (const XMLCh* const uri,
110  const XMLCh* const localname,
111  const XMLCh* const qname) = 0;
112 
113  XMLEq& eq() { return eq_; };
114 # ifdef DEBUG
115  static int indent_;
116 # endif
117  protected:
118  // Required to enable a change of the Handler while parsing.
119  xercesc::SAX2XMLReader* parser_;
120  xercesc::DefaultHandler& root_;
121 
122  XMLEq& eq_;
123  };
124 # ifdef DEBUG
125  int Handler::indent_ = 0;
126 # endif
127 
132  class UnsupHandler : public Handler
133  {
134  public:
135  UnsupHandler(xercesc::SAX2XMLReader* parser,
136  Handler& root);
137 
138  void
139  start (const XMLCh* const uri,
140  const XMLCh* const localname,
141  const XMLCh* const qname,
142  const xercesc::Attributes& attrs);
143  void
144  end (const XMLCh* const uri,
145  const XMLCh* const localname,
146  const XMLCh* const qname);
147  private:
148  int depth_;
149  };
150  } // !xml
151 } // !vcsn
152 
153 # if ! defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
155 # endif // !VCSN_USE_INTERFACE_ONLY || VCSN_USE_LIB
156 
157 #endif // !VCSN_XML_HANDLERS_BASE_HH