|
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 void CXmlParser::DoParseL() |
|
171 /** |
|
172 This method gets executed when a request to parse a file is issued. |
|
173 This function generates just one element event. |
|
174 */ |
|
175 { |
|
176 OnStartDocumentL(); |
|
177 OnStartElementL(); |
|
178 OnEndElementL(); |
|
179 OnEndDocumentL(); |
|
180 } |
|
181 |
|
182 |
|
183 |
|
184 void CXmlParser::OnStartDocumentL() |
|
185 { |
|
186 RDocumentParameters documentParameters; |
|
187 |
|
188 iContentHandler->OnStartDocumentL(documentParameters, KErrorCodeOnStartDocument); |
|
189 } |
|
190 |
|
191 |
|
192 void CXmlParser::OnEndDocumentL() |
|
193 { |
|
194 iContentHandler->OnEndDocumentL(KErrorCodeOnEndDocument); |
|
195 } |
|
196 |
|
197 |
|
198 |
|
199 void CXmlParser::OnStartElementL() |
|
200 { |
|
201 RTagInfo element; |
|
202 RAttributeArray attributes; |
|
203 |
|
204 iContentHandler->OnStartElementL(element, attributes, KErrorCodeOnStartElement); |
|
205 } |
|
206 |
|
207 |
|
208 void CXmlParser::OnEndElementL() |
|
209 { |
|
210 RTagInfo element; |
|
211 |
|
212 iContentHandler->OnEndElementL(element, KErrorCodeOnEndElement); |
|
213 } |
|
214 |
|
215 |
|
216 |
|
217 void CXmlParser::OnContentL() |
|
218 { |
|
219 const TBuf8<2> bytes; |
|
220 |
|
221 iContentHandler->OnContentL(bytes, KErrorCodeOnContent); |
|
222 } |
|
223 |
|
224 |
|
225 |
|
226 void CXmlParser::OnStartPrefixMappingL() |
|
227 { |
|
228 RString prefix; |
|
229 RString uri; |
|
230 |
|
231 iContentHandler->OnStartPrefixMappingL(prefix, uri, KErrorCodeOnStartPrefixMapping); |
|
232 } |
|
233 |
|
234 |
|
235 void CXmlParser::OnEndPrefixMappingL() |
|
236 { |
|
237 RString prefix; |
|
238 |
|
239 iContentHandler->OnEndPrefixMappingL(prefix, KErrorCodeOnEndPrefixMapping); |
|
240 } |
|
241 |
|
242 |
|
243 |
|
244 void CXmlParser::OnIgnorableWhiteSpaceL() |
|
245 { |
|
246 const TBuf8<2> bytes; |
|
247 |
|
248 iContentHandler->OnIgnorableWhiteSpaceL(bytes, KErrorCodeOnIgnorableWhiteSpace); |
|
249 } |
|
250 |
|
251 |
|
252 |
|
253 void CXmlParser::OnSkippedEntityL() |
|
254 { |
|
255 RString name; |
|
256 |
|
257 iContentHandler->OnSkippedEntityL(name, KErrorCodeOnSkippedEntity); |
|
258 } |
|
259 |
|
260 |
|
261 |
|
262 void CXmlParser::OnProcessingInstructionL() |
|
263 { |
|
264 TBuf8<2> target; |
|
265 TBuf8<2> data; |
|
266 |
|
267 iContentHandler->OnProcessingInstructionL(target, data, KErrorCodeOnProcessingInstruction); |
|
268 } |
|
269 |
|
270 |
|
271 void CXmlParser::OnExtensionL() |
|
272 { |
|
273 RString data; |
|
274 TInt token = 0; |
|
275 |
|
276 MWbxmlExtensionHandler* ptr = |
|
277 static_cast<MWbxmlExtensionHandler*> |
|
278 (iContentHandler->GetExtendedInterface(MWbxmlExtensionHandler::EExtInterfaceUid)); |
|
279 |
|
280 if (!ptr) |
|
281 { |
|
282 User::Leave(KErrXmlUnsupportedExtInterface); |
|
283 } |
|
284 |
|
285 ptr->OnExtensionL(data, token, KErrorCodeOnExtension); |
|
286 } |
|
287 |
|
288 |
|
289 void CXmlParser::OnError(TInt aError) |
|
290 { |
|
291 iContentHandler->OnError(aError); |
|
292 } |
|
293 |
|
294 |
|
295 // __________________________________________________________________________ |
|
296 // Exported proxy for instantiation method resolution |
|
297 // Define the interface UIDs |
|
298 const TImplementationProxy ImplementationTable[] = { |
|
299 IMPLEMENTATION_PROXY_ENTRY(0x10273875,CXmlParser::NewL), |
|
300 IMPLEMENTATION_PROXY_ENTRY(0x10273876,CXmlParser::NewL), |
|
301 IMPLEMENTATION_PROXY_ENTRY(0x10273877,CXmlParser::NewL), |
|
302 IMPLEMENTATION_PROXY_ENTRY(0x10273878,CXmlParser::NewL), |
|
303 IMPLEMENTATION_PROXY_ENTRY(0x10273879,CXmlParser::NewL), |
|
304 }; |
|
305 |
|
306 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) |
|
307 { |
|
308 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); |
|
309 |
|
310 return ImplementationTable; |
|
311 } |