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