wrt-plugins-tizen_0.4.23
[framework/web/wrt-plugins-tizen.git] / src / Messaging / ConversationFilterValidator.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 #include "ConversationFilterValidator.h"
19 #include "ConversationFilterValidatorFactory.h"
20
21 #include "log.h"
22 #include <Logger.h>
23
24 using namespace DeviceAPI::Tizen;
25
26 namespace DeviceAPI {
27         namespace Messaging {
28
29                 ConversationFilterValidator::ConversationFilterValidator(PropertyStructArray properties):FilterValidator(properties){
30                         m_isTypeSetted = false;
31                 }
32
33                 ConversationFilterValidator::~ConversationFilterValidator() {
34                         m_isTypeSetted = false;
35                 }
36
37
38                 bool ConversationFilterValidator::validateAttributeRange(std::string& attrName, DeviceAPI::Tizen::AnyPtr& initialValue, DeviceAPI::Tizen::AnyPtr& endValue, int depth){
39                         if(initialValue == NULL || endValue == NULL)
40                                 return false;
41
42                         bool retVal = false;
43
44                         if(attrName.compare(ConversationFilterValidatorFactory::ATTRIBUTE_TIMESTAMP)!=0){
45                                 LoggerE(">>> [ERROR] Not Supported attribute :[" << attrName << "]");
46                                 return false;
47                         }
48
49                         retVal = FilterValidator::validateAttributeRange(attrName, initialValue, endValue, depth);
50                         return retVal;
51                 }
52
53                 bool ConversationFilterValidator::validateAttribute(std::string& attrName, DeviceAPI::Tizen::MatchFlag& matchFlag,
54                                 DeviceAPI::Tizen::AnyPtr& matchValue, int depth){
55
56                                 if(matchValue == NULL)
57                                         return false;
58
59                                 bool retBool = false;
60
61                                 if(validateAttributeEach(attrName, matchFlag, matchValue, depth) == false){
62                                         MsgLogWanning(">>>[Warning] attrName:[" << attrName << "] is invalid value:[" << matchValue->toString() << "]");
63                                         return false;
64                                 }
65
66                                 retBool = FilterValidator::validateAttribute(attrName, matchFlag, matchValue,depth);
67                                 LoggerD(">>> retBool:" << retBool);
68                                 return retBool;
69                 }
70
71                 bool ConversationFilterValidator::validateAttributeEach(std::string& attrName, DeviceAPI::Tizen::MatchFlag& matchFlag, DeviceAPI::Tizen::AnyPtr& value, int depth){
72                         LoggerD("<<< attrName:[" << attrName << "], value:[" << value->toString() << "]");
73
74                         if(attrName.compare(ConversationFilterValidatorFactory::ATTRIBUTE_TYPE)==0){
75                                 if(m_isTypeSetted == true){
76                                         MsgLoggerE(">>> [ERROR] duplicated type :[" << attrName << "], value:[" << value->toString()<< "]");
77                                         return false;
78                                 }else{
79                                         m_isTypeSetted = true;
80                                 }
81                         }
82
83                         return true;
84                 }
85
86         }
87 }