|
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: CXcapRlsServicesUsage |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include <XdmErrors.h> |
|
22 #include <XdmDocumentNode.h> |
|
23 #include <XdmNodeAttribute.h> |
|
24 #include "XcapRlsServicesUsage.h" |
|
25 |
|
26 // Used specification |
|
27 // OMA-RLS_XDM_Specification-V1_0-20060214-C, 14 February 2006 |
|
28 |
|
29 // ---------------------------------------------------- |
|
30 // CXcapRlsServicesUsage::CXcapRlsServicesUsage |
|
31 // |
|
32 // ---------------------------------------------------- |
|
33 // |
|
34 CXcapRlsServicesUsage::CXcapRlsServicesUsage( const CXdmEngine& aXdmEngine ) : |
|
35 CXcapAppUsage( aXdmEngine ), |
|
36 iResourceLists( NULL ) |
|
37 { |
|
38 } |
|
39 |
|
40 // ---------------------------------------------------- |
|
41 // CXcapRlsServicesUsage::NewL |
|
42 // |
|
43 // ---------------------------------------------------- |
|
44 // |
|
45 CXcapRlsServicesUsage* CXcapRlsServicesUsage::NewL( const TXcapAppUsageParams& aParameters ) |
|
46 { |
|
47 CXcapRlsServicesUsage* self = new ( ELeave ) CXcapRlsServicesUsage( aParameters.iXdmEngine ); |
|
48 CleanupStack::PushL( self ); // << self |
|
49 self->ConstructL(); |
|
50 CleanupStack::Pop( self ); // >> self |
|
51 return self; |
|
52 } |
|
53 |
|
54 // ---------------------------------------------------- |
|
55 // CXcapRlsServicesUsage::~CXcapRlsServicesUsage |
|
56 // |
|
57 // ---------------------------------------------------- |
|
58 // |
|
59 CXcapRlsServicesUsage::~CXcapRlsServicesUsage() |
|
60 { |
|
61 delete iResourceLists; |
|
62 } |
|
63 |
|
64 // ---------------------------------------------------- |
|
65 // CXcapRlsServicesUsage::ConstructL |
|
66 // |
|
67 // ---------------------------------------------------- |
|
68 // |
|
69 void CXcapRlsServicesUsage::ConstructL() |
|
70 { |
|
71 iResourceLists = CXcapAppUsage::NewL( iXdmEngine, KXdmResourceListsUsageUid ); |
|
72 } |
|
73 |
|
74 // ---------------------------------------------------- |
|
75 // CXcapRlsServicesUsage::AUID |
|
76 // |
|
77 // ---------------------------------------------------- |
|
78 // |
|
79 TPtrC8 CXcapRlsServicesUsage::AUID() const |
|
80 { |
|
81 return TPtrC8( KXdmRlsServicesUsageAUID ); |
|
82 } |
|
83 |
|
84 // ---------------------------------------------------- |
|
85 // CXcapRlsServicesUsage::ContentType |
|
86 // |
|
87 // ---------------------------------------------------- |
|
88 // |
|
89 TPtrC8 CXcapRlsServicesUsage::ContentType() const |
|
90 { |
|
91 return TPtrC8( KXdmRlsServicesUsageContType ); |
|
92 } |
|
93 |
|
94 // ---------------------------------------------------- |
|
95 // CXcapRlsServicesUsage::DefaultNamespace |
|
96 // |
|
97 // ---------------------------------------------------- |
|
98 // |
|
99 TPtrC8 CXcapRlsServicesUsage::DefaultNamespace() const |
|
100 { |
|
101 return TPtrC8( KXdmRlsServicesNamespace ); |
|
102 } |
|
103 |
|
104 // ---------------------------------------------------- |
|
105 // CXcapRlsServicesUsage::ValidateNodeL |
|
106 // |
|
107 // ---------------------------------------------------- |
|
108 // |
|
109 TBool CXcapRlsServicesUsage::ValidateNodeL( CXdmDocumentNode& aXdmNode ) |
|
110 { |
|
111 // This method is called by base class for each element |
|
112 // in document, here we have to declare every element, check element |
|
113 // datatype, restrictions for values and also do all checking that concerns |
|
114 // the structure of the element. If the datatype is some of |
|
115 // the common datatypes defined in xcapappusage.h, the node |
|
116 // can pe passed to the base class for value validation. |
|
117 // If the node belongs to this namespace, the return value |
|
118 // should be true, false otherwise. |
|
119 |
|
120 |
|
121 TBool found( EFalse ); |
|
122 TDataType dataType ( EDataTypeUndefined ); |
|
123 TPtrC element = aXdmNode.NodeName(); |
|
124 // <rls-services> |
|
125 if ( Match( element, KXdmRlsServices ) ) |
|
126 { |
|
127 found = ETrue; |
|
128 } |
|
129 // <service> |
|
130 else if ( Match( element, KXdmService ) ) |
|
131 { |
|
132 // required attribute uri |
|
133 if ( !aXdmNode.HasAttribute( KXdmUri ) ) |
|
134 { |
|
135 LeaveWithErrorL( KXcapErrorMissingRequiredAttribute ); |
|
136 } |
|
137 |
|
138 // there should be either <resource-list> or |
|
139 // <list> element and mandatory <packages> element |
|
140 TBool resourcelist( EFalse ); |
|
141 TBool list( EFalse ); |
|
142 TBool packages( EFalse ); |
|
143 // go through all childs |
|
144 TInt count( aXdmNode.NodeCount() ); |
|
145 for ( TInt i(0); i < count; i++ ) |
|
146 { |
|
147 TPtrC childName = aXdmNode.ChileNode(i)->NodeName(); |
|
148 if ( Match( childName, KXdmResourceList ) ) |
|
149 { |
|
150 resourcelist = ETrue; |
|
151 } |
|
152 else if ( Match( childName, KXdmList ) ) |
|
153 { |
|
154 list = ETrue; |
|
155 } |
|
156 else if ( Match( childName, KXdmPackages ) ) |
|
157 { |
|
158 packages = ETrue; |
|
159 } |
|
160 } |
|
161 // <resource-list> or <list>, not both |
|
162 if ( resourcelist && list ) |
|
163 { |
|
164 LeaveWithErrorL( KXcapErrorSchemaViolation ); |
|
165 } |
|
166 // each <service> must have at least one <packages> element |
|
167 if ( !packages ) |
|
168 { |
|
169 LeaveWithErrorL( KXcapErrorMissingRequiredElement ); |
|
170 } |
|
171 found = ETrue; |
|
172 } |
|
173 // <resource-list> |
|
174 else if ( Match( element, KXdmResourceList ) ) |
|
175 { |
|
176 dataType = EDataTypeAnyURI; |
|
177 found = ETrue; |
|
178 } |
|
179 // <packages> |
|
180 else if ( Match( element, KXdmPackages ) ) |
|
181 { |
|
182 // each <packages> shall specify at least presence event package, |
|
183 // go through all childs |
|
184 TBool presence ( EFalse ); |
|
185 TInt count( aXdmNode.NodeCount() ); |
|
186 for ( TInt i(0); i < count; i++ ) |
|
187 { |
|
188 if ( Match( aXdmNode.ChileNode(i)->NodeName(), KXdmPackage ) ) |
|
189 { |
|
190 TPtrC8 data = aXdmNode.ChileNode(i)->LeafNodeContent(); |
|
191 if ( !data.CompareF( KXdmPresence ) ) |
|
192 { |
|
193 presence = ETrue; |
|
194 } |
|
195 } |
|
196 } |
|
197 // check that the <package>presence<package> exists |
|
198 if ( !presence ) |
|
199 { |
|
200 LeaveWithErrorL( KXcapErrorMissingRequiredElementValue ); |
|
201 } |
|
202 found = ETrue; |
|
203 } |
|
204 // <package> |
|
205 else if ( Match( element, KXdmPackage ) ) |
|
206 { |
|
207 dataType = EDataTypeString; |
|
208 found = ETrue; |
|
209 } |
|
210 // <list> type=rl:listType from urn:ietf:params:xml:ns:resource-lists |
|
211 // however belongs to the default namespace |
|
212 // ( btw, there is mistake in specification example ) |
|
213 else if ( Match( element, KXdmList ) ) |
|
214 { |
|
215 found = iResourceLists->ValidateNodeL( aXdmNode ); |
|
216 } |
|
217 // <entry>,<display-name> from urn:ietf:params:xml:ns:resource-lists |
|
218 if ( !found ) |
|
219 { |
|
220 found = iResourceLists->ValidateNodeL( aXdmNode ); |
|
221 if ( found ) |
|
222 { |
|
223 SetPrefixL( aXdmNode, KXdmResourceListsNsPrefix ); |
|
224 } |
|
225 } |
|
226 if ( dataType != EDataTypeUndefined ) |
|
227 { |
|
228 // pass to the base class for data validation |
|
229 ValidateDataL( dataType, aXdmNode ); |
|
230 } |
|
231 return found; |
|
232 } |
|
233 |
|
234 // ---------------------------------------------------- |
|
235 // CXcapRlsServicesUsage::ValidateAttributeL |
|
236 // |
|
237 // ---------------------------------------------------- |
|
238 // |
|
239 void CXcapRlsServicesUsage::ValidateAttributeL( const CXdmNodeAttribute& aXdmNodeAttr ) |
|
240 { |
|
241 // This method is called by base class for each attribute |
|
242 // in document, here we have to define data types |
|
243 // for attributes, and pass them to the base class |
|
244 // for the actual data checking. |
|
245 |
|
246 // uri |
|
247 if ( Match( aXdmNodeAttr.NodeName(), KXdmUri ) ) |
|
248 { |
|
249 ValidateDataL( EDataTypeAnyURI, aXdmNodeAttr ); |
|
250 } |
|
251 // the rest are rom urn:ietf:params:xml:ns:resource-lists |
|
252 else |
|
253 { |
|
254 iResourceLists->ValidateAttributeL( aXdmNodeAttr ); |
|
255 } |
|
256 } |
|
257 |
|
258 // ---------------------------------------------------- |
|
259 // CXcapRlsServicesUsage::AddNamespaceInformationL |
|
260 // |
|
261 // ---------------------------------------------------- |
|
262 // |
|
263 void CXcapRlsServicesUsage::AddNamespaceInformationL( CXdmDocument& aXdmDocument ) |
|
264 { |
|
265 aXdmDocument.AppendNamespaceL( KXdmRlsServicesNamespace, KNullDesC8 ); |
|
266 aXdmDocument.AppendNamespaceL( KXdmResourceListsNamespace, KXdmResourceListsNsPrefix ); |
|
267 } |
|
268 |
|
269 |
|
270 // End of File |
|
271 |