All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ReaderHandler.cpp
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.cpp
22 
23  \brief This class implements Xerces interface for a handler that receives general document events.
24  */
25 
26 // TerraLib
27 #include "ReaderHandler.h"
28 
29 // Xerces-C++
30 #include <xercesc/sax/Locator.hpp>
31 #include <xercesc/sax2/Attributes.hpp>
32 #include <xercesc/util/XMLChar.hpp>
33 #include <xercesc/util/XMLString.hpp>
34 
36  : m_uri(0),
37  m_localname(0),
38  m_qname(0),
39  m_attrs(0),
40  m_value(0),
41  m_len(0),
42  /*m_locator(0),*/
43  m_nodeType(te::xml::UNKNOWN),
44  m_isInContractedForm(false)
45 {
46 }
47 
49 {
50  m_nodeType = te::xml::UNKNOWN;
51  m_nspaces.clear();
52 }
53 
54 void te::xerces::ReaderHandler::characters(const XMLCh* const chars, const XMLSize_t length)
55 {
56  xercesc_3_1::XMLChar1_0::isAllSpaces(chars, length) ? m_nodeType = te::xml::WHITESPACE : m_nodeType = te::xml::VALUE;
57  m_value = chars;
58  m_len = length;
59 }
60 
62 {
63  m_nodeType = te::xml::END_DOCUMENT;
64 }
65 
66 void te::xerces::ReaderHandler::endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname)
67 {
68  if(m_nodeType == te::xml::START_ELEMENT)
69  {
70  m_isInContractedForm = true;
71  return;
72  }
73 
74  m_nodeType = te::xml::END_ELEMENT;
75  m_uri = uri;
76  m_localname = localname;
77  m_qname = qname;
78 }
79 
80 void te::xerces::ReaderHandler::ignorableWhitespace(const XMLCh* const /*chars*/, const XMLSize_t /*length*/)
81 {
82  m_nodeType = te::xml::UNKNOWN;
83  //m_value = chars;
84  //m_len = length;
85 }
86 
87 void te::xerces::ReaderHandler::processingInstruction(const XMLCh* const target, const XMLCh* const data)
88 {
89  m_nodeType = te::xml::UNKNOWN;
90 }
91 
92 void te::xerces::ReaderHandler::setDocumentLocator(const xercesc::Locator* const /*locator*/)
93 {
94  //m_locator = locator;
95 }
96 
98 {
99  m_nodeType = te::xml::START_DOCUMENT;
100 }
101 
102 void te::xerces::ReaderHandler::startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const xercesc::Attributes& attrs)
103 {
104  m_nodeType = te::xml::START_ELEMENT;
105  m_uri = uri;
106  m_localname = localname;
107  m_qname = qname;
108  m_attrs = &attrs;
109 }
110 
111 void te::xerces::ReaderHandler::startPrefixMapping(const XMLCh* const prefix, const XMLCh* const uri)
112 {
113  m_nodeType = te::xml::UNKNOWN;
114 
115  m_nspaces.push_back(std::pair<const XMLCh*, const XMLCh*>(prefix, uri));
116 }
117 
118 void te::xerces::ReaderHandler::endPrefixMapping(const XMLCh* const prefix)
119 {
120  m_nodeType = te::xml::UNKNOWN;
121 }
122 
123 void te::xerces::ReaderHandler::skippedEntity(const XMLCh* const /*name*/)
124 {
125  m_nodeType = te::xml::UNKNOWN;
126 }
127 
129 {
130  return m_nodeType;
131 }
132 
134 {
135  m_nodeType = type;
136 }
137 
139 {
140  return m_isInContractedForm;
141 }
142 
144 {
145  m_isInContractedForm = d;
146 }
void processingInstruction(const XMLCh *const target, const XMLCh *const data)
It receives notification of a processing instruction.
void endPrefixMapping(const XMLCh *const prefix)
It receives notification of the end of an namespace prefix mapping.
void setNodeType(te::xml::NodeType type)
void setDocumentLocator(const xercesc::Locator *const locator)
It receives an object for locating the origin of SAX document events.
NodeType
The type of node read by XML reader.
Definition: Enums.h:40
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.
This class implements Xerces interface for a handler that receives general document events...
void startDocument()
It receives notification of the beginning of a document.
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
void skippedEntity(const XMLCh *const name)
It receives notification of a skipped entity.
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.