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 #include <FBaseSysLog.h>
19 #include <FBaseUtilFileUnzipper.h>
20 #include <FUiEffects_ParserXMLParser.h>
21 #include <FUiEffects_ParserEffectParser.h>
22 #include "../FUiEffects_EffectErrorMessages.h"
24 namespace Tizen { namespace Ui { namespace Effects { namespace _Parser
27 EffectParser* XmlParser::__pCurrentParent = null;
28 bool XmlParser::__justParse = false;
30 XmlParser::XmlParser(EffectParser* pParent)
32 __pCurrentParent = pParent;
34 SysLog(NID_UI_EFFECT, "Effects. An object of XMLParser class created!");
37 XmlParser::~XmlParser()
39 __pCurrentParent = null;
42 SysLog(NID_UI_EFFECT, "Effects. An object of XMLParser class destroyed!");
46 XmlParser::StartElementNs(void * pCtx, const xmlChar* pLocalName, const xmlChar* pPrefix, const xmlChar* pUri,
47 int namespaceCount, const xmlChar** ppNamespaces, int attributeCount, int defaultedCount, const xmlChar** ppAttributes)
51 __pCurrentParent->StartElement((const char*)pLocalName);
54 if (attributeCount > 0)
57 unsigned int index = 0;
59 for (int indexAttribute = 0; indexAttribute < attributeCount; ++indexAttribute, index += 5)
61 const xmlChar *pLocalAttributeName = ppAttributes[index];
62 std::string attributesName((const char* )pLocalAttributeName);
64 const xmlChar *pValueBegin = ppAttributes[index+3];
65 std::string attributesValue((const char* )pValueBegin);
67 size_t pos = attributesValue.find('"');
68 value = attributesValue.substr(0, pos);
72 __pCurrentParent->Attribute(attributesName.c_str(), value.c_str());
81 XmlParser::EndElementNs(void* pCtx, const xmlChar* pLocalName, const xmlChar* pPrefix, const xmlChar* pUri)
85 __pCurrentParent->EndElement((const char*) pLocalName);
92 XmlParser::CharactersM(void* pCtx, const xmlChar* pCh, int len)
94 std::string wholeDoc = (char*) pCh;
95 size_t pos1 = wholeDoc.find('<');
96 // check whether the character has been found
97 if (pos1 == std::string::npos)
104 __pCurrentParent->Attribute("", wholeDoc.substr(pos1).c_str());
111 XmlParser::Error(void* pCtx, const char* pMsg, ... )
115 va_start(args, pMsg);
116 vsprintf(buffer, pMsg, args);
123 XmlParser::Warning(void* pCtx, const char* pMsg, ... )
127 va_start(args, pMsg);
128 vsprintf(buffer, pMsg, args);
135 XmlParser::ExtractFromArchive(const char* pArchivePath, const char* pDestinationPath)
138 Tizen::Base::Utility::FileUnzipper unzipper;
140 Tizen::Base::String archivePath = pArchivePath;
141 Tizen::Base::String destinationPath = pDestinationPath;
143 unzipper.Construct(archivePath);
144 if (unzipper.UnzipTo(destinationPath) != E_SUCCESS)
153 XmlParser::Parse(const char* pFilePath, bool sendCallbacks)
155 __justParse = !sendCallbacks;
157 xmlSAXHandler saxHandler;
158 memset(&saxHandler, 0, sizeof(saxHandler));
161 saxHandler.initialized = XML_SAX2_MAGIC;
162 saxHandler.startElementNs = StartElementNs;
163 saxHandler.endElementNs = EndElementNs;
164 saxHandler.warning = Warning;
165 saxHandler.error = Error;
166 saxHandler.characters = CharactersM;
169 int parseResult = xmlSAXUserParseFile(&saxHandler, null, pFilePath);
171 SysTryReturn(NID_UI_EFFECT,
175 Tizen::Ui::Effects::_UiEffectError::EP_XML_PARSING_FAILED
181 } } } } // Tizen::Ui::Effects::_Parser