|
1 /* |
|
2 * Copyright (c) 2005 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: CXcapIetfCommonPolicyUsage |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include <XdmErrors.h> |
|
22 #include <XdmDocumentNode.h> |
|
23 #include <XdmNodeAttribute.h> |
|
24 #include "XcapIetfCommonPolicyUsage.h" |
|
25 |
|
26 // Used specifications |
|
27 // draft-ietf-geopriv-common-policy-08, 05 March 2006, expires 06 September 2006 |
|
28 |
|
29 // ---------------------------------------------------- |
|
30 // CXcapIetfCommonPolicyUsage::CXcapIetfCommonPolicyUsage |
|
31 // |
|
32 // ---------------------------------------------------- |
|
33 // |
|
34 CXcapIetfCommonPolicyUsage::CXcapIetfCommonPolicyUsage( const CXdmEngine& aXdmEngine ) |
|
35 :CXcapAppUsage( aXdmEngine ) |
|
36 { |
|
37 } |
|
38 |
|
39 // ---------------------------------------------------- |
|
40 // CXcapIetfCommonPolicyUsage::NewL |
|
41 // |
|
42 // ---------------------------------------------------- |
|
43 // |
|
44 CXcapIetfCommonPolicyUsage* CXcapIetfCommonPolicyUsage::NewL( const TXcapAppUsageParams& aParameters ) |
|
45 { |
|
46 CXcapIetfCommonPolicyUsage* self = new ( ELeave ) CXcapIetfCommonPolicyUsage( aParameters.iXdmEngine ); |
|
47 CleanupStack::PushL( self ); // << self |
|
48 self->ConstructL(); |
|
49 CleanupStack::Pop( self ); // >> self |
|
50 return self; |
|
51 } |
|
52 |
|
53 // ---------------------------------------------------- |
|
54 // CXcapIetfCommonPolicyUsage::~CXcapIetfCommonPolicyUsage |
|
55 // |
|
56 // ---------------------------------------------------- |
|
57 // |
|
58 CXcapIetfCommonPolicyUsage::~CXcapIetfCommonPolicyUsage() |
|
59 { |
|
60 } |
|
61 |
|
62 // ---------------------------------------------------- |
|
63 // CXcapIetfCommonPolicyUsage::ConstructL |
|
64 // |
|
65 // ---------------------------------------------------- |
|
66 // |
|
67 void CXcapIetfCommonPolicyUsage::ConstructL() |
|
68 { |
|
69 } |
|
70 |
|
71 // ---------------------------------------------------- |
|
72 // CXcapIetfCommonPolicyUsage::AUID |
|
73 // |
|
74 // ---------------------------------------------------- |
|
75 // |
|
76 TPtrC8 CXcapIetfCommonPolicyUsage::AUID() const |
|
77 { |
|
78 return TPtrC8( KXdmIetfCommonPolicyUsageAUID ); |
|
79 } |
|
80 |
|
81 // ---------------------------------------------------- |
|
82 // CXcapIetfCommonPolicyUsage::ContentType |
|
83 // |
|
84 // ---------------------------------------------------- |
|
85 // |
|
86 TPtrC8 CXcapIetfCommonPolicyUsage::ContentType() const |
|
87 { |
|
88 return TPtrC8( KXdmIetfCommonPolicyUsageContType ); |
|
89 } |
|
90 |
|
91 // ---------------------------------------------------- |
|
92 // CXcapIetfCommonPolicyUsage::DefaultNamespace |
|
93 // |
|
94 // ---------------------------------------------------- |
|
95 // |
|
96 TPtrC8 CXcapIetfCommonPolicyUsage::DefaultNamespace() const |
|
97 { |
|
98 return TPtrC8( KXdmIetfCommonPolicyNamespace ); |
|
99 } |
|
100 |
|
101 // ---------------------------------------------------- |
|
102 // CXcapIetfCommonPolicyUsage::ValidateNodeL |
|
103 // |
|
104 // ---------------------------------------------------- |
|
105 // |
|
106 TBool CXcapIetfCommonPolicyUsage::ValidateNodeL( CXdmDocumentNode& aXdmNode ) |
|
107 { |
|
108 // This method is called by base class for each element |
|
109 // in document, here we have to declare every element, check element |
|
110 // datatype, restrictions for values and also do all checking that concerns |
|
111 // the structure of the element. If the datatype is some of |
|
112 // the common datatypes defined in xcapappusage.h, the node |
|
113 // can pe passed to the base class for value validation. |
|
114 // If the node belongs to this namespace, the return value |
|
115 // should be true, false otherwise. |
|
116 |
|
117 TBool found ( EFalse ); |
|
118 TDataType dataType ( EDataTypeUndefined ); |
|
119 TPtrC element = aXdmNode.NodeName(); |
|
120 |
|
121 // <ruleset> |
|
122 if ( Match( element, KXdmRuleset ) ) |
|
123 { |
|
124 TInt count( aXdmNode.NodeCount() ); |
|
125 for ( TInt i(0); i < count; i++ ) |
|
126 { |
|
127 // ruleset should not contain any other type elements |
|
128 // than <rule> |
|
129 if ( !Match( aXdmNode.ChileNode(i)->NodeName(), KXdmRule ) ) |
|
130 { |
|
131 LeaveWithErrorL( KXcapErrorSchemaViolation ); |
|
132 } |
|
133 } |
|
134 found = ETrue; |
|
135 } |
|
136 // <rule> |
|
137 else if ( Match( element, KXdmRule ) ) |
|
138 { |
|
139 // required attribute id |
|
140 if ( !aXdmNode.HasAttribute( KXdmId ) ) |
|
141 { |
|
142 LeaveWithErrorL( KXcapErrorMissingRequiredAttribute ); |
|
143 } |
|
144 found = ETrue; |
|
145 } |
|
146 // <conditions> |
|
147 else if ( Match( element, KXdmConditions ) ) |
|
148 { |
|
149 found = ETrue; |
|
150 } |
|
151 // <actions> |
|
152 else if ( Match( element, KXdmActions ) ) |
|
153 { |
|
154 found = ETrue; |
|
155 } |
|
156 // <transformations> |
|
157 else if ( Match( element, KXdmTransformations ) ) |
|
158 { |
|
159 found = ETrue; |
|
160 } |
|
161 // <validity> |
|
162 else if ( Match( element, KXdmValidity ) ) |
|
163 { |
|
164 // <validity> should contain <from> and <until> |
|
165 TBool from( EFalse ); |
|
166 TBool until( EFalse ); |
|
167 TInt count( aXdmNode.NodeCount() ); |
|
168 for ( TInt i(0); i < count; i++ ) |
|
169 { |
|
170 TPtrC childName = aXdmNode.ChileNode(i)->NodeName(); |
|
171 if ( Match( childName, KXdmFrom ) ) |
|
172 { |
|
173 from = ETrue; |
|
174 } |
|
175 else if ( Match( childName, KXdmUntil ) ) |
|
176 { |
|
177 until = ETrue; |
|
178 } |
|
179 } |
|
180 if ( !from || !until ) |
|
181 { |
|
182 LeaveWithErrorL( KXcapErrorMissingRequiredElement ); |
|
183 } |
|
184 found = ETrue; |
|
185 } |
|
186 // <from> |
|
187 else if ( Match( element, KXdmFrom ) ) |
|
188 { |
|
189 dataType = EDataTypeDateTime; |
|
190 found = ETrue; |
|
191 } |
|
192 // <to> |
|
193 else if ( Match( element, KXdmTo ) ) |
|
194 { |
|
195 dataType = EDataTypeDateTime; |
|
196 found = ETrue; |
|
197 } |
|
198 // <identity> |
|
199 else if ( Match( element, KXdmIdentity ) ) |
|
200 { |
|
201 // <identity> should contain either <one> or <many> |
|
202 // elements, not both |
|
203 TBool one( EFalse ); |
|
204 TBool many( EFalse ); |
|
205 TInt count( aXdmNode.NodeCount() ); |
|
206 for ( TInt i(0); i < count; i++ ) |
|
207 { |
|
208 TPtrC childName = aXdmNode.ChileNode(i)->NodeName(); |
|
209 if ( Match( childName, KXdmOne ) ) |
|
210 { |
|
211 one = ETrue; |
|
212 } |
|
213 else if ( Match( childName, KXdmMany ) ) |
|
214 { |
|
215 many = ETrue; |
|
216 } |
|
217 } |
|
218 if ( one && many ) |
|
219 { |
|
220 LeaveWithErrorL( KXcapErrorSchemaViolation ); |
|
221 } |
|
222 found = ETrue; |
|
223 } |
|
224 // <id> |
|
225 else if ( Match( element, KXdmId ) ) |
|
226 { |
|
227 // required attribute entity |
|
228 if ( !aXdmNode.HasAttribute( KXdmEntity ) ) |
|
229 { |
|
230 LeaveWithErrorL( KXcapErrorMissingRequiredAttribute ); |
|
231 } |
|
232 found = ETrue; |
|
233 } |
|
234 // <any-identity> |
|
235 else if ( Match( element, KXdmAnyIdentity ) ) |
|
236 { |
|
237 found = ETrue; |
|
238 } |
|
239 // <except> |
|
240 else if ( Match( element, KXdmExcept ) ) |
|
241 { |
|
242 found = ETrue; |
|
243 } |
|
244 // <sphere> |
|
245 else if ( Match( element, KXdmSphere ) ) |
|
246 { |
|
247 // required attribute value |
|
248 if ( !aXdmNode.HasAttribute( KXdmValue ) ) |
|
249 { |
|
250 LeaveWithErrorL( KXcapErrorMissingRequiredAttribute ); |
|
251 } |
|
252 found = ETrue; |
|
253 } |
|
254 // <one> |
|
255 else if ( Match( element, KXdmOne ) ) |
|
256 { |
|
257 // required attribute id |
|
258 if ( !aXdmNode.HasAttribute( KXdmId ) ) |
|
259 { |
|
260 LeaveWithErrorL( KXcapErrorMissingRequiredAttribute ); |
|
261 } |
|
262 found = ETrue; |
|
263 } |
|
264 // <many> |
|
265 else if ( Match( element, KXdmMany) ) |
|
266 { |
|
267 found = ETrue; |
|
268 } |
|
269 // <until> |
|
270 else if ( Match( element, KXdmUntil ) ) |
|
271 { |
|
272 dataType = EDataTypeDateTime; |
|
273 found = ETrue; |
|
274 } |
|
275 |
|
276 // if the node is some of the basic types, |
|
277 // pass it to the base class for data validation |
|
278 if ( dataType != EDataTypeUndefined ) |
|
279 { |
|
280 ValidateDataL( dataType, aXdmNode ); |
|
281 } |
|
282 return found; |
|
283 } |
|
284 |
|
285 // ---------------------------------------------------- |
|
286 // CXcapIetfCommonPolicyUsage::ValidateAttributeL |
|
287 // |
|
288 // ---------------------------------------------------- |
|
289 // |
|
290 void CXcapIetfCommonPolicyUsage::ValidateAttributeL( const CXdmNodeAttribute& aXdmNodeAttr ) |
|
291 { |
|
292 // This method is called by base class for each attribute |
|
293 // in document, here we have to define data types |
|
294 // for attributes, and pass them to the base class |
|
295 // for the actual data checking. |
|
296 |
|
297 TDataType dataType ( EDataTypeUndefined ); |
|
298 TPtrC attribute = aXdmNodeAttr.NodeName(); |
|
299 |
|
300 // id |
|
301 if ( Match( attribute, KXdmId ) ) |
|
302 { |
|
303 dataType = EDataTypeString; |
|
304 } |
|
305 // domain |
|
306 else if ( Match( attribute, KXdmDomain ) ) |
|
307 { |
|
308 dataType = EDataTypeString; |
|
309 } |
|
310 // value |
|
311 else if ( Match( attribute, KXdmValue ) ) |
|
312 { |
|
313 dataType = EDataTypeString; |
|
314 } |
|
315 |
|
316 // pass to base class for data validation |
|
317 ValidateDataL( dataType, aXdmNodeAttr ); |
|
318 } |
|
319 |
|
320 // ---------------------------------------------------- |
|
321 // CXcapIetfCommonPolicyUsage::AddNamespaceInformationL |
|
322 // |
|
323 // ---------------------------------------------------- |
|
324 // |
|
325 void CXcapIetfCommonPolicyUsage::AddNamespaceInformationL( CXdmDocument& aXdmDocument ) |
|
326 { |
|
327 aXdmDocument.AppendNamespaceL( KXdmIetfCommonPolicyNamespace, KNullDesC8 ); |
|
328 } |
|
329 |
|
330 // End of File |
|
331 |