2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 * @file FUi_UiBuilderXmlHandler.cpp
19 * @brief This is the implementation file for _UiBuilderXmlHandler class.
23 #include <FSysSystemInfo.h>
24 #include <FBaseSysLog.h>
25 #include "FUi_UiBuilderXmlHandler.h"
26 #include "FUi_UiBuilderControlElement.h"
28 using namespace Tizen::Ui;
30 namespace Tizen { namespace Ui
32 void StartElementSaxFunc(void* pCtx, const xmlChar* pName, const xmlChar** pAttributes);
33 void ParseCharactersSaxFunc(void *ctx, const xmlChar *ch, int len);
34 xmlSAXHandler mySaxHandler = {
35 null, null, null, null, null, null, null, null, null, null, null, null, null, null,
37 null, null, ParseCharactersSaxFunc, null, null, null, null, null, null, null, null, null, null, null, null, null, null
40 _UiBuilderXmlHandler* XMLHandler = null;
42 _UiBuilderXmlHandler::_UiBuilderXmlHandler(void)
45 , __formXmlResolutionExists(false)
47 , __errorResult(E_SUCCESS)
48 , __layoutMode(UIBUILDER_ATTRIBUTE_PORTRAIT)
58 _UiBuilderXmlHandler::~_UiBuilderXmlHandler(void)
63 _UiBuilderXmlHandler::Construct(_UiBuilder* pGenerator)
68 __pGenerator = pGenerator;
75 _UiBuilderXmlHandler::ParseXml(char* pXmlBuffer, int size)
77 xmlSAXHandlerPtr pMySaxhandler = &mySaxHandler;
78 xmlSubstituteEntitiesDefault(1);
79 xmlSAXUserParseMemory(pMySaxhandler, null, pXmlBuffer, size);
82 if (__errorResult != E_SUCCESS)
84 SysLogException(NID_UI, E_INVALID_FORMAT, "[E_INVALID_FORMAT][UiBuilder] %ls", XMLHandler->__errorLog.GetPointer());
92 ParseCharactersSaxFunc(void*ctx, const xmlChar*ch, int len)
94 if (XMLHandler->__formXmlResolutionExists == true)
96 Tizen::Graphics::_LogicalResolution formXmlResolution;
97 if (xmlStrncmp( ch, (xmlChar*)"720", len) == 0)
99 formXmlResolution = Tizen::Graphics::RESOLUTION_LOGICAL_720;
100 XMLHandler->__errorResult = XMLHandler->__pGenerator->SetFormXmlResolution(formXmlResolution);
104 formXmlResolution = Tizen::Graphics::RESOLUTION_LOGICAL_480;
105 XMLHandler->__errorResult = XMLHandler->__pGenerator->SetFormXmlResolution(formXmlResolution);
107 XMLHandler->__formXmlResolutionExists = false;
112 StartElementSaxFunc(void* pCtx, const xmlChar* pName, const xmlChar** pAttributes)
114 if (XMLHandler->__errorResult != E_SUCCESS)
116 xmlStopParser((xmlParserCtxt*)pCtx);
119 if (xmlStrcasecmp(pName, (xmlChar*) "Layout") == 0)
121 XMLHandler->SetAttribute(pAttributes);
123 else if (xmlStrcasecmp(pName, (xmlChar*) "Property") == 0)
125 XMLHandler->SetProperty(pAttributes);
127 else if (xmlStrcasecmp(pName, (xmlChar*) "Scene") == 0 || xmlStrcasecmp(pName, (xmlChar*) "ScenePanel") == 0 || xmlStrcasecmp(pName, (xmlChar*) "ScenePopup") == 0 || xmlStrcasecmp(pName, (xmlChar*) "SceneQuickPanelFrame") == 0)
129 XMLHandler->SetXmlVersion(pAttributes);
131 else if (xmlStrcasecmp(pName, (xmlChar*) "panelLayout") == 0)
135 else if (xmlStrcasecmp(pName, (xmlChar*) "itemSet") == 0)
139 else if (xmlStrcasecmp(pName, (xmlChar*) "LogicalCoordinate") == 0 || xmlStrcasecmp(pName, (xmlChar*) "BaseResolution") == 0)
141 XMLHandler->__formXmlResolutionExists = true;
143 else if (xmlStrcasecmp(pName, (xmlChar*) "headerItem") == 0)
145 XMLHandler->SetItem(pName, pAttributes);
148 else if (xmlStrcasecmp(pName, (xmlChar*) "buttonItem") == 0)
150 XMLHandler->SetItem(pName, pAttributes);
153 else if (xmlStrcasecmp(pName, (xmlChar*) "footerItem") == 0)
155 XMLHandler->SetItem(pName, pAttributes);
158 else if (xmlStrcasecmp(pName, (xmlChar*) "backButton") == 0)
160 XMLHandler->SetItem(pName, pAttributes);
163 else if (xmlStrcasecmp(pName, (xmlChar*) "item") == 0)
165 XMLHandler->SetItem(pName, pAttributes);
170 XMLHandler->__pControl = XMLHandler->__pGenerator->CreateControl();
171 if (XMLHandler->__pControl == null)
173 XMLHandler->__errorLog = "Failed to create UiBuilderControl";
174 XMLHandler->__errorResult = E_INVALID_FORMAT;
177 XMLHandler->__pControl->Construct((char*) pName);
179 if (pAttributes != null)
181 for (int i = 0; (pAttributes[i] != null); i++)
183 if (xmlStrcasecmp(pAttributes[i], (xmlChar*) "id") == 0)
185 if (pAttributes[++i] != null)
187 XMLHandler->__pControl->SetId((char*) pAttributes[i]);
190 else if (xmlStrcasecmp(pAttributes[i], (xmlChar*) "parent") == 0)
192 if (pAttributes[++i] != null)
194 XMLHandler->__pControl->SetParentWin((char*) pAttributes[i]);
203 _UiBuilderXmlHandler::ParseAttribute(const xmlChar** pAttributes, int index, const Tizen::Base::String& name)
205 bool findAttribute = false;
207 if (index == LAYOUT_SETTING)
210 const Tizen::Base::String parentWindow = __pControl->GetParentWin();
211 _UiBuilderControl* pParentControl = XMLHandler->__pGenerator->GetControl(parentWindow);
212 if (parentWindow.GetLength() != 0)
214 Tizen::Base::String layoutType(L"");
215 _UiBuilderControlLayout* pParentProperty = pParentControl->GetAttribute(__layoutMode);
216 if (pParentProperty->GetLayoutElement(L"type", layoutType))
218 __pProperty->SetLayoutElement(index, L"parentType", layoutType);
223 for (int i = 0; pAttributes[i] != null; i++)
225 if (pAttributes[++i] != null)
227 if (__pProperty != null)
229 __pProperty->SetLayoutElement(index, (char*) pAttributes[i - 1], (char*) pAttributes[i]);
235 else if (name.Equals(L"mode", false) && pAttributes[index] != null)
237 if (xmlStrcasecmp(pAttributes[index], (xmlChar*) "Portrait") == 0)
239 __pProperty = XMLHandler->__pControl->GetAttribute(UIBUILDER_ATTRIBUTE_PORTRAIT);
240 __layoutMode = UIBUILDER_ATTRIBUTE_PORTRAIT;
241 findAttribute = true;
243 else if (xmlStrcasecmp(pAttributes[index], (xmlChar*) "Landscape") == 0)
245 __pProperty = XMLHandler->__pControl->GetAttribute(UIBUILDER_ATTRIBUTE_LANDSCAPE);
246 __layoutMode = UIBUILDER_ATTRIBUTE_LANDSCAPE;
247 findAttribute = true;
249 if (findAttribute == false)
251 __pProperty = XMLHandler->__pControl->GetAttribute(UIBUILDER_ATTRIBUTE_PORTRAIT);
254 else if (name.Equals(L"style", false) && pAttributes[index] != null)
256 __pProperty->SetStyle((char*) pAttributes[index]);
258 else if (name.Equals(L"x", false) && pAttributes[index] != null)
260 __xPosition = (char*) pAttributes[index];
262 else if (name.Equals(L"y", false) && pAttributes[index] != null)
264 __yPosition = (char*) pAttributes[index];
266 else if (name.Equals(L"width", false) && pAttributes[index] != null)
268 __width = (char*) pAttributes[index];
270 else if (name.Equals(L"height", false) && pAttributes[index] != null)
272 __height = (char*) pAttributes[index];
276 __errorLog = L"Failed to ExecAttribute";
277 __errorResult = E_INVALID_FORMAT;
284 _UiBuilderXmlHandler::SetAttribute(const xmlChar** pAttributes)
286 if (pAttributes != null)
288 for (int i = 0; (pAttributes[i] != null); i++)
290 if (xmlStrcasecmp(pAttributes[i], (xmlChar*) "mode") == 0)
292 ParseAttribute(pAttributes, ++i, L"mode");
294 else if (xmlStrcasecmp(pAttributes[i], (xmlChar*) "style") == 0)
296 ParseAttribute(pAttributes, ++i, L"style");
298 else if (xmlStrcasecmp(pAttributes[i], (xmlChar*) "x") == 0)
300 ParseAttribute(pAttributes, ++i, L"x");
302 else if (xmlStrcasecmp(pAttributes[i], (xmlChar*) "y") == 0)
304 ParseAttribute(pAttributes, ++i, L"y");
306 else if (xmlStrcasecmp(pAttributes[i], (xmlChar*) "width") == 0)
308 ParseAttribute(pAttributes, ++i, L"width");
310 else if (xmlStrcasecmp(pAttributes[i], (xmlChar*) "height") == 0)
312 ParseAttribute(pAttributes, ++i, L"height");
318 __errorLog = L"Failed to SetAttribute";
319 __errorResult = E_INVALID_FORMAT;
322 __pProperty = XMLHandler->__pControl->GetAttribute(__layoutMode);
323 __pProperty->SetRect(__xPosition, __yPosition, __width, __height);
326 if (pAttributes != null)
328 ParseAttribute(pAttributes, LAYOUT_SETTING, (char*) "layout");
332 __errorLog = L"Failed to layout setting";
333 __errorResult = E_INVALID_FORMAT;
339 _UiBuilderXmlHandler::SetProperty(const xmlChar** pAttributes)
342 if (pAttributes != null)
344 for (int i = 0; (pAttributes[i] != null); i++)
346 if (pAttributes[++i] != null)
348 XMLHandler->__pControl->SetElement(index, (char*) pAttributes[i - 1], (char*) pAttributes[i]);
355 __errorLog = L"Failed to SetProperty";
356 __errorResult = E_INVALID_FORMAT;
362 _UiBuilderXmlHandler::SetItem(const xmlChar* name, const xmlChar** pAttributes)
365 int controlIndex = 0;
367 while (pAttributes[index] != null)
369 if (pAttributes[++index] != null)
371 XMLHandler->__pControl->SetItemElement(controlIndex, (char*) pAttributes[index - 1], (char*) pAttributes[index]);
377 __errorLog = L"Failed to SetItem";
378 __errorResult = E_INVALID_FORMAT;
383 XMLHandler->__pControl->SetItemName((char*) name);
387 _UiBuilderXmlHandler::SetXmlVersion(const xmlChar** pAttributes)
389 if (pAttributes != null)
391 for (int i = 0; (pAttributes[i] != null); i++)
393 if (xmlStrcasecmp(pAttributes[i], (xmlChar*) "Dversion") == 0)
395 if (pAttributes[++i] != null)
397 int ver = atoi((char*) pAttributes[i]);
398 XMLHandler->__pGenerator->SetVersion(ver);
405 __errorLog = "Failed to SetXmlVersion";
406 __errorResult = E_INVALID_FORMAT;