fd712bc441cc78baf4c9ba8f2d67bf0ea1fd1172
[platform/core/uifw/libscl-ui-nui.git] / scl / main_entry_parser.cpp
1 /*
2  * Copyright (c) 2012 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <assert.h>
19 #include <string.h>
20 #include <libxml/parser.h>
21
22 #include "main_entry_parser.h"
23 #include "xml_parser_utils.h"
24 #include "simple_debug.h"
25
26 using namespace std;
27
28 class MainEntryParserImpl {
29     public:
30         int parsing_main_entry(const char *input_file) {
31             xmlDocPtr doc;
32             xmlNodePtr cur_node;
33
34             doc = xmlReadFile(input_file, NULL, 0);
35             if (doc == NULL) {
36                 return -1;
37             }
38
39             cur_node = xmlDocGetRootElement(doc);
40             if (cur_node == NULL) {
41                 xmlFreeDoc(doc);
42                 return -1;
43             }
44             if (0 != xmlStrcmp(cur_node->name, (const xmlChar*)"main-entry"))
45             {
46                 xmlFreeDoc(doc);
47                 return -1;
48             }
49
50             make_xml_files(cur_node);
51
52             xmlFreeDoc(doc);
53
54             return 0;
55         }
56         int reload_main_entry(const char *input_file) {
57             m_xml_files.reset();
58             return parsing_main_entry(input_file);
59         }
60         void make_xml_files(const xmlNodePtr p_node) {
61             assert(p_node != NULL);
62             xmlNodePtr node = p_node->xmlChildrenNode;
63             while (node != NULL) {
64                 if (0 == xmlStrcmp(node->name, (const xmlChar *)"files")) {
65                     parsing_files_node(node);
66                 }
67                 node = node->next;
68             }
69         }
70
71         void parsing_files_node(const xmlNodePtr p_node) {
72             assert(p_node != NULL);
73             xmlNodePtr node = p_node->xmlChildrenNode;
74
75             while (node != NULL) {
76                 if (0 == xmlStrcmp(node->name, (const xmlChar *)"input-mode-configure")) {
77                     m_xml_files.input_mode_configure = (char*)xmlNodeGetContent(node);
78                 } else if (0 == xmlStrcmp(node->name, (const xmlChar *)"layout")) {
79                     m_xml_files.layout = (char*)xmlNodeGetContent(node);
80                 } else if (0 == xmlStrcmp(node->name, (const xmlChar *)"key-label-property")) {
81                     m_xml_files.key_label_property = (char*)xmlNodeGetContent(node);
82                 } else if (0 == xmlStrcmp(node->name, (const xmlChar *)"modifier-decoration")) {
83                     m_xml_files.modifier_decoration = (char*)xmlNodeGetContent(node);
84                 } else if (0 == xmlStrcmp(node->name, (const xmlChar *)"default-configure")) {
85                     m_xml_files.default_configure = (char*)xmlNodeGetContent(node);
86                 } else if (0 == xmlStrcmp(node->name, (const xmlChar *)"autopopup-configure")) {
87                     m_xml_files.autopopup_configure = (char*)xmlNodeGetContent(node);
88                 } else if (0 == xmlStrcmp(node->name, (const xmlChar *)"magnifier-configure")) {
89                     m_xml_files.magnifier_configure = (char*)xmlNodeGetContent(node);
90                 } else if (0 == xmlStrcmp(node->name, (const xmlChar *)"nine-patch-file-list")) {
91                     m_xml_files.nine_patch_file_list = (char*)xmlNodeGetContent(node);
92                 }
93                 node = node->next;
94             }
95         }
96         XMLFiles m_xml_files;
97 };
98
99 MainEntryParser::MainEntryParser() {
100     m_impl = new MainEntryParserImpl;
101 }
102
103 MainEntryParser::~MainEntryParser() {
104     if (m_impl) {
105         delete m_impl;
106     }
107 }
108
109 MainEntryParser*
110 MainEntryParser::get_instance() {
111     static MainEntryParser instance;
112     return &instance;
113 }
114
115 int
116 MainEntryParser::init(const char* path) {
117     return m_impl->parsing_main_entry(path);
118 }
119
120 int
121 MainEntryParser::reload(const char* path) {
122     return m_impl->reload_main_entry(path);
123 }
124
125 XMLFiles&
126 MainEntryParser::get_xml_files() {
127     return m_impl->m_xml_files;
128 }