All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Annotation.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/Annotation.cpp
22 
23  \brief Support for Annotation serialization.
24 */
25 
26 // TerraLib
27 #include "../../xml/Reader.h"
28 #include "../../xml/Writer.h"
29 #include "../../xsd/Annotation.h"
30 #include "../../xsd/AppInfo.h"
31 #include "../../xsd/Documentation.h"
32 #include "Annotation.h"
33 #include "Utils.h"
34 
35 // STL
36 #include <cassert>
37 #include <memory>
38 #include <string>
39 
41 {
42  assert(reader.getNodeType() == te::xml::START_ELEMENT);
43  assert(reader.getElementLocalName() == "annotation");
44 
45  std::auto_ptr<te::xsd::Annotation> annotation(new te::xsd::Annotation());
46 
47  // Id
48  ReadIdentifiable(annotation.get(), reader);
49 
50  reader.next();
51 
52  while(reader.getNodeType() == te::xml::START_ELEMENT &&
53  ((reader.getElementLocalName() == "appinfo") ||
54  (reader.getElementLocalName() == "documentation")))
55  {
56  std::string tag = reader.getElementLocalName();
57  if(tag == "appinfo")
58  {
59  // Reads the AppInfo
60  te::xsd::AppInfo* appinfo = new te::xsd::AppInfo(0, 0);
61 
62  // Source
63  std::size_t pos = reader.getAttrPosition("version");
64  if(pos != std::string::npos)
65  appinfo->setSource(new std::string(reader.getAttr(pos)));
66 
67  // Value
68  reader.next();
69  assert(reader.getNodeType() == te::xml::VALUE);
70  appinfo->setValue(new std::string(reader.getElementValue()));
71 
72  // Adds the appinfo on annotation
73  annotation->add(appinfo);
74 
75  reader.next();
76  assert(reader.getNodeType() == te::xml::END_ELEMENT); // End of AppInfo element
77 
78  reader.next();
79 
80  continue;
81  }
82 
83  if(tag == "documentation")
84  {
85  // Reads the Documentation
87 
88  // Source
89  std::size_t pos = reader.getAttrPosition("version");
90  if(pos != std::string::npos)
91  doc->setSource(new std::string(reader.getAttr(pos)));
92 
93  // xml:lang
94  pos = reader.getAttrPosition("xml:lang");
95  if(pos != std::string::npos)
96  doc->setLang(new std::string(reader.getAttr(pos)));
97 
98  // Value
99  reader.next();
100  assert(reader.getNodeType() == te::xml::VALUE);
101  doc->setValue(new std::string(reader.getElementValue()));
102 
103  // Adds the appinfo on annotation
104  annotation->add(doc);
105 
106  reader.next();
107  assert(reader.getNodeType() == te::xml::END_ELEMENT); // End of Documentation element
108 
109  reader.next();
110  }
111  }
112 
113  assert(reader.getNodeType() == te::xml::END_ELEMENT);
114  reader.next();
115 
116  return annotation.release();
117 }
118 
120 {
121 }
void setSource(std::string *source)
It sets the URI reference that specifies the source of the information.
void setLang(std::string *lang)
It sets the language of the information.
This class models a XML reader object.
Definition: Reader.h:55
virtual bool next()=0
It gets the next event to be read.
TESERIALIZATIONEXPORT te::xsd::Annotation * ReadAnnotation(te::xml::Reader &reader)
Definition: Annotation.cpp:40
A class that models a documentation element used to enter text comments in annotations.
Definition: Documentation.h:48
virtual std::string getElementValue() const =0
It returns the element data value in the case of VALUE node.
TESERIALIZATIONEXPORT void Save(const te::fe::Filter *filter, te::xml::Writer &writer)
Definition: Filter.cpp:54
void ReadIdentifiable(te::xsd::Identifiable *identifiable, te::xml::Reader &reader)
Definition: Utils.cpp:41
This class models an object that specifies information to be used by applications.
Definition: AppInfo.h:48
void setValue(std::string *value)
It sets the information to be used by the application.
Definition: AppInfo.cpp:65
A class that models a XSD annotation element.
Definition: Annotation.h:55
void setValue(std::string *doc)
It sets the information associated to the annotation.
Support for Annotation serialization.
void setSource(std::string *source)
It sets the URI that specifies the source of the information.
Definition: AppInfo.cpp:71
Utility methods for Schema serialization.
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.
virtual std::size_t getAttrPosition(const std::string &name) const =0
It returns the attribute position.
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.
This class models a XML writer object.
Definition: Writer.h:52