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