terralib/qt/af/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 "../../core/uri/URI.h"
24 #include "../../dataaccess/datasource/DataSourceInfo.h"
25 #include "../../dataaccess/datasource/DataSourceInfoManager.h"
26 #include "../../maptools/DataSetLayer.h"
27 
28 #include <QUrl>
29 
31 {
32  if(l == nullptr)
33  return;
34 
35  l->setTitle(format(l->getTitle(), encode));
36 
37  std::list<te::common::TreeItemPtr> ls = l->getChildren();
38  std::list<te::common::TreeItemPtr>::iterator it;
39 
40  if(l->getType() == "DATASETLAYER")
41  {
42  te::map::DataSetLayer* dl = static_cast<te::map::DataSetLayer*>(l);
43 
45  }
46 
47  for(it = ls.begin(); it != ls.end(); ++it)
48  format(dynamic_cast<te::map::AbstractLayer*>((*it).get()), encode);
49 }
50 
52 {
53  d->setTitle(format(d->getTitle(), encode));
55 
56  const te::core::URI& i = d->getConnInfo();
57  std::string path = i.host() + i.path();
58 
59  if (!path.empty())
60  path = format(path, encode);
61 }
62 
64 {
68 
69  for(it = beg; it != end; ++it)
70  format(it->second.get(), encode);
71 }
72 
73 std::string te::qt::af::XMLFormatter::format(const std::string &s, const bool& encode)
74 {
75  return (encode) ?
76  QUrl::toPercentEncoding(s.c_str()).data() :
77  QUrl::fromPercentEncoding(QByteArray(s.c_str())).toUtf8().data();
78 }
std::map< std::string, DataSourceInfoPtr >::iterator iterator
const std::list< TreeItemPtr > & getChildren() const
It returns the children of this tree item.
std::string path() const
Retrieving the path.
Definition: URI.cpp:118
void setDescription(const std::string &d)
This is the base class for layers.
Definition: AbstractLayer.h:77
virtual const std::string & getTitle() const
It returns the layer title.
virtual const std::string & getType() const =0
It returns the layer type.
static void formatDataSourceInfos(const bool &encode)
Formats all data source informations registered in the te::da::DataSourceInfoManager object...
void setDataSetName(const std::string &name)
static void format(te::map::AbstractLayer *l, const bool &encode)
Formats the layer informations.
const std::string & getDescription() const
virtual void setTitle(const std::string &title)
It sets the layer title.
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.
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
const te::core::URI & getConnInfo() const
std::string host() const
Retrieving the host.
Definition: URI.cpp:108
A class for representing an Uniform Resource Identifier (URI).
Definition: URI.h:49
const std::string & getDataSetName() const
A class for xml serialization formatting strings.
A class that represents a data source component.
A layer with reference to a dataset.
Definition: DataSetLayer.h:47
void setTitle(const std::string &title)