|
1 /* |
|
2 * Copyright (c) 2002-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: CCFContains class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 #include "cfcontains.h" |
|
22 #include "cfcontextobject.h" |
|
23 #include "cfcontextoperationutils.h" |
|
24 #include "cfbasicoptrace.h" |
|
25 |
|
26 #include <gmxmlnode.h> |
|
27 |
|
28 // CONSTANTS |
|
29 _LIT( KScriptContainsName, "contains" ); |
|
30 |
|
31 // ============================ MEMBER FUNCTIONS =============================== |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CCFContains::CCFContains |
|
35 // C++ default constructor can NOT contain any code, that |
|
36 // might leave. |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 CCFContains::CCFContains( MCFOperationServices& aServices, |
|
40 CCFOperationNode* aParent, |
|
41 HBufC* aName, |
|
42 HBufC* aSource ) |
|
43 : CCFContextOperation( aServices, aParent, aName, aSource ) |
|
44 { |
|
45 FUNC_LOG; |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CCFContains::ConstructL |
|
50 // Symbian 2nd phase constructor can leave. |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 void CCFContains::ConstructL( const TDesC& aCmpVal ) |
|
54 { |
|
55 FUNC_LOG; |
|
56 |
|
57 iCmpValue = aCmpVal.AllocL(); |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CCFContains::NewL |
|
62 // Two-phased constructor. |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CCFContains* CCFContains::NewL( MCFOperationServices& aServices, |
|
66 CCFOperationNode* aParent, |
|
67 TDesC& aName, |
|
68 TDesC& aSource, |
|
69 const TDesC& aCmpVal ) |
|
70 { |
|
71 FUNC_LOG; |
|
72 |
|
73 CCFContains* self = NewLC( aServices, aParent, aName, aSource, aCmpVal ); |
|
74 CleanupStack::Pop( self ); |
|
75 return self; |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CCFContains::NewLC |
|
80 // Two-phased constructor. |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 CCFContains* CCFContains::NewLC( MCFOperationServices& aServices, |
|
84 CCFOperationNode* aParent, |
|
85 TDesC& aName, |
|
86 TDesC& aSource, |
|
87 const TDesC& aCmpVal ) |
|
88 { |
|
89 FUNC_LOG; |
|
90 |
|
91 HBufC* name = aName.AllocLC(); |
|
92 HBufC* source = aSource.AllocLC(); |
|
93 CCFContains* self |
|
94 = new( ELeave ) CCFContains( aServices, aParent, name, source ); |
|
95 CleanupStack::PushL( self ); |
|
96 self->ConstructL( aCmpVal ); |
|
97 |
|
98 // Cleanup |
|
99 CleanupStack::Pop( self ); |
|
100 CleanupStack::Pop( source ); |
|
101 CleanupStack::Pop( name ); |
|
102 |
|
103 CleanupStack::PushL( self ); |
|
104 return self; |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // CCFContains::ParseL |
|
109 // Construction with parsing from a DOM node. |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 CCFContains* CCFContains::ParseL( MCFOperationServices& aServices, |
|
113 CCFOperationNode* aParent, |
|
114 CMDXMLNode& aNode ) |
|
115 { |
|
116 FUNC_LOG; |
|
117 |
|
118 if ( aNode.NodeName().CompareF( KScriptContainsName ) != 0 ) |
|
119 { |
|
120 return NULL; // Cannot create contains operation from the given node. |
|
121 } |
|
122 |
|
123 TPtrC contextSource; |
|
124 TPtrC contextType; |
|
125 TCmpType cmpType( CCFContextOperation::EInvalidCmpType ); |
|
126 TPtrC cmpValue; |
|
127 TInt contextLevelDelay( 0 ); |
|
128 TBool argsOK = CFContextOperationUtils::ParseTwoComparisonArgs( aNode, |
|
129 contextSource, |
|
130 contextType, |
|
131 cmpType, |
|
132 cmpValue, |
|
133 contextLevelDelay ); |
|
134 if ( cmpType != CCFContextOperation::EStringCmp ) |
|
135 { |
|
136 argsOK = EFalse; |
|
137 } |
|
138 |
|
139 CCFContains* self = NULL; |
|
140 if ( argsOK ) |
|
141 { |
|
142 self = NewL( aServices, |
|
143 aParent, |
|
144 contextType, |
|
145 contextSource, |
|
146 cmpValue ); |
|
147 if ( contextLevelDelay ) |
|
148 { |
|
149 self->iContextLevelDelay = contextLevelDelay; |
|
150 } |
|
151 } |
|
152 else |
|
153 { |
|
154 INFO( "CCFContains::ParseL - Unsupported arguments" ); |
|
155 } |
|
156 |
|
157 CREATE_DOM_INFO( self, aNode ); |
|
158 |
|
159 return self; |
|
160 } |
|
161 |
|
162 |
|
163 // Destructor |
|
164 CCFContains::~CCFContains() |
|
165 { |
|
166 FUNC_LOG; |
|
167 |
|
168 delete iCmpValue; |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // CCFContains::IsTrueL |
|
173 // Returns ETrue if this operation is true. |
|
174 // (other items were commented in a header). |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 TBool CCFContains::IsTrueL( const CCFContextObject& aContextObject ) |
|
178 { |
|
179 FUNC_LOG; |
|
180 |
|
181 TBool value( EFalse ); |
|
182 TInt err( KErrNone ); |
|
183 |
|
184 err = aContextObject.Value().Find( *iCmpValue ); |
|
185 |
|
186 // Value was found |
|
187 if ( err != KErrNotFound ) |
|
188 { |
|
189 value = ETrue; |
|
190 } |
|
191 |
|
192 return value; |
|
193 } |