|
1 /* |
|
2 * Copyright (c) 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: feed data class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 #include <e32std.h> |
|
25 #include <badesca.h> |
|
26 |
|
27 #include <SenDomFragmentBase.h> |
|
28 #include <xmlengnodelist.h> |
|
29 |
|
30 #include "senatomfeed.h" |
|
31 #include "senatomentry.h" |
|
32 |
|
33 #include "sendebug.h" |
|
34 #include "senlogger.h" |
|
35 |
|
36 EXPORT_C CSenAtomFeed* CSenAtomFeed::NewL( TInt64 aId ) |
|
37 { |
|
38 TLSLOG_L(KSenMessagesLogChannel, KSenMessagesLogLevel, "CSenAtomFeed::NewL( TInt64 aId )"); |
|
39 CSenAtomFeed* self = NewLC( aId ); |
|
40 CleanupStack::Pop( self ); |
|
41 return self; |
|
42 } |
|
43 |
|
44 EXPORT_C CSenAtomFeed* CSenAtomFeed::NewLC( TInt64 aId ) |
|
45 { |
|
46 TLSLOG_L(KSenMessagesLogChannel, KSenMessagesLogLevel, "CSenAtomFeed::NewLC( TInt64 aId )"); |
|
47 CSenAtomFeed* self = new (ELeave) CSenAtomFeed; |
|
48 CleanupStack::PushL( self ); |
|
49 self->BaseConstructL(); |
|
50 if ( aId != 0 ) |
|
51 { |
|
52 self->iId = aId; |
|
53 } |
|
54 return self; |
|
55 } |
|
56 |
|
57 CSenAtomFeed::CSenAtomFeed(): CSenAtomMessage() |
|
58 { |
|
59 TLSLOG_L(KSenMessagesLogChannel, KSenMessagesLogLevel, "CSenAtomFeed()"); |
|
60 } |
|
61 |
|
62 EXPORT_C void CSenAtomFeed::BaseConstructL() |
|
63 { |
|
64 TLSLOG_L(KSenMessagesLogChannel, KSenMessagesLogLevel, "CSenAtomFeed::BaseConstructL()"); |
|
65 CSenFragmentBase::BaseConstructL(_L8("http://www.w3.org/2005/Atom"),_L8("feed")); |
|
66 } |
|
67 |
|
68 EXPORT_C CSenAtomFeed::~CSenAtomFeed() |
|
69 { |
|
70 TLSLOG_L(KSenMessagesLogChannel, KSenMessagesLogLevel, "CSenAtomFeed::~CSenAtomFeed()"); |
|
71 iEntries.ResetAndDestroy(); |
|
72 iEntries.Close(); |
|
73 } |
|
74 |
|
75 |
|
76 |
|
77 EXPORT_C TInt CSenAtomFeed::EntryCount() //const |
|
78 { |
|
79 /*/testing |
|
80 TXmlEngElement feed = AsElementL(); |
|
81 RXmlEngNodeList<TXmlEngElement> list; |
|
82 const TPtrC8 tNsUri = NsUri(); |
|
83 CleanupClosePushL(list); |
|
84 feed.GetElementsByTagNameL(list, KSenAtomEntryName, tNsUri); |
|
85 TInt a = list.Count(); |
|
86 CleanupStack::PopAndDestroy(&list); |
|
87 TInt b = iEntries.Count(); |
|
88 //testing*/ |
|
89 return iEntries.Count(); |
|
90 } |
|
91 |
|
92 EXPORT_C TInt CSenAtomFeed::AddEntryL(CSenAtomEntry& aEntry) |
|
93 { |
|
94 TXmlEngElement feed = AsElementL(); |
|
95 RSenDocument doc = AsDocumentL(); |
|
96 feed.AppendChildL(aEntry.AsElementL()); |
|
97 CSenAtomEntry* ptrEnt = &aEntry; |
|
98 TInt err = iEntries.Append(ptrEnt); |
|
99 return err; |
|
100 } |
|
101 |
|
102 EXPORT_C CSenAtomEntry* CSenAtomFeed::Entry( TInt aIndex ) const |
|
103 { |
|
104 if ( aIndex >= 0 && aIndex < iEntries.Count() ) |
|
105 return iEntries[aIndex]; |
|
106 else |
|
107 return 0; |
|
108 } |
|
109 |
|
110 EXPORT_C void CSenAtomFeed::RemoveEntryL(const TDesC8& aEntryId ) |
|
111 { |
|
112 |
|
113 //from table |
|
114 for (TInt aIndex = 0; aIndex < iEntries.Count(); aIndex++ ) |
|
115 { |
|
116 const TDesC8& tmp = iEntries[aIndex]->IdTag();//delete this |
|
117 if(aEntryId.Compare(iEntries[aIndex]->IdTag())==0) |
|
118 { |
|
119 delete iEntries[aIndex]; |
|
120 iEntries.Remove( aIndex ); |
|
121 } |
|
122 } |
|
123 |
|
124 //from element |
|
125 TXmlEngElement feed = AsElementL(); |
|
126 TXmlEngElement entry; |
|
127 TXmlEngElement id; |
|
128 RXmlEngNodeList<TXmlEngElement> list; |
|
129 RXmlEngNodeList<TXmlEngElement> listIn; |
|
130 const TPtrC8 tNsUri = NsUri(); |
|
131 CleanupClosePushL(list); |
|
132 CleanupClosePushL(listIn); |
|
133 feed.GetElementsByTagNameL(list, KSenAtomEntryName, tNsUri); |
|
134 while(list.HasNext()){ |
|
135 entry = list.Next(); |
|
136 entry.GetElementsByTagNameL(listIn, KSenAtomIdName, KSenAtomSpace); |
|
137 while(listIn.HasNext()){ |
|
138 id = listIn.Next(); |
|
139 TPtrC8 idBuf = id.Text(); |
|
140 if(aEntryId.Compare(idBuf)==0){ |
|
141 entry.Remove(); |
|
142 break; |
|
143 } |
|
144 } |
|
145 } |
|
146 CleanupStack::PopAndDestroy(&listIn); |
|
147 CleanupStack::PopAndDestroy(&list); |
|
148 } |
|
149 |
|
150 |
|
151 EXPORT_C void CSenAtomFeed::RemoveEntryL( CSenAtomEntry& aEntryToRemove ) |
|
152 { |
|
153 const TDesC8& iEntryId = aEntryToRemove.IdTag(); |
|
154 RemoveEntryL(iEntryId); |
|
155 } |
|
156 |
|
157 |
|
158 EXPORT_C const TDesC8& CSenAtomFeed::SubtitleL(){ |
|
159 |
|
160 TXmlEngElement feed = AsElementL(); |
|
161 RXmlEngNodeList<TXmlEngElement> list; |
|
162 |
|
163 CleanupClosePushL(list); |
|
164 |
|
165 feed.GetElementsByTagNameL(list, KSenAtomSubtitleName, KSenAtomSpace); |
|
166 if(list.Count()>0) { |
|
167 TXmlEngElement subtitle = list.Next(); |
|
168 TPtrC8 icPtr = subtitle.Text(); |
|
169 CleanupStack::PopAndDestroy(&list); |
|
170 HBufC8* out = icPtr.Alloc(); |
|
171 return *out; |
|
172 }else{ |
|
173 CleanupStack::PopAndDestroy(&list); |
|
174 return KNullDesC8(); |
|
175 }; |
|
176 } |
|
177 |
|
178 EXPORT_C void CSenAtomFeed::SetSubtitleL( const TDesC8& aSubtitle){ |
|
179 |
|
180 TXmlEngElement feed = AsElementL(); |
|
181 TXmlEngElement logo = feed.AddNewElementL(KSenAtomSubtitleName); |
|
182 if(aSubtitle!=KNullDesC8){ |
|
183 logo.SetTextNoEncL(aSubtitle); |
|
184 } |
|
185 } |
|
186 |
|
187 EXPORT_C void CSenAtomFeed::SetGeneratorL( const TDesC8& aUri, const TDesC8& aVersion, const TDesC8& aText){ |
|
188 |
|
189 TXmlEngElement entry = AsElementL(); |
|
190 TXmlEngElement generator = entry.AddNewElementL(KSenAtomGeneratorName); |
|
191 if(aUri!=KNullDesC8) |
|
192 generator.AddNewAttributeSameNsL(KSenAtomURI,aUri); |
|
193 if(aVersion!=KNullDesC8) |
|
194 generator.AddNewAttributeSameNsL(KSenAtomVersion,aUri); |
|
195 generator.SetTextNoEncL(aText); |
|
196 } |
|
197 |
|
198 EXPORT_C TXmlEngElement CSenAtomFeed::GetGeneratorL(){ |
|
199 |
|
200 TXmlEngElement feed = AsElementL(); |
|
201 RXmlEngNodeList<TXmlEngElement> list; |
|
202 |
|
203 CleanupClosePushL(list); |
|
204 |
|
205 feed.GetElementsByTagNameL(list, KSenAtomGeneratorName, KSenAtomSpace); |
|
206 if(list.Count()>0) { |
|
207 TXmlEngElement generator = list.Next(); |
|
208 return generator; |
|
209 }else{ |
|
210 CleanupStack::PopAndDestroy(&list); |
|
211 return TXmlEngElement(0); |
|
212 } |
|
213 } |
|
214 |
|
215 /*EXPORT_C const TDesC8& CSenAtomFeed::GeneratorL(){ |
|
216 |
|
217 TXmlEngElement feed = AsElementL(); |
|
218 RXmlEngNodeList<TXmlEngElement> list; |
|
219 |
|
220 CleanupClosePushL(list); |
|
221 |
|
222 feed.GetElementsByTagNameL(list, KSenAtomGeneratorName, KSenAtomSpace); |
|
223 if(list.Count()>0) { |
|
224 TXmlEngElement logo = list.Next(); |
|
225 TPtrC8 icPtr = logo.AttributeValueL(KSenAtomURI, KSenAtomSpace); |
|
226 CleanupStack::PopAndDestroy(&list); |
|
227 HBufC8* out = icPtr.Alloc(); |
|
228 return *out; |
|
229 }else{ |
|
230 CleanupStack::PopAndDestroy(&list); |
|
231 return KNullDesC8(); |
|
232 }; |
|
233 } |
|
234 */ |
|
235 EXPORT_C const TDesC8& CSenAtomFeed::LogoL(){ |
|
236 |
|
237 TXmlEngElement feed = AsElementL(); |
|
238 RXmlEngNodeList<TXmlEngElement> list; |
|
239 |
|
240 CleanupClosePushL(list); |
|
241 |
|
242 feed.GetElementsByTagNameL(list, KSenAtomLogoName, KSenAtomSpace); |
|
243 if(list.Count()>0) { |
|
244 TXmlEngElement logo = list.Next(); |
|
245 TPtrC8 icPtr = logo.AttributeValueL(KSenAtomURI, KSenAtomSpace); |
|
246 CleanupStack::PopAndDestroy(&list); |
|
247 HBufC8* out = icPtr.Alloc(); |
|
248 return *out; |
|
249 }else{ |
|
250 CleanupStack::PopAndDestroy(&list); |
|
251 return KNullDesC8(); |
|
252 } |
|
253 } |
|
254 |
|
255 EXPORT_C void CSenAtomFeed::SetLogoL( const TDesC8& aUri){ |
|
256 |
|
257 TXmlEngElement entry = AsElementL(); |
|
258 TXmlEngElement logo = entry.AddNewElementL(KSenAtomLogoName); |
|
259 if(aUri!=KNullDesC8) |
|
260 logo.AddNewAttributeSameNsL(KSenAtomURI,aUri); |
|
261 |
|
262 } |
|
263 |
|
264 EXPORT_C void CSenAtomFeed::SetIconL( const TDesC8& aUri){ |
|
265 |
|
266 TXmlEngElement feed = AsElementL(); |
|
267 TXmlEngElement icon = feed.AddNewElementL(KSenAtomIconName); |
|
268 if(aUri!=KNullDesC8) |
|
269 icon.AddNewAttributeSameNsL(KSenAtomURI,aUri); |
|
270 |
|
271 } |
|
272 |
|
273 EXPORT_C const TDesC8& CSenAtomFeed::IconL(){ |
|
274 |
|
275 TXmlEngElement feed = AsElementL(); |
|
276 RXmlEngNodeList<TXmlEngElement> list; |
|
277 |
|
278 CleanupClosePushL(list); |
|
279 |
|
280 feed.GetElementsByTagNameL(list, KSenAtomIconName, KSenAtomSpace); |
|
281 if(list.Count()>0) { |
|
282 TXmlEngElement icon = list.Next(); |
|
283 TPtrC8 icPtr = icon.AttributeValueL(KSenAtomURI, KSenAtomSpace); |
|
284 CleanupStack::PopAndDestroy(&list); |
|
285 HBufC8* out = icPtr.Alloc(); |
|
286 return *out; |
|
287 }else{ |
|
288 CleanupStack::PopAndDestroy(&list); |
|
289 return KNullDesC8(); |
|
290 }; |
|
291 } |
|
292 |
|
293 //*********************************************** CALLBACKS ***************///// |
|
294 |
|
295 |
|
296 EXPORT_C void CSenAtomFeed::OnStartElementL(const RTagInfo& aElement, |
|
297 const RAttributeArray& aAttributes, TInt /*aErrorCode*/) |
|
298 { |
|
299 |
|
300 |
|
301 const TPtrC8 saxLocalName = aElement.LocalName().DesC(); |
|
302 const TPtrC8 saxNsUri = aElement.Uri().DesC(); |
|
303 const TPtrC8 saxPrefix = aElement.Prefix().DesC(); |
|
304 |
|
305 if(saxLocalName==KSenAtomFeedName){ |
|
306 iState= KSenStateIgnore; |
|
307 } else{ |
|
308 iState= KSenStateSave; |
|
309 } |
|
310 if(saxLocalName==KSenAtomEntryName){ |
|
311 ParseEntryL(aElement, aAttributes); |
|
312 CSenFragmentBase::OnStartElementL(aElement,aAttributes,TInt(KErrNone)); |
|
313 }else |
|
314 { |
|
315 CSenFragmentBase::OnStartElementL(aElement,aAttributes,TInt(KErrNone)); |
|
316 } |
|
317 } |
|
318 |
|
319 EXPORT_C void CSenAtomFeed::OnContentL(const TDesC8& aBytes, TInt /*aErrorCode*/) |
|
320 { |
|
321 CSenFragmentBase::OnContentL(aBytes, TInt(KErrNone)); |
|
322 } |
|
323 |
|
324 EXPORT_C void CSenAtomFeed::OnEndElementL(const RTagInfo& aElement,TInt /*aErrorCode*/) |
|
325 { |
|
326 |
|
327 const TPtrC8 saxLocalName = aElement.LocalName().DesC(); |
|
328 const TPtrC8 saxNsUri = aElement.Uri().DesC(); |
|
329 const TPtrC8 saxPrefix = aElement.Prefix().DesC(); |
|
330 |
|
331 const TPtrC8 tLocalName = LocalName(); |
|
332 const TPtrC8 tNsUri = NsUri(); |
|
333 const TPtrC8 tPrefix = NsPrefix(); |
|
334 //const TPtrC8 tmp = AsXmlL()->Des(); |
|
335 |
|
336 if(saxLocalName==KSenAtomFeedName){ |
|
337 iState= KSenStateIgnore; |
|
338 } else{ |
|
339 iState= KSenStateSave; |
|
340 } |
|
341 if(saxLocalName==KSenAtomEntryName) |
|
342 { |
|
343 RSenDocument& feed = AsDocumentL(); |
|
344 iEntries.Append(iEntry); |
|
345 iEntry->AsElementL().CopyToL(feed); |
|
346 delete iEntry; |
|
347 iEntry = NULL; |
|
348 CSenFragmentBase::OnEndElementL(aElement, TInt(KErrNone)); |
|
349 } |
|
350 else |
|
351 CSenFragmentBase::OnEndElementL(aElement, TInt(KErrNone)); |
|
352 |
|
353 } |
|
354 |
|
355 EXPORT_C void CSenAtomFeed::ParseEntryL(const RTagInfo& aElement, const RAttributeArray& /*aAttributes*/) |
|
356 { |
|
357 |
|
358 const TPtrC8 saxLocalName = aElement.LocalName().DesC(); |
|
359 const TPtrC8 saxNsUri = aElement.Uri().DesC(); |
|
360 const TPtrC8 saxPrefix = aElement.Prefix().DesC(); |
|
361 |
|
362 iEntry = CSenAtomEntry::NewL(); |
|
363 OnDelegateParsingL(*iEntry); |
|
364 } |