All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SimpleLink.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/xlink/SimpleLink.cpp
22 
23  \brief Support for SimpleLink serialization.
24 */
25 
26 // TerraLib
27 #include "../../xlink/SimpleLink.h"
28 #include "../../xml/Reader.h"
29 #include "../../xml/Writer.h"
30 #include "SimpleLink.h"
31 
32 // STL
33 #include <cassert>
34 #include <memory>
35 
37 {
38  std::auto_ptr<te::xl::SimpleLink> link(new te::xl::SimpleLink);
39 
40  std::size_t n = reader.getNumberOfAttrs();
41  for(std::size_t i = 0; i < n; ++i)
42  {
43  std::string attributeName = reader.getAttrLocalName(i);
44  std::string attributeValue = reader.getAttr(i);
45 
46  if(attributeName == "href")
47  link->setHref(attributeValue);
48 
49  else if(attributeName == "title")
50  link->setTitle(attributeValue);
51 
52  else if(attributeName == "role")
53  link->setRole(attributeValue);
54 
55  else if(attributeName == "arcrole")
56  link->setArcRole(attributeValue);
57 
58  else if(attributeName == "show")
59  {
60  if(attributeValue == "embed")
61  link->setShow(te::xl::SHOW_EMBED);
62 
63  else if(attributeValue == "new")
64  link->setShow(te::xl::SHOW_NEW);
65 
66  else if(attributeValue == "other")
67  link->setShow(te::xl::SHOW_OTHER);
68  }
69 
70  else if(attributeName == "actuate")
71  {
72  if(attributeValue == "onLoad")
73  link->setActuate(te::xl::ACTUATE_ONLOAD);
74 
75  else if(attributeValue == "onRequest")
76  link->setActuate(te::xl::ACTUATE_ONREQUEST);
77 
78  else if(attributeValue == "other")
79  link->setActuate(te::xl::ACTUATE_OTHER);
80  }
81  }
82 
83  return link.release();
84 }
85 
87 {
88  assert(link);
89 
90  if(!link->getHref().empty())
91  writer.writeAttribute("xlink:href", link->getHref());
92 
93  if(!link->getTitle().empty())
94  writer.writeAttribute("xlink:title", link->getTitle());
95 
96  if(!link->getRole().empty())
97  writer.writeAttribute("xlink:role", link->getRole());
98 
99  if(!link->getArcRole().empty())
100  writer.writeAttribute("xlink:arcrole", link->getArcRole());
101 
102  switch(link->getShow())
103  {
104  case te::xl::SHOW_NONE:
105  break;
106 
107  case te::xl::SHOW_EMBED:
108  writer.writeAttribute("xlink:show", "embed");
109  break;
110 
111  case te::xl::SHOW_NEW:
112  writer.writeAttribute("xlink:show", "new");
113  break;
114 
116  writer.writeAttribute("xlink:show", "replace");
117  break;
118 
119  case te::xl::SHOW_OTHER:
120  writer.writeAttribute("xlink:show", "other");
121  }
122 
123  switch(link->getActuate())
124  {
126  break;
127 
129  writer.writeAttribute("xlink:actuate", "onLoad");
130  break;
131 
133  writer.writeAttribute("xlink:actuate", "onRequest");
134  break;
135 
137  writer.writeAttribute("xlink:actuate", "other");
138  }
139 }
const std::string & getArcRole() const
Definition: SimpleLink.cpp:70
const std::string & getHref() const
Definition: SimpleLink.cpp:50
This class models a XML reader object.
Definition: Reader.h:55
TESERIALIZATIONEXPORT te::xl::SimpleLink * ReadSimpleLink(te::xml::Reader &reader)
Definition: SimpleLink.cpp:36
virtual std::string getAttrLocalName(std::size_t i) const =0
It returns the local part of the attribute name for the i-th attribute.
Simple link.
Definition: SimpleLink.h:48
virtual std::size_t getNumberOfAttrs() const =0
It returns the number of attributes in the case of an element node.
ShowType getShow() const
Definition: SimpleLink.cpp:90
virtual void writeAttribute(const std::string &attName, const std::string &value)
Definition: Writer.cpp:90
TESERIALIZATIONEXPORT void Save(const te::fe::Filter *filter, te::xml::Writer &writer)
Definition: Filter.cpp:54
ActuateType getActuate() const
Definition: SimpleLink.cpp:100
Support for SimpleLink serialization.
const std::string & getRole() const
Definition: SimpleLink.cpp:60
const std::string & getTitle() const
Definition: SimpleLink.cpp:80
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