All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExternalGraphic.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/ExternalGraphic.cpp
22 
23  \brief Support for ExternalGraphic serialization.
24 */
25 
26 // TerraLib
27 #include "../../se/ExternalGraphic.h"
28 #include "../../xml/Reader.h"
29 #include "../../xml/Writer.h"
30 #include "../xlink/SimpleLink.h"
31 #include "ExternalGraphic.h"
32 #include "InlineContent.h"
33 #include "Utils.h"
34 
35 // STL
36 #include <cassert>
37 #include <memory>
38 
40 {
41  assert(reader.getNodeType() == te::xml::START_ELEMENT);
42  assert(reader.getElementLocalName() == "ExternalGraphic");
43 
44  reader.next();
45 
46  std::auto_ptr<te::se::ExternalGraphic> eg(new te::se::ExternalGraphic);
47 
48  if(reader.getElementLocalName() == "OnlineResource")
49  eg->setOnlineResource(ReadSimpleLink(reader));
50  else // InlineContent
51  eg->setInlineContent(ReadInlineContent(reader));
52 
53  reader.next();
54  assert(reader.getNodeType() == te::xml::END_ELEMENT);
55 
56  reader.next();
57 
58  // Format
59  assert(reader.getElementLocalName() == "Format");
60  reader.next();
61  assert(reader.getNodeType() == te::xml::VALUE);
62  eg->setFormat(reader.getElementValue());
63  reader.next();
64 
65  // Recodes (...)
66 
67  assert(reader.getNodeType() == te::xml::END_ELEMENT);
68  reader.next();
69 
70  assert(reader.getNodeType() == te::xml::END_ELEMENT);
71  reader.next();
72 
73  return eg.release();
74 }
75 
77 {
78  if(eg == 0)
79  return;
80 
81  writer.writeStartElement("se:ExternalGraphic");
82 
83  const te::xl::SimpleLink* link = eg->getOnlineResource();
84  if(link)
86  else
87  {
88  const te::se::InlineContent* ic = eg->getInlineContent();
89  assert(ic);
90  Save(ic, writer);
91  }
92  const std::string& format = eg->getFormat();
93  assert(!format.empty());
94  writer.writeElement("se:Format", format);
95 
96  // Recodes (...)
97 
98  writer.writeEndElement("se:ExternalGraphic");
99 }
const te::xl::SimpleLink * getOnlineResource() const
TESERIALIZATIONEXPORT te::se::InlineContent * ReadInlineContent(te::xml::Reader &reader)
InlineContent is XML- or base64-encoded encoded content in some externally-defined format that is inc...
Definition: InlineContent.h:51
Utility methods for Symbology serialization.
TEDATAACCESSEXPORT void Save(const std::string &fileName)
Definition: Serializer.cpp:191
This class models a XML reader object.
Definition: Reader.h:55
TESERIALIZATIONEXPORT te::xl::SimpleLink * ReadSimpleLink(te::xml::Reader &reader)
Definition: SimpleLink.cpp:36
The ExternalGraphic allows a reference to be made to an external graphic file with a Web URL or to in...
virtual bool next()=0
It gets the next event to be read.
Simple link.
Definition: SimpleLink.h:48
virtual void writeStartElement(const std::string &qName)
Definition: Writer.cpp:44
void WriteOnlineResourceHelper(const te::xl::SimpleLink *link, te::xml::Writer &writer)
Definition: Utils.cpp:66
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
TESERIALIZATIONEXPORT te::se::ExternalGraphic * ReadExternalGraphic(te::xml::Reader &reader)
const std::string & getFormat() const
The ExternalGraphic allows a reference to be made to an external graphic file with a Web URL or to in...
const InlineContent * getInlineContent() const
virtual void writeElement(const std::string &qName, const std::string &value)
Definition: Writer.cpp:54
Support for InlineContent 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.
This class models a XML writer object.
Definition: Writer.h:52