2 // Open Service Platform
3 // Copyright (c) 2012 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 #include <FBaseSysLog.h>
19 #include "ParseUtil.h"
21 using namespace Tizen::Base;
22 using namespace Tizen::Base::Utility;
25 ParseParameter(const Tizen::Base::String& src, const Tizen::Base::String& delimeter, const Tizen::Base::String& key, int &value)
30 StringTokenizer strTok(src, delimeter);
31 SysTryCatch(NID_APP, strTok.GetTokenCount()>0, r = E_KEY_NOT_FOUND, E_KEY_NOT_FOUND, "[E_KEY_NOT_FOUND] delimeter:%ls", delimeter.GetPointer());
33 while (strTok.HasMoreTokens())
35 r = strTok.GetNextToken(token);
36 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
41 r = strTok.GetNextToken(strValue);
42 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
44 r = Integer::Parse(strValue, value);
45 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
54 ParseParameter(const Tizen::Base::String& src, const Tizen::Base::String& delimeter, const Tizen::Base::String& key, Tizen::Base::String &value)
59 StringTokenizer strTok(src, delimeter);
60 SysTryCatch(NID_APP, strTok.GetTokenCount()>0, r = E_KEY_NOT_FOUND, E_KEY_NOT_FOUND, "[E_KEY_NOT_FOUND] Propagating.");
62 while (strTok.HasMoreTokens())
64 r = strTok.GetNextToken(token);
65 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
69 r = strTok.GetNextToken(value);
70 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
72 else // In case of additional collon such as path:http://localhost:8080/xxx
74 r = value.Append(delimeter);
75 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
76 r = value.Append(token);
77 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
86 SplitParameters(const Tizen::Base::String& src, const Tizen::Base::String& delimeter, Tizen::Base::String& key, Tizen::Base::String &value)
92 StringTokenizer strTok(src, delimeter);
93 SysTryCatch(NID_APP, strTok.GetTokenCount()>0, r = E_KEY_NOT_FOUND, E_KEY_NOT_FOUND, "[E_KEY_NOT_FOUND] Propagating.");
95 while (strTok.HasMoreTokens())
97 r = strTok.GetNextToken(token);
98 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
109 value.Append(delimeter);
121 FindKey(const Tizen::Base::String& src, const Tizen::Base::String& delimeter, Tizen::Base::String& key)
123 result r = E_SUCCESS;
126 StringTokenizer strTok(src, delimeter);
127 SysTryCatch(NID_APP, strTok.GetTokenCount()>0, r = E_KEY_NOT_FOUND, E_KEY_NOT_FOUND, "[E_KEY_NOT_FOUND] Propagating.");
129 while (strTok.HasMoreTokens())
131 r = strTok.GetNextToken(token);
132 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
134 key = token; // Get the key which occurs first.
143 FindKeyUnit(const UnitTransMap* pMap, const Tizen::Base::String& srcKey, Tizen::Base::String& dstKey, UnitType &srcType, UnitType &dstType, Tizen::Base::String &conCatStr, int& conCatIndex )
145 result r = E_SUCCESS;
148 SysTryCatch(NID_APP, pMap, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Propagating.");
150 while ( pMap[i].srcKey != null && pMap[i].dstKey != null )
152 if ( srcKey.Equals(String(pMap[i].srcKey), true))
154 dstKey = String(pMap[i].dstKey);
155 srcType = pMap[i].srcType;
156 dstType = pMap[i].dstType;
158 if ( pMap[i].conCatStr )
160 conCatStr = String(pMap[i].conCatStr);
164 conCatStr = String(L"");
167 conCatIndex = pMap[i].conCatIndex;
169 // SysLog(NID_APP, "src:%s, dst:%s, srcType:%d, dstType:%d, conCat:%s, conCatIndex:%d", pMap[i].srcKey,pMap[i].dstKey,pMap[i].srcType,pMap[i].dstType,pMap[i].conCatStr,pMap[i].conCatIndex);
179 PeekListValue(const Tizen::Base::Collection::IList* pList, int index, const Tizen::Base::String& delimeter, const Tizen::Base::String& key, Tizen::Base::String& value )
181 result r = E_SUCCESS;
182 String *pNodeData=null;
184 SysTryCatch(NID_APP, pList != null, r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The obj was not found.\n");
185 SysTryCatch(NID_APP, pList->GetCount() > index , r = E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Propagating..\n");
187 pNodeData = dynamic_cast<String*>(const_cast<Object*>(pList->GetAt(index)));
188 SysTryCatch(NID_APP, pNodeData != null, r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The file was not found.\n");
189 SysTryCatch(NID_APP, pNodeData->GetLength() > 0 , r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The file path is too short.\n");
191 r = ParseParameter(*pNodeData, key, delimeter, value);
198 FindListKey(const Tizen::Base::Collection::IList* pList, int index, const Tizen::Base::String& delimeter, Tizen::Base::String& key )
200 result r = E_SUCCESS;
201 String *pNodeData=null;
203 SysTryCatch(NID_APP, pList != null, r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The obj was not found.\n");
204 SysTryCatch(NID_APP, pList->GetCount() > index , r = E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Propagating.list count:%d, index:%d", pList->GetCount(), index);
206 pNodeData = dynamic_cast<String*>(const_cast<Object*>(pList->GetAt(index)));
207 SysTryCatch(NID_APP, pNodeData != null, r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The file was not found.\n");
208 SysTryCatch(NID_APP, pNodeData->GetLength() > 0 , r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The file path is too short.\n");
210 r = FindKey(*pNodeData, delimeter, key);
217 CountListKey(const Tizen::Base::Collection::IList* pList, const Tizen::Base::String& delimeter, const Tizen::Base::String& key )
219 result r = E_SUCCESS;
223 SysTryCatch(NID_APP, pList != null, r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The obj was not found.\n");
225 count = pList->GetCount();
227 for (int i = 0; i<count; i++ )
230 r = FindListKey(pList, i, delimeter, value);
231 if ( r == E_SUCCESS && value == key )