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 * MessageFilterValidator.cpp
19 * Created on: 2011. 10. 31.
23 #include "MessageFilterValidator.h"
24 #include "MessageFilterValidatorFactory.h"
26 #include <dpl/log/log.h>
29 using namespace WrtDeviceApis::Commons;
30 using namespace WrtDeviceApis::CommonsJavaScript;
31 using namespace TizenApis::Api::Tizen;
37 MessageFilterValidator::MessageFilterValidator(PropertyStructArray properties)
38 :FilterValidator(properties){
39 m_isTypeSetted = false;
41 initMatchFlagVectors();
42 initAttributeAndMatchFlagsMap();
45 MessageFilterValidator::~MessageFilterValidator(){
48 void MessageFilterValidator::initMatchFlagVectors(){
49 m_typeMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
51 m_idMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
53 m_folderIdMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
55 m_timestampMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
57 m_fromMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
58 m_fromMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_CONTAINS);
59 m_fromMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_STARTSWITH);
60 m_fromMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_ENDSWITH);
62 m_toMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
63 m_toMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_CONTAINS);
64 m_toMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_STARTSWITH);
65 m_toMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_ENDSWITH);
67 m_ccMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
68 m_ccMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_CONTAINS);
69 m_ccMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_STARTSWITH);
70 m_ccMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_ENDSWITH);
72 m_bccMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
73 m_bccMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_CONTAINS);
74 m_bccMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_STARTSWITH);
75 m_bccMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_ENDSWITH);
77 m_bodyMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_CONTAINS);
79 m_isReadMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
81 m_priorityMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
83 m_subjectMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
84 m_subjectMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_CONTAINS);
87 void MessageFilterValidator::initAttributeAndMatchFlagsMap(){
88 m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_TYPE] = m_typeMatchFlagVec;
89 m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_ID] = m_idMatchFlagVec;
90 m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_FOLDER] = m_folderIdMatchFlagVec;
91 m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_TIMESTAMP] = m_timestampMatchFlagVec;
92 m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_FROM] = m_fromMatchFlagVec;
93 m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_CC] = m_ccMatchFlagVec;
94 m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_BCC] = m_bccMatchFlagVec;
95 m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_BODY] = m_bodyMatchFlagVec;
96 m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_IS_READ] = m_isReadMatchFlagVec;
97 m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_PRIORITY] = m_priorityMatchFlagVec;
98 m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_SUBJECT] = m_subjectMatchFlagVec;
99 m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_TO] = m_toMatchFlagVec;
102 bool MessageFilterValidator::validateAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth){
103 if(initialValue == NULL || endValue == NULL)
108 if(attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_TIMESTAMP)!=0){
109 MsgLogError(">>> [ERROR] Not Supported attribute :[" << attrName << "]");
113 retVal = FilterValidator::validateAttributeRange(attrName, initialValue, endValue, depth);
118 bool MessageFilterValidator::vectorContains(std::vector<std::string>& vec, Api::Tizen::MatchFlag& value){
119 std::string matchStr;
122 case Api::Tizen::MATCH_EXACTLY:
123 matchStr = "EXACTLY";
125 case Api::Tizen::MATCH_FULLSTRING:
126 matchStr = "FULLSTRING";
128 case Api::Tizen::MATCH_CONTAINS:
129 matchStr = "CONTAINS";
131 case Api::Tizen::MATCH_STARTSWITH:
132 matchStr = "STARTSWITH";
134 case Api::Tizen::MATCH_ENDSWITH:
135 matchStr = "ENDSWITH";
137 case Api::Tizen::MATCH_EXISTS:
145 std::vector<std::string>::iterator it;
146 for(it=vec.begin(); it<vec.end(); it++){
147 if((*it).compare(matchStr) == 0){
155 bool MessageFilterValidator::validateAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag,
156 Api::Tizen::AnyPtr& matchValue, int depth){
157 bool retBool = false;
159 if(matchValue == NULL)
162 if(validateAttributeEach(attrName, matchFlag, matchValue, depth) == false){
163 MsgLogWanning(">>>[Warning] attrName:[" << attrName << "] is invalid value:[" << matchValue->toString() << "]");
167 retBool = FilterValidator::validateAttribute(attrName, matchFlag, matchValue, depth);
168 LogDebug(">>> retBool:" << retBool);
172 bool MessageFilterValidator::validateAttributeEach(std::string& attrName,MatchFlag& matchFlag, Api::Tizen::AnyPtr& value, int depth){
173 LogDebug("<<< attrName:[" << attrName << "], value:[" << value->toString() << "]");
175 if(attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_TYPE)==0){
176 if(m_isTypeSetted == true){
177 MsgLogError(">>> [ERROR] duplicated type :[" << attrName << "], value:[" <<
178 value->toString()<< "]");
181 m_isTypeSetted = true;
185 if(m_attributeAndMatchFlagsMap.count(attrName) == 0)
187 MsgLogWanning(">>>[Waning] attrName is not supported:[" << attrName << "]");
191 std::vector<std::string> vec = m_attributeAndMatchFlagsMap.find(attrName)->second;
193 if(vectorContains(vec, matchFlag)==false){
194 MsgLogWanning(">>>[Waning]MatchFlag check fail unsupported flag:[" << matchFlag << "] for Attribute:[" << attrName << "]");
198 LogDebug(">>> return true");
202 } //namespace Messaging