2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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.
17 * FolderFilterValidator.cpp
19 * Created on: 2011. 10. 31.
23 #include "FolderFilterValidator.h"
24 #include "FolderFilterValidatorFactory.h"
26 #include <dpl/log/log.h>
29 using namespace WrtDeviceApis::Commons;
30 using namespace WrtDeviceApis::CommonsJavaScript;
31 using namespace TizenApis::Api::Tizen;
37 FolderFilterValidator::FolderFilterValidator(PropertyStructArray properties,
38 MatchFlagStrArray matchFlag, Api::Tizen::PrimitiveType idType):FilterValidator(properties, matchFlag){
39 m_isAccountIdSetted = false;
41 initMatchFlagVectors();
42 initAttributeAndMatchFlagsMap();
45 FolderFilterValidator::~FolderFilterValidator(){
48 void FolderFilterValidator::initMatchFlagVectors(){
49 m_accountIdMatchFlagVec.push_back(FolderFilterValidatorFactory::MATCH_EXACTLY);
50 m_folderPathMatchFlagVec.push_back(FolderFilterValidatorFactory::MATCH_EXACTLY);
53 void FolderFilterValidator::initAttributeAndMatchFlagsMap(){
54 m_attributeAndMatchFlagsMap[FolderFilterValidatorFactory::ATTRIBUTE_ACCOUNTID] = m_accountIdMatchFlagVec;
55 m_attributeAndMatchFlagsMap[FolderFilterValidatorFactory::ATTRIBUTE_FOLDERPATH] = m_folderPathMatchFlagVec;
58 bool FolderFilterValidator::validateAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth){
63 bool FolderFilterValidator::vectorContains(std::vector<std::string>& vec, std::string& value){
64 std::vector<std::string>::iterator it;
65 for(it=vec.begin(); it<vec.end(); it++){
66 if((*it).compare(value) == 0){
74 bool FolderFilterValidator::validateAttribute(std::string& attrName, Api::Tizen::AnyArrayPtr& values,
75 std::string& matchFlag, bool caseSensitive, int depth){
78 AnyArray::iterator iter;
79 for(iter=values->begin(); iter!=values->end(); iter++){
81 if(validateAttributeEach(attrName, value, matchFlag, depth) == false){
82 MsgLogWanning(">>>[Warning] attrName:[" << attrName << "] is invalid value:[" << value->toString() << "]");
86 LogDebug("## 001 ##");
87 retBool = FilterValidator::validateAttribute(attrName, values, matchFlag, caseSensitive, depth);
88 LogDebug("## 002 ##");
89 LogDebug(">>> retBool:" << retBool);
93 bool FolderFilterValidator::validateAttributeEach(std::string& attrName, Api::Tizen::AnyPtr& value, std::string& matchFlag, int depth){
94 LogDebug("<<< attrName:[" << attrName << "], value:[" << value->toString() << "]");
96 if(attrName.compare(FolderFilterValidatorFactory::ATTRIBUTE_ACCOUNTID)==0){
97 LogDebug("<<< m_isAccountIdSetted :[" << m_isAccountIdSetted << "]");
98 if(m_isAccountIdSetted == true){
99 LogError(">>> [ERROR] duplicated account :[" << attrName << "], value:[" <<
100 value->toString()<< "]");
103 m_isAccountIdSetted = true;
107 if(m_attributeAndMatchFlagsMap.count(attrName) == 0)
109 MsgLogWanning(">>>[Waning] attrName is not supported:[" << attrName << "]");
113 std::vector<std::string> vec = m_attributeAndMatchFlagsMap.find(attrName)->second;
115 if(vectorContains(vec, matchFlag)==false){
116 MsgLogWanning(">>>[Waning]MatchFlag check fail unsupported flag:[" << matchFlag << "] for Attribute:[" << attrName << "]");