|
1 /*------------------------------------------------------------------ |
|
2 - |
|
3 * Software Name : UserEmulator |
|
4 * Version : v4.2.1309 |
|
5 * |
|
6 * Copyright (c) 2009 France Telecom. All rights reserved. |
|
7 * This software is distributed under the License |
|
8 * "Eclipse Public License - v 1.0" the text of which is available |
|
9 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
10 * |
|
11 * Initial Contributors: |
|
12 * France Telecom |
|
13 * |
|
14 * Contributors: |
|
15 *------------------------------------------------------------------ |
|
16 - |
|
17 * File Name: XmlHandler.h |
|
18 * |
|
19 * Created: 13/08/2009 |
|
20 * Author(s): Marcell Kiss, Reshma Sandeep Das |
|
21 * |
|
22 * Description: |
|
23 * XML Parser implementation |
|
24 * There are two methods to parse XML document, i.e.; |
|
25 * - StartParsingL() -> parse XML document without active object. |
|
26 * - StartParsingWithAoL() -> parse XML document with active object. |
|
27 *------------------------------------------------------------------ |
|
28 - |
|
29 * |
|
30 */ |
|
31 |
|
32 #ifndef XMLHANDLER_H__ |
|
33 #define XMLHANDLER_H__ |
|
34 |
|
35 // System Includes |
|
36 #include <e32base.h> |
|
37 #include <xml\contenthandler.h> // for MContentHandler |
|
38 #include <xml\parser.h> // for CParser |
|
39 |
|
40 //User Includes |
|
41 #include "Constants.h" |
|
42 |
|
43 using namespace Xml; |
|
44 |
|
45 /** |
|
46 * TActionType |
|
47 * Enumaration defining different action types |
|
48 */ |
|
49 enum TActionType |
|
50 { |
|
51 EActionTypeUnknown = 0, |
|
52 EActionTypeView, |
|
53 EActionTypeApp, |
|
54 EActionTypeUrl, |
|
55 EActionTypeAppUrl, |
|
56 EActionTypeJavaApp, |
|
57 EActionTypeWait, |
|
58 EActionTypeKeys, |
|
59 EActionTypeOrientationChange, |
|
60 EActionTypePointerEvent, |
|
61 EActionCloseApp, |
|
62 EActionTypeOrientation, |
|
63 EActionTypeScreenReset, |
|
64 EActionTypeStartScript, |
|
65 EActionTypeEndScript, |
|
66 EActionTypeLoopStart, |
|
67 EActionTypeLoopEnd |
|
68 }; |
|
69 |
|
70 /** |
|
71 * TState |
|
72 * Enumaration containing different states of the XML parser |
|
73 */ |
|
74 enum TState |
|
75 { |
|
76 EIdle, |
|
77 EStartDocument, |
|
78 EEndDocument, |
|
79 EOnContent, |
|
80 EOnStartElement, |
|
81 EOnEndElement, |
|
82 EOnStartPrefixMapping, |
|
83 EOnEndPrefixMapping, |
|
84 EOnIgnorableWhiteSpace, |
|
85 EOnSkippedEntity, |
|
86 EOnProcessingInstruction, |
|
87 EOnError |
|
88 }; |
|
89 /** |
|
90 * CAction |
|
91 * Class that contains information for each action element in the XML file |
|
92 */ |
|
93 class CAction : public CBase |
|
94 { |
|
95 public: |
|
96 /** |
|
97 * Destructor |
|
98 */ |
|
99 virtual ~CAction(); |
|
100 |
|
101 /** |
|
102 * Enumeration describing the action type |
|
103 */ |
|
104 TActionType iType; |
|
105 /** |
|
106 * buffer containing parameters like appuid, pointerevents |
|
107 */ |
|
108 HBufC* iParams; |
|
109 /** |
|
110 * buffer containing screenshot tag |
|
111 */ |
|
112 HBufC* iScreenshotTag; |
|
113 /** |
|
114 * buffer containing print logs |
|
115 */ |
|
116 HBufC* iPrintLog; |
|
117 /** |
|
118 * An array contining list of keyevents |
|
119 */ |
|
120 RArray<TUint> iKeys; |
|
121 }; |
|
122 |
|
123 /** |
|
124 * MXmlHandlerObserver, an observer to CXmlHandler class. |
|
125 */ |
|
126 class MXmlHandlerObserver |
|
127 { |
|
128 public: |
|
129 /** |
|
130 * Callback to notify the observer on XML file parse completion |
|
131 * @param aError Error Code |
|
132 * @param aState XML parser state |
|
133 */ |
|
134 virtual void OnParseCompletedL( TInt aError, TState aState) = 0; |
|
135 }; |
|
136 |
|
137 /** |
|
138 * CXmlHandler, a class to parse XML file and then output log information |
|
139 * to a buffer. |
|
140 */ |
|
141 class CXmlHandler: public CActive, MContentHandler |
|
142 { |
|
143 |
|
144 public: // Constructors and destructor |
|
145 |
|
146 /** |
|
147 * Static constructor |
|
148 * @param aObserver A reference to the XML handler observer. |
|
149 * @param aActionList Ref to the action list array |
|
150 * @return CXmlHandler* A pointer to the newly alocated CXmlHandler class. |
|
151 * NULL, if the class cannot be created |
|
152 */ |
|
153 static CXmlHandler* NewL( MXmlHandlerObserver& aObserver,RPointerArray<CAction>& aActionList); |
|
154 /** |
|
155 * Static constructor. On return the instance is left to the CleanupStack |
|
156 * @param aObserver A reference to the XML handler observer. |
|
157 * @param aActionList Ref to the action list array |
|
158 * @return CXmlHandler* A pointer to the newly alocated CXmlHandler class. |
|
159 * NULL, if the class cannot be created |
|
160 */ |
|
161 static CXmlHandler* NewLC( MXmlHandlerObserver& aObserver,RPointerArray<CAction>& aActionList); |
|
162 |
|
163 |
|
164 /** |
|
165 * Destructor |
|
166 */ |
|
167 virtual ~CXmlHandler(); |
|
168 |
|
169 public: // Public methods |
|
170 |
|
171 /** |
|
172 * Parses XML document |
|
173 * @param aFileName XML file name |
|
174 * return error code |
|
175 */ |
|
176 TInt StartParsingL( const TDesC& aFileName ); |
|
177 /** |
|
178 * Parses XML document with an Active object |
|
179 * @param aFileName XML file name |
|
180 */ |
|
181 void StartParsingWithAoL( const TDesC& aFileName ); |
|
182 |
|
183 private: // Constructors |
|
184 |
|
185 /** |
|
186 * Constructor |
|
187 * @param aObserver A reference to the XML handler observer. |
|
188 * @param aActionList Ref to the action list array |
|
189 */ |
|
190 CXmlHandler( MXmlHandlerObserver& aObserver,RPointerArray<CAction>& aActionList); |
|
191 |
|
192 /** |
|
193 * ConstructL |
|
194 */ |
|
195 void ConstructL(); |
|
196 |
|
197 private: // from CActive |
|
198 |
|
199 /** |
|
200 * Cancels any outstanding request. |
|
201 */ |
|
202 void DoCancel(); |
|
203 |
|
204 /** |
|
205 * Handles the completion of the active request. |
|
206 */ |
|
207 void RunL(); |
|
208 |
|
209 private: |
|
210 // from MContentHandler |
|
211 void OnStartDocumentL( const RDocumentParameters &aDocParam, TInt aErrorCode ); |
|
212 void OnEndDocumentL( TInt aErrorCode ); |
|
213 void OnStartElementL( const RTagInfo &aElement, const RAttributeArray &aAttributes, |
|
214 TInt aErrorCode ); |
|
215 void OnEndElementL( const RTagInfo &aElement, TInt aErrorCode ); |
|
216 void OnContentL( const TDesC8 &aBytes, TInt aErrorCode ); |
|
217 void OnStartPrefixMappingL( const RString &aPrefix, const RString &aUri, |
|
218 TInt aErrorCode ); |
|
219 void OnEndPrefixMappingL( const RString &aPrefix, TInt aErrorCode ); |
|
220 void OnIgnorableWhiteSpaceL( const TDesC8 &aBytes, TInt aErrorCode ); |
|
221 void OnSkippedEntityL( const RString &aName, TInt aErrorCode ); |
|
222 void OnProcessingInstructionL( const TDesC8 &aTarget, const TDesC8 &aData, |
|
223 TInt aErrorCode); |
|
224 void OnError( TInt aErrorCode ); |
|
225 TAny *GetExtendedInterface( const TInt32 aUid ); |
|
226 |
|
227 private: |
|
228 /** |
|
229 * Function to expand the actual buffer size |
|
230 * @param aText buffer |
|
231 */ |
|
232 void AppendTextL( const TDesC& aText ); |
|
233 |
|
234 private: // Private data |
|
235 |
|
236 /** |
|
237 * Enumeration with different content types |
|
238 */ |
|
239 enum { |
|
240 EContentNone, |
|
241 EContentName, |
|
242 EContentType, |
|
243 EContentParams, |
|
244 EContentPrintLog, |
|
245 EContentKeys, |
|
246 EContentScreenshot, |
|
247 EContentUnknown |
|
248 }; |
|
249 |
|
250 /** |
|
251 * Handle to XML Observer |
|
252 */ |
|
253 MXmlHandlerObserver& iObserver; |
|
254 /** |
|
255 * Handle to parser object |
|
256 */ |
|
257 CParser* iParser; |
|
258 /** |
|
259 * Handle to XML buffer |
|
260 */ |
|
261 HBufC8* iBuffer; |
|
262 /** |
|
263 * Buffer containing the final display message |
|
264 */ |
|
265 HBufC* iDisplayResult; |
|
266 /** |
|
267 * XML parser state |
|
268 */ |
|
269 TState iState; |
|
270 /** |
|
271 * File handle |
|
272 */ |
|
273 RFile iFile; |
|
274 /** |
|
275 * Reference to array containing list of action elements |
|
276 */ |
|
277 RPointerArray<CAction>& iActionList; // not owned |
|
278 |
|
279 /** |
|
280 * XML content |
|
281 */ |
|
282 HBufC8* iContent; |
|
283 /** |
|
284 * Content type |
|
285 */ |
|
286 TInt iContentType; |
|
287 /** |
|
288 * Reference to action objects |
|
289 */ |
|
290 CAction* iAction; |
|
291 /** |
|
292 * Index to the CLoopObj element in the iLoopObjList |
|
293 */ |
|
294 TInt iIndex; |
|
295 /** |
|
296 * Action list index element |
|
297 */ |
|
298 TInt iActionListIndex; |
|
299 }; |
|
300 |
|
301 #endif /* XMLHANDLER_H__ */ |
|
302 |
|
303 // End of File |