Serializers.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
3 
4  This file is part of the TerraLib - a Framework for building GIS enabled
5  applications.
6 
7  TerraLib is free software: you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation, either version 3 of the License,
10  or (at your option) any later version.
11 
12  TerraLib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with TerraLib. See COPYING. If not, write to
19  TerraLib Team at <terralib-team@terralib.org>.
20  */
21 
22 /*!
23  \file terralib/core/plugin/DefaultSerializers.cpp
24 
25  \brief A singleton that can be used to register plugin finders.
26 
27  \author Gilberto Ribeiro de Queiroz
28  \author Matheus Cavassan Zaglia
29  */
30 
31 // TerraLib
32 #include "Serializers.h"
33 #include "Exception.h"
34 #include "../filesystem/FileSystem.h"
35 #include "../encoding/CharEncoding.h"
36 #include "../translator/Translator.h"
37 
38 // Boost
39 #include <boost/filesystem.hpp>
40 #include <boost/format.hpp>
41 #include <boost/property_tree/json_parser.hpp>
42 #include <boost/property_tree/ptree.hpp>
43 
45  const std::string& file_name)
46 {
47  boost::property_tree::ptree doc;
48 
49  if (!te::core::FileSystem::exists(file_name))
50  {
51  boost::format err_msg(TE_TR("The file %1% doesn't exist."));
53  << ErrorDescription((err_msg % file_name).str());
54  }
55  boost::property_tree::json_parser::read_json(file_name, doc);
56 
57  PluginInfo plugin;
58 
59  plugin.name = doc.get<std::string>("name");
60  plugin.display_name = doc.get<std::string>("display_name");
61  plugin.description = doc.get<std::string>("description");
62  plugin.version = doc.get<std::string>("version");
63  plugin.release = doc.get<std::string>("release");
64  plugin.engine = doc.get<std::string>("engine");
65  plugin.license_description = doc.get<std::string>("license_description");
66  plugin.license_URL = doc.get<std::string>("license_URL");
67  plugin.site = doc.get<std::string>("site");
68  // plugin.description = doc.get<std::string>("provider");
69 
70  for (const boost::property_tree::ptree::value_type& v :
71  doc.get_child("dependencies"))
72  plugin.dependencies.push_back(v.second.get_value<std::string>());
73  for(const boost::property_tree::ptree::value_type& v :
74  doc.get_child("resources"))
75  {
76  Resource r;
77 
78  r.first = v.first;
79  r.second = v.second.get_value<std::string>();
80 
81  plugin.resources.push_back(r);
82  }
83 
84  // plugin.description = doc.get<std::string>("parameters");
85  // plugin.description = doc.get<std::string>("host_application");
86 
87  return plugin;
88 }
std::string license_description
A brief description about the plugin license.
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
Definition: FileSystem.cpp:142
std::string engine
The type of plugin execution engine: C++, JAVA, LUA or any other supported engine.
std::pair< std::string, std::string > Resource
Definition: LibraryInfo.h:60
Basic information about a plugin.
std::vector< Resource > resources
The list of resources used by plugin.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
General utilities for serializing plugin information.
std::string description
A brief explanation about the plugin.
boost::error_info< struct tag_error_description, std::string > ErrorDescription
The base type for error report messages.
std::string display_name
The plugin name to be displayed in a graphical interface.
std::string name
The plugin name: an internal value used to identify the plugin in the system. Must be a unique value...
std::vector< std::string > dependencies
The list of required plugins in order to launch the plugin.
std::string license_URL
An URL where someone can find more information on the license.
std::string release
The release date of the plugin. This may be used to identify new versions of a given plugin...
TECOREEXPORT PluginInfo JSONPluginInfoSerializer(const std::string &file_name)
A plugin finder that search for plugins in some special directories defined by compile time macros...
Definition: Serializers.cpp:44
std::string site
An URL pointing to the plugin site.
std::string version
The plugin version.
An exception indicating that a given argument is not valid, for instance if a given item already exis...