|
1 // Copyright (c) 1999-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 #ifndef __XMLPARS_H__ |
|
17 #define __XMLPARS_H__ |
|
18 |
|
19 // System includes |
|
20 // |
|
21 #include <e32base.h> |
|
22 #include <cbnfparser.h> |
|
23 |
|
24 // Local includes |
|
25 // |
|
26 #include "XmlLog.h" |
|
27 |
|
28 // Forward class declarations |
|
29 // |
|
30 class CAttributeLookupTable; |
|
31 class CBNFNode; |
|
32 class CXmlElement; |
|
33 |
|
34 // DATA STRUCTURES |
|
35 // |
|
36 |
|
37 // Replacement strings for predefined XML entities |
|
38 _LIT(KPredefEntityLT, "<"); |
|
39 _LIT(KPredefEntityGT, ">"); |
|
40 _LIT(KPredefEntityAMP, "&"); |
|
41 _LIT(KPredefEntityAPOS, "'"); |
|
42 _LIT(KPredefEntityQUOT, """); |
|
43 |
|
44 // CXmlParser CLASS DEFINITION |
|
45 // |
|
46 //##ModelId=3B6679A00264 |
|
47 class CXmlParser : public CBNFParser |
|
48 { |
|
49 public: // Data type definitions |
|
50 // Positive error codes to signal clients about actions |
|
51 enum TSignals |
|
52 { |
|
53 EDTDDefinitionFound = 1, |
|
54 ENoDTDDefined |
|
55 }; |
|
56 |
|
57 // Definition of our own rule types |
|
58 enum TXmlParserNodeTypes |
|
59 { |
|
60 EFirstXmlParserNodeType = ELastParserNodeType, |
|
61 EChar, |
|
62 ELetter, |
|
63 ES, |
|
64 EFirstNameChar, |
|
65 ENMoreNameChar, |
|
66 ELastXmlParserNodeType |
|
67 }; |
|
68 |
|
69 public: // Methods |
|
70 |
|
71 //##ModelId=3B6679A10374 |
|
72 static CXmlParser* NewL(CAttributeLookupTable& aAttributeLUT); |
|
73 //##ModelId=3B6679A10373 |
|
74 virtual ~CXmlParser(); |
|
75 |
|
76 // Ready the parser to take in a document. Must be called before any data passed |
|
77 // into ProcessDataL! |
|
78 // INPUT: |
|
79 // aRootNode - the to be root node of the document we are about to parse |
|
80 //##ModelId=3B6679A1035F |
|
81 void ResetL(CXmlElement* aRootNode); |
|
82 |
|
83 // Perform parsing for the incoming data |
|
84 // INPUT: |
|
85 // aData - buffer of text to be parsed. Parser makes a copy if the buffer. |
|
86 //##ModelId=3B6679A10337 |
|
87 void ProcessDataL(HBufC8& aData); |
|
88 |
|
89 // Perform parsing for the incoming data |
|
90 // INPUT: |
|
91 // aData - buffer of text to be parser. Parser TAKES OWNERSHIP OF THE BUFFER! |
|
92 //##ModelId=3B6679A1034B |
|
93 void ProcessDataL(HBufC16* aData); |
|
94 |
|
95 // Signal, that all the data has been passed in. CommitL should be called when all |
|
96 // the data has been parsed. |
|
97 //##ModelId=3B6679A1032E |
|
98 void CommitL(); |
|
99 |
|
100 // Continue parsing after returning with a signal that requires actions from the client. |
|
101 //##ModelId=3B6679A1032D |
|
102 void ContinueL(); // Just go on parsing after a stop or pause without adding data |
|
103 |
|
104 // Get the current error status of the parser |
|
105 // OUTPUT: |
|
106 // return TInt - an error code defined in XmlLib.h or KErrNone, if everything was Ok. |
|
107 //##ModelId=3B6679A10325 |
|
108 inline TInt ErrorCode(); |
|
109 |
|
110 // Get document type definitions string (if found) |
|
111 // OUTPUT: |
|
112 // const HBufC* - the document type |
|
113 //##ModelId=3B6679A10324 |
|
114 inline const HBufC* DocType(); |
|
115 |
|
116 // OUTPUT: |
|
117 // const HBufC* - Url string defining the location of external DTD document |
|
118 //##ModelId=3B6679A10323 |
|
119 inline const HBufC* DTDUrl(); |
|
120 |
|
121 // Detect status of data gathering in the parser. If no DTD was available when it was |
|
122 // requested, the parser enters a data gathering mode, in which it just buffers the incoming |
|
123 // data for further parsing. |
|
124 // OUTPUT: |
|
125 // TBool - ETrue, if data is currently being gathered, EFalse if parsing on normally |
|
126 //##ModelId=3B6679A1031A |
|
127 inline TBool DataGathering() const; |
|
128 |
|
129 // OUTPUT: |
|
130 // const CBNFNode* - The DTD tree root node |
|
131 //##ModelId=3B6679A10319 |
|
132 inline const CBNFNode* DTD() const; |
|
133 |
|
134 // Setting data gathering mode either active or inactive |
|
135 // INPUT: |
|
136 // TBool aDataGathering - ETrue sets the data gathering active, EFalse disables it. |
|
137 //##ModelId=3B6679A10305 |
|
138 inline void SetDataGathering(TBool aDataGathering); |
|
139 |
|
140 // Set a valid DTD for the parser to use |
|
141 // INPUT: |
|
142 // CBNFNode* aDTD - the DTD tree root node |
|
143 //##ModelId=3B6679A102E8 |
|
144 inline void SetDTD(CBNFNode* aDTD); |
|
145 |
|
146 protected: // Methods |
|
147 |
|
148 //##ModelId=3B6679A10369 |
|
149 virtual void ResetL(); |
|
150 //##ModelId=3B6679A102E7 |
|
151 virtual CBNFNode* TreeL(); |
|
152 //##ModelId=3B6679A102D2 |
|
153 CXmlParser(CAttributeLookupTable& aALUT); |
|
154 |
|
155 // Second phase c'tor. All allocation occurs in this function. |
|
156 // |
|
157 //##ModelId=3B6679A102C8 |
|
158 void ConstructL(); |
|
159 |
|
160 // |
|
161 // Tree building rule callback functions |
|
162 // |
|
163 //##ModelId=3B6679A102B4 |
|
164 static void PostCharDataL(CBNFParser& aParser); |
|
165 //##ModelId=3B6679A102A0 |
|
166 static void PostCDStart(CBNFParser& aParser); |
|
167 //##ModelId=3B6679A1028C |
|
168 static void PostCDataL(CBNFParser& aParser); |
|
169 //##ModelId=3B6679A10278 |
|
170 static void PostCDSectL(CBNFParser& aParser); |
|
171 //##ModelId=3B6679A10264 |
|
172 static void PostNameL(CBNFParser& aParser); |
|
173 //##ModelId=3B6679A10250 |
|
174 static void PostNodeNameL(CBNFParser& aParser); |
|
175 //##ModelId=3B6679A1023C |
|
176 static void PreAttribute(CBNFParser& aParser); |
|
177 //##ModelId=3B6679A10228 |
|
178 static void PostPureAttValueL(CBNFParser& aParser); |
|
179 //##ModelId=3B6679A10214 |
|
180 static void PostAttrName(CBNFParser& aParser); |
|
181 //##ModelId=3B6679A101F6 |
|
182 static void PostAttributeL(CBNFParser& aParser); |
|
183 //##ModelId=3B6679A101E2 |
|
184 static void PostTagStartL(CBNFParser& aParser); |
|
185 //##ModelId=3B6679A101CE |
|
186 static void PostEmptyElemClose(CBNFParser& aParser); |
|
187 //##ModelId=3B6679A101BA |
|
188 static void PostETag(CBNFParser& aParser); |
|
189 //##ModelId=3B6679A101A6 |
|
190 static void PostPureSystemLiteralL(CBNFParser& aParser); |
|
191 //##ModelId=3B6679A10192 |
|
192 static void PostPubidLiteralL(CBNFParser& aParser); |
|
193 //##ModelId=3B6679A1017E |
|
194 static void PreExternalID(CBNFParser& aParser); |
|
195 //##ModelId=3B6679A1016A |
|
196 static void PostDTDidAndUrl(CBNFParser& aParser); |
|
197 //##ModelId=3B6679A10156 |
|
198 static void PostCharReferenceValue(CBNFParser& aParser); |
|
199 //##ModelId=3B6679A10142 |
|
200 static void PostEntityRefL(CBNFParser& aParser); |
|
201 //##ModelId=3B6679A1012E |
|
202 static void PostVersionNumL(CBNFParser& aParser); |
|
203 //##ModelId=3B6679A1011A |
|
204 static void PostDoctypedecl(CBNFParser& aParser); |
|
205 //##ModelId=3B6679A100FC |
|
206 static void PostDocRootName(CBNFParser& aParser); |
|
207 //##ModelId=3B6679A100E8 |
|
208 static void PostProlog(CBNFParser& aParser); |
|
209 |
|
210 // Internal utility functions |
|
211 // |
|
212 //##ModelId=3B6679A100D4 |
|
213 void CharRefReplacement(TPtr& aString); |
|
214 //##ModelId=3B6679A100C0 |
|
215 void EolNormalization(TPtr aString); |
|
216 |
|
217 // The following methods were implemented to speed up the parser |
|
218 // Some of the parsing rules were implemented as their own types of |
|
219 // rules and these methods are the handler functions for those types. |
|
220 //##ModelId=3B6679A100A2 |
|
221 virtual TBool PerformRuleL(CBNFNode& aRule, CFragmentedString::TStringMatch& aMatched); |
|
222 //##ModelId=3B6679A1008E |
|
223 TBool CharL(CFragmentedString::TStringMatch& aMatched); |
|
224 //##ModelId=3B6679A1007A |
|
225 TBool LetterL(CFragmentedString::TStringMatch& aMatched); |
|
226 //##ModelId=3B6679A10066 |
|
227 TBool SL(CFragmentedString::TStringMatch& aMatched); |
|
228 //##ModelId=3B6679A10052 |
|
229 TBool FirstNameCharL(CFragmentedString::TStringMatch& aMatched); |
|
230 //##ModelId=3B6679A1003E |
|
231 TBool NMoreNameCharL(CFragmentedString::TStringMatch& aMatched); |
|
232 //##ModelId=3B6679A0038F |
|
233 CBNFNode& NewXmlRuleL(CBNFNode* aRootRule, const TDesC& aRuleName, TXmlParserNodeTypes aRuleType); |
|
234 //##ModelId=3B6679A003C1 |
|
235 CBNFNode& NewXmlRuleL(CBNFNode* aRootRule, const TDesC& aRuleName, TXmlParserNodeTypes aRuleType, HBufC* aData, TRuleCallback* aPreRule, TRuleCallback* aPostRule); |
|
236 |
|
237 private: // Attributes |
|
238 |
|
239 // Document tree root node from which down the tree shall be built |
|
240 //##ModelId=3B6679A0037D |
|
241 CXmlElement* iRootNode; // NOT OWNED |
|
242 |
|
243 // Storage pointers for the DocType and DTD url |
|
244 //##ModelId=3B6679A00371 |
|
245 HBufC* iDocType; |
|
246 //##ModelId=3B6679A0035F |
|
247 HBufC* iDTDUrl; |
|
248 |
|
249 // Parsing time pointer to the node that is currently being contstructed |
|
250 //##ModelId=3B6679A00353 |
|
251 CXmlElement* iCurrentNode; |
|
252 |
|
253 // A flag denoting whether we have already found the first tag of the document. |
|
254 // Enables the first tag Name and attributes to be inserted to the given root node. |
|
255 //##ModelId=3B6679A00341 |
|
256 TBool iRootTagFound; |
|
257 |
|
258 // Parsing time data storages. Used to temporarily store the matched components |
|
259 //##ModelId=3B6679A00335 |
|
260 HBufC* iName; |
|
261 //##ModelId=3B6679A00323 |
|
262 HBufC* iAttrName; |
|
263 //##ModelId=3B6679A00317 |
|
264 HBufC* iAttValue; |
|
265 //##ModelId=3B6679A0030D |
|
266 HBufC* iCData; |
|
267 //##ModelId=3B6679A002FB |
|
268 HBufC* iSystemLiteral; |
|
269 //##ModelId=3B6679A002F1 |
|
270 HBufC* iPubidLiteral; |
|
271 //##ModelId=3B6679A002E7 |
|
272 HBufC* iXmlVersionString; |
|
273 //##ModelId=3B6679A002DB |
|
274 HBufC* iDocRootName; |
|
275 |
|
276 // An error code defining the failure reason, if something went wrong |
|
277 // Positive error code values are used to signal XmlLib about actions that should be taken |
|
278 //##ModelId=3B6679A002D1 |
|
279 TInt iErrorCode; |
|
280 |
|
281 // DTD tree for entity replacement |
|
282 //##ModelId=3B6679A002BF |
|
283 CBNFNode* iDTD; // NOT OWNED |
|
284 |
|
285 // Data gathering mode, if we didn't get a DTD, then we need to gather the data in a buffer |
|
286 // and perform the parsing in the validation phase |
|
287 //##ModelId=3B6679A002B5 |
|
288 TBool iDataGathering; |
|
289 __XML_DECLARE_LOG |
|
290 |
|
291 }; |
|
292 |
|
293 // Inline functions |
|
294 // |
|
295 inline TInt CXmlParser::ErrorCode() |
|
296 { |
|
297 return(iErrorCode); |
|
298 } |
|
299 |
|
300 inline const HBufC* CXmlParser::DocType() |
|
301 { |
|
302 return(iDocType); |
|
303 } |
|
304 |
|
305 inline const HBufC* CXmlParser::DTDUrl() |
|
306 { |
|
307 return(iDTDUrl); |
|
308 } |
|
309 |
|
310 inline TBool CXmlParser::DataGathering() const |
|
311 { |
|
312 return(iDataGathering); |
|
313 } |
|
314 |
|
315 inline void CXmlParser::SetDataGathering(TBool aDataGathering) |
|
316 { |
|
317 iDataGathering = aDataGathering; |
|
318 } |
|
319 |
|
320 inline const CBNFNode* CXmlParser::DTD() const |
|
321 { |
|
322 return(iDTD); |
|
323 } |
|
324 |
|
325 inline void CXmlParser::SetDTD(CBNFNode* aDTD) |
|
326 { |
|
327 iDTD = aDTD; |
|
328 } |
|
329 |
|
330 #endif // __XMLPARS_H __ |