2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0/
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 int formXmlResolution = 0;
98 if (xmlStrncmp( ch, (xmlChar*)"720", len) == 0)
100 formXmlResolution = 720;
101 XMLHandler->__errorResult = XMLHandler->__pGenerator->SetFormXmlResolution(formXmlResolution);
105 formXmlResolution = 480;
106 XMLHandler->__errorResult = XMLHandler->__pGenerator->SetFormXmlResolution(formXmlResolution);
108 XMLHandler->__formXmlResolutionExists = false;
113 StartElementSaxFunc(void* pCtx, const xmlChar* pName, const xmlChar** pAttributes)
115 if (XMLHandler->__errorResult != E_SUCCESS)
117 xmlStopParser((xmlParserCtxt*)pCtx);
120 if (xmlStrcasecmp(pName, (xmlChar*) "Layout") == 0)
122 XMLHandler->SetAttribute(pAttributes);
124 else if (xmlStrcasecmp(pName, (xmlChar*) "Property") == 0)
126 XMLHandler->SetProperty(pAttributes);
128 else if (xmlStrcasecmp(pName, (xmlChar*) "Scene") == 0 || xmlStrcasecmp(pName, (xmlChar*) "ScenePanel") == 0 || xmlStrcasecmp(pName, (xmlChar*) "ScenePopup") == 0 || xmlStrcasecmp(pName, (xmlChar*) "SceneQuickPanelFrame") == 0)
130 XMLHandler->SetXmlVersion(pAttributes);
132 else if (xmlStrcasecmp(pName, (xmlChar*) "panelLayout") == 0)
136 else if (xmlStrcasecmp(pName, (xmlChar*) "itemSet") == 0)
140 else if (xmlStrcasecmp(pName, (xmlChar*) "LogicalCoordinate") == 0 || xmlStrcasecmp(pName, (xmlChar*) "BaseResolution") == 0)
142 XMLHandler->__formXmlResolutionExists = true;
144 else if (xmlStrcasecmp(pName, (xmlChar*) "headerItem") == 0)
146 XMLHandler->SetItem(pName, pAttributes);
149 else if (xmlStrcasecmp(pName, (xmlChar*) "buttonItem") == 0)
151 XMLHandler->SetItem(pName, pAttributes);
154 else if (xmlStrcasecmp(pName, (xmlChar*) "footerItem") == 0)
156 XMLHandler->SetItem(pName, pAttributes);
159 else if (xmlStrcasecmp(pName, (xmlChar*) "backButton") == 0)
161 XMLHandler->SetItem(pName, pAttributes);
164 else if (xmlStrcasecmp(pName, (xmlChar*) "item") == 0)
166 XMLHandler->SetItem(pName, pAttributes);
171 XMLHandler->__pControl = XMLHandler->__pGenerator->CreateControl();
172 if (XMLHandler->__pControl == null)
174 XMLHandler->__errorLog = "Failed to create UiBuilderControl";
175 XMLHandler->__errorResult = E_INVALID_FORMAT;
178 XMLHandler->__pControl->Construct((char*) pName);
180 if (pAttributes != null)
182 for (int i = 0; (pAttributes[i] != null); i++)
184 if (xmlStrcasecmp(pAttributes[i], (xmlChar*) "id") == 0)
186 if (pAttributes[++i] != null)
188 XMLHandler->__pControl->SetId((char*) pAttributes[i]);
191 else if (xmlStrcasecmp(pAttributes[i], (xmlChar*) "parent") == 0)
193 if (pAttributes[++i] != null)
195 XMLHandler->__pControl->SetParentWin((char*) pAttributes[i]);
204 _UiBuilderXmlHandler::ParseAttribute(const xmlChar** pAttributes, int index, const Tizen::Base::String& name)
206 bool findAttribute = false;
208 if (index == LAYOUT_SETTING)
211 const Tizen::Base::String parentWindow = __pControl->GetParentWin();
212 _UiBuilderControl* pParentControl = XMLHandler->__pGenerator->GetControl(parentWindow);
213 if (parentWindow.GetLength() != 0)
215 Tizen::Base::String layoutType(L"");
216 _UiBuilderControlLayout* pParentProperty = pParentControl->GetAttribute(__layoutMode);
217 if (pParentProperty->GetLayoutElement(L"type", layoutType))
219 __pProperty->SetLayoutElement(index, L"parentType", layoutType);
224 for (int i = 0; pAttributes[i] != null; i++)
226 if (pAttributes[++i] != null)
228 if (__pProperty != null)
230 __pProperty->SetLayoutElement(index, (char*) pAttributes[i - 1], (char*) pAttributes[i]);
236 else if (name.Equals(L"mode", false) && pAttributes[index] != null)
238 if (xmlStrcasecmp(pAttributes[index], (xmlChar*) "Portrait") == 0)
240 __pProperty = XMLHandler->__pControl->GetAttribute(UIBUILDER_ATTRIBUTE_PORTRAIT);
241 __layoutMode = UIBUILDER_ATTRIBUTE_PORTRAIT;
242 findAttribute = true;
244 else if (xmlStrcasecmp(pAttributes[index], (xmlChar*) "Landscape") == 0)
246 __pProperty = XMLHandler->__pControl->GetAttribute(UIBUILDER_ATTRIBUTE_LANDSCAPE);
247 __layoutMode = UIBUILDER_ATTRIBUTE_LANDSCAPE;
248 findAttribute = true;
250 if (findAttribute == false)
252 __pProperty = XMLHandler->__pControl->GetAttribute(UIBUILDER_ATTRIBUTE_PORTRAIT);
255 else if (name.Equals(L"style", false) && pAttributes[index] != null)
257 __pProperty->SetStyle((char*) pAttributes[index]);
259 else if (name.Equals(L"x", false) && pAttributes[index] != null)
261 __xPosition = (char*) pAttributes[index];
263 else if (name.Equals(L"y", false) && pAttributes[index] != null)
265 __yPosition = (char*) pAttributes[index];
267 else if (name.Equals(L"width", false) && pAttributes[index] != null)
269 __width = (char*) pAttributes[index];
271 else if (name.Equals(L"height", false) && pAttributes[index] != null)
273 __height = (char*) pAttributes[index];
277 __errorLog = L"Failed to ExecAttribute";
278 __errorResult = E_INVALID_FORMAT;
285 _UiBuilderXmlHandler::SetAttribute(const xmlChar** pAttributes)
287 if (pAttributes != null)
289 for (int i = 0; (pAttributes[i] != null); i++)
291 if (xmlStrcasecmp(pAttributes[i], (xmlChar*) "mode") == 0)
293 ParseAttribute(pAttributes, ++i, L"mode");
295 else if (xmlStrcasecmp(pAttributes[i], (xmlChar*) "style") == 0)
297 ParseAttribute(pAttributes, ++i, L"style");
299 else if (xmlStrcasecmp(pAttributes[i], (xmlChar*) "x") == 0)
301 ParseAttribute(pAttributes, ++i, L"x");
303 else if (xmlStrcasecmp(pAttributes[i], (xmlChar*) "y") == 0)
305 ParseAttribute(pAttributes, ++i, L"y");
307 else if (xmlStrcasecmp(pAttributes[i], (xmlChar*) "width") == 0)
309 ParseAttribute(pAttributes, ++i, L"width");
311 else if (xmlStrcasecmp(pAttributes[i], (xmlChar*) "height") == 0)
313 ParseAttribute(pAttributes, ++i, L"height");
319 __errorLog = L"Failed to SetAttribute";
320 __errorResult = E_INVALID_FORMAT;
323 __pProperty = XMLHandler->__pControl->GetAttribute(__layoutMode);
324 __pProperty->SetRect(__xPosition, __yPosition, __width, __height);
327 if (pAttributes != null)
329 ParseAttribute(pAttributes, LAYOUT_SETTING, (char*) "layout");
333 __errorLog = L"Failed to layout setting";
334 __errorResult = E_INVALID_FORMAT;
340 _UiBuilderXmlHandler::SetProperty(const xmlChar** pAttributes)
343 if (pAttributes != null)
345 for (int i = 0; (pAttributes[i] != null); i++)
347 if (pAttributes[++i] != null)
349 XMLHandler->__pControl->SetElement(index, (char*) pAttributes[i - 1], (char*) pAttributes[i]);
356 __errorLog = L"Failed to SetProperty";
357 __errorResult = E_INVALID_FORMAT;
363 _UiBuilderXmlHandler::SetItem(const xmlChar* name, const xmlChar** pAttributes)
366 int controlIndex = 0;
368 while (pAttributes[index] != null)
370 if (pAttributes[++index] != null)
372 XMLHandler->__pControl->SetItemElement(controlIndex, (char*) pAttributes[index - 1], (char*) pAttributes[index]);
378 __errorLog = L"Failed to SetItem";
379 __errorResult = E_INVALID_FORMAT;
384 XMLHandler->__pControl->SetItemName((char*) name);
388 _UiBuilderXmlHandler::SetXmlVersion(const xmlChar** pAttributes)
390 if (pAttributes != null)
392 for (int i = 0; (pAttributes[i] != null); i++)
394 if (xmlStrcasecmp(pAttributes[i], (xmlChar*) "Dversion") == 0)
396 if (pAttributes[++i] != null)
398 int ver = atoi((char*) pAttributes[i]);
399 XMLHandler->__pGenerator->SetVersion(ver);
406 __errorLog = "Failed to SetXmlVersion";
407 __errorResult = E_INVALID_FORMAT;