|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <e32std.h> |
|
17 #include <ecom/implementationproxy.h> |
|
18 |
|
19 #include <xml/attribute.h> |
|
20 #include <xml/contenthandler.h> |
|
21 #include <xml/documentparameters.h> |
|
22 #include <xml/stringdictionarycollection.h> |
|
23 #include <xml/taginfo.h> |
|
24 #include <xml/wbxmlextensionhandler.h> |
|
25 #include <xml/xmlframeworkerrors.h> |
|
26 #include <xml/plugins/parserinterface.h> |
|
27 #include <xml/plugins/parserinitparams.h> |
|
28 |
|
29 #include "t_testconstants.h" |
|
30 |
|
31 using namespace Xml; |
|
32 |
|
33 class CXmlParser : public CBase, public MParser |
|
34 { |
|
35 public: |
|
36 |
|
37 static MParser* NewL(TAny* aInitParams); |
|
38 virtual ~CXmlParser(); |
|
39 |
|
40 // From MParser |
|
41 |
|
42 TInt EnableFeature(TInt /*aParserFeature*/) |
|
43 { |
|
44 return KErrNotSupported; |
|
45 } |
|
46 TInt DisableFeature(TInt /*aParserFeature*/) |
|
47 { |
|
48 return KErrNone; |
|
49 } |
|
50 TBool IsFeatureEnabled(TInt /*aParserFeature*/) const |
|
51 { |
|
52 return EFalse; |
|
53 } |
|
54 void Release(); |
|
55 void ParseChunkL (const TDesC8& aDescriptor); |
|
56 void ParseLastChunkL(const TDesC8& aDescriptor); |
|
57 |
|
58 // From MContentSouce |
|
59 |
|
60 void SetContentSink (MContentHandler& aContentHandler); |
|
61 |
|
62 RStringPool& StringPool(); |
|
63 |
|
64 private: |
|
65 |
|
66 CXmlParser(TParserInitParams* aInitParams); |
|
67 void ConstructL(); |
|
68 |
|
69 void DoParseL(); |
|
70 |
|
71 inline void OnStartDocumentL(); |
|
72 inline void OnEndDocumentL(); |
|
73 inline void OnStartElementL(); |
|
74 inline void OnEndElementL(); |
|
75 inline void OnContentL(); |
|
76 inline void OnStartPrefixMappingL(); |
|
77 inline void OnEndPrefixMappingL(); |
|
78 inline void OnIgnorableWhiteSpaceL(); |
|
79 inline void OnSkippedEntityL(); |
|
80 inline void OnProcessingInstructionL(); |
|
81 inline void OnExtensionL(); |
|
82 inline void OnError(TInt aError); |
|
83 |
|
84 private: |
|
85 MContentHandler* iContentHandler; |
|
86 RStringDictionaryCollection* iStringDictionaryCollection; |
|
87 CCharSetConverter* iCharSetConverter; |
|
88 RElementStack* iElementStack; |
|
89 }; |
|
90 |
|
91 MParser* CXmlParser::NewL(TAny* aInitParams) |
|
92 { |
|
93 |
|
94 CXmlParser* self = new(ELeave) CXmlParser(reinterpret_cast<TParserInitParams*>(aInitParams)); |
|
95 |
|
96 CleanupStack::PushL(self); |
|
97 self->ConstructL(); |
|
98 CleanupStack::Pop(self); |
|
99 |
|
100 return (static_cast<MParser*>(self)); |
|
101 } |
|
102 |
|
103 |
|
104 |
|
105 CXmlParser::CXmlParser(TParserInitParams* aInitParams) |
|
106 : iContentHandler (reinterpret_cast<MContentHandler*>(aInitParams->iContentHandler)), |
|
107 iStringDictionaryCollection (reinterpret_cast<RStringDictionaryCollection*>(aInitParams->iStringDictionaryCollection)), |
|
108 iCharSetConverter (reinterpret_cast<CCharSetConverter*>(aInitParams->iCharSetConverter)), |
|
109 iElementStack (reinterpret_cast<RElementStack*>(aInitParams->iElementStack)) |
|
110 { |
|
111 } |
|
112 |
|
113 |
|
114 |
|
115 void CXmlParser::ConstructL() |
|
116 { |
|
117 // do nothing; |
|
118 } |
|
119 |
|
120 |
|
121 |
|
122 void CXmlParser::Release() |
|
123 { |
|
124 delete (this); |
|
125 } |
|
126 |
|
127 |
|
128 |
|
129 CXmlParser::~CXmlParser() |
|
130 { |
|
131 // We don't own this |
|
132 iContentHandler = NULL; |
|
133 iStringDictionaryCollection = NULL; |
|
134 iCharSetConverter = NULL; |
|
135 iElementStack = NULL; |
|
136 } |
|
137 |
|
138 |
|
139 void CXmlParser::ParseChunkL (const TDesC8& /*aDescriptor*/) |
|
140 { |
|
141 DoParseL(); |
|
142 } |
|
143 |
|
144 |
|
145 void CXmlParser::ParseLastChunkL(const TDesC8& /*aDescriptor*/) |
|
146 { |
|
147 DoParseL(); |
|
148 } |
|
149 |
|
150 |
|
151 RStringPool& CXmlParser::StringPool() |
|
152 { |
|
153 return iStringDictionaryCollection->StringPool(); |
|
154 } |
|
155 |
|
156 |
|
157 |
|
158 void CXmlParser::SetContentSink (MContentHandler& aContentHandler) |
|
159 /** |
|
160 This method allows for the correct streaming of data to another plugin in the chain. |
|
161 |
|
162 @post the next plugin in the chain is set to receive our callbacks. |
|
163 |
|
164 */ |
|
165 { |
|
166 iContentHandler = &aContentHandler; |
|
167 } |
|
168 |
|
169 |
|
170 |
|
171 void CXmlParser::DoParseL() |
|
172 /** |
|
173 This method gets executed when a request to parse a file is issued. |
|
174 This function generates just one element event. |
|
175 */ |
|
176 { |
|
177 OnStartDocumentL(); |
|
178 OnStartElementL(); |
|
179 OnEndElementL(); |
|
180 OnEndDocumentL(); |
|
181 } |
|
182 |
|
183 |
|
184 |
|
185 void CXmlParser::OnStartDocumentL() |
|
186 { |
|
187 RDocumentParameters documentParameters; |
|
188 |
|
189 iContentHandler->OnStartDocumentL(documentParameters, KErrorCodeOnStartDocument); |
|
190 } |
|
191 |
|
192 |
|
193 void CXmlParser::OnEndDocumentL() |
|
194 { |
|
195 iContentHandler->OnEndDocumentL(KErrorCodeOnEndDocument); |
|
196 } |
|
197 |
|
198 |
|
199 |
|
200 void CXmlParser::OnStartElementL() |
|
201 { |
|
202 RTagInfo element; |
|
203 RAttributeArray attributes; |
|
204 |
|
205 iContentHandler->OnStartElementL(element, attributes, KErrorCodeOnStartElement); |
|
206 } |
|
207 |
|
208 |
|
209 void CXmlParser::OnEndElementL() |
|
210 { |
|
211 RTagInfo element; |
|
212 |
|
213 iContentHandler->OnEndElementL(element, KErrorCodeOnEndElement); |
|
214 } |
|
215 |
|
216 |
|
217 |
|
218 void CXmlParser::OnContentL() |
|
219 { |
|
220 const TBuf8<2> bytes; |
|
221 |
|
222 iContentHandler->OnContentL(bytes, KErrorCodeOnContent); |
|
223 } |
|
224 |
|
225 |
|
226 |
|
227 void CXmlParser::OnStartPrefixMappingL() |
|
228 { |
|
229 RString prefix; |
|
230 RString uri; |
|
231 |
|
232 iContentHandler->OnStartPrefixMappingL(prefix, uri, KErrorCodeOnStartPrefixMapping); |
|
233 } |
|
234 |
|
235 |
|
236 void CXmlParser::OnEndPrefixMappingL() |
|
237 { |
|
238 RString prefix; |
|
239 |
|
240 iContentHandler->OnEndPrefixMappingL(prefix, KErrorCodeOnEndPrefixMapping); |
|
241 } |
|
242 |
|
243 |
|
244 |
|
245 void CXmlParser::OnIgnorableWhiteSpaceL() |
|
246 { |
|
247 const TBuf8<2> bytes; |
|
248 |
|
249 iContentHandler->OnIgnorableWhiteSpaceL(bytes, KErrorCodeOnIgnorableWhiteSpace); |
|
250 } |
|
251 |
|
252 |
|
253 |
|
254 void CXmlParser::OnSkippedEntityL() |
|
255 { |
|
256 RString name; |
|
257 |
|
258 iContentHandler->OnSkippedEntityL(name, KErrorCodeOnSkippedEntity); |
|
259 } |
|
260 |
|
261 |
|
262 |
|
263 void CXmlParser::OnProcessingInstructionL() |
|
264 { |
|
265 TBuf8<2> target; |
|
266 TBuf8<2> data; |
|
267 |
|
268 iContentHandler->OnProcessingInstructionL(target, data, KErrorCodeOnProcessingInstruction); |
|
269 } |
|
270 |
|
271 |
|
272 void CXmlParser::OnExtensionL() |
|
273 { |
|
274 RString data; |
|
275 TInt token = 0; |
|
276 |
|
277 MWbxmlExtensionHandler* ptr = |
|
278 static_cast<MWbxmlExtensionHandler*> |
|
279 (iContentHandler->GetExtendedInterface(MWbxmlExtensionHandler::EExtInterfaceUid)); |
|
280 |
|
281 if (!ptr) |
|
282 { |
|
283 User::Leave(KErrXmlUnsupportedExtInterface); |
|
284 } |
|
285 |
|
286 ptr->OnExtensionL(data, token, KErrorCodeOnExtension); |
|
287 } |
|
288 |
|
289 |
|
290 void CXmlParser::OnError(TInt aError) |
|
291 { |
|
292 iContentHandler->OnError(aError); |
|
293 } |
|
294 |
|
295 |
|
296 // __________________________________________________________________________ |
|
297 // Exported proxy for instantiation method resolution |
|
298 // Define the interface UIDs |
|
299 const TImplementationProxy ImplementationTable[] = { |
|
300 IMPLEMENTATION_PROXY_ENTRY(0x10273870,CXmlParser::NewL), |
|
301 IMPLEMENTATION_PROXY_ENTRY(0x10273871,CXmlParser::NewL), |
|
302 IMPLEMENTATION_PROXY_ENTRY(0x10273872,CXmlParser::NewL), |
|
303 IMPLEMENTATION_PROXY_ENTRY(0x10273873,CXmlParser::NewL), |
|
304 IMPLEMENTATION_PROXY_ENTRY(0x10273874,CXmlParser::NewL), |
|
305 IMPLEMENTATION_PROXY_ENTRY(0x60000000,CXmlParser::NewL), |
|
306 IMPLEMENTATION_PROXY_ENTRY(0x8FFFFFFF,CXmlParser::NewL), |
|
307 }; |
|
308 |
|
309 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) |
|
310 { |
|
311 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); |
|
312 |
|
313 return ImplementationTable; |
|
314 } |
|
315 |