29 #include "../terralib/common/BoostUtils.h" 30 #include "../terralib/core/utils/Platform.h" 31 #include "../terralib/core/uri/Utils.h" 32 #include "../terralib/dataaccess/datasource/DataSourceInfoManager.h" 33 #include "../terralib/dataaccess/serialization/xml/Serializer.h" 34 #include "../terralib/maptools/serialization/xml/Layer.h" 35 #include "../terralib/xml/AbstractWriter.h" 36 #include "../terralib/xml/AbstractWriterFactory.h" 37 #include "../terralib/xml/Reader.h" 38 #include "../terralib/xml/ReaderFactory.h" 39 #include "../terralib/Version.h" 42 #include <boost/algorithm/string/replace.hpp> 49 size_t count = layer->getChildrenCount();
51 for (
size_t i = 0; i < count; ++i)
58 std::map<std::string, std::string>::const_iterator end = invalidToValidIds.end();
60 if (invalidToValidIds.find(layer->getDataSourceId()) != end)
61 layer->setDataSourceId(invalidToValidIds.find(layer->getDataSourceId())->second);
64 std::vector<std::string>
getDataSourceIds(
const std::list<te::map::AbstractLayerPtr>& layers)
66 std::vector<std::string> dsIds;
68 for (std::list<te::map::AbstractLayerPtr>::const_iterator itL = layers.begin(); itL != layers.end(); ++itL)
72 if (layer->getType() !=
"FOLDERLAYER")
73 dsIds.push_back(layer->getDataSourceId());
76 std::list<te::map::AbstractLayerPtr> converted;
78 std::list<te::common::TreeItemPtr> children = layer->getChildren();
79 std::list<te::common::TreeItemPtr>::iterator childrenB = children.begin();
80 std::list<te::common::TreeItemPtr>::iterator childrenE = children.end();
82 while (childrenB != childrenE)
85 converted.push_back(currentLayer);
90 dsIds.insert(dsIds.end(), childrenDsIds.begin(), childrenDsIds.end());
101 writer->setURI(proj.
m_fileName.toUtf8().data());
105 writer->writeStartDocument(
"UTF-8",
"no");
107 writer->writeStartElement(
"Project");
109 boost::replace_all(schema_loc,
" ",
"%20");
111 writer->writeAttribute(
"xmlns:xsd",
"http://www.w3.org/2001/XMLSchema-instance");
112 writer->writeAttribute(
"xmlns:te_da",
"http://www.terralib.org/schemas/dataaccess");
113 writer->writeAttribute(
"xmlns:te_map",
"http://www.terralib.org/schemas/maptools");
114 writer->writeAttribute(
"xmlns:te_qt_af",
"http://www.terralib.org/schemas/common/af");
116 writer->writeAttribute(
"xmlns:se",
"http://www.opengis.net/se");
117 writer->writeAttribute(
"xmlns:ogc",
"http://www.opengis.net/ogc");
118 writer->writeAttribute(
"xmlns:xlink",
"http://www.w3.org/1999/xlink");
120 writer->writeAttribute(
"xmlns",
"http://www.terralib.org/schemas/qt/af");
121 writer->writeAttribute(
"xsd:schemaLocation",
"http://www.terralib.org/schemas/qt/af " + schema_loc);
122 writer->writeAttribute(
"version", TERRALIB_VERSION_STRING);
124 writer->writeElement(
"Title", proj.
m_title.toUtf8().data());
125 writer->writeElement(
"Author", proj.
m_author.toUtf8().data());
128 writer->writeStartElement(
"te_da:DataSourceList");
130 writer->writeAttribute(
"xmlns:te_common",
"http://www.terralib.org/schemas/common");
138 for(it=itBegin; it!=itEnd; ++it)
141 if (std::find(dsIdVec.begin(), dsIdVec.end(), it->second->getId()) == dsIdVec.end())
144 writer->writeStartElement(
"te_da:DataSource");
146 writer->writeAttribute(
"id", it->second->getId());
147 writer->writeAttribute(
"type", it->second->getType());
148 writer->writeAttribute(
"access_driver", it->second->getAccessDriver());
150 writer->writeStartElement(
"te_da:Title");
151 writer->writeValue(it->second->getTitle());
152 writer->writeEndElement(
"te_da:Title");
154 writer->writeStartElement(
"te_da:Description");
155 writer->writeValue(it->second->getDescription());
156 writer->writeEndElement(
"te_da:Description");
158 writer->writeStartElement(
"te_da:URI");
160 writer->writeEndElement(
"te_da:URI");
162 writer->writeEndElement(
"te_da:DataSource");
165 writer->writeEndElement(
"te_da:DataSourceList");
168 writer->writeStartElement(
"ComponentList");
169 writer->writeEndElement(
"ComponentList");
171 writer->writeStartElement(
"te_map:LayerList");
175 for(std::list<te::map::AbstractLayerPtr>::const_iterator itL = layers.begin(); itL != layers.end(); ++itL)
176 lserial.
write((*itL).get(), *writer.get());
178 writer->writeEndElement(
"te_map:LayerList");
180 writer->writeEndElement(
"Project");
182 writer->writeToFile();
187 QFileInfo info(projFile);
188 std::string fName = projFile.toUtf8().data();
190 if(!info.exists() || !info.isFile())
192 QString msg = QObject::tr(
"Could not read project file: ") + projFile;
198 xmlReader->read(fName);
200 if(!xmlReader->next())
202 QString msg = QObject::tr(
"Could not read project information in the file: ") + projFile +
".";
208 QString msg = QObject::tr(
"Error reading the document ") + projFile + QObject::tr(
", the start element wasn't found.");
212 if(xmlReader->getElementLocalName() !=
"Project")
214 QString msg = QObject::tr(
"The first tag in the document ") + projFile + QObject::tr(
" is not 'Project'.");
220 assert(xmlReader->getElementLocalName() ==
"Title");
224 proj.
m_title = xmlReader->getElementValue().c_str();
230 assert(xmlReader->getElementLocalName() ==
"Author");
236 proj.
m_author = xmlReader->getElementValue().c_str();
244 assert(xmlReader->getElementLocalName() ==
"DataSourceList");
250 xmlReader->getElementLocalName() ==
"DataSourceList")
256 std::map<std::string, std::string> invalidDsConnInfo;
259 (xmlReader->getElementLocalName() ==
"DataSource"))
262 std::string dsId =
ds->getId();
264 invalidDsConnInfo.insert(std::make_pair(dsId,
ds->getId()));
270 assert(xmlReader->getElementLocalName() ==
"ComponentList");
275 assert(xmlReader->getElementLocalName() ==
"LayerList");
283 (xmlReader->getElementLocalName() !=
"LayerList"))
289 layers.push_back(layer);
293 assert(xmlReader->getElementLocalName() ==
"LayerList");
297 assert(xmlReader->getElementLocalName() ==
"Project");
std::map< std::string, DataSourceInfoPtr >::iterator iterator
This is the base class for layers.
TECOREEXPORT std::string URIEncode(const std::string &srcUri)
Encodes an decoded URI. The algorithm implementation is based on http://www.codeguru.com/cpp/cpp/algorithms/strings/article.php/c12759/URI-Encoding-and-Decoding.htm.
void SaveProject(const ProjectMetadata &proj, const std::list< te::map::AbstractLayerPtr > &layers)
This class models the concept of a project for the TerraView.
void LoadProject(const QString &projFile, ProjectMetadata &proj, std::list< te::map::AbstractLayerPtr > &layers)
static te::xml::AbstractWriter * make()
It creates a new XML writer using the dafault implementation.
static te::dt::Date ds(2010, 01, 01)
static te::xml::Reader * make()
It creates a new XML reader using the dafault implementation.
void updateLayerDataSource(const te::map::AbstractLayerPtr &layer, const std::map< std::string, std::string > &invalidToValidIds)
te::map::AbstractLayer * read(te::xml::Reader &reader) const
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
std::vector< std::string > getDataSourceIds(const std::list< te::map::AbstractLayerPtr > &layers)
void write(const te::map::AbstractLayer *alayer, te::xml::AbstractWriter &writer) const
TECOREEXPORT std::string FindInTerraLibPath(const std::string &path)
Returns the path relative to a directory or file in the context of TerraLib.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
TEDATAACCESSEXPORT void ReadDataSourceInfo(const std::string &datasourcesFileName)