|
1 /* |
|
2 * Copyright (c) 2002-2006 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: Class implements XML Parser capable of service multiple handlers |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 // INCLUDE FILES |
|
26 #include "senparserimpl.h" |
|
27 #include "SenFragmentBase.h" |
|
28 |
|
29 #include <xml/matchdata.h> // to select libxml2 sax parser |
|
30 namespace |
|
31 { |
|
32 #ifdef RD_SEN_FORCE_LIBXML_SAX_PLUGIN_MIMETYPE |
|
33 _LIT8(KXmlParserMimeType, "text/wsstarlibxml2"); |
|
34 _LIT8(KXmlVariant, "wsstarlibxml2"); |
|
35 #else |
|
36 _LIT8(KXmlParserMimeType, "text/xml"); // Expat on S60 3.0, and on S60 3.1, goes according to variant |
|
37 _LIT8(KXmlVariant, "libxml2"); // LibXml2 SAX parser |
|
38 #endif |
|
39 } |
|
40 |
|
41 CSenParserImpl* CSenParserImpl::NewL() |
|
42 { |
|
43 CSenParserImpl* self = CSenParserImpl::NewLC(); |
|
44 CleanupStack::Pop(self); |
|
45 return self; |
|
46 } |
|
47 |
|
48 CSenParserImpl* CSenParserImpl::NewLC() |
|
49 { |
|
50 CSenParserImpl* self = new (ELeave) CSenParserImpl(NULL); |
|
51 CleanupStack::PushL(self); |
|
52 self->ConstructL(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 CSenParserImpl* CSenParserImpl::NewL(CParser* apParser) |
|
57 { |
|
58 CSenParserImpl* self = CSenParserImpl::NewLC(apParser); |
|
59 CleanupStack::Pop(self); |
|
60 return self; |
|
61 } |
|
62 |
|
63 CSenParserImpl* CSenParserImpl::NewLC(CParser* apParser) |
|
64 { |
|
65 CSenParserImpl* self = new (ELeave) CSenParserImpl(apParser); |
|
66 CleanupStack::PushL(self); |
|
67 return self; |
|
68 } |
|
69 |
|
70 CSenParserImpl* CSenParserImpl::NewL(const TDesC8& aParserMimeType) |
|
71 { |
|
72 CSenParserImpl* self = CSenParserImpl::NewLC(aParserMimeType); |
|
73 CleanupStack::Pop(self); |
|
74 return self; |
|
75 } |
|
76 |
|
77 CSenParserImpl* CSenParserImpl::NewLC(const TDesC8& aParserMimeType) |
|
78 { |
|
79 CSenParserImpl* self = new (ELeave) CSenParserImpl(NULL); |
|
80 CleanupStack::PushL(self); |
|
81 self->ConstructL(aParserMimeType); |
|
82 return self; |
|
83 } |
|
84 |
|
85 CSenParserImpl::CSenParserImpl(CParser* apParser) |
|
86 : ipParser(apParser) |
|
87 { |
|
88 } |
|
89 |
|
90 |
|
91 void CSenParserImpl::ConstructL() |
|
92 { |
|
93 CMatchData* pMatchData = CMatchData::NewL(); |
|
94 CleanupStack::PushL(pMatchData); |
|
95 // Set the default variant type (libxml2) |
|
96 pMatchData->SetVariantL(KXmlVariant); |
|
97 pMatchData->SetMimeTypeL(KXmlParserMimeType); |
|
98 ipContentHandler = CSenContentHandler::NewL(); |
|
99 ipParser = CParser::NewL(*pMatchData, *ipContentHandler); // to select libxml2 sax parser |
|
100 |
|
101 CleanupStack::PopAndDestroy(pMatchData); |
|
102 } |
|
103 |
|
104 void CSenParserImpl::ConstructL(const TDesC8& aParserMimeType) |
|
105 { |
|
106 ipContentHandler = CSenContentHandler::NewL(); |
|
107 ipParser = CParser::NewL(aParserMimeType, *ipContentHandler); // Left to client to chose the appropriat parser |
|
108 } |
|
109 |
|
110 CSenParserImpl::~CSenParserImpl() |
|
111 { |
|
112 delete ipContentHandler; |
|
113 delete ipParser; |
|
114 } |
|
115 |
|
116 void CSenParserImpl::SetContentHandler(CSenFragmentBase& aContentHandler) |
|
117 { |
|
118 ipContentHandler->SetContentHandler(aContentHandler); |
|
119 } |
|
120 |
|
121 void CSenParserImpl::ParseBeginL() |
|
122 { |
|
123 ipParser->ParseBeginL(); |
|
124 } |
|
125 |
|
126 void CSenParserImpl::ParseBeginL(const TDesC8& aDocumentMimeType) |
|
127 { |
|
128 ipParser->ParseBeginL(aDocumentMimeType); |
|
129 } |
|
130 |
|
131 void CSenParserImpl::ParseL(const TDesC8& aFragment, |
|
132 CSenFragmentBase& aContentHandler) |
|
133 { |
|
134 ipContentHandler->SetContentHandler(aContentHandler); |
|
135 aContentHandler.SetParser(*this); |
|
136 |
|
137 ipParser->ParseL(aFragment); |
|
138 // Following enables Symbian XML framework to invoke OnErrorL() callback: |
|
139 ipParser->ParseEndL(); |
|
140 } |
|
141 |
|
142 void CSenParserImpl::ParseL(RFs& aFs, const TDesC& aFilename, CSenFragmentBase& aContentHandler) |
|
143 { |
|
144 ipContentHandler->SetContentHandler(aContentHandler); |
|
145 aContentHandler.SetParser(*this); |
|
146 Xml::ParseL( *ipParser, aFs, aFilename ); |
|
147 } |
|
148 |
|
149 void CSenParserImpl::ParseL(RFile& aFile, CSenFragmentBase& aContentHandler) |
|
150 { |
|
151 ipContentHandler->SetContentHandler(aContentHandler); |
|
152 aContentHandler.SetParser(*this); |
|
153 Xml::ParseL( *ipParser, aFile ); |
|
154 } |
|
155 |
|
156 void CSenParserImpl::ParseEndL() |
|
157 { |
|
158 ipParser->ParseEndL(); |
|
159 } |
|
160 |
|
161 void CSenParserImpl::SetProcessorChainL(const RContentProcessorUids& aPlugins) |
|
162 { |
|
163 ipParser->SetProcessorChainL(aPlugins); |
|
164 } |
|
165 |
|
166 TInt CSenParserImpl::EnableFeature(TInt aParserFeature) |
|
167 { |
|
168 return ipParser->EnableFeature(aParserFeature); |
|
169 } |
|
170 |
|
171 TInt CSenParserImpl::DisableFeature(TInt aParserFeature) |
|
172 { |
|
173 return ipParser->DisableFeature(aParserFeature); |
|
174 } |
|
175 |
|
176 TBool CSenParserImpl::IsFeatureEnabled(TInt aParserFeature) const |
|
177 { |
|
178 return ipParser->IsFeatureEnabled(aParserFeature); |
|
179 } |
|
180 |
|
181 void CSenParserImpl::AddPreloadedDictionaryL(const TDesC8& aPublicId) |
|
182 { |
|
183 ipParser->AddPreloadedDictionaryL(aPublicId); |
|
184 } |
|
185 |
|
186 RStringPool& CSenParserImpl::StringPool() |
|
187 { |
|
188 return ipParser->StringPool(); |
|
189 } |
|
190 |
|
191 RStringDictionaryCollection& CSenParserImpl::StringDictionaryCollection() |
|
192 { |
|
193 return ipParser->StringDictionaryCollection(); |
|
194 } |
|
195 |
|
196 CSenContentHandler* CSenContentHandler::NewL(MContentHandler& aContentHandler) |
|
197 { |
|
198 CSenContentHandler* self = CSenContentHandler::NewLC(aContentHandler); |
|
199 CleanupStack::Pop(self); |
|
200 return self; |
|
201 } |
|
202 |
|
203 CSenContentHandler* CSenContentHandler::NewLC(MContentHandler& aContentHandler) |
|
204 { |
|
205 CSenContentHandler* self = new (ELeave) CSenContentHandler(&aContentHandler); |
|
206 CleanupStack::PushL(self); |
|
207 return self; |
|
208 } |
|
209 |
|
210 CSenContentHandler* CSenContentHandler::NewL() |
|
211 { |
|
212 CSenContentHandler* self = CSenContentHandler::NewLC(); |
|
213 CleanupStack::Pop(self); |
|
214 return self; |
|
215 } |
|
216 |
|
217 CSenContentHandler* CSenContentHandler::NewLC() |
|
218 { |
|
219 CSenContentHandler* self = new (ELeave) CSenContentHandler(NULL); |
|
220 CleanupStack::PushL(self); |
|
221 return self; |
|
222 } |
|
223 |
|
224 CSenContentHandler::CSenContentHandler(MContentHandler* apContentHandler) |
|
225 : ipContentHandler(apContentHandler) |
|
226 { |
|
227 } |
|
228 |
|
229 MContentHandler& CSenContentHandler::ContentHandler() |
|
230 { |
|
231 return *ipContentHandler; |
|
232 } |
|
233 |
|
234 CSenContentHandler::~CSenContentHandler() |
|
235 { |
|
236 } |
|
237 |
|
238 void CSenContentHandler::SetContentHandler(MContentHandler& aContentHandler) |
|
239 { |
|
240 ipContentHandler = &aContentHandler; |
|
241 } |
|
242 |
|
243 void CSenContentHandler::OnStartDocumentL(const RDocumentParameters& aDocParam, TInt aErrorCode) |
|
244 { |
|
245 ipContentHandler->OnStartDocumentL(aDocParam, aErrorCode); |
|
246 } |
|
247 |
|
248 void CSenContentHandler::OnEndDocumentL(TInt aErrorCode) |
|
249 { |
|
250 ipContentHandler->OnEndDocumentL(aErrorCode); |
|
251 } |
|
252 |
|
253 void CSenContentHandler::OnStartElementL(const RTagInfo& aElement, const RAttributeArray& aAttributes, |
|
254 TInt aErrorCode) |
|
255 { |
|
256 ipContentHandler->OnStartElementL(aElement, aAttributes, aErrorCode); |
|
257 } |
|
258 |
|
259 void CSenContentHandler::OnEndElementL(const RTagInfo& aElement, TInt aErrorCode) |
|
260 { |
|
261 ipContentHandler->OnEndElementL(aElement, aErrorCode); |
|
262 } |
|
263 |
|
264 void CSenContentHandler::OnContentL(const TDesC8& aBytes, TInt aErrorCode) |
|
265 { |
|
266 ipContentHandler->OnContentL(aBytes, aErrorCode); |
|
267 } |
|
268 |
|
269 void CSenContentHandler::OnStartPrefixMappingL(const RString& aPrefix, const RString& aUri, |
|
270 TInt aErrorCode) |
|
271 { |
|
272 ipContentHandler->OnStartPrefixMappingL(aPrefix, aUri, aErrorCode); |
|
273 } |
|
274 |
|
275 void CSenContentHandler::OnEndPrefixMappingL(const RString& aPrefix, TInt aErrorCode) |
|
276 { |
|
277 ipContentHandler->OnEndPrefixMappingL(aPrefix, aErrorCode); |
|
278 } |
|
279 |
|
280 void CSenContentHandler::OnIgnorableWhiteSpaceL(const TDesC8& aBytes, TInt aErrorCode) |
|
281 { |
|
282 ipContentHandler->OnIgnorableWhiteSpaceL(aBytes, aErrorCode); |
|
283 } |
|
284 |
|
285 void CSenContentHandler::OnSkippedEntityL(const RString& aName, TInt aErrorCode) |
|
286 { |
|
287 ipContentHandler->OnSkippedEntityL(aName, aErrorCode); |
|
288 } |
|
289 |
|
290 void CSenContentHandler::OnProcessingInstructionL(const TDesC8& aTarget, const TDesC8& aData, |
|
291 TInt aErrorCode) |
|
292 { |
|
293 ipContentHandler->OnProcessingInstructionL(aTarget, aData, aErrorCode); |
|
294 } |
|
295 |
|
296 void CSenContentHandler::OnError(TInt aErrorCode) |
|
297 { |
|
298 ipContentHandler->OnError(aErrorCode); |
|
299 } |
|
300 |
|
301 TAny* CSenContentHandler::GetExtendedInterface(const TInt32 aUid) |
|
302 { |
|
303 return ipContentHandler->GetExtendedInterface(aUid); |
|
304 } |
|
305 |
|
306 // End of File |
|
307 |
|
308 |
|
309 |