Loading...
Searching...
No Matches
Reader.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 terralib/xml/Reader.h
22
23 \brief This class models a XML reader object.
24*/
25
26#ifndef __TERRALIB_XML_INTERNAL_READER_H
27#define __TERRALIB_XML_INTERNAL_READER_H
28
29// TerraLib
30#include "Config.h"
31#include "Enums.h"
32
33// STL
34#include <string>
35
36// Boost
37#include <boost/cstdint.hpp>
38#include <boost/noncopyable.hpp>
39
40namespace te
41{
42 namespace xml
43 {
44 /*!
45 \class Reader
46
47 \brief This class models a XML reader object.
48
49 This API is intend to simplify the task of reading XML files. We have
50 tried to model it close to the Libxml2 API (see http://xmlsoft.org/xmlreader.html for more information)
51 but keeping all Xerces-C++ support capabilities: schema validation and grammar cache.
52
53 \ingroup xml
54 */
55 class TEXMLEXPORT Reader : public boost::noncopyable
56 {
57 public:
58
59 /*! \brief Default constructor. */
60 Reader() { }
61
62 /*! \brief Virtual destructor. */
63 virtual ~Reader() { }
64
65 /*!
66 \brief It enables or disables the parser namespace processing.
67
68 \param d If true the internal parser will perform the namespace processing otherwise this will not be done.
69
70 \note By default the reader is set to do namespace processing.
71 */
72 virtual void setDoNamespaces(bool d) = 0;
73
74 /*!
75 \brief It enables or disables the parser schema processing.
76
77 \param d If true the internal parser will perform the schema processing otherwise this will not be done.
78
79 \note If set to true the namespace processing must also be turned on.
80
81 \note By default the reader is set to parser schema.
82 */
83 virtual void setDoSchema(bool d) = 0;
84
85 /*!
86 \brief If true the parser will perform a validation scheme.
87
88 \param d If true the parser will perform a validation scheme.
89
90 \note By default the reader is set to validate the scheme.
91 */
92 virtual void setValidationScheme(bool d) = 0;
93
94 /*!
95 \brief If true the reader will use cached grammar if it exists in the pool.
96
97 \param d If true the reader will use cached grammar if it exists in the pool.
98
99 \note By default the reader is set to use cached grammar.
100 */
101 virtual void setUseCachedGrammarInParse(bool d) = 0;
102
103 /*!
104 \brief If true it caches the grammar in the pool for re-use in subsequent parses.
105
106 \param d If If true it caches the grammar in the pool for re-use in subsequent parses.
107
108 \note By default the reader is set to cache the grammar.
109 */
110 virtual void setCacheGrammarFromParse(bool d) = 0;
111
112 /*!
113 \brief If true the parser will ignore the white space characters.
114
115 \param d If true the parser will ignore the white space characters.
116
117 \note By default the reader is set to consider white spaces.
118 */
119 virtual void setIgnoreWhiteSpaces(bool d) = 0;
120
121 /*!
122 \brief It prepare the given file to be read.
123
124 You must call read to start parsing the XML document.
125
126 \param fileURI A path to a XML file or any URI where it can be found.
127
128 \exception Exception It throws an exception if the file doesn't exist or if the internal parser can not read it.
129 */
130 virtual void read(const std::string& fileURI) = 0;
131
132 /*!
133 \brief It prepare the given content to be read.
134
135 You must call read to start parsing the XML document.
136
137 \param content A string containing the XML content.
138
139 \exception Exception It throws an exception if the content cannot be read
140 */
141 virtual void readFromContent(const std::string& content) = 0;
142
143 /*!
144 \brief It gets the next event to be read.
145
146 \return True if an event was read otherwise false.
147
148 \exception Exception It throws an exception if something goes wrong during the text read.
149 */
150 virtual bool next() = 0;
151
152 /*!
153 \brief It return the type of node read.
154
155 \return The type of node read.
156 */
157 virtual NodeType getNodeType() const = 0;
158
159 /*!
160 \brief It returns the URI of the associated namespace in the case of an element node.
161
162 \return The URI of the associated namespace in the case of an element node.
163 */
164 virtual std::string getElementURI() const = 0;
165
166 /*!
167 \brief It returns the local part of the element name in the case of an element node.
168
169 \return The local part of the element name in the case of an element node.
170 */
171 virtual std::string getElementLocalName() const = 0;
172
173 /*!
174 \brief It returns the qualified name in the case of an element node.
175
176 \return The qualified name in the case of an element node.
177 */
178 virtual std::string getElementQName() const = 0;
179
180 /*!
181 \brief It returns the element data value in the case of VALUE node.
182
183 \return The element data value in the case of VALUE node.
184 */
185 virtual std::string getElementValue() const = 0;
186
187 /*!
188 \brief It returns the element data value in the case of VALUE node.
189
190 \return The element data value in the case of VALUE node.
191
192 \note Just call this method if you know that the element value can be converted to a 32-bit integer.
193 */
194 virtual boost::int32_t getElementValueAsInt32() const;
195
196 /*!
197 \brief It returns the element data value in the case of VALUE node.
198
199 \return The element data value in the case of VALUE node.
200
201 \note Just call this method if you know that the element value can be converted to a double.
202 */
203 virtual double getElementValueAsDouble() const;
204
205 /*!
206 \brief It returns the element data value in the case of VALUE node.
207
208 \return The element data value in the case of VALUE node.
209
210 \note Just call this method if you know that the element value can be converted to a boolean.
211 */
212 virtual bool getElementValueAsBoolean() const;
213
214 /*!
215 \brief It returns the element data value in the case of VALUE node.
216
217 \return The element data value in the case of VALUE node.
218
219 \note Just call this method if you know that the element value can be converted to a bool.
220 */
221 //virtual bool getElementValueAsBool() const;
222
223 /*!
224 \brief It returns the element data value length in the case of VALUE or CDATA node.
225
226 \return The element data value in the case of VALUE or CDATA node.
227 */
228 virtual std::size_t getElementDataLen() const = 0;
229
230 /*!
231 \brief It tells if the element has attributes in the case of an element node.
232
233 \return True if the element has attributes in the case of an element node, otherwise, false.
234 */
235 virtual bool hasAttrs() const = 0;
236
237 /*!
238 \brief It returns the number of attributes in the case of an element node.
239
240 \return The number of attributes in the case of an element node.
241 */
242 virtual std::size_t getNumberOfAttrs() const = 0;
243
244 /*!
245 \brief It returns the attribute value in the case of an element node with valid attributes.
246
247 \param name The attribute name.
248
249 \return The attribute value in the case of an element node with valid attributes.
250 */
251 virtual std::string getAttr(const std::string& name) const = 0;
252
253 /*!
254 \brief It returns the attribute value in the case of an element node with valid attributes.
255
256 \param i The attribute position.
257
258 \return The attribute value in the case of an element node with valid attributes.
259 */
260 virtual std::string getAttr(std::size_t i) const = 0;
261
262 /*!
263 \brief It returns the attribute value in the case of an element node with valid attributes.
264
265 \param name The attribute name.
266
267 \return The attribute value in the case of an element node with valid attributes.
268
269 \note Just call this method if you know that the attribute value can be converted to a 32-bit integer.
270 */
271 virtual boost::int32_t getAttrAsInt32(const std::string& name) const;
272
273 /*!
274 \brief It returns the attribute value in the case of an element node with valid attributes.
275
276 \param i The attribute position.
277
278 \return The attribute value in the case of an element node with valid attributes.
279
280 \note Just call this method if you know that the attribute value can be converted to a 32-bit integer.
281 */
282 virtual boost::int32_t getAttrAsInt32(std::size_t i) const;
283
284 /*!
285 \brief It returns the attribute value in the case of an element node with valid attributes.
286
287 \param i The attribute position.
288
289 \return The attribute value in the case of an element node with valid attributes.
290
291 \note Just call this method if you know that the attribute value can be converted to a 32-bit unsigned integer.
292 */
293 virtual boost::uint32_t getAttrAsUInt32(std::size_t i) const;
294
295 /*!
296 \brief It returns the attribute value in the case of an element node with valid attributes.
297
298 \param name The attribute name.
299
300 \return The attribute value in the case of an element node with valid attributes.
301
302 \note Just call this method if you know that the attribute value can be converted to a 32-bit unsigned integer.
303 */
304 virtual boost::uint32_t getAttrAsUInt32(const std::string name) const;
305
306 /*!
307 \brief It returns the attribute value in the case of an element node with valid attributes.
308
309 \param name The attribute name.
310
311 \return The attribute value in the case of an element node with valid attributes.
312
313 \note Just call this method if you know that the attribute value can be converted to a double.
314 */
315 virtual double getAttrAsDouble(const std::string& name) const;
316
317 /*!
318 \brief It returns the attribute value in the case of an element node with valid attributes.
319
320 \param i The attribute position.
321
322 \return The attribute value in the case of an element node with valid attributes.
323
324 \note Just call this method if you know that the attribute value can be converted to a double.
325 */
326 virtual double getAttrAsDouble(std::size_t i) const;
327
328 /*!
329 \brief It returns the local part of the attribute name for the i-th attribute.
330
331 \param i The attribute position index.
332
333 \return The local part of the attribute name in the case of an element node.
334 */
335 virtual std::string getAttrLocalName(std::size_t i) const = 0;
336
337 /*!
338 \brief It returns the qualified name for the i-th attribute.
339
340 \param i The attribute position index.
341
342 \return The qualified attribute name in the case of an element node.
343 */
344 virtual std::string getAttrQName(std::size_t i) const = 0;
345
346 /*!
347 \brief It returns the attribute URI of the associated namespace in the case of an element node.
348
349 \param i The attribute position index.
350
351 \return The attribute URI of the associated namespace in the case of an element node.
352 */
353 virtual std::string getAttrURI(std::size_t i) const = 0;
354
355 /*!
356 \brief It returns the attribute position.
357
358 \param name The attribute name.
359
360 \return The attribute position.
361 */
362 virtual std::size_t getAttrPosition(const std::string& name) const = 0;
363
364 virtual std::size_t getNumberOfNamespaces() const = 0;
365
366 virtual void getNamespace(std::size_t i, std::pair<std::string, std::string>& ns) const = 0;
367
368 /*!
369 \brief It sets the maximal allowed buffer size used for parsing.
370
371 \param size The maximal allowed buffer size used for parsing.
372
373 \note Default: 65536 bytes (64 kbytes), see the macro TE_XML_READER_MAX_BUFFSIZE.
374 \note The default value may be implementation dependent!
375 */
376 virtual void setInternalBufferSize(const std::size_t size) = 0;
377 };
378
379 } // end namespace xml
380} // end namespace te
381
382#endif // __TERRALIB_XML_INTERNAL_READER_H
383
This class models a XML reader object.
Definition: Reader.h:56
virtual std::string getAttrURI(std::size_t i) const =0
It returns the attribute URI of the associated namespace in the case of an element node.
virtual std::string getElementValue() const =0
It returns the element data value in the case of VALUE node.
virtual std::size_t getAttrPosition(const std::string &name) const =0
It returns the attribute position.
virtual void setCacheGrammarFromParse(bool d)=0
If true it caches the grammar in the pool for re-use in subsequent parses.
virtual void readFromContent(const std::string &content)=0
It prepare the given content to be read.
virtual void setDoNamespaces(bool d)=0
It enables or disables the parser namespace processing.
virtual NodeType getNodeType() const =0
It return the type of node read.
virtual void setInternalBufferSize(const std::size_t size)=0
It sets the maximal allowed buffer size used for parsing.
virtual std::size_t getNumberOfNamespaces() const =0
virtual double getAttrAsDouble(const std::string &name) const
It returns the attribute value in the case of an element node with valid attributes.
virtual bool hasAttrs() const =0
It tells if the element has attributes in the case of an element node.
virtual void setIgnoreWhiteSpaces(bool d)=0
If true the parser will ignore the white space characters.
virtual void getNamespace(std::size_t i, std::pair< std::string, std::string > &ns) const =0
virtual double getAttrAsDouble(std::size_t i) const
It returns the attribute value in the case of an element node with valid attributes.
virtual void setValidationScheme(bool d)=0
If true the parser will perform a validation scheme.
virtual bool next()=0
It gets the next event to be read.
virtual std::string getAttrLocalName(std::size_t i) const =0
It returns the local part of the attribute name for the i-th attribute.
virtual double getElementValueAsDouble() const
It returns the element data value in the case of VALUE node.
virtual void setDoSchema(bool d)=0
It enables or disables the parser schema processing.
virtual std::string getElementURI() const =0
It returns the URI of the associated namespace in the case of an element node.
virtual std::string getAttr(std::size_t i) const =0
It returns the attribute value in the case of an element node with valid attributes.
virtual void setUseCachedGrammarInParse(bool d)=0
If true the reader will use cached grammar if it exists in the pool.
virtual boost::int32_t getAttrAsInt32(std::size_t i) const
It returns the attribute value in the case of an element node with valid attributes.
virtual std::string getElementLocalName() const =0
It returns the local part of the element name in the case of an element node.
virtual boost::uint32_t getAttrAsUInt32(std::size_t i) const
It returns the attribute value in the case of an element node with valid attributes.
virtual std::size_t getNumberOfAttrs() const =0
It returns the number of attributes in the case of an element node.
virtual std::string getElementQName() const =0
It returns the qualified name in the case of an element node.
virtual void read(const std::string &fileURI)=0
It prepare the given file to be read.
virtual std::string getAttr(const std::string &name) const =0
It returns the attribute value in the case of an element node with valid attributes.
Reader()
Default constructor.
Definition: Reader.h:60
virtual boost::int32_t getElementValueAsInt32() const
It returns the element data value in the case of VALUE node.
virtual std::string getAttrQName(std::size_t i) const =0
It returns the qualified name for the i-th attribute.
virtual bool getElementValueAsBoolean() const
It returns the element data value in the case of VALUE node.
virtual boost::uint32_t getAttrAsUInt32(const std::string name) const
It returns the attribute value in the case of an element node with valid attributes.
virtual std::size_t getElementDataLen() const =0
It returns the element data value in the case of VALUE node.
virtual boost::int32_t getAttrAsInt32(const std::string &name) const
It returns the attribute value in the case of an element node with valid attributes.
virtual ~Reader()
Virtual destructor.
Definition: Reader.h:63
NodeType
The type of node read by XML reader.
Definition: Enums.h:41
TerraLib.
#define TEXMLEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:88
Proxy configuration file for TerraView (see terraview_config.h).
Enumerations of XML module.