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