1 /* |
|
2 * Copyright (c) 2004 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: Sources |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <s32buf.h> |
|
22 #include <s32file.h> |
|
23 |
|
24 #include "nsmlxmlparser.h" |
|
25 |
|
26 |
|
27 // ============================ MEMBER FUNCTIONS =============================== |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CNSmlTruncatedData::NewL |
|
33 // Two-phased constructor. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 EXPORT_C CNSmlTruncatedData* CNSmlTruncatedData::NewL() |
|
37 { |
|
38 CNSmlTruncatedData* self = CNSmlTruncatedData::NewLC(); |
|
39 CleanupStack::Pop(); |
|
40 |
|
41 return self; |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CNSmlTruncatedData::NewLC |
|
46 // Two-phased constructor. |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 EXPORT_C CNSmlTruncatedData* CNSmlTruncatedData::NewLC() |
|
50 { |
|
51 CNSmlTruncatedData* self = new (ELeave) CNSmlTruncatedData(); |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(); |
|
54 |
|
55 return self; |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CNSmlTruncatedData::~CNSmlTruncatedData |
|
60 // Destructor |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 EXPORT_C CNSmlTruncatedData::~CNSmlTruncatedData() |
|
64 { |
|
65 iAttachments.ResetAndDestroy(); |
|
66 iAttachments.Close(); |
|
67 |
|
68 iBodys.ResetAndDestroy(); |
|
69 iBodys.Close(); |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CNSmlTruncatedData::AddAttachmentL |
|
74 // Adds an attachment to iAttachments. Takes copies of buffers, caller must |
|
75 // destroy the original buffers. |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 EXPORT_C void CNSmlTruncatedData::AddAttachmentL(HBufC8* aName, TInt aSize, HBufC8* aType) |
|
79 { |
|
80 CNSmlAttachmentTruncateInfo* attach = new (ELeave) CNSmlAttachmentTruncateInfo(); |
|
81 CleanupStack::PushL(attach); |
|
82 |
|
83 attach->SetMembersL(aName, aType, aSize); |
|
84 |
|
85 iAttachments.Append(attach); |
|
86 |
|
87 CleanupStack::Pop(); // attach |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CNSmlTruncatedData::AddBodyL |
|
92 // Adds a body. Takes copies of buffers, caller must destroy the |
|
93 // original buffers. |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 EXPORT_C void CNSmlTruncatedData::AddBodyL(TInt aSize, HBufC8* aType) |
|
97 { |
|
98 CNSmlBodyTruncateInfo* body = new (ELeave) CNSmlBodyTruncateInfo(); |
|
99 CleanupStack::PushL(body); |
|
100 |
|
101 body->SetMembersL(aType, aSize); |
|
102 |
|
103 iBodys.Append(body); |
|
104 |
|
105 CleanupStack::Pop(); // body |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CNSmlTruncatedData::GenerateXmlL |
|
110 // Generates truncate data xml |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 EXPORT_C void CNSmlTruncatedData::GenerateXmlL( TPtr8& aXml, const CNSmlXmlParser* aParser ) const |
|
114 { |
|
115 aParser->AppendElement(aXml, KTruncatedElement()); |
|
116 |
|
117 TInt size = 0; |
|
118 HBufC8* type = 0; |
|
119 HBufC8* name = 0; |
|
120 |
|
121 for ( TInt j = 0; j < iBodys.Count(); ++j ) |
|
122 { |
|
123 iBodys[j]->GetMembersL(type, size); |
|
124 |
|
125 aParser->AppendElement(aXml, KTruncatedBodyElement()); |
|
126 |
|
127 if ( size != KErrNotFound ) |
|
128 { |
|
129 aParser->AppendElement(aXml, KTruncatedSizeElement(), aParser->IntegerToString(size)); |
|
130 } |
|
131 |
|
132 if ( type ) |
|
133 { |
|
134 aParser->AppendElement(aXml, KTruncatedTypeElement(), *type); |
|
135 delete type; type = NULL; |
|
136 } |
|
137 |
|
138 aParser->AppendEndElement(aXml, KTruncatedBodyElement()); |
|
139 } |
|
140 |
|
141 for ( TInt i = 0; i < iAttachments.Count(); ++i ) |
|
142 { |
|
143 size = 0; |
|
144 type = NULL; |
|
145 name = NULL; |
|
146 |
|
147 iAttachments[i]->GetMembersL(name, type, size); |
|
148 |
|
149 aParser->AppendElement(aXml, KTruncatedAttachElement()); |
|
150 |
|
151 if ( name ) |
|
152 { |
|
153 aParser->AppendElement(aXml, KTruncatedNameElement(), *name); |
|
154 delete name; name = NULL; |
|
155 } |
|
156 |
|
157 if ( size != KErrNotFound ) |
|
158 { |
|
159 aParser->AppendElement(aXml, KTruncatedSizeElement(), aParser->IntegerToString(size)); |
|
160 } |
|
161 |
|
162 if ( type ) |
|
163 { |
|
164 aParser->AppendElement(aXml, KTruncatedTypeElement(), *type); |
|
165 delete type; type = NULL; |
|
166 } |
|
167 |
|
168 aParser->AppendEndElement(aXml, KTruncatedAttachElement()); |
|
169 } |
|
170 |
|
171 aParser->AppendEndElement(aXml, KTruncatedElement()); |
|
172 } |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // CNSmlTruncatedData::CountXmlSizeL |
|
176 // Counts the size of truncate data xml if it was generated using current values |
|
177 // in member variables. |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 EXPORT_C TInt CNSmlTruncatedData::CountXmlSizeL( const CNSmlXmlParser* aParser ) const |
|
181 { |
|
182 TInt size = 0; |
|
183 size += aParser->SizeOfElements( KTruncatedElement() ); |
|
184 |
|
185 for ( TInt j = 0; j < iBodys.Count(); ++j ) |
|
186 { |
|
187 TInt bodySize = 0; |
|
188 HBufC8* bodyType = 0; |
|
189 iBodys[j]->GetMembersL(bodyType, bodySize); |
|
190 |
|
191 size += aParser->SizeOfElements( KTruncatedBodyElement() ); |
|
192 |
|
193 if ( bodySize != KErrNotFound ) |
|
194 { |
|
195 size += aParser->SizeOfInteger( KTruncatedSizeElement() ); |
|
196 } |
|
197 |
|
198 if ( bodyType ) |
|
199 { |
|
200 size += aParser->SizeOfString( bodyType, KTruncatedTypeElement() ); |
|
201 delete bodyType; bodyType = NULL; |
|
202 } |
|
203 |
|
204 } |
|
205 |
|
206 for ( TInt i = 0; i < iAttachments.Count(); ++i ) |
|
207 { |
|
208 TInt attachSize = 0; |
|
209 HBufC8* attachType = 0; |
|
210 HBufC8* attachName = 0; |
|
211 iAttachments[i]->GetMembersL(attachName, attachType, attachSize); |
|
212 |
|
213 size += aParser->SizeOfElements( KTruncatedAttachElement() ); |
|
214 |
|
215 if ( attachName ) |
|
216 { |
|
217 size += aParser->SizeOfString( attachName, KTruncatedNameElement() ); |
|
218 delete attachName; attachName = NULL; |
|
219 } |
|
220 |
|
221 if ( attachSize != KErrNotFound ) |
|
222 { |
|
223 size += aParser->SizeOfInteger( KTruncatedSizeElement() ); |
|
224 } |
|
225 |
|
226 if ( attachType ) |
|
227 { |
|
228 size += aParser->SizeOfString( attachType, KTruncatedTypeElement() ); |
|
229 delete attachType; attachType = NULL; |
|
230 } |
|
231 |
|
232 } |
|
233 |
|
234 return size; |
|
235 } |
|
236 |
|
237 // ----------------------------------------------------------------------------- |
|
238 // CNSmlTruncatedData::ConvertIntoEntitiesL |
|
239 // Converts special characters in strings into entities. |
|
240 // ----------------------------------------------------------------------------- |
|
241 // |
|
242 EXPORT_C void CNSmlTruncatedData::ConvertIntoEntitiesL( const CNSmlXmlParser* aParser ) |
|
243 { |
|
244 TInt size = 0; |
|
245 HBufC8* type = NULL; |
|
246 HBufC8* name = NULL; |
|
247 |
|
248 for ( TInt j = 0; j < iBodys.Count(); ++j ) |
|
249 { |
|
250 iBodys[j]->GetMembersL(type, size); |
|
251 CleanupStack::PushL(type); |
|
252 |
|
253 if( type ) |
|
254 aParser->CharactersToEntitiesL(type, 0, type->Length()); |
|
255 |
|
256 iBodys[j]->SetMembersL(type, size); |
|
257 CleanupStack::Pop(); // type |
|
258 delete type; type = NULL; |
|
259 } |
|
260 |
|
261 for ( TInt i = 0; i < iAttachments.Count(); ++i ) |
|
262 { |
|
263 iAttachments[i]->GetMembersL(name, type, size); |
|
264 CleanupStack::PushL(type); |
|
265 CleanupStack::PushL(name); |
|
266 |
|
267 if( name ) |
|
268 { |
|
269 aParser->CharactersToEntitiesL(name, 0, name->Length()); |
|
270 } |
|
271 if( type ) |
|
272 { |
|
273 aParser->CharactersToEntitiesL(type, 0, type->Length()); |
|
274 } |
|
275 |
|
276 iAttachments[i]->SetMembersL(name, type, size); |
|
277 CleanupStack::Pop(2); // name, type |
|
278 |
|
279 delete name; name = NULL; |
|
280 delete type; type = NULL; |
|
281 } |
|
282 |
|
283 } |
|
284 |
|
285 // ----------------------------------------------------------------------------- |
|
286 // CNSmlTruncatedData::CNSmlTruncatedData |
|
287 // Private constructor |
|
288 // ----------------------------------------------------------------------------- |
|
289 // |
|
290 CNSmlTruncatedData::CNSmlTruncatedData() |
|
291 { |
|
292 } |
|
293 |
|
294 // ----------------------------------------------------------------------------- |
|
295 // CNSmlTruncatedData::ConstructL |
|
296 // Second phase construction |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 void CNSmlTruncatedData::ConstructL() |
|
300 { |
|
301 iAttachments.Reset(); |
|
302 iBodys.Reset(); |
|
303 } |
|
304 |
|
305 // End of File |
|