All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Utils.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 terralib/se/serialization/xml/Utils.cpp
22 
23  \brief Utility methods for Symbology serialization.
24 */
25 
26 // TerraLib
27 #include "../../../fe/PropertyName.h"
28 #include "../../../se/Symbolizer.h"
29 #include "../../../xml/AbstractWriter.h"
30 #include "../../../xml/Reader.h"
31 #include "../../../xlink/serialization/xml/XLinkSerializer.h"
32 #include "../../../fe/serialization/xml/Expression.h"
33 #include "../../Description.h"
34 #include "../../ParameterValue.h"
35 #include "../../SelectedChannel.h"
36 #include "SymbologySerializer.h"
37 #include "Utils.h"
38 
39 // STL
40 #include <cassert>
41 
42 void te::se::serialize::WriteStringPtrHelper(const std::string& elementName, const std::string* s, te::xml::AbstractWriter& writer)
43 {
44  if(s != 0 && !s->empty()) writer.writeElement(elementName, *s);
45 }
46 
48 {
49  if(p == 0)
50  return;
51 
52  writer.writeStartElement(elementName);
53  Save(p, writer);
54  writer.writeEndElement(elementName);
55 }
56 
58 {
59  if(link == 0)
60  return;
61 
62  writer.writeStartElement("se:BaseSymbolizer");
63  WriteOnlineResourceHelper(link, writer);
64  writer.writeEndElement("se:BaseSymbolizer");
65 }
66 
68 {
69  if(link == 0)
70  return;
71 
72  writer.writeStartElement("se:OnlineResource");
73  te::xl::serialize::Save(link, writer);
74  writer.writeEndElement("se:OnlineResource");
75 }
76 
78 {
79  assert(symbolizer);
80 
81  writer.writeAttribute("version", symbolizer->getVersion());
82  //writer.writeAttribute("uom", symbolizer->getUom()); // TODO: URI from te::common:: UnitOfMeasure!
83  WriteStringPtrHelper("se:Name", &symbolizer->getName(), writer);
84  Save(symbolizer->getDescription(), writer);
85  WriteBaseSymbolizerHelper(symbolizer->getBaseSymbolizer(), writer);
86 }
87 
89 {
90  if(reader.hasAttrs())
91  {
92  // TODO: Verify first if the symbolizer has the attributes version and uom!
93 
94  // Version
95  std::string version = reader.getAttr("version");
96  symbolizer->setVersion(version);
97 
98  // Uom
99  std::string uom = reader.getAttr("uom");
100  //symbolizer->setUom(version); // TODO: te:common:: UnitOfMeasure from URI!
101  }
102 
103  reader.next();
104 
105  // Name
106  if(reader.getElementLocalName() == "Name")
107  {
108  reader.next();
109  assert(reader.getNodeType() == te::xml::VALUE);
110  symbolizer->setName(reader.getElementValue());
111  reader.next();
112  assert(reader.getNodeType() == te::xml::END_ELEMENT);
113  reader.next();
114  }
115 
116  // Description
117  if(reader.getElementLocalName() == "Description")
118  symbolizer->setDescription(ReadDescription(reader));
119 
120  // TODO: BaseSymbolizer
121 }
122 
124 {
125  if(sc == 0)
126  return;
127 
128  writer.writeStartElement(elementName);
129  Save(sc, writer);
130  writer.writeEndElement(elementName);
131 }
132 
134 {
135  if(p == 0)
136  return;
137 
138  writer.writeStartElement("se:Geometry");
140  writer.writeEndElement("se:Geometry");
141 }
142 
144 {
145  assert(reader.getNodeType() == te::xml::START_ELEMENT);
146  assert(reader.getElementLocalName() == "Geometry");
147 
148  reader.next();
149 
151  assert(exp);
152 
153  std::auto_ptr<te::fe::PropertyName> pName(dynamic_cast<te::fe::PropertyName*>(exp));
154  assert(pName.get());
155 
156  assert(reader.getNodeType() == te::xml::END_ELEMENT);
157  reader.next();
158 
159  return pName.release();
160 }
A selected channel to be display.
void setVersion(const std::string &version)
Definition: Symbolizer.cpp:99
This class models a XML reader object.
Definition: Reader.h:55
virtual void writeStartElement(const std::string &qName)=0
A Symbolizer describes how a feature is to appear on a map.
Definition: Symbolizer.h:80
const std::string & getVersion() const
Definition: Symbolizer.cpp:104
This class models a XML writer object.
The "ParameterValueType" uses WFS-Filter expressions to give values for SE graphic parameters...
void WriteStringPtrHelper(const std::string &elementName, const std::string *s, te::xml::AbstractWriter &writer)
Definition: Utils.cpp:42
virtual std::string getElementLocalName() const =0
It returns the local part of the element name in the case of an element node.
void WriteBaseSymbolizerHelper(const te::xl::SimpleLink *link, te::xml::AbstractWriter &writer)
Definition: Utils.cpp:57
void setName(const std::string &name)
Definition: Symbolizer.cpp:67
virtual void writeElement(const std::string &qName, const std::string &value)=0
static T & getInstance()
It returns a reference to the singleton instance.
Definition: Singleton.h:120
void WriteSymbolizerHelper(const te::se::Symbolizer *symbolizer, te::xml::AbstractWriter &writer)
Definition: Utils.cpp:77
const std::string & getName() const
Definition: Symbolizer.cpp:72
This class is used to encode the name of any property of an object.
Definition: PropertyName.h:54
This is an abstract class that models a Filter Encoding expression.
Definition: Expression.h:50
TEDATAACCESSEXPORT void Save(const std::string &fileName)
Definition: Serializer.cpp:201
void setDescription(Description *d)
Definition: Symbolizer.cpp:77
Utility methods for the Symbology serialization.
void WriteOnlineResourceHelper(const te::xl::SimpleLink *link, te::xml::AbstractWriter &writer)
Definition: Utils.cpp:67
void WriteGeometryPropertyHelper(const te::fe::PropertyName *p, te::xml::AbstractWriter &writer)
Definition: Utils.cpp:133
te::fe::PropertyName * ReadGeometryPropertyHelper(te::xml::Reader &reader)
Definition: Utils.cpp:143
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.
Data serialization for the Symbology Encoder module.
virtual void writeAttribute(const std::string &attName, const std::string &value)=0
const Description * getDescription() const
Definition: Symbolizer.cpp:83
virtual NodeType getNodeType() const =0
It return the type of node read.
const te::xl::SimpleLink * getBaseSymbolizer() const
Definition: Symbolizer.cpp:94
virtual std::string getElementValue() const =0
It returns the element data value in the case of VALUE node.
virtual void writeEndElement(const std::string &qName)=0
void WriteParameterValuePtrHelper(const std::string &elementName, const te::se::ParameterValue *p, te::xml::AbstractWriter &writer)
Definition: Utils.cpp:47
TESEEXPORT te::se::Description * ReadDescription(te::xml::Reader &reader)
virtual bool hasAttrs() const =0
It tells if the element has attributes in the case of an element node.
virtual bool next()=0
It gets the next event to be read.
void ReadSymbolizerHelper(te::se::Symbolizer *symbolizer, te::xml::Reader &reader)
Definition: Utils.cpp:88
void WriteSelectedChannelHelper(const std::string &elementName, const te::se::SelectedChannel *sc, te::xml::AbstractWriter &writer)
Definition: Utils.cpp:123