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 <vector>
35 
36 // Xerces-C++
37 #include <xercesc/sax2/ContentHandler.hpp>
38 
39 namespace te
40 {
41  namespace xerces
42  {
43  /*!
44  \class ReaderHandler
45 
46  \brief This class implements Xerces interface for a handler that receives general document events.
47 
48  \sa Reader, ErrorHandler
49 
50  \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.
51  */
52  class ReaderHandler : public xercesc::ContentHandler
53  {
54  public:
55 
56  /*! \brief Default constructor. */
57  ReaderHandler();
58 
59  /*! \brief Destructor. */
61 
62  void reset();
63 
64  /*!
65  \brief It receives notification of character data.
66 
67  \param chars The characters from the XML document.
68  \param length The number of characters to read from the array.
69 
70  \exception SAXException It may throws an exception.
71  */
72  void characters(const XMLCh* const chars, const XMLSize_t length);
73 
74  /*!
75  \brief It receives notification of the end of a document.
76 
77  \exception SAXException It may throws an exception.
78  */
79  void endDocument();
80 
81  /*!
82  \brief It receives notification of the end of an element.
83 
84  \param uri The URI of the associated namespace for this element.
85  \param localname The local part of the element name.
86  \param qname The QName of this element.
87 
88  \exception SAXException It may throws an exception.
89  */
90  void endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname);
91 
92  /*!
93  \brief It receives notification of ignorable whitespace in element content.
94 
95  \param chars The characters from the XML document.
96  \param length The number of characters to read from the array.
97 
98  \exception SAXException It may throws an exception.
99  */
100  void ignorableWhitespace(const XMLCh* const chars, const XMLSize_t length);
101 
102  /*!
103  \brief It receives notification of a processing instruction.
104 
105  \param target The processing instruction target.
106  \param data The processing instruction data, or null if none was supplied.
107 
108  \exception SAXException It may throws an exception.
109  */
110  void processingInstruction(const XMLCh* const target, const XMLCh* const data);
111 
112  /*!
113  \brief It receives an object for locating the origin of SAX document events.
114 
115  \param locator An object that can return the location of any SAX document event.
116  */
117  void setDocumentLocator(const xercesc::Locator* const locator);
118 
119  /*!
120  \brief It receives notification of the beginning of a document.
121 
122  \exception SAXException It may throws an exception.
123  */
124  void startDocument();
125 
126  /*!
127  \brief It receives notification of the beginning of an element.
128 
129  \param uri The URI of the associated namespace for this element.
130  \param localname The local part of the element name
131  \param qname The QName of this element.
132  \param attrs The attributes attached to the element, if any.
133 
134  \exception SAXException It may throws an exception.
135  */
136  void startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const xercesc::Attributes& attrs);
137 
138  /*!
139  \brief It receives notification of the start of an namespace prefix mapping.
140 
141  \param prefix The namespace prefix used.
142  \param uri The namespace URI used.
143 
144  \exception SAXException It may throws an exception.
145  */
146  void startPrefixMapping(const XMLCh* const prefix, const XMLCh* const uri);
147 
148  /*!
149  \brief It receives notification of the end of an namespace prefix mapping.
150 
151  \param prefix The namespace prefix used.
152 
153  \exception SAXException It may throws an exception.
154  */
155  void endPrefixMapping(const XMLCh* const prefix);
156 
157  /*!
158  \brief It receives notification of a skipped entity.
159 
160  \param name The name of the skipped entity.
161 
162  \exception SAXException It may throws an exception.
163  */
164  void skippedEntity(const XMLCh* const name);
165 
166  /*!
167  \brief It return the type of node read by the handler.
168 
169  \return The type of node read by the handler.
170  */
172 
173  /*!
174  \brief TODO
175 
176  \return TODO
177  */
178  const XMLCh* getElementURI() const { return m_uri; }
179 
180  /*!
181  \brief TODO
182 
183  \return TODO
184  */
185  const XMLCh* getElementLocalName() const { return m_localname; }
186 
187  /*!
188  \brief TODO
189 
190  \return TODO
191  */
192  const XMLCh* getElementQName() const { return m_qname; }
193 
194  /*!
195  \brief TODO
196 
197  \return TODO
198  */
199  const xercesc::Attributes* getElementAttrs() const { return m_attrs; }
200 
201  const XMLCh* getElementValue() const { return m_value; }
202 
203  //const XMLCh* getIgnorableWhiteSpace() const { return m_value; }
204 
205  XMLSize_t getDataLen() const { return m_len; }
206 
207  std::size_t getNumberOfNamespaces() const { return m_nspaces.size(); }
208 
209  const std::pair<const XMLCh*, const XMLCh*>& getNamespace(std::size_t i) const { return m_nspaces[i]; }
210 
211  void setNodeType(te::xml::NodeType type);
212 
213  bool isInContractedForm() const;
214 
215  void setInContractedForm(bool d);
216 
217  protected:
218 
219  const XMLCh* m_uri; //!< URI of the associated namespace for the current element.
220  const XMLCh* m_localname; //!< The local part of the current element name.
221  const XMLCh* m_qname; //!< The QName of the current element.
222  const xercesc::Attributes* m_attrs; //!< The attributes attached to the current element, if any.
223  const XMLCh* m_value; //!< May be characters from the XML document, ignorable white spaces, CDATA or any other string.
224  XMLSize_t m_len; //!< The number of characters in the m_value array.
225  std::vector<std::pair<const XMLCh*, const XMLCh*> > m_nspaces; //!< A vector of namespaces (prefix, uri).
226  te::xml::NodeType m_nodeType; //!< The type of node read by the parser.
227  bool m_isInContractedForm; //!< A flag that indicates if the reader handler is on an contracted form element.
228  };
229 
230  } // end namespace xerces
231 } // end namespace te
232 
233 #endif // __TERRALIB_XERCES_INTERNAL_CONTENTHANDLER_H
234 
void processingInstruction(const XMLCh *const target, const XMLCh *const data)
It receives notification of a processing instruction.
const XMLCh * m_localname
The local part of the current element name.
const XMLCh * m_qname
The QName of the current element.
std::size_t getNumberOfNamespaces() const
const xercesc::Attributes * getElementAttrs() const
TODO.
void endPrefixMapping(const XMLCh *const prefix)
It receives notification of the end of an namespace prefix mapping.
const XMLCh * getElementQName() const
TODO.
void setNodeType(te::xml::NodeType type)
const std::pair< const XMLCh *, const XMLCh * > & getNamespace(std::size_t i) const
void setDocumentLocator(const xercesc::Locator *const locator)
It receives an object for locating the origin of SAX document events.
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
This class implements Xerces interface for a handler that receives general document events...
Definition: ReaderHandler.h:52
const xercesc::Attributes * m_attrs
The attributes attached to the current element, if any.
const XMLCh * getElementURI() const
TODO.
URI C++ Library.
void characters(const XMLCh *const chars, const XMLSize_t length)
It receives notification of character data.
void ignorableWhitespace(const XMLCh *const chars, const XMLSize_t length)
It receives notification of ignorable whitespace in element content.
const XMLCh * m_value
May be characters from the XML document, ignorable white spaces, CDATA or any other string...
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.
const XMLCh * getElementLocalName() const
TODO.
void endDocument()
It receives notification of the end of a document.
te::xml::NodeType getNodeType() const
It return the type of node read by the handler.
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.
bool isInContractedForm() const
XMLSize_t getDataLen() const
const XMLCh * getElementValue() const
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:60
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.