2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file WidgetConfigurationManager.cpp
18 * @author Piotr Fatyga (p.fatyga@samsung.com)
19 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
23 #include "WidgetConfigurationManager.h"
25 #include <dpl/wrt-dao-ro/global_config.h>
26 #include "root_parser.h"
27 #include "parser_runner.h"
28 #include "widget_parser.h"
29 #include <wrt_error.h>
30 #include <dpl/utils/mime_type_utils.h>
31 #include <dpl/localization/w3c_file_localization.h>
32 #include <dpl/utils/wrt_utility.h>
33 #include <dpl/singleton_impl.h>
34 IMPLEMENT_SINGLETON(WidgetConfigurationManager)
36 //TODO Rewrite this as steps/tasks
37 namespace // anonymous
39 const char *const DEFAULT_LANGUAGE = "default";
40 const size_t MAX_WIDGET_PATH_SIZE = 1024;
42 //#define WRT_WIDGET_DEFAULT_ICON_WIDTH 80
43 //#define WRT_WIDGET_DEFAULT_ICON_HEIGHT 80
45 //#define WRT_WIDGET_CONFIG_BASE_LOCALE "locales"
46 const char *const WRT_WIDGET_CONFIG_FILE_NAME = "config.xml";
49 bool WidgetConfigurationManager::locateAndParseConfigurationFile(
50 const std::string& _currentPath,
51 WrtDB::WidgetRegisterInfo& pWidgetConfigInfo,
52 const std::string& baseFolder,
55 using namespace WrtDB;
61 ConfigParserData& configInfo = pWidgetConfigInfo.configInfo;
63 // check if this installation from browser, or not.
64 size_t pos = _currentPath.rfind("/");
65 std::ostringstream infoPath;
66 infoPath << _currentPath.substr(pos + 1);
69 std::string language = "";
71 if (infoPath.str() != WRT_WIDGET_CONFIG_FILE_NAME) {
72 // in case of general installation using wgt archive
73 //TODO: use DPL::String in the caller to this function too.
74 DPL::String currentPath = DPL::FromUTF8String(_currentPath);
76 if (currentPath.empty() || baseFolder.empty()) {
77 *pErrCode = WRT_ERR_INVALID_ARG;
81 //TODO: rewrite this madness
82 char cfgAbsPath[MAX_WIDGET_PATH_SIZE + 1] = { 0 };
84 struct dirent* ptr = NULL;
86 dir = opendir(_currentPath.c_str());
88 *pErrCode = WRT_ERR_UNKNOWN;
92 //TODO why don't we use fopen here
93 bool has_config_xml = false;
95 while ((ptr = readdir(dir)) != NULL) { //Find configuration file, based
97 if (ptr->d_type == DT_REG) {
98 if (!strcmp(ptr->d_name, WRT_WIDGET_CONFIG_FILE_NAME)) {
99 _WrtUtilSetAbsolutePath(cfgAbsPath,
100 _currentPath.c_str(), ptr->d_name);
101 //Parse widget configuration file
102 LogDebug("Found config: " << cfgAbsPath);
106 parser.Parse(cfgAbsPath, ElementParserPtr(new
115 Catch(ElementParser::Exception::Base)
117 LogDebug("Invalid widget configuration file!");
118 // _rethrown_exception.Dump();
119 *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE;
125 // WidgetConfigurationParser & parser =
126 // WidgetConfigurationParserSingleton::Instance();
128 // (!parser.parseConfigurationFile(cfgAbsPath, configInfo,
129 // baseFolder.c_str(), pWidgetConfigInfo.signature_type)) {
130 // LogDebug("Invalid widget configuration
133 // WRT_WM_ERR_INVALID_ARCHIVE;
138 has_config_xml = true;
145 //We must have config.xml so leaveing if we doesn't
146 if (!has_config_xml) {
147 LogDebug("Invalid archive");
148 *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE;
152 // in case of browser installation
155 parser.Parse(_currentPath, ElementParserPtr(new
163 Catch(ElementParser::Exception::Base)
165 LogDebug("Invalid widget configuration file!");
166 // _rethrown_exception.Dump();
167 *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE;
173 if (!_WrtUtilStringToLower(baseFolder.c_str(), &tmp_language)) {
174 *pErrCode = WRT_ERR_UNKNOWN;
179 *pErrCode = WRT_ERR_UNKNOWN;
182 language = tmp_language;
185 if (!!configInfo.widget_id) {
186 if (!pWidgetConfigInfo.guid) {
187 pWidgetConfigInfo.guid = configInfo.widget_id;
189 if (pWidgetConfigInfo.guid != configInfo.widget_id) {
190 *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE;
191 LogDebug("Invalid archive");
197 if (!!configInfo.tizenId) {
198 if (pWidgetConfigInfo.pkgName != *configInfo.tizenId) {
199 *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE;
200 LogDebug("Invalid archive - Tizen ID not same error");
205 if (!!configInfo.version) {
206 if (!pWidgetConfigInfo.version) {
207 pWidgetConfigInfo.version = configInfo.version;
209 if (pWidgetConfigInfo.version != configInfo.version) {
210 *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE;
211 LogDebug("Invalid archive");
217 if (!!configInfo.minVersionRequired) {
218 pWidgetConfigInfo.minVersion = configInfo.minVersionRequired;
219 } else if (!!configInfo.tizenMinVersionRequired) {
220 pWidgetConfigInfo.minVersion = configInfo.tizenMinVersionRequired;
226 void WidgetConfigurationManager::processFile(
227 const std::string& path,
228 WrtDB::WidgetRegisterInfo &
233 if (!locateAndParseConfigurationFile(path, widgetConfiguration,
234 DEFAULT_LANGUAGE, &pErrCode))
236 LogWarning("Widget archive: Failed while parsing config file");
237 ThrowMsg(Exception::ProcessFailed, path);