2 * Copyright 2012-2013 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 "main_entry_parser.h"
20 #include "xmlresource.h"
21 #include "xml_parser_utils.h"
24 using namespace xmlresource;
26 static int get_keyset_id(const xmlNodePtr cur_node);
27 static int get_layout_id(const xmlNodePtr cur_node);
29 Main_Entry_Parser* Main_Entry_Parser::m_instance = NULL;
31 Main_Entry_Parser::Main_Entry_Parser() {
34 Main_Entry_Parser::~Main_Entry_Parser() {
36 Main_Entry_Parser* Main_Entry_Parser::get_instance() {
37 if (m_instance == NULL) {
38 m_instance = new Main_Entry_Parser();
43 Main_Entry_Parser::Main_Entry_Parser::init(const char *entry_filepath) {
44 char input_file[_POSIX_PATH_MAX] = {0};
45 XMLResource *xml_resource = XMLResource::get_instance();
46 snprintf(input_file, _POSIX_PATH_MAX, "%s/%s",
47 xml_resource->get_resource_directory(), entry_filepath);
48 parsing_main_entry(input_file);
51 XMLFiles& Main_Entry_Parser::get_xml_files() {
55 void Main_Entry_Parser::parsing_main_entry(const char *entry_filepath) {
59 doc = xmlReadFile(entry_filepath, NULL, 0);
61 printf("Could not load file.\n");
65 cur_node = xmlDocGetRootElement(doc);
66 if (cur_node == NULL) {
67 printf("empty document.\n");
71 if (0 != xmlStrcmp(cur_node->name, (const xmlChar*)"main-entry"))
73 printf("root name %s error!\n", cur_node->name);
78 make_xml_files(cur_node);
84 Main_Entry_Parser::make_xml_files(const xmlNodePtr p_node) {
85 assert(p_node != NULL);
86 xmlNodePtr node = p_node->xmlChildrenNode;
87 while (node != NULL) {
88 if (0 == xmlStrcmp(node->name, (const xmlChar *)"files")) {
89 parsing_files_node(node);
96 Main_Entry_Parser::parsing_files_node(const xmlNodePtr p_node) {
97 assert(p_node != NULL);
98 xmlNodePtr node = p_node->xmlChildrenNode;
100 while (node != NULL) {
101 if (0 == xmlStrcmp(node->name, (const xmlChar *)"inputmode-name-list")) {
102 m_xml_files.inputmode_name_list = (char*)xmlNodeGetContent(node);
104 else if (0 == xmlStrcmp(node->name, (const xmlChar *)"inputmode-popup-name-list")) {
105 m_xml_files.inputmode_popup_name_list = (char*)xmlNodeGetContent(node);
107 else if (0 == xmlStrcmp(node->name, (const xmlChar *)"layout-name-list")) {
108 m_xml_files.layout_name_list = (char*)xmlNodeGetContent(node);
110 else if (0 == xmlStrcmp(node->name, (const xmlChar *)"keyset-name-list")) {
111 m_xml_files.keyset_name_list = (char*)xmlNodeGetContent(node);
113 else if (0 == xmlStrcmp(node->name, (const xmlChar *)"input-mode-configure")) {
114 m_xml_files.input_mode_configure = (char*)xmlNodeGetContent(node);
116 else if (0 == xmlStrcmp(node->name, (const xmlChar *)"input-mode-popup-configure")) {
117 m_xml_files.input_mode_popup_configure = (char*)xmlNodeGetContent(node);
119 else if (0 == xmlStrcmp(node->name, (const xmlChar *)"layout")) {
120 m_xml_files.layout = (char*)xmlNodeGetContent(node);
122 else if (0 == xmlStrcmp(node->name, (const xmlChar *)"layout-keyset")) {
123 m_xml_files.layout_keyset = (char*)xmlNodeGetContent(node);
125 else if (0 == xmlStrcmp(node->name, (const xmlChar *)"configure-files")) {
126 parsing_configure_files(node);
128 else if (0 == xmlStrcmp(node->name, (const xmlChar *)"coordinate-files")) {
129 parsing_coordinate_files(node);
131 else if (0 == xmlStrcmp(node->name, (const xmlChar *)"property-files")) {
132 parsing_property_files(node);
134 else if (0 == xmlStrcmp(node->name, (const xmlChar *)"key-label-property")) {
135 m_xml_files.key_label_property = (char*)xmlNodeGetContent(node);
137 else if (0 == xmlStrcmp(node->name, (const xmlChar *)"modifier-decoration")) {
138 m_xml_files.modifier_decoration = (char*)xmlNodeGetContent(node);
140 else if (0 == xmlStrcmp(node->name, (const xmlChar *)"default-configure")) {
141 m_xml_files.default_configure = (char*)xmlNodeGetContent(node);
143 else if (0 == xmlStrcmp(node->name, (const xmlChar *)"autopopup-configure")) {
144 m_xml_files.autopopup_configure = (char*)xmlNodeGetContent(node);
146 else if (0 == xmlStrcmp(node->name, (const xmlChar *)"magnifier-configure")) {
147 m_xml_files.magnifier_configure = (char*)xmlNodeGetContent(node);
149 else if (0 == xmlStrcmp(node->name, (const xmlChar *)"nine-patch-file-list")) {
150 m_xml_files.nine_patch_file_list = (char*)xmlNodeGetContent(node);
157 Main_Entry_Parser::parsing_configure_files(const xmlNodePtr p_node) {
158 assert(p_node != NULL);
159 xmlNodePtr node = p_node->xmlChildrenNode;
161 while (node != NULL) {
162 if (0 == xmlStrcmp(node->name, (const xmlChar *)"file")) {
163 xmlChar* keyset = xmlGetProp(node, (const xmlChar*)"keyset");
164 assert(keyset != NULL);
165 xmlChar* file_name = xmlNodeGetContent(node);
166 assert(file_name != NULL);
167 m_xml_files.layout_key_configure.insert(Iter_data::value_type((const char*)keyset, (char*)file_name));
173 Main_Entry_Parser::parsing_property_files(const xmlNodePtr p_node) {
174 assert(p_node != NULL);
175 xmlNodePtr node = p_node->xmlChildrenNode;
177 while (node != NULL) {
178 if (0 == xmlStrcmp(node->name, (const xmlChar *)"file")) {
179 xmlChar* keyset = xmlGetProp(node, (const xmlChar*)"keyset");
180 xmlChar* file_name = xmlNodeGetContent(node);
181 assert(keyset != NULL);
182 assert(file_name != NULL);
184 m_xml_files.layout_key_property.insert(Iter_data::value_type((const char*)keyset, (char*)file_name));
191 Main_Entry_Parser::parsing_coordinate_files(const xmlNodePtr p_node) {
192 assert(p_node != NULL);
193 xmlNodePtr node = p_node->xmlChildrenNode;
195 while (node != NULL) {
196 if (0 == xmlStrcmp(node->name, (const xmlChar *)"file")) {
197 xmlChar* layout = xmlGetProp(node, (const xmlChar*)"layout");
198 xmlChar* file_name = xmlNodeGetContent(node);
199 assert(layout != NULL);
200 assert(file_name != NULL);
202 m_xml_files.layout_key_coordinate.insert(Iter_data::value_type((const char*)layout, (char*)file_name));
209 Main_Entry_Parser::get_file_full_path(char* dest_path, const char* file_type) {
210 assert(file_type != NULL);
211 assert(dest_path != NULL);
213 Main_Entry_Parser* main_entry_parser = Main_Entry_Parser::get_instance();
214 XMLFiles& xml_files = main_entry_parser->get_xml_files();
216 const char* input_file = NULL;
217 if (0 == strcmp(file_type, "input_mode_configure")) {
218 input_file = xml_files.input_mode_configure;
220 else if (0 == strcmp(file_type, "layout")) {
221 input_file = xml_files.layout;
223 else if (0 == strcmp(file_type, "label_property")) {
224 input_file = xml_files.key_label_property;
226 else if (0 == strcmp(file_type, "modifier_decoration")) {
227 input_file = xml_files.modifier_decoration;
229 else if (0 == strcmp(file_type, "default_configure")) {
230 input_file = xml_files.default_configure;
232 else if (0 == strcmp(file_type, "autopopup_configure")) {
233 input_file = xml_files.autopopup_configure;
235 else if (0 == strcmp(file_type, "magnifier_configure")) {
236 input_file = xml_files.magnifier_configure;
238 else if (0 == strcmp(file_type, "nine_patch_file_list")) {
239 input_file = xml_files.nine_patch_file_list;
241 printf("file_type : %s is not exist.\n", file_type);
245 if (input_file && dest_path) {
246 XMLResource *xml_resource = XMLResource::get_instance();
247 snprintf(dest_path, _POSIX_PATH_MAX, "%s/%s",
248 xml_resource->get_resource_directory(), input_file);