All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
XMLFormatter.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 #include "XMLFormatter.h"
22 
23 #include "../../dataaccess/datasource/DataSourceInfo.h"
24 #include "../../dataaccess/datasource/DataSourceInfoManager.h"
25 #include "../../maptools/DataSetLayer.h"
26 
27 #include "Project.h"
28 
29 #include <QtCore/QUrl>
30 
31 namespace te {
32  namespace qt {
33  namespace af {
34 
35  void XMLFormatter::format(Project *p, const bool& encode)
36  {
37  p->setAuthor(format(p->getAuthor(), encode));
38  p->setTitle(format(p->getTitle(), encode));
39 
40  std::list<te::map::AbstractLayerPtr> ls = p->getTopLayers();
41  std::list<te::map::AbstractLayerPtr>::iterator it;
42 
43  for(it = ls.begin(); it != ls.end(); ++it)
44  format((*it).get(), encode);
45  }
46 
48  {
49  if(l == 0)
50  return;
51 
52  l->setTitle(format(l->getTitle(), encode));
53 
54  std::list<te::common::TreeItemPtr> ls = l->getChildren();
55  std::list<te::common::TreeItemPtr>::iterator it;
56 
57  if(l->getType() == "DATASETLAYER")
58  {
59  te::map::DataSetLayer* dl = static_cast<te::map::DataSetLayer*>(l);
60 
62  }
63 
64  for(it = ls.begin(); it != ls.end(); ++it)
65  format(dynamic_cast<te::map::AbstractLayer*>((*it).get()), encode);
66  }
67 
69  {
70  d->setTitle(format(d->getTitle(), encode));
72 
73  std::map<std::string, std::string>& i = d->getConnInfo();
74  std::map<std::string, std::string>::iterator it = i.find("SOURCE");
75 
76  if(it != i.end())
77  it->second = format(it->second, encode);
78 
79  it = i.find("URI");
80 
81  if(it != i.end())
82  it->second = format(it->second, encode);
83  }
84 
86  {
90 
91  for(it = beg; it != end; ++it)
92  format(it->second.get(), encode);
93  }
94 
95  std::string XMLFormatter::format(const std::string &s, const bool& encode)
96  {
97  return (encode) ?
98  QUrl::toPercentEncoding(s.c_str()).data() :
99  QUrl::fromPercentEncoding(QByteArray(s.c_str())).toStdString();
100  }
101  } // namespace af
102  } // namespace qt
103 } // namespace te
virtual const std::string & getType() const =0
It returns the layer type.
std::map< std::string, DataSourceInfoPtr >::iterator iterator
const std::list< TreeItemPtr > & getChildren() const
It returns the children of this tree item.
Definition: TreeItem.cpp:70
const std::string & getTitle() const
It gets the title of the project.
Definition: Project.cpp:51
void setDescription(const std::string &d)
const std::string & getDataSetName() const
This is the base class for layers.
Definition: AbstractLayer.h:76
virtual const std::string & getTitle() const
It returns the layer title.
void setDataSetName(const std::string &name)
This class models the concept of a project for the TerraLib Application Framework.
const std::string & getDescription() const
const std::map< std::string, std::string > & getConnInfo() const
virtual void setTitle(const std::string &title)
It sets the layer title.
const std::list< te::map::AbstractLayerPtr > & getTopLayers() const
It gets all the top layers of the project (folder and single layers).
Definition: Project.cpp:67
const std::string & getTitle() const
std::string encode(const traits &ts, const std::string &comp)
Encode the URI (sub) component.
Definition: urisyn.cpp:157
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
void setTitle(const std::string &title)
It sets the title of the project.
Definition: Project.cpp:45
void setAuthor(const std::string &author)
It sets the author of the project.
Definition: Project.cpp:56
const std::string & getAuthor() const
It gets the author of the project.
Definition: Project.cpp:62
This class models the concept of a project for the TerraLib Application Framework.
Definition: Project.h:50
A class that represents a data source component.
A layer with reference to a dataset.
Definition: DataSetLayer.h:47
A class for xml serialization formatting strings.
static void formatDataSourceInfos(const bool &encode)
Formats all data source informations registered in the te::da::DataSourceInfoManager object...
void setTitle(const std::string &title)
static void format(Project *p, const bool &encode)
Formats the project informations.