All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Description.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011-2011 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/serialization/se/Description.cpp
22 
23  \brief Support for Description serialization.
24 */
25 
26 // TerraLib
27 #include "../../se/Description.h"
28 #include "../../xml/Reader.h"
29 #include "../../xml/Writer.h"
30 #include "Description.h"
31 
32 // STL
33 #include <cassert>
34 #include <memory>
35 
37 {
38  assert(reader.getNodeType() == te::xml::START_ELEMENT);
39  assert(reader.getElementLocalName() == "Description");
40 
41  reader.next();
42 
43  std::auto_ptr<te::se::Description> description(new te::se::Description);
44 
45  // Title
46  if(reader.getElementLocalName() == "Title")
47  {
48  reader.next();
49  assert(reader.getNodeType() == te::xml::VALUE);
50  std::string title = reader.getElementValue();
51  description->setTitle(title);
52  reader.next();
53 
54  assert(reader.getNodeType() == te::xml::END_ELEMENT);
55  reader.next();
56  }
57 
58  // Abstract
59  if(reader.getElementLocalName() == "Abstract")
60  {
61  reader.next();
62  assert(reader.getNodeType() == te::xml::VALUE);
63  std::string abs = reader.getElementValue();
64  description->setAbstract(abs);
65  reader.next();
66 
67  assert(reader.getNodeType() == te::xml::END_ELEMENT);
68  reader.next();
69  }
70 
71  assert(reader.getNodeType() == te::xml::END_ELEMENT);
72  reader.next();
73 
74  return description.release();
75 }
76 
78 {
79  if(d == 0)
80  return;
81 
82  writer.writeStartElement("se:Description");
83 
84  if(!d->getTitle().empty())
85  writer.writeElement("se:Title", d->getTitle());
86 
87  if(!d->getAbstract().empty())
88  writer.writeElement("se:Abstract", d->getAbstract());
89 
90  writer.writeEndElement("se:Description");
91 }
92 
This class models a XML reader object.
Definition: Reader.h:55
const std::string & getAbstract() const
Definition: Description.cpp:52
virtual bool next()=0
It gets the next event to be read.
TESERIALIZATIONEXPORT te::se::Description * ReadDescription(te::xml::Reader &reader)
Definition: Description.cpp:36
virtual void writeStartElement(const std::string &qName)
Definition: Writer.cpp:44
A Description gives human-readable descriptive information for the object it is included within...
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)
Definition: Writer.cpp:156
TESERIALIZATIONEXPORT void Save(const te::fe::Filter *filter, te::xml::Writer &writer)
Definition: Filter.cpp:54
virtual void writeElement(const std::string &qName, const std::string &value)
Definition: Writer.cpp:54
A Description gives human-readable descriptive information for the object it is included within...
Definition: Description.h:56
virtual NodeType getNodeType() const =0
It return the type of node read.
virtual std::string getElementLocalName() const =0
It returns the local part of the element name in the case of an element node.
const std::string & getTitle() const
Definition: Description.cpp:42
This class models a XML writer object.
Definition: Writer.h:52