1##
2#    Copyright (c) 2007 Cyrus Daboo. All rights reserved.
3#
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
7#
8#        http://www.apache.org/licenses/LICENSE-2.0
9#
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.
15##
16
17
18class PyCalendarOutputFilter(object):
19
20    def __init__(self, type):
21        self.mType = type
22        self.mAllSubComponents = False
23        self.mSubComponents = None
24        self.mAllProperties = False
25        self.mProperties = None
26
27    def getType(self):
28        return self.mType
29
30    # Test to see if component type can be written out
31    def testComponent(self, type):
32        return self.mType == type
33
34    def isAllSubComponents(self):
35        return self.mAllSubComponents
36
37    def setAllSubComponents(self):
38        self.mAllSubComponents = True
39        self.mSubComponents = None
40
41    def addSubComponent(self, comp):
42        if self.mSubComponents == None:
43            self.mSubComponents = {}
44
45        self.mSubComponents[comp.getType()] = comp
46
47    # Test to see if sub-component type can be written out
48    def testSubComponent(self, type):
49        return self.mAllSubComponents or (self.mSubComponents is not None) \
50                and self.mSubComponents.has_key(type)
51
52    def hasSubComponentFilters(self):
53        return self.mSubComponents is not None
54
55    def getSubComponentFilter(self, type):
56        if self.mSubComponents is not None:
57            return self.mSubComponents.get(type, None)
58        else:
59            return None
60
61    def isAllProperties(self):
62        return self.mAllProperties
63
64    def setAllProperties(self):
65        self.mAllProperties = True
66        self.mProperties = None
67
68    def addProperty(self, name, no_value):
69        if self.mProperties is None:
70            self.mProperties = {}
71
72        self.mProperties[name] = no_value
73
74    def hasPropertyFilters(self):
75        return self.mProperties is not None
76
77    # Test to see if property can be written out and also return whether
78    # the property value is used
79    def testPropertyValue(self, name):
80
81        if self.mAllProperties:
82            return True, False
83
84        if self.mProperties is None:
85            return False, False
86
87        result = self.mProperties.get(name, None)
88        return result is not None, result
89