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 Reader.h
22 
23  \brief A class that models a XML reader object built on top of Xerces-C++.
24 */
25 
26 #ifndef __TERRALIB_XERCES_INTERNAL_READER_H
27 #define __TERRALIB_XERCES_INTERNAL_READER_H
28 
29 // TerraLib
30 #include "../xml/Reader.h"
31 #include "Config.h"
32 
33 // STL
34 #include <string>
35 
36 // Xerces-C++
37 #include <xercesc/util/XercesDefs.hpp>
38 
39 // Forward declaration
40 XERCES_CPP_NAMESPACE_BEGIN
41 class Attributes;
42 class SAX2XMLReader;
43 class XMLPScanToken;
44 XERCES_CPP_NAMESPACE_END
45 
46 namespace te
47 {
48  namespace xerces
49  {
50 // Forward declaration
51  class ErrorHandler;
52  class ReaderHandler;
53 
54  /*!
55  \class Reader
56 
57  \brief A class that models a XML reader object built on top of Xerces-C++
58 
59  This API is intend to simplify the task of reading XML files. We have
60  tried to model it close to the Libxml2 API (see http://xmlsoft.org/xmlreader.html for more information)
61  but keeping all Xerces-C++ support capabilities: schema validation and grammar cache.
62 
63  If you prefer to use the SAX or DOM parsers, please, look
64  the Xerces-C++ documentation available at http://xerces.apache.org/xerces-c.
65  */
66  class Reader : public te::xml::Reader
67  {
68  public:
69 
70  /*! \brief Default constructor. */
71  Reader();
72 
73  /*! \brief Destructor. */
75 
76  void setDoNamespaces(bool d);
77 
78  void setDoSchema(bool d);
79 
80  void setValidationScheme(bool d);
81 
83 
85 
86  void setIgnoreWhiteSpaces(bool d);
87 
88  void read(const std::string& fileURI);
89 
90  void readFromContent(const std::string& content) override;
91 
92  bool next();
93 
95 
96  std::string getElementURI() const;
97 
98  std::string getElementLocalName() const;
99 
100  std::string getElementQName() const;
101 
102  std::string getElementValue() const;
103 
104  std::size_t getElementDataLen() const;
105 
106  bool hasAttrs() const;
107 
108  std::size_t getNumberOfAttrs() const;
109 
110  std::string getAttr(const std::string& name) const;
111 
112  std::string getAttr(std::size_t i) const;
113 
114  std::string getAttrLocalName(std::size_t i) const;
115 
116  std::string getAttrQName(std::size_t i) const;
117 
118  std::string getAttrURI(std::size_t i) const;
119 
120  std::size_t getAttrPosition(const std::string& name) const;
121 
122  std::size_t getNumberOfNamespaces() const;
123 
124  void getNamespace(std::size_t i, std::pair<std::string, std::string>& ns) const;
125 
126  void setInternalBufferSize(const std::size_t size);
127 
128  /*!
129  \brief It resets the parser.
130 
131  \exception Exception It throws an exception if it is not possible to reset the parser.
132 
133  \note Xerces extended method.
134  */
135  void reset();
136 
137  private:
138 
139  xercesc::SAX2XMLReader* m_parser; //!< A pointer to the parser used by the reader.
140  ReaderHandler* m_readerH; //!< A pointer to a content handler.
141  ErrorHandler* m_errH; //!< A pointer to an error handler.
142  xercesc::XMLPScanToken* m_token; //!< This keeps the parser state.
143  bool m_ignoreWhiteSpaces; //!< A flag that indicates if the parser should ignore white spaces.
144  };
145 
146  } // end namespace xerces
147 } // end namespace te
148 
149 #endif // __TERRALIB_XERCES_INTERNAL_READER_H
150 
te::xerces::Reader::setInternalBufferSize
void setInternalBufferSize(const std::size_t size)
It sets the maximal allowed buffer size used for parsing.
te::xerces::Reader::getElementValue
std::string getElementValue() const
It returns the element data value in the case of VALUE node.
te::xerces::ErrorHandler
This class implements Xerces interface for error handlers.
Definition: ErrorHandler.h:51
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::xerces::Reader::setValidationScheme
void setValidationScheme(bool d)
If true the parser will perform a validation scheme.
te::xerces::Reader::m_parser
xercesc::SAX2XMLReader * m_parser
A pointer to the parser used by the reader.
Definition: Reader.h:139
te::xerces::Reader::setDoSchema
void setDoSchema(bool d)
It enables or disables the parser schema processing.
te::xerces::Reader::getElementLocalName
std::string getElementLocalName() const
It returns the local part of the element name in the case of an element node.
te::xerces::Reader::setUseCachedGrammarInParse
void setUseCachedGrammarInParse(bool d)
If true the reader will use cached grammar if it exists in the pool.
te::xerces::Reader::getAttrURI
std::string getAttrURI(std::size_t i) const
It returns the attribute URI of the associated namespace in the case of an element node.
te::xerces::Reader::getAttrQName
std::string getAttrQName(std::size_t i) const
It returns the qualified name for the i-th attribute.
te::xerces::Reader::~Reader
~Reader()
Destructor.
te::xerces::Reader::getElementURI
std::string getElementURI() const
It returns the URI of the associated namespace in the case of an element node.
te::xml::Reader
This class models a XML reader object.
Definition: Reader.h:56
te::xerces::Reader::readFromContent
void readFromContent(const std::string &content) override
It prepare the given content to be read.
te::xerces::Reader::getAttr
std::string getAttr(std::size_t i) const
It returns the attribute value in the case of an element node with valid attributes.
te::xerces::Reader::reset
void reset()
It resets the parser.
te::xerces::Reader::getNodeType
te::xml::NodeType getNodeType() const
It return the type of node read.
te::xerces::Reader::getNamespace
void getNamespace(std::size_t i, std::pair< std::string, std::string > &ns) const
te::xerces::Reader::getAttr
std::string getAttr(const std::string &name) const
It returns the attribute value in the case of an element node with valid attributes.
te::xerces::Reader
A class that models a XML reader object built on top of Xerces-C++.
Definition: Reader.h:67
te::xerces::Reader::getAttrPosition
std::size_t getAttrPosition(const std::string &name) const
It returns the attribute position.
te::xml::NodeType
NodeType
The type of node read by XML reader.
Definition: Enums.h:41
te::xerces::ReaderHandler
This class implements Xerces interface for a handler that receives general document events.
Definition: ReaderHandler.h:56
te::xerces::Reader::setDoNamespaces
void setDoNamespaces(bool d)
It enables or disables the parser namespace processing.
te::xerces::Reader::Reader
Reader()
Default constructor.
te::xerces::Reader::getElementQName
std::string getElementQName() const
It returns the qualified name in the case of an element node.
te::xerces::Reader::m_ignoreWhiteSpaces
bool m_ignoreWhiteSpaces
A flag that indicates if the parser should ignore white spaces.
Definition: Reader.h:143
te::xerces::Reader::next
bool next()
It gets the next event to be read.
te::xerces::Reader::getElementDataLen
std::size_t getElementDataLen() const
It returns the element data value in the case of VALUE node.
te::xerces::Reader::setIgnoreWhiteSpaces
void setIgnoreWhiteSpaces(bool d)
If true the parser will ignore the white space characters.
te::xerces::Reader::m_errH
ErrorHandler * m_errH
A pointer to an error handler.
Definition: Reader.h:141
te::xerces::Reader::read
void read(const std::string &fileURI)
It prepare the given file to be read.
te::xerces::Reader::getNumberOfNamespaces
std::size_t getNumberOfNamespaces() const
Config.h
Proxy configuration file for TerraView (see terraview_config.h).
te::xerces::Reader::setCacheGrammarFromParse
void setCacheGrammarFromParse(bool d)
If true it caches the grammar in the pool for re-use in subsequent parses.
te::xerces::Reader::getAttrLocalName
std::string getAttrLocalName(std::size_t i) const
It returns the local part of the attribute name for the i-th attribute.
te::xerces::Reader::hasAttrs
bool hasAttrs() const
It tells if the element has attributes in the case of an element node.
te::xerces::Reader::getNumberOfAttrs
std::size_t getNumberOfAttrs() const
It returns the number of attributes in the case of an element node.
te::xerces::Reader::m_readerH
ReaderHandler * m_readerH
A pointer to a content handler.
Definition: Reader.h:140
te::xerces::Reader::m_token
xercesc::XMLPScanToken * m_token
This keeps the parser state.
Definition: Reader.h:142