2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (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 * @file StAppSettingManager.cpp
19 * @brief This is the implementation file for AppSetting Manager class.
23 #include <libxml/xmlreader.h>
24 #include "StAppSettingManager.h"
26 using namespace Tizen::App;
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Collection;
29 using namespace Tizen::Base::Utility;
31 static const int ID_APPSETTING_MANAGER_CHANGED_VALUE_KEY_DELIMIT_MAX_COUNT = 2;
32 static const int ID_APPSETTING_MANAGER_ELEMENT_NODE_DELIMIT_COUNT = 5;
33 static const int ID_APPSETTING_MANAGER_NODE_ATTRIUBTE_DELIMIT_COUNT = 8;
35 static const wchar_t* ID_APPSETTING_CHANGED_VALUE_KEY_DELIMIT = L":";
36 static const wchar_t* ID_APPSETTING_CHANGED_VALUE_BOOL_TYPE = L"bool";
37 static const wchar_t* ID_APPSETTING_CHANGED_VALUE_INTEGER_TYPE = L"integer";
39 static const int APP_SETTING_DEFAULT_TOKEN_COUNT = 1;
40 static const int XML_READER_FOR_FILE_DEFAULT_OPTION = 524288;
42 int separatorCount = 1;
43 static const wchar_t* appSettingElementNodeDelimit[] =
52 static const wchar_t* appSettingNodeAttributeDelimit[] =
64 AppSettingManager* AppSettingManager::__pAppSettingManagerInstance = null;
66 Node::Node(Tizen::Base::String id, Tizen::Base::String type, Node* pParent, Tizen::Base::String parentId)
68 , __pRegisteredObserverList(null)
69 , __pNodeAttribute(null)
70 , __parentId(parentId)
79 RemoveAllObserverListener();
97 Node::GetParentId(void)
103 Node::GetParent(void)
109 Node::AddAttribute(Tizen::Base::String key, Tizen::Base::String value)
111 result r = E_SUCCESS;
113 if (__pNodeAttribute == null)
115 __pNodeAttribute = new (std::nothrow) HashMap();
116 r = __pNodeAttribute->Construct();
120 delete __pNodeAttribute;
121 __pNodeAttribute = null;
123 AppLogDebug("Construct Fail [%s]", GetErrorMessage(r));
128 r = __pNodeAttribute->Add(new (std::nothrow) String(key), new (std::nothrow) String(value));
134 Node::SetAttribute(Tizen::Base::String key, Tizen::Base::String value)
136 if (__pNodeAttribute == null)
138 return E_INVALID_OPERATION;
142 result r = __pNodeAttribute->ContainsKey(key, isFind);
144 || (isFind == false))
146 AppLogDebug("ContainsKey fail[result : %s][isFind : %d]", GetErrorMessage(r), isFind);
155 r = __pNodeAttribute->SetValue(*(new (std::nothrow) String(key)), *(new (std::nothrow) String(value)));
158 ChangedAttributeValue(value);
165 Node::GetAttributeN(Tizen::Base::String key)
167 String* pValue = null;
170 if (__pNodeAttribute == null)
172 AppLogDebug("__pNodeAttribute is null");
176 result r = __pNodeAttribute->ContainsKey(key, isFind);
178 || (isFind == false))
180 AppLogDebug("ContainsKey fail[result : %s][isFind : %d]", GetErrorMessage(r), isFind);
184 pValue = static_cast<String*>(__pNodeAttribute->GetValue(key));
185 return (new (std::nothrow) String(*pValue));
188 Tizen::Base::Collection::IMapEnumerator*
189 Node::GetAttributeIEnumeratorN(void)
191 if (__pNodeAttribute == null)
193 AppLogDebug("__pNodeAttribute is null");
197 IMapEnumerator* pMapEnum = __pNodeAttribute->GetMapEnumeratorN();
202 Node::RemoveAttriube(Tizen::Base::String key)
204 if (__pNodeAttribute == null)
206 return E_INVALID_OPERATION;
210 result r = __pNodeAttribute->ContainsKey(key, isFind);
212 || (isFind == false))
214 AppLogDebug("ContainsKey fail[result : %s][isFind : %d]", GetErrorMessage(r), isFind);
223 r = __pNodeAttribute->Remove(key, true);
228 Node::RemoveAllAttribute(void)
230 if (__pNodeAttribute != null)
232 __pNodeAttribute->RemoveAll();
233 delete __pNodeAttribute;
234 __pNodeAttribute = null;
239 Node::RemoveAllObserverListener(void)
241 if (__pRegisteredObserverList != null)
243 __pRegisteredObserverList->RemoveAll();
244 delete __pRegisteredObserverList;
245 __pRegisteredObserverList = null;
250 Node::GetAttriubteCount(void)
252 int attributeCount = 0;
254 if (__pNodeAttribute == null)
256 AppLogDebug("__pNodeAttribute is null");
257 return attributeCount;
260 attributeCount = __pNodeAttribute->GetCount();
261 return attributeCount;
265 Node::RegisterObserverlistener(ObserverAttribute* pObserver)
267 if (__pRegisteredObserverList == null)
269 __pRegisteredObserverList = new (std::nothrow) LinkedListT<ObserverAttribute*>;
270 if (__pRegisteredObserverList == null)
272 AppLogDebug("__pRegisteredObserverList is null");
277 if (pObserver == null)
279 AppLogDebug("pObserver is null");
283 if (!__pRegisteredObserverList->Contains(pObserver))
285 __pRegisteredObserverList->Add(pObserver);
286 AppLogDebug("ObserverAttribute Add");
290 AppLogDebug("ObserverAttribute fail");
295 Node::UnRegisterObserverlistener(ObserverAttribute* pObserver)
297 if (__pRegisteredObserverList == null)
299 AppLogDebug("__pNodeAttribute is null");
303 ObserverAttribute* pObser = null;
304 IEnumeratorT<ObserverAttribute*>* pEnum = __pRegisteredObserverList->GetEnumeratorN();
305 while (pEnum->MoveNext() == E_SUCCESS)
307 result r = pEnum->GetCurrent(pObser);
310 AppLogDebug("GetCurrent Fail [%s]", GetErrorMessage(r));
314 if (pObser == pObserver)
316 __pRegisteredObserverList->Remove(pObserver);
324 Node::ChangedAttributeValue(Tizen::Base::String value)
326 if ((__pNodeAttribute == null)
327 || (__pRegisteredObserverList == null))
329 AppLogDebug("__pNodeAttribute or __pRegisteredObserverList is null");
333 ObserverAttribute* pObser = null;
334 IEnumeratorT<ObserverAttribute*>* pEnum = __pRegisteredObserverList->GetEnumeratorN();
335 while (pEnum->MoveNext() == E_SUCCESS)
337 result r = pEnum->GetCurrent(pObser);
340 AppLogDebug("GetCurrent Fail [%s]", GetErrorMessage(r));
344 pObser->OnChangedAttributeValue(this->__id, value, this->__type);
350 ElementLeaf::DebugLog(void)
352 if (__pNodeAttribute == null)
354 AppLogDebug("__pNodeAttribute is null");
359 String* pValue = null;
360 IMapEnumerator* pMapEnum = __pNodeAttribute->GetMapEnumeratorN();
362 while (pMapEnum->MoveNext() == E_SUCCESS)
364 pKey = static_cast<String*>(pMapEnum->GetKey());
365 pValue = static_cast<String*>(pMapEnum->GetValue());
366 AppLogDebug("pKey [%ls], pValue [%ls]", pKey->GetPointer(), pValue->GetPointer());
370 AppLogDebug("__pCurrent Id [%ls], _pParentId [%ls]", (this->__id).GetPointer(), this->__parentId.GetPointer());
373 Tizen::Base::Collection::IEnumerator*
374 ElementLeaf::GetCurrentIEnumerator(void)
380 ElementLeaf::GetNodeType(void)
382 return NODE_TYPE_LEAF;
386 ElementLeaf::CreateEnumerator(void)
388 return dynamic_cast<Enumerator*>((new (std::nothrow) NullEnumerator()));
391 ElementNode::ElementNode(Tizen::Base::String id, Tizen::Base::String type, Node* pParent, Tizen::Base::String parentId)
392 : Node(id, type, pParent, parentId), __pCurrentEnum(null), __pChild(null)
396 ElementNode::~ElementNode(void)
398 if (__pCurrentEnum != null)
400 delete __pCurrentEnum;
401 __pCurrentEnum = null;
407 ElementNode::Add(Node& node)
409 if (__pChild == null)
411 __pChild = new (std::nothrow) LinkedList();
412 if (__pChild == null)
414 AppLogDebug("__pChild is null");
419 result r = __pChild->Add(node);
422 AppLogDebug(" Add fail [%s]", GetErrorMessage(r));
430 ElementNode::AddSilbing(Tizen::Base::String id, Tizen::Base::String type, NodeType nodetype)
432 Node* pSibling = null;
434 if ((this->GetParent())->GetNodeType() != NODE_TYPE_ELEMENT)
436 AppLogDebug("GetNodeType() is [%d]", (this->GetParent())->GetNodeType());
440 if (nodetype == NODE_TYPE_ELEMENT)
442 pSibling = dynamic_cast<Node*>(new (std::nothrow) ElementNode(id, type, this->GetParent(), this->GetParentId()));
446 pSibling = dynamic_cast<Node*>(new (std::nothrow) ElementLeaf(id, type, this->GetParent(), this->GetParentId()));
449 if (pSibling == null)
451 AppLogDebug(" Add fail [E_FAILURE]]");
455 ElementNode* pElementNode = dynamic_cast<ElementNode*>(this->GetParent());
456 if (pElementNode == null)
458 AppLogDebug(" dynamic_cast<ElementNode*>(this->GetParent()) is null");
463 result r = pElementNode->Add(*pSibling);
466 AppLogDebug(" Add fail [%s]", GetErrorMessage(r));
475 ElementNode::AddChild(Tizen::Base::String id, Tizen::Base::String type, NodeType nodetype)
479 if (GetNodeType() != NODE_TYPE_ELEMENT)
481 AppLogDebug("GetNodeType() is [%d]", GetNodeType());
485 if (nodetype == NODE_TYPE_ELEMENT)
487 pChild = dynamic_cast<Node*>(new (std::nothrow) ElementNode(id, type, this, this->__id));
491 pChild = dynamic_cast<Node*>(new (std::nothrow) ElementLeaf(id, type, this, this->__id));
496 AppLogDebug(" Add fail [E_FAILURE]]");
500 result r =Add(*pChild);
503 AppLogDebug(" Add fail [%s]", GetErrorMessage(r));
512 ElementNode::Remove(Tizen::Base::String id, Node* pParent)
514 if (this->__id.Equals(id, false))
516 AppLogDebug("can not delete yourself");
520 IEnumerator* pEnum = null;
521 if (pParent->GetNodeType() == NODE_TYPE_ELEMENT)
523 ElementNode* pElementNode = (dynamic_cast<ElementNode*>(pParent));
524 if (pElementNode == null)
526 AppLogDebug("(dynamic_cast<ElementNode*>(pParent) is null");
529 if (pElementNode->__pChild == null)
531 AppLogDebug(" pElementNode->__pChild is null");
535 pEnum = pElementNode->__pChild->GetEnumeratorN();
539 AppLogDebug(" pParent is not NODE_TYPE_ELEMENT");
540 return E_INVALID_OPERATION;
544 while (pEnum->MoveNext() == E_SUCCESS)
546 pObj = static_cast<Node*>(pEnum->GetCurrent());
547 if ((pObj->GetId()).Equals(id, false))
549 ElementNode* pElementNode = dynamic_cast<ElementNode*>(pParent);
550 if (pElementNode == null)
557 return pElementNode->__pChild->Remove(*pObj, true);
563 AppLogDebug(" Node is not found");
568 ElementNode::RemoveAllChild(void)
570 if (__pChild != null)
572 __pChild->RemoveAll();
579 ElementNode::GetChild(Tizen::Base::String id)
581 if (__pChild == null)
583 AppLogDebug("__pChild is null");
588 IEnumerator* pEnum = __pChild->GetEnumeratorN();
589 while (pEnum->MoveNext())
591 pObj = static_cast<Node*>(pEnum->GetCurrent());
592 if ((pObj->GetId()).Equals(id, false))
604 ElementNode::GetChild(int index)
606 if (__pChild == null)
608 AppLogDebug("__pChild is null");
612 Node* pNode = static_cast<Node*>(__pChild->GetAt(index));
617 ElementNode::GetChildCount(void)
619 if (__pChild == null)
621 AppLogDebug("__pChild is null");
625 return __pChild->GetCount();
629 ElementNode::RemoveChildAt(Tizen::Base::String id)
631 return Remove(id, dynamic_cast<Node*>(this));
635 ElementNode::RemoveSilbingAt(Tizen::Base::String id)
637 return Remove(id, dynamic_cast<Node*>(this->GetParent()));
641 ElementNode::CreateEnumerator(void)
643 return dynamic_cast<Enumerator*>((new (std::nothrow) ElementEnumerator(this)));
646 Tizen::Base::Collection::IEnumerator*
647 ElementNode::GetCurrentIEnumerator(void)
649 if (__pChild == null)
651 AppLogDebug("__pChild is null");
655 if (__pCurrentEnum == null)
657 __pCurrentEnum = __pChild->GetEnumeratorN();
660 return __pCurrentEnum;
664 ElementNode::ResetCurrentIEnumerator(void)
666 if (__pCurrentEnum != null)
668 __pCurrentEnum->Reset();
673 ElementNode::GetNodeType(void)
675 return NODE_TYPE_ELEMENT;
679 ElementNode::DebugLog(void)
681 if (__pChild != null)
683 IEnumerator* pEnum = __pChild->GetEnumeratorN();
684 ElementNode* pObj = null;
685 while (pEnum->MoveNext() == E_SUCCESS)
687 pObj = static_cast<ElementNode*>(pEnum->GetCurrent());
688 AppLogDebug("__pCurrent Id [%ls], _pParentId [%ls] __type [%ls]", pObj->__id.GetPointer(), pObj->__parentId.GetPointer(), pObj->__type.GetPointer());
694 AppLogDebug("__pChild is null");
697 if (__pNodeAttribute != null)
700 String* pValue = null;
701 IMapEnumerator* pMapEnum = __pNodeAttribute->GetMapEnumeratorN();
703 while (pMapEnum->MoveNext() == E_SUCCESS)
705 pKey = static_cast<String*>(pMapEnum->GetKey());
706 pValue = static_cast<String*>(pMapEnum->GetValue());
707 AppLogDebug("pKey [%ls], pValue [%ls]", pKey->GetPointer(), pValue->GetPointer());
710 AppLogDebug("__pCurrent Id [%ls], _pParentId [%ls]", (this->__id).GetPointer(), this->__parentId.GetPointer());
714 AppLogDebug("__pNodeAttribute is null");
718 ElementEnumerator::ElementEnumerator(Node* pRootNode )
719 : __pRootNode(pRootNode)
722 if (__pRootNode != null)
724 __enumeratorStack.Push(__pRootNode);
728 ElementEnumerator::~ElementEnumerator(void)
731 __pCurrentIEnumerator = null;
736 ElementEnumerator::Reset(void)
739 while (IsEmpty() == false)
741 __enumeratorStack.Pop(pNode);
742 if (pNode->GetNodeType() == Node::NODE_TYPE_ELEMENT)
744 ElementNode* pElementNode = dynamic_cast<ElementNode*>(pNode);
745 if (pElementNode != null)
747 pElementNode->ResetCurrentIEnumerator();
754 ElementEnumerator::IsEmpty(void)
756 if (__enumeratorStack.GetCount() == 0)
764 ElementEnumerator::MoveNext(void)
766 if (IsEmpty() == true)
772 result r = __enumeratorStack.Peek(pNode);
775 AppLogDebug("Peek is fail [%s]", GetErrorMessage(r));
778 __pCurrentIEnumerator = pNode->GetCurrentIEnumerator();
780 if ((__pCurrentIEnumerator != null)
781 && (__pCurrentIEnumerator->MoveNext() == E_SUCCESS))
783 pNode = static_cast<Node*>(__pCurrentIEnumerator->GetCurrent());
784 r = __enumeratorStack.Push(pNode);
787 AppLogDebug("Push is fail [%s]", GetErrorMessage(r));
794 while (IsEmpty() == false)
796 r = __enumeratorStack.Pop(pNode);
799 AppLogDebug("Pop is fail [%s]", GetErrorMessage(r));
803 if (pNode->GetNodeType() == Node::NODE_TYPE_ELEMENT)
805 ElementNode* pElementNode = dynamic_cast<ElementNode*>(pNode);
806 if (pElementNode != null)
808 pElementNode->ResetCurrentIEnumerator();
812 if (IsEmpty() == false)
814 r = __enumeratorStack.Peek(pNode);
817 AppLogDebug("Peek is fail [%s]", GetErrorMessage(r));
821 __pCurrentIEnumerator = pNode->GetCurrentIEnumerator();
822 if ((__pCurrentIEnumerator != null)
823 && (__pCurrentIEnumerator->MoveNext() == E_SUCCESS))
825 pNode = static_cast<Node*>(__pCurrentIEnumerator->GetCurrent());
826 r = __enumeratorStack.Push(pNode);
829 AppLogDebug("Peek is fail [%s]", GetErrorMessage(r));
842 ElementEnumerator::GetCurrentObject(void)
844 if (__pCurrentIEnumerator != null)
846 return __pCurrentIEnumerator->GetCurrent();
852 NullEnumerator::MoveNext(void)
858 NullEnumerator::GetCurrentObject(void)
863 IOAppSetting::IOAppSetting(void)
865 , __pAppSettingInstance(null)
866 , __pChangedAttributeHashMap(null)
870 IOAppSetting::~IOAppSetting(void)
872 if (__pChangedAttributeHashMap != null)
874 __pChangedAttributeHashMap->RemoveAll();
875 delete __pChangedAttributeHashMap;
876 __pChangedAttributeHashMap = null;
879 if (__pAppSettingInstance != null)
881 __pAppSettingInstance->ReleaseInstanceByAppId(__appId);
882 __pAppSettingInstance = null;
887 IOAppSetting::Constructor(Tizen::Base::String appId)
889 result r = E_SUCCESS;
891 __appId.Append(appId);
893 __pAppSettingInstance = AppSetting::GetInstanceByAppId(__appId);
894 if (__pAppSettingInstance == null)
896 AppLogDebug("GetInstanceByAppId is null");
900 if (__pChangedAttributeHashMap == null)
902 __pChangedAttributeHashMap = new (std::nothrow) HashMap();
903 r = __pChangedAttributeHashMap->Construct();
907 delete __pChangedAttributeHashMap;
908 __pChangedAttributeHashMap = null;
910 __pAppSettingInstance->ReleaseInstanceByAppId(__appId);
911 __pAppSettingInstance = null;
913 AppLogDebug("Construct Fail [%s]", GetErrorMessage(r));
922 IOAppSetting::OnChangedAttributeValue(Tizen::Base::String id, Tizen::Base::String value, Tizen::Base::String type)
924 result r = E_FAILURE;
926 if (__pChangedAttributeHashMap == null)
928 AppLogDebug("__pChangedAttributeHashMap is null");
932 id.Append(ID_APPSETTING_CHANGED_VALUE_KEY_DELIMIT);
936 r = __pChangedAttributeHashMap->ContainsKey(id, isFind);
939 AppLogDebug("ContainsKey fail[%s]", GetErrorMessage(r));
945 r = __pChangedAttributeHashMap->SetValue(*(new (std::nothrow) String(id)), *(new (std::nothrow) String(value)));
949 r = __pChangedAttributeHashMap->Add(new (std::nothrow) String(id), new (std::nothrow) String(value));
956 IOAppSetting::UpdateChangedValue(void)
958 if ((__pChangedAttributeHashMap == null)
959 || (__pAppSettingInstance == null))
961 AppLogDebug("__pChangedAttributeHashMap or __pAppSettingInstance is null");
966 String* pValue = null;
967 String tokenValue[ID_APPSETTING_MANAGER_CHANGED_VALUE_KEY_DELIMIT_MAX_COUNT];
968 IMapEnumerator* pMapEnum = __pChangedAttributeHashMap->GetMapEnumeratorN();
970 while (pMapEnum->MoveNext() == E_SUCCESS)
972 pKey = static_cast<String*>(pMapEnum->GetKey());
973 pValue = static_cast<String*>(pMapEnum->GetValue());
975 StringTokenizer stringTokenizer(*pKey, ID_APPSETTING_CHANGED_VALUE_KEY_DELIMIT);
976 if (stringTokenizer.GetTokenCount() != static_cast<int>(ID_APPSETTING_MANAGER_CHANGED_VALUE_KEY_DELIMIT_MAX_COUNT))
978 AppLogDebug("failed to Get id and type [%d]", stringTokenizer.GetTokenCount());
982 bool isConntinueRoutine = true;
983 for (int i = 0; i <= stringTokenizer.GetTokenCount(); i++)
985 result r = stringTokenizer.GetNextToken(tokenValue[i]);
988 AppLogDebug("GetNextToken failed[%s]", GetErrorMessage(r));
989 isConntinueRoutine = false;
994 if (isConntinueRoutine == false)
999 if (tokenValue[APP_SETTING_DEFAULT_TOKEN_COUNT].Equals(ID_APPSETTING_CHANGED_VALUE_BOOL_TYPE, false))
1001 bool retValue = GetStringToBoolValue(*pValue);
1002 result r = __pAppSettingInstance->SetValue(tokenValue[0], retValue);
1005 AppLogDebug("SetValue fail [id:%ls][type:%ls][value:%d]", tokenValue[0].GetPointer(), tokenValue[APP_SETTING_DEFAULT_TOKEN_COUNT].GetPointer(), retValue);
1008 else if (tokenValue[APP_SETTING_DEFAULT_TOKEN_COUNT].Equals(ID_APPSETTING_CHANGED_VALUE_INTEGER_TYPE, false))
1010 int retValue = GetStringToIntegerValue(*pValue);
1011 result r = __pAppSettingInstance->SetValue(tokenValue[0], retValue);
1014 AppLogDebug("SetValue fail [id:%ls][type:%ls][value:%d]", tokenValue[0].GetPointer(), tokenValue[APP_SETTING_DEFAULT_TOKEN_COUNT].GetPointer(), retValue);
1019 String retValue = pValue->GetPointer();
1020 result r = __pAppSettingInstance->SetValue(tokenValue[0], retValue);
1023 AppLogDebug("SetValue fail [id:%ls][type:%ls][value:%ls]", tokenValue[0].GetPointer(), tokenValue[APP_SETTING_DEFAULT_TOKEN_COUNT].GetPointer(), pValue->GetPointer());
1028 __pChangedAttributeHashMap->RemoveAll();
1032 IOAppSetting::GetStringToBoolValue(Tizen::Base::String value)
1034 if (Boolean::Parse(value) == true)
1042 IOAppSetting::GetStringToIntegerValue(Tizen::Base::String value)
1044 int intgerValue = 0;
1045 result r = Integer::Parse(value, intgerValue);
1048 AppLogDebug("Integer::Parse fail");
1055 AppSettingManager::AppSettingManager(void)
1056 : __pRootListHashMap(null)
1060 AppSettingManager::~AppSettingManager(void)
1062 if (__pRootListHashMap != null)
1064 __pRootListHashMap->RemoveAll();
1065 delete __pRootListHashMap;
1066 __pRootListHashMap = null;
1071 AppSettingManager::GetInstance(void)
1073 if (__pAppSettingManagerInstance == null)
1078 return __pAppSettingManagerInstance;
1082 AppSettingManager::Construct(void)
1084 __pRootListHashMap = new (std::nothrow) HashMap();
1085 result r = __pRootListHashMap->Construct();
1089 delete __pRootListHashMap;
1090 __pRootListHashMap = null;
1092 AppLogDebug("Construct Fail [%s]", GetErrorMessage(r));
1100 AppSettingManager::CreateInstance(void)
1102 __pAppSettingManagerInstance = new (std::nothrow) AppSettingManager();
1103 result r = __pAppSettingManagerInstance->Construct();
1106 delete __pAppSettingManagerInstance;
1107 __pAppSettingManagerInstance = null;
1111 std::atexit(DestroyInstance);
1115 AppSettingManager::DestroyInstance(void)
1117 delete __pAppSettingManagerInstance;
1118 __pAppSettingManagerInstance = null;
1122 AppSettingManager::XmlAppSettingFileRead(Tizen::Base::String filePath, ElementNode* pRootNode)
1124 ByteBuffer* pBuf = StringUtil::StringToUtf8N(filePath);
1126 || (pRootNode == null))
1128 AppLogDebug("pBuf or pRootNode is null");
1132 xmlTextReaderPtr reader = xmlReaderForFile((const char*) pBuf->GetPointer(), NULL, XML_READER_FOR_FILE_DEFAULT_OPTION);
1135 AppLogDebug("reader is null");
1139 ArrayList* idList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1140 idList->Construct();
1141 idList->Add(new (std::nothrow) String(L"Start"));
1143 int xmlreadType = 0;
1144 Node* pParentOfNewNode = dynamic_cast<Node*>(pRootNode);
1145 while (xmlTextReaderRead(reader))
1147 const xmlChar* name = xmlTextReaderConstName(reader);
1148 xmlreadType = xmlTextReaderNodeType(reader);
1149 if ((xmlreadType != XML_READER_TYPE_ELEMENT)
1150 && (xmlreadType != XML_READER_TYPE_END_ELEMENT))
1152 if (xmlStrcasecmp(name, (const xmlChar*) null) == 0)
1154 AppLogDebug("value field must be not empty");
1160 if (xmlreadType == XML_READER_TYPE_END_ELEMENT)
1162 if (pParentOfNewNode != null)
1164 pParentOfNewNode = pParentOfNewNode->GetParent();
1169 if (xmlTextReaderAttributeCount(reader) == 0)
1171 if (xmlStrcasecmp(name, (const xmlChar*) "separator") != 0)
1177 String elementIdType;
1179 Node::NodeType newNodeType = Node::NODE_TYPE_LEAF;
1181 StringUtil::Utf8ToString((char*)(xmlTextReaderConstName(reader)), elementIdType);
1182 StringUtil::Utf8ToString((char*)(xmlTextReaderGetAttribute(reader, (xmlChar*) "id")), elementId);
1184 for (int i = 0; i < ID_APPSETTING_MANAGER_ELEMENT_NODE_DELIMIT_COUNT; i++)
1186 if (elementIdType.Equals(appSettingElementNodeDelimit[i], false))
1188 newNodeType = Node::NODE_TYPE_ELEMENT;
1193 Node* pCurrentNode = null;
1194 if (newNodeType == Node::NODE_TYPE_ELEMENT)
1196 ElementNode* pElementNode = dynamic_cast<ElementNode*>(pParentOfNewNode);
1197 if (pElementNode != null)
1199 if (idList->Contains(String(elementId)))
1201 AppLogDebug("continue elementId[%ls]", elementId.GetPointer());
1204 pParentOfNewNode = pElementNode->AddChild(elementId, elementIdType, newNodeType);
1205 pCurrentNode = pParentOfNewNode;
1207 idList->Add(new (std::nothrow) String(elementId));
1212 ElementNode* pElementNode = dynamic_cast<ElementNode*>(pParentOfNewNode);
1213 if (pElementNode != null)
1215 if (xmlStrcasecmp(name, (const xmlChar*) "separator") == 0)
1218 separatorId.Format(20, L"IDSP_%d", separatorCount);
1220 if (idList->Contains(String(separatorId)))
1224 pCurrentNode = pElementNode->AddChild(separatorId, elementIdType, newNodeType);
1225 idList->Add(new (std::nothrow) String(separatorId));
1230 if (idList->Contains(String(elementId)))
1232 AppLogDebug("continue elementId[%ls]", elementId.GetPointer());
1235 AppLogDebug("continue elementId[%ls]", elementId.GetPointer());
1236 pCurrentNode = pElementNode->AddChild(elementId, elementIdType, newNodeType);
1237 idList->Add(new (std::nothrow) String(elementId));
1242 ByteBuffer* pBuf = null;
1243 xmlChar* xmlAttriuteText = null;
1244 for (int i = 0; i < ID_APPSETTING_MANAGER_NODE_ATTRIUBTE_DELIMIT_COUNT; i++)
1246 pBuf = StringUtil::StringToUtf8N(appSettingNodeAttributeDelimit[i]);
1247 if ((xmlAttriuteText = xmlTextReaderGetAttribute(reader, pBuf->GetPointer())) != null)
1250 StringUtil::Utf8ToString((char*)xmlAttriuteText, value);
1252 if (pCurrentNode != null)
1254 pCurrentNode->AddAttribute(appSettingNodeAttributeDelimit[i], value);
1259 if (xmlStrcasecmp(name, (const xmlChar*) "separator") == 0)
1261 if (pCurrentNode != null)
1263 pCurrentNode->AddAttribute(appSettingNodeAttributeDelimit[1], L"separator");
1264 pCurrentNode->AddAttribute(appSettingNodeAttributeDelimit[2], L"true");
1271 xmlFreeTextReader(reader);
1280 AppSettingManager::AddAppSettingRootNode(Tizen::Base::String rootId)
1282 ElementNode* pRoot = new (std::nothrow) ElementNode(rootId, L"Root");
1285 AppLogDebug("Root Create failed");
1289 result r = __pRootListHashMap->Add(*(new (std::nothrow) String(rootId)), *pRoot);
1292 AppLogDebug("Add failed = %s", GetErrorMessage(r));
1301 AppSettingManager::GetAppSettingRootNode(Tizen::Base::String rootId)
1303 ElementNode* pValue = null;
1304 bool isFind = false;
1306 if (__pRootListHashMap == null)
1308 AppLogDebug("__pRootListHashMap is null");
1312 result r = __pRootListHashMap->ContainsKey(rootId, isFind);
1314 || (isFind == false))
1316 AppLogDebug("ContainsKey fail[result : %s][isFind : %d]", GetErrorMessage(r), isFind);
1320 pValue = static_cast<ElementNode*>(__pRootListHashMap->GetValue(rootId));
1325 AppSettingManager::RemoveAppSettingRootNode(Tizen::Base::String rootId)
1327 if (__pRootListHashMap == null)
1329 return E_INVALID_OPERATION;
1332 bool isFind = false;
1333 result r = __pRootListHashMap->ContainsKey(rootId, isFind);
1335 || (isFind == false))
1337 AppLogDebug("ContainsKey fail[result : %s][isFind : %d]", GetErrorMessage(r), isFind);
1339 if (isFind == false)
1346 r = __pRootListHashMap->Remove(rootId, false);
1350 Tizen::Base::Collection::IMapEnumerator*
1351 AppSettingManager::GetRottNodeIEnumeratorN(void)
1353 if (__pRootListHashMap == null)
1355 AppLogDebug("__pRootListHashMap is null");
1359 IMapEnumerator* pMapEnum = __pRootListHashMap->GetMapEnumeratorN();
1364 AppSettingManager::GetRootNodeCount(void)
1366 int rootNodeCount = 0;
1368 if (__pRootListHashMap == null)
1370 AppLogDebug("__pRootListHashMap is null");
1371 return rootNodeCount;
1374 rootNodeCount = __pRootListHashMap->GetCount();
1375 return rootNodeCount;