2 * Copyright (c) 2012 - 2014 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.
18 #include <libxml/parser.h>
25 #include "xmlresource.h"
26 #include "simple_debug.h"
28 using namespace xmlresource;
30 string g_entry_filepath;
32 XMLResource::XMLResource() {
33 m_main_entry_parser = NULL;
34 m_input_mode_configure_parser = NULL;
35 m_layout_parser = NULL;
36 m_modifier_decoration_parser = NULL;
37 m_label_properties_parser = NULL;
38 m_default_configure_parser = NULL;
39 m_autopopup_configure_parser = NULL;
40 m_magnifier_configure_parser = NULL;
41 m_nine_patch_file_list_parser = NULL;
44 XMLResource::~XMLResource() {
45 m_main_entry_parser = NULL;
46 m_input_mode_configure_parser = NULL;
47 m_layout_parser = NULL;
48 m_modifier_decoration_parser = NULL;
49 m_label_properties_parser = NULL;
50 m_default_configure_parser = NULL;
51 m_autopopup_configure_parser = NULL;
52 m_magnifier_configure_parser = NULL;
53 m_nine_patch_file_list_parser = NULL;
57 XMLResource::get_instance() {
58 static XMLResource instance;
63 get_layout_files(PSclInputModeConfigure input_mode_table,
64 size_t input_mode_size, vector<string> &vec_file) {
66 for (unsigned int mode = 0; mode < input_mode_size; mode++) {
67 SclInputModeConfigure &input_mode = input_mode_table[mode];
68 for (int direct = 0; direct < DISPLAYMODE_MAX; direct++) {
69 char * layout_file_path = input_mode.layouts[direct];
71 && 0 != strcmp(layout_file_path, "")) {
72 vec_file.push_back(layout_file_path);
78 std::sort(vec_file.begin(), vec_file.end());
79 // use std::unique() to puts duplicates to the [last, end)
80 vector<string>::iterator last = std::unique(vec_file.begin(), vec_file.end());
81 // remove the duplicated items, [last, end)
82 vec_file.erase(last, vec_file.end());
86 XMLResource::init(const char *entry_filepath) {
87 g_entry_filepath = entry_filepath;
88 if (m_main_entry_parser == NULL) {
89 m_main_entry_parser = MainEntryParser::get_instance();
90 char input_file[_POSIX_PATH_MAX] = {0};
91 snprintf(input_file, _POSIX_PATH_MAX, "%s/%s", get_resource_directory(), entry_filepath);
92 if (0 != m_main_entry_parser->init(input_file)) {
93 /* main entry is necessary */
94 SCLLOG(SclLog::ERROR, "main entry init");
98 /* get each type of xml file name */
99 XMLFiles& xml_files = m_main_entry_parser->get_xml_files();
101 SCLLOG(SclLog::MESSAGE, "init inputmode configure\n\n");
102 if (m_input_mode_configure_parser == NULL) {
103 m_input_mode_configure_parser = InputModeConfigParser::get_instance();
104 char input_file[_POSIX_PATH_MAX] = {0};
105 snprintf(input_file, _POSIX_PATH_MAX, "%s/%s", get_resource_directory(), xml_files.input_mode_configure);
106 if (0 != m_input_mode_configure_parser->init(input_file)) {
107 /* input mode configure is necessary */
108 SCLLOG(SclLog::ERROR, "input mode configure init");
112 SCLLOG(SclLog::MESSAGE, "init default_configure\n\n");
113 if (m_default_configure_parser == NULL) {
114 m_default_configure_parser = DefaultConfigParser::get_instance();
115 char input_file[_POSIX_PATH_MAX] = {0};
116 snprintf(input_file, _POSIX_PATH_MAX, "%s/%s", get_resource_directory(), xml_files.default_configure);
118 if (0 != m_default_configure_parser->init(input_file)) {
119 /* default configure is not necessary */
120 SCLLOG(SclLog::WARNING, "default configure init");
124 SCLLOG(SclLog::MESSAGE, "init modifier_decoration\n\n");
125 if (m_modifier_decoration_parser == NULL) {
126 m_modifier_decoration_parser = ModifierDecorationParser::get_instance();
127 char input_file[_POSIX_PATH_MAX] = {0};
128 snprintf(input_file, _POSIX_PATH_MAX, "%s/%s", get_resource_directory(), xml_files.modifier_decoration);
130 if (0 != m_modifier_decoration_parser->init(input_file)) {
131 /* modifier decoration is not necessary */
132 SCLLOG(SclLog::WARNING, "modifier decoration init");
135 SCLLOG(SclLog::MESSAGE, "init label_properties\n\n");
136 if (m_label_properties_parser == NULL) {
137 m_label_properties_parser = LabelPropertyParser::get_instance();
138 char input_file[_POSIX_PATH_MAX] = {0};
139 snprintf(input_file, _POSIX_PATH_MAX, "%s/%s", get_resource_directory(), xml_files.key_label_property);
141 if (0 != m_label_properties_parser->init(input_file)) {
142 /* label properties is not necessary */
143 SCLLOG(SclLog::WARNING, "label properties init");
147 SCLLOG(SclLog::MESSAGE, "init autopopup_configure\n\n");
148 if (m_autopopup_configure_parser == NULL) {
149 m_autopopup_configure_parser = AutoPopupConfigParser::get_instance();
150 char input_file[_POSIX_PATH_MAX] = {0};
151 snprintf(input_file, _POSIX_PATH_MAX, "%s/%s", get_resource_directory(), xml_files.autopopup_configure);
152 if (0 != m_autopopup_configure_parser->init(input_file)) {
153 /* autopopup configure is not necessary */
154 SCLLOG(SclLog::WARNING, "autopopup configure init");
157 SCLLOG(SclLog::MESSAGE, "init magnifier_configure\n\n");
158 if (m_magnifier_configure_parser == NULL) {
159 m_magnifier_configure_parser = MagnifierConfigParser::get_instance();
160 char input_file[_POSIX_PATH_MAX] = {0};
161 snprintf(input_file, _POSIX_PATH_MAX, "%s/%s", get_resource_directory(), xml_files.magnifier_configure);
163 if (0 != m_magnifier_configure_parser->init(input_file)) {
164 /* magnifier configure is not necessary */
165 SCLLOG(SclLog::WARNING, "magnifier configure init");
169 SCLLOG(SclLog::MESSAGE, "init nine_patch_file_list\n\n");
170 if (m_nine_patch_file_list_parser == NULL) {
171 m_nine_patch_file_list_parser = NinePatchFileParser::get_instance();
172 char input_file[_POSIX_PATH_MAX] = {0};
173 snprintf(input_file, _POSIX_PATH_MAX, "%s/%s", get_resource_directory(), xml_files.nine_patch_file_list);
175 if (0 != m_nine_patch_file_list_parser->init(input_file)) {
176 /* nine patch file list is not necessary */
177 SCLLOG(SclLog::WARNING, "nine patch file list init");
181 SCLLOG(SclLog::MESSAGE, "init layout\n\n");
182 if (m_layout_parser == NULL) {
183 m_layout_parser = LayoutParser::get_instance();
185 vector<string> vec_layout_file_name;
187 m_input_mode_configure_parser->get_input_mode_configure_table(),
188 m_input_mode_configure_parser->get_inputmode_size(),
189 vec_layout_file_name);
190 if ( 0 != m_layout_parser->init(get_resource_directory(),
191 vec_layout_file_name)) {
192 /* layout is necessary */
193 SCLLOG(SclLog::ERROR, "layout init");
197 SCLLOG(SclLog::MESSAGE, "init Text XML resources OK.\n\n");
202 XMLResource::load(int layout_id) {
203 m_layout_parser->load(layout_id);
207 XMLResource::unload() {
208 m_layout_parser->unload();
212 XMLResource::loaded(int layout_id) {
213 return m_layout_parser->loaded(layout_id);
217 XMLResource::reload() {
218 if (m_main_entry_parser) {
219 char input_file[_POSIX_PATH_MAX] = { 0 };
220 snprintf(input_file, _POSIX_PATH_MAX, "%s/%s", get_resource_directory(), g_entry_filepath.c_str());
221 if (0 != m_main_entry_parser->reload(input_file)) {
222 /* main entry is necessary */
223 SCLLOG(SclLog::ERROR, "main entry reload");
226 /* get each type of xml file name */
227 XMLFiles& xml_files = m_main_entry_parser->get_xml_files();
229 if (m_input_mode_configure_parser) {
230 char input_file[_POSIX_PATH_MAX] = { 0 };
231 snprintf(input_file, _POSIX_PATH_MAX, "%s/%s", get_resource_directory(), xml_files.input_mode_configure);
232 if (0 != m_input_mode_configure_parser->reload(input_file)) {
233 /* input mode configure is necessary */
234 SCLLOG(SclLog::ERROR, "input mode configure reload");
238 SCLLOG(SclLog::MESSAGE, "reload default_configure\n\n");
239 if (m_default_configure_parser) {
240 char input_file[_POSIX_PATH_MAX] = { 0 };
241 snprintf(input_file, _POSIX_PATH_MAX, "%s/%s", get_resource_directory(), xml_files.default_configure);
243 if (0 != m_default_configure_parser->reload(input_file)) {
244 /* default configure is not necessary */
245 SCLLOG(SclLog::WARNING, "default configure reload");
249 SCLLOG(SclLog::MESSAGE, "reload modifier_decoration\n\n");
250 if (m_modifier_decoration_parser) {
251 char input_file[_POSIX_PATH_MAX] = { 0 };
252 snprintf(input_file, _POSIX_PATH_MAX, "%s/%s", get_resource_directory(), xml_files.modifier_decoration);
254 if (0 != m_modifier_decoration_parser->reload(input_file)) {
255 /* modifier decoration is not necessary */
256 SCLLOG(SclLog::WARNING, "modifier decoration reload");
259 SCLLOG(SclLog::MESSAGE, "reload label_properties\n\n");
260 if (m_label_properties_parser) {
261 char input_file[_POSIX_PATH_MAX] = { 0 };
262 snprintf(input_file, _POSIX_PATH_MAX, "%s/%s", get_resource_directory(), xml_files.key_label_property);
264 if (0 != m_label_properties_parser->reload(input_file)) {
265 /* label properties is not necessary */
266 SCLLOG(SclLog::WARNING, "label properties reload");
270 SCLLOG(SclLog::MESSAGE, "reload autopopup_configure\n\n");
271 if (m_autopopup_configure_parser) {
272 char input_file[_POSIX_PATH_MAX] = { 0 };
273 snprintf(input_file, _POSIX_PATH_MAX, "%s/%s", get_resource_directory(), xml_files.autopopup_configure);
274 if (0 != m_autopopup_configure_parser->reload(input_file)) {
275 /* autopopup configure is not necessary */
276 SCLLOG(SclLog::WARNING, "autopopup configure reload");
279 SCLLOG(SclLog::MESSAGE, "reload magnifier_configure\n\n");
280 if (m_magnifier_configure_parser) {
281 char input_file[_POSIX_PATH_MAX] = { 0 };
282 snprintf(input_file, _POSIX_PATH_MAX, "%s/%s", get_resource_directory(), xml_files.magnifier_configure);
284 if (0 != m_magnifier_configure_parser->reload(input_file)) {
285 /* magnifier configure is not necessary */
286 SCLLOG(SclLog::WARNING, "magnifier configure reload");
290 SCLLOG(SclLog::MESSAGE, "reload nine_patch_file_list\n\n");
291 if (m_nine_patch_file_list_parser) {
292 char input_file[_POSIX_PATH_MAX] = { 0 };
293 snprintf(input_file, _POSIX_PATH_MAX, "%s/%s", get_resource_directory(), xml_files.nine_patch_file_list);
295 if (0 != m_nine_patch_file_list_parser->reload(input_file)) {
296 /* nine patch file list is not necessary */
297 SCLLOG(SclLog::WARNING, "nine patch file list reload");
301 SCLLOG(SclLog::MESSAGE, "reload layout\n\n");
302 if (m_layout_parser && m_input_mode_configure_parser) {
303 vector<string> vec_layout_file_name;
305 m_input_mode_configure_parser->get_input_mode_configure_table(),
306 m_input_mode_configure_parser->get_inputmode_size(),
307 vec_layout_file_name);
308 if (0 != m_layout_parser->reload(get_resource_directory(),
309 vec_layout_file_name)) {
310 /* layout is necessary */
311 SCLLOG(SclLog::ERROR, "layout init");
318 XMLResource::get_nine_patch_list() {
319 return m_nine_patch_file_list_parser->get_nine_patch_list();
323 XMLResource::get_labelproperty_size() {
324 return m_label_properties_parser->get_size();
328 XMLResource::get_nine_patch_info(const char *filename, SclNinePatchInfo *info) {
329 return m_nine_patch_file_list_parser->get_nine_patch_info(filename, info);
333 XMLResource::get_inputmode_id(const char *name) {
334 return m_input_mode_configure_parser->get_inputmode_id(name);
338 XMLResource::get_inputmode_name(int id) {
339 return m_input_mode_configure_parser->get_inputmode_name(id);
343 XMLResource::get_inputmode_size() {
344 return m_input_mode_configure_parser->get_inputmode_size();
347 PSclInputModeConfigure
348 XMLResource::get_input_mode_configure_table() {
349 return m_input_mode_configure_parser->get_input_mode_configure_table();
353 XMLResource::get_layout_id(const char *name) {
354 return m_layout_parser->get_layout_index(name);
358 XMLResource::get_layout_size() {
359 return m_layout_parser->get_layout_size();
363 XMLResource::get_modifier_decoration_id(const char *name) {
364 return m_modifier_decoration_parser->get_modifier_decoration_id(name);
368 XMLResource::get_layout_table() {
369 return m_layout_parser->get_layout_table();
372 PSclLayoutKeyCoordinatePointerTable
373 XMLResource::get_key_coordinate_pointer_frame() {
374 return m_layout_parser->get_key_coordinate_pointer_frame();
377 PSclModifierDecoration
378 XMLResource::get_modifier_decoration_table() {
379 return m_modifier_decoration_parser->get_modifier_decoration_table();
382 PSclLabelPropertiesTable
383 XMLResource::get_label_properties_frame() {
384 return m_label_properties_parser->get_label_properties_frame();
388 XMLResource::get_default_configure() {
389 return m_default_configure_parser->get_default_configure();
392 PSclAutoPopupConfigure
393 XMLResource::get_autopopup_configure() {
394 return m_autopopup_configure_parser->get_autopopup_configure();
397 PSclMagnifierWndConfigure
398 XMLResource::get_magnifier_configure() {
399 return m_magnifier_configure_parser->get_magnifier_configure();