ReaderHandler.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file ReaderHandler.h
22 
23  \brief This class implements Xerces interface for a handler that receives general document events.
24 */
25 
26 #ifndef __TERRALIB_XERCES_INTERNAL_CONTENTHANDLER_H
27 #define __TERRALIB_XERCES_INTERNAL_CONTENTHANDLER_H
28 
29 // TerraLib
30 #include "../xml/Enums.h"
31 #include "Config.h"
32 
33 // STL
34 #include <string>
35 #include <vector>
36 
37 // Xerces-C++
38 #include <xercesc/sax2/ContentHandler.hpp>
39 
40 namespace te
41 {
42  namespace xerces
43  {
44  /*!
45  \class ReaderHandler
46 
47  \brief This class implements Xerces interface for a handler that receives general document events.
48 
49  \sa Reader, ErrorHandler
50 
51  \todo Trabalhar com o handler lexico p/ saber se estamos lidando com valores de um elemento ou com um CDATA. Hoje tudo esta como VALUE.
52  */
53  class ReaderHandler : public xercesc::ContentHandler
54  {
55  public:
56 
57  /*! \brief Default constructor. */
58  ReaderHandler();
59 
60  /*! \brief Destructor. */
62 
63  void reset();
64 
65  /*!
66  \brief It receives notification of character data.
67 
68  \param chars The characters from the XML document.
69  \param length The number of characters to read from the array.
70 
71  \exception SAXException It may throws an exception.
72  */
73  void characters(const XMLCh* const chars, const XMLSize_t length);
74 
75  /*!
76  \brief It receives notification of the end of a document.
77 
78  \exception SAXException It may throws an exception.
79  */
80  void endDocument();
81 
82  /*!
83  \brief It receives notification of the end of an element.
84 
85  \param uri The URI of the associated namespace for this element.
86  \param localname The local part of the element name.
87  \param qname The QName of this element.
88 
89  \exception SAXException It may throws an exception.
90  */
91  void endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname);
92 
93  /*!
94  \brief It receives notification of ignorable whitespace in element content.
95 
96  \param chars The characters from the XML document.
97  \param length The number of characters to read from the array.
98 
99  \exception SAXException It may throws an exception.
100  */
101  void ignorableWhitespace(const XMLCh* const chars, const XMLSize_t length);
102 
103  /*!
104  \brief It receives notification of a processing instruction.
105 
106  \param target The processing instruction target.
107  \param data The processing instruction data, or null if none was supplied.
108 
109  \exception SAXException It may throws an exception.
110  */
111  void processingInstruction(const XMLCh* const target, const XMLCh* const data);
112 
113  /*!
114  \brief It receives an object for locating the origin of SAX document events.
115 
116  \param locator An object that can return the location of any SAX document event.
117  */
118  void setDocumentLocator(const xercesc::Locator* const locator);
119 
120  /*!
121  \brief It receives notification of the beginning of a document.
122 
123  \exception SAXException It may throws an exception.
124  */
125  void startDocument();
126 
127  /*!
128  \brief It receives notification of the beginning of an element.
129 
130  \param uri The URI of the associated namespace for this element.
131  \param localname The local part of the element name
132  \param qname The QName of this element.
133  \param attrs The attributes attached to the element, if any.
134 
135  \exception SAXException It may throws an exception.
136  */
137  void startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const xercesc::Attributes& attrs);
138 
139  /*!
140  \brief It receives notification of the start of an namespace prefix mapping.
141 
142  \param prefix The namespace prefix used.
143  \param uri The namespace URI used.
144 
145  \exception SAXException It may throws an exception.
146  */
147  void startPrefixMapping(const XMLCh* const prefix, const XMLCh* const uri);
148 
149  /*!
150  \brief It receives notification of the end of an namespace prefix mapping.
151 
152  \param prefix The namespace prefix used.
153 
154  \exception SAXException It may throws an exception.
155  */
156  void endPrefixMapping(const XMLCh* const prefix);
157 
158  /*!
159  \brief It receives notification of a skipped entity.
160 
161  \param name The name of the skipped entity.
162 
163  \exception SAXException It may throws an exception.
164  */
165  void skippedEntity(const XMLCh* const name);
166 
167  /*!
168  \brief It return the type of node read by the handler.
169 
170  \return The type of node read by the handler.
171  */
173 
174  /*!
175  \brief TODO
176 
177  \return TODO
178  */
179  const XMLCh* getElementURI() const { return m_uri; }
180 
181  /*!
182  \brief TODO
183 
184  \return TODO
185  */
186  const XMLCh* getElementLocalName() const { return m_localname; }
187 
188  /*!
189  \brief TODO
190 
191  \return TODO
192  */
193  const XMLCh* getElementQName() const { return m_qname; }
194 
195  /*!
196  \brief TODO
197 
198  \return TODO
199  */
200  const xercesc::Attributes* getElementAttrs() const { return m_attrs; }
201 
202  const std::string getElementValue() const { return m_value; }
203 
204  //const XMLCh* getIgnorableWhiteSpace() const { return m_value; }
205 
206  XMLSize_t getDataLen() const { return m_len; }
207 
208  std::size_t getNumberOfNamespaces() const { return m_nspaces.size(); }
209 
210  const std::pair<const XMLCh*, const XMLCh*>& getNamespace(std::size_t i) const { return m_nspaces[i]; }
211 
212  void setNodeType(te::xml::NodeType type);
213 
214  bool isInContractedForm() const;
215 
216  void setInContractedForm(bool d);
217 
218  protected:
219 
220  const XMLCh* m_uri; //!< URI of the associated namespace for the current element.
221  const XMLCh* m_localname; //!< The local part of the current element name.
222  const XMLCh* m_qname; //!< The QName of the current element.
223  const xercesc::Attributes* m_attrs; //!< The attributes attached to the current element, if any.
224  std::string m_value; //!< May be characters from the XML document, ignorable white spaces, CDATA or any other string.
225  XMLSize_t m_len; //!< The number of characters in the m_value array.
226  std::vector<std::pair<const XMLCh*, const XMLCh*> > m_nspaces; //!< A vector of namespaces (prefix, uri).
227  te::xml::NodeType m_nodeType; //!< The type of node read by the parser.
228  bool m_isInContractedForm; //!< A flag that indicates if the reader handler is on an contracted form element.
229  };
230 
231  } // end namespace xerces
232 } // end namespace te
233 
234 #endif // __TERRALIB_XERCES_INTERNAL_CONTENTHANDLER_H
235 
void processingInstruction(const XMLCh *const target, const XMLCh *const data)
It receives notification of a processing instruction.
const XMLCh * getElementLocalName() const
TODO.
const XMLCh * m_localname
The local part of the current element name.
const xercesc::Attributes * getElementAttrs() const
TODO.
const XMLCh * m_qname
The QName of the current element.
const std::pair< const XMLCh *, const XMLCh * > & getNamespace(std::size_t i) const
void endPrefixMapping(const XMLCh *const prefix)
It receives notification of the end of an namespace prefix mapping.
const std::string getElementValue() const
void setNodeType(te::xml::NodeType type)
XMLSize_t getDataLen() const
void setDocumentLocator(const xercesc::Locator *const locator)
It receives an object for locating the origin of SAX document events.
bool isInContractedForm() const
const XMLCh * m_uri
URI of the associated namespace for the current element.
NodeType
The type of node read by XML reader.
Definition: Enums.h:40
std::string m_value
May be characters from the XML document, ignorable white spaces, CDATA or any other string...
This class implements Xerces interface for a handler that receives general document events...
Definition: ReaderHandler.h:53
const xercesc::Attributes * m_attrs
The attributes attached to the current element, if any.
const XMLCh * getElementQName() const
TODO.
TerraLib.
void characters(const XMLCh *const chars, const XMLSize_t length)
It receives notification of character data.
std::size_t getNumberOfNamespaces() const
void ignorableWhitespace(const XMLCh *const chars, const XMLSize_t length)
It receives notification of ignorable whitespace in element content.
void startDocument()
It receives notification of the beginning of a document.
bool m_isInContractedForm
A flag that indicates if the reader handler is on an contracted form element.
te::xml::NodeType getNodeType() const
It return the type of node read by the handler.
void endDocument()
It receives notification of the end of a document.
ReaderHandler()
Default constructor.
void endElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname)
It receives notification of the end of an element.
void startPrefixMapping(const XMLCh *const prefix, const XMLCh *const uri)
It receives notification of the start of an namespace prefix mapping.
const XMLCh * getElementURI() const
TODO.
void setInContractedForm(bool d)
void skippedEntity(const XMLCh *const name)
It receives notification of a skipped entity.
std::vector< std::pair< const XMLCh *, const XMLCh * > > m_nspaces
A vector of namespaces (prefix, uri).
XMLSize_t m_len
The number of characters in the m_value array.
te::xml::NodeType m_nodeType
The type of node read by the parser.
~ReaderHandler()
Destructor.
Definition: ReaderHandler.h:61
void startElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const xercesc::Attributes &attrs)
It receives notification of the beginning of an element.