0
|
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.cpp
|
|
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 |
// System Includes
|
|
33 |
#include <coemain.h>
|
|
34 |
#include <f32file.h>
|
|
35 |
#include <eikenv.h>
|
|
36 |
#include <xml/parserfeature.h>
|
|
37 |
#include <utf.h>
|
|
38 |
#include <aknnotewrappers.h>
|
|
39 |
#include <coecntrl.h>
|
|
40 |
|
|
41 |
// User Includes
|
|
42 |
#include <UserEmulator_0x2001C3AF.rsg>
|
|
43 |
#include "XmlHandler.h"
|
|
44 |
#include "Utils.h"
|
|
45 |
#include "UserEmulatorAppUi.h"
|
|
46 |
|
|
47 |
//Constants
|
|
48 |
/**
|
|
49 |
* XML Tags
|
|
50 |
*/
|
|
51 |
_LIT8(KAction,"action");
|
|
52 |
_LIT8(KName,"name");
|
|
53 |
_LIT8(KType,"type");
|
|
54 |
_LIT8(KParams,"params");
|
|
55 |
_LIT8(KPrintLog,"print");
|
|
56 |
_LIT8(KKeys,"keys");
|
|
57 |
_LIT8(KLoop,"loop");
|
|
58 |
_LIT8(KCount,"count");
|
|
59 |
_LIT8(KScreenShot,"screenshot");
|
|
60 |
|
|
61 |
/**
|
|
62 |
* Action Types
|
|
63 |
*/
|
|
64 |
_LIT( KParamActionsApp, "app" );
|
|
65 |
_LIT( KParamActionsView, "view" );
|
|
66 |
_LIT( KParamActionsJavaApp, "javaapp" );
|
|
67 |
_LIT( KParamActionsWait, "wait" );
|
|
68 |
_LIT( KParamActionsOrient, "orientation" );
|
|
69 |
_LIT( KParamActionsScreenReset, "screenreset" );
|
|
70 |
_LIT( KParamActionsPointerEvent, "pointerevent" );
|
|
71 |
_LIT( KParamActionsKeyPress, "keypress" );
|
|
72 |
_LIT( KParamCloseApp, "closeapp");
|
|
73 |
_LIT( KParamActionsLoop, "loop");
|
|
74 |
_LIT( KParamActionsLoopEnd, "loopend");
|
|
75 |
|
|
76 |
/**
|
|
77 |
* Keys
|
|
78 |
*/
|
|
79 |
_LIT(KLeftSoftKey,"LSK");
|
|
80 |
_LIT(KRightSoftKey,"RSK");
|
|
81 |
_LIT(KMiddleSoftKey,"MSK");
|
|
82 |
_LIT(KDownArrowKey,"DAK");
|
|
83 |
_LIT(KUpArrowKey,"UAK");
|
|
84 |
_LIT(KRightArrowKey,"RAK");
|
|
85 |
_LIT(KLeftArrowKey,"LAK");
|
|
86 |
_LIT(KKeySpace,"SP");
|
|
87 |
_LIT(KKeyBackSpace,"BS");
|
|
88 |
_LIT(KKeyGreaterThan, "gt");
|
|
89 |
_LIT(KKeyAmpersand,"amp");
|
|
90 |
_LIT(KKeyLessThan,"lt");
|
|
91 |
_LIT(KKeyOkKey,"OK");
|
|
92 |
_LIT(KKeyMenu,"MENU"); //EAKeyApplication0
|
|
93 |
_LIT(KKeyYes,"KYES"); //EKeyYes
|
|
94 |
_LIT(KKeyNo,"KNO"); //EKeyNo
|
|
95 |
_LIT(KKeyCamera,"CAM");
|
|
96 |
_LIT(KKeyHash,"#");
|
|
97 |
|
|
98 |
/**
|
|
99 |
* General Constants
|
|
100 |
*/
|
|
101 |
_LIT(KOpeningTag, "<" );
|
|
102 |
_LIT(KClosingTag, ">" );
|
|
103 |
_LIT(KSlash, "/" );
|
|
104 |
_LIT(KEndOfLine, "\f" ); // CEikEdwin uses '\f' as EOF mark.
|
|
105 |
|
|
106 |
_LIT(KF842,"0xF842");
|
|
107 |
_LIT(KF843,"0xF843");
|
|
108 |
_LIT(Ka7,"0xa7");
|
|
109 |
_LIT(KF80A,"0xF80A");
|
|
110 |
_LIT(KF809,"0xF809");
|
|
111 |
_LIT(KF808,"0xF808");
|
|
112 |
_LIT(KF807,"0xF807");
|
|
113 |
_LIT(K0008,"0x0008");
|
|
114 |
_LIT(K0020,"0x0020");
|
|
115 |
_LIT(K0026,"0x0026");
|
|
116 |
_LIT(K003C,"0x003C");
|
|
117 |
_LIT(K003E,"0x003E");
|
|
118 |
_LIT(KF852,"0xF852");
|
|
119 |
_LIT(KF862,"0xF862");
|
|
120 |
_LIT(KF863,"0xF863");
|
|
121 |
_LIT(KF893,"0xF893");
|
|
122 |
|
|
123 |
|
|
124 |
_LIT8(KXmlMimeType, "text/xml" );
|
|
125 |
|
|
126 |
const TInt KMaxFileNameLength=200;
|
|
127 |
|
|
128 |
|
|
129 |
// METHODS DEFINITION
|
|
130 |
// -----------------------------------------------------------------------------
|
|
131 |
// CXmlHandler::NewL
|
|
132 |
// Creates the instance of class and returns it.
|
|
133 |
// -----------------------------------------------------------------------------
|
|
134 |
//
|
|
135 |
|
|
136 |
CXmlHandler* CXmlHandler::NewL( MXmlHandlerObserver& aObserver, RPointerArray<CAction>& aActionList)
|
|
137 |
{
|
|
138 |
CXmlHandler* self = CXmlHandler::NewLC( aObserver ,aActionList);
|
|
139 |
CleanupStack::Pop();
|
|
140 |
return self;
|
|
141 |
}
|
|
142 |
|
|
143 |
// -----------------------------------------------------------------------------
|
|
144 |
// CXmlHandler::NewLC
|
|
145 |
// Creates the instance of class and pushes it to the CleanupStack and return
|
|
146 |
// it.
|
|
147 |
// -----------------------------------------------------------------------------
|
|
148 |
//
|
|
149 |
CXmlHandler* CXmlHandler::NewLC( MXmlHandlerObserver& aObserver ,
|
|
150 |
RPointerArray<CAction>& aActionList)
|
|
151 |
{
|
|
152 |
CXmlHandler* self = new ( ELeave ) CXmlHandler( aObserver, aActionList);
|
|
153 |
CleanupStack::PushL( self );
|
|
154 |
self->ConstructL();
|
|
155 |
return self;
|
|
156 |
}
|
|
157 |
|
|
158 |
// -----------------------------------------------------------------------------
|
|
159 |
// CXmlHandler::~CXmlHandler
|
|
160 |
// Cancels any outstanding requests and deletes members.
|
|
161 |
// -----------------------------------------------------------------------------
|
|
162 |
//
|
|
163 |
CXmlHandler::~CXmlHandler()
|
|
164 |
{
|
|
165 |
Cancel();
|
|
166 |
delete iParser;
|
|
167 |
delete iDisplayResult;
|
|
168 |
delete iBuffer;
|
|
169 |
delete iContent;
|
|
170 |
iContent=NULL;
|
|
171 |
}
|
|
172 |
|
|
173 |
// -----------------------------------------------------------------------------
|
|
174 |
// CXmlHandler::CXmlHandler
|
|
175 |
// Calls base classes constructor with priority value. Add class to the
|
|
176 |
// active sheduler.
|
|
177 |
// -----------------------------------------------------------------------------
|
|
178 |
//
|
|
179 |
CXmlHandler::CXmlHandler( MXmlHandlerObserver& aObserver ,RPointerArray<CAction>& aActionList)
|
|
180 |
:CActive( EPriorityStandard ),
|
|
181 |
iObserver( aObserver ),
|
|
182 |
iParser( 0 ),
|
|
183 |
iDisplayResult( 0 ),
|
|
184 |
iState( EIdle ),
|
|
185 |
iActionList(aActionList),
|
|
186 |
iActionListIndex(0)
|
|
187 |
{
|
|
188 |
iIndex = 0;
|
|
189 |
|
|
190 |
CActiveScheduler::Add( this );
|
|
191 |
}
|
|
192 |
// -----------------------------------------------------------------------------
|
|
193 |
// CXmlHandler::DoCancel
|
|
194 |
// From CActive. Cancels any outstanding request according the engine state.
|
|
195 |
// -----------------------------------------------------------------------------
|
|
196 |
//
|
|
197 |
void CXmlHandler::DoCancel()
|
|
198 |
{
|
|
199 |
TRAP_IGNORE(iParser->ParseEndL());
|
|
200 |
iFile.Close();
|
|
201 |
delete iBuffer;
|
|
202 |
iBuffer = 0;
|
|
203 |
}
|
|
204 |
|
|
205 |
// -----------------------------------------------------------------------------
|
|
206 |
// CXmlHandler::RunL
|
|
207 |
// From CActive. Handles the state changes and notifing the observer.
|
|
208 |
// -----------------------------------------------------------------------------
|
|
209 |
//
|
|
210 |
void CXmlHandler::RunL()
|
|
211 |
{
|
|
212 |
if ( KErrNone == iStatus.Int() )
|
|
213 |
{
|
|
214 |
// If the buffer length is zero, it means we have reached
|
|
215 |
// the end of the file.
|
|
216 |
if ( iBuffer->Length() == 0)
|
|
217 |
{
|
|
218 |
iParser->ParseEndL();
|
|
219 |
iFile.Close();
|
|
220 |
delete iBuffer;
|
|
221 |
iBuffer = 0;
|
|
222 |
}
|
|
223 |
|
|
224 |
// Otherwise, we continue reading the next chunk of the XML file.
|
|
225 |
else
|
|
226 |
{
|
|
227 |
// Parse the next "part" of the XML document.
|
|
228 |
iParser->ParseL( *iBuffer );
|
|
229 |
|
|
230 |
// Read the next chunk of the file.
|
|
231 |
TPtr8 bufferPtr( iBuffer->Des() );
|
|
232 |
iFile.Read( bufferPtr, KBuffer1024, iStatus );
|
|
233 |
|
|
234 |
// Don't forget to call this..
|
|
235 |
SetActive();
|
|
236 |
}
|
|
237 |
}
|
|
238 |
else
|
|
239 |
{
|
|
240 |
iObserver.OnParseCompletedL( iStatus.Int(), iState );
|
|
241 |
}
|
|
242 |
}
|
|
243 |
|
|
244 |
// -----------------------------------------------------------------------------
|
|
245 |
// CXmlHandler::ConstructL
|
|
246 |
// Construction of parser and buffer allocations
|
|
247 |
// -----------------------------------------------------------------------------
|
|
248 |
//
|
|
249 |
void CXmlHandler::ConstructL()
|
|
250 |
{
|
|
251 |
iDisplayResult = HBufC::NewL( KBuffer1024 );
|
|
252 |
iContent = HBufC8::NewL(KBuffer128);
|
|
253 |
}
|
|
254 |
|
|
255 |
// -----------------------------------------------------------------------------
|
|
256 |
// CXmlHandler::StartParsingL
|
|
257 |
// Function to start parsing the XML script without active object
|
|
258 |
// -----------------------------------------------------------------------------
|
|
259 |
//
|
|
260 |
TInt CXmlHandler::StartParsingL( const TDesC& aFileName )
|
|
261 |
{
|
|
262 |
// If file name is too long then don't parse it just mark it as a failed script
|
|
263 |
TInt pos=aFileName.LocateReverse('\\');
|
|
264 |
if(aFileName.Right(aFileName.Length()-pos).Length()>KMaxFileNameLength)
|
|
265 |
{
|
|
266 |
TRAPD(err, iObserver.OnParseCompletedL( KErrGeneral,EOnError ));
|
|
267 |
return err;
|
|
268 |
}
|
|
269 |
|
|
270 |
RFile file;
|
|
271 |
User::LeaveIfError( file.Open( CCoeEnv::Static()->FsSession(), aFileName,
|
|
272 |
EFileRead ) );
|
|
273 |
CleanupClosePushL( file );
|
|
274 |
|
|
275 |
iDisplayResult->Des().Zero();
|
|
276 |
TInt size;
|
|
277 |
User::LeaveIfError( file.Size( size ) );
|
|
278 |
delete iBuffer;
|
|
279 |
iBuffer = 0;
|
|
280 |
iBuffer = HBufC8::NewL( size );
|
|
281 |
TPtr8 bufferPtr( iBuffer->Des() );
|
|
282 |
User::LeaveIfError( file.Read( bufferPtr ) );
|
|
283 |
|
|
284 |
file.Close();
|
|
285 |
CleanupStack::PopAndDestroy(); // file
|
|
286 |
|
|
287 |
delete iParser;
|
|
288 |
iParser= NULL;
|
|
289 |
iParser = CParser::NewL( KXmlMimeType, *this );
|
|
290 |
|
|
291 |
iActionListIndex = iActionList.Count();
|
|
292 |
TRAPD(err,iParser->ParseBeginL());
|
|
293 |
if(err!=KErrNone)
|
|
294 |
return err;
|
|
295 |
TRAPD(err1,iParser->ParseL( *iBuffer ));
|
|
296 |
if(err1!=KErrNone)
|
|
297 |
return err1;
|
|
298 |
TRAPD(err2,iParser->ParseEndL());
|
|
299 |
if(err2!=KErrNone)
|
|
300 |
return err2;
|
|
301 |
|
|
302 |
return KErrNone;
|
|
303 |
|
|
304 |
}
|
|
305 |
|
|
306 |
// -----------------------------------------------------------------------------
|
|
307 |
// CXmlHandler::StartParsingWithAoL
|
|
308 |
// Function to start parsing the XML script
|
|
309 |
// -----------------------------------------------------------------------------
|
|
310 |
//
|
|
311 |
|
|
312 |
void CXmlHandler::StartParsingWithAoL( const TDesC& aFileName )
|
|
313 |
{
|
|
314 |
// Remember to cancel any outstanding request first.
|
|
315 |
if ( IsActive() )
|
|
316 |
{
|
|
317 |
Cancel();
|
|
318 |
}
|
|
319 |
// If file name is too long then don't parse it just mark it as a failed script
|
|
320 |
TInt pos=aFileName.LocateReverse('\\');
|
|
321 |
if(aFileName.Right(aFileName.Length()-pos).Length()>KMaxFileNameLength)
|
|
322 |
{
|
|
323 |
|
|
324 |
TRAPD(err, iObserver.OnParseCompletedL( KErrGeneral,EOnError ));
|
|
325 |
return;
|
|
326 |
}
|
|
327 |
User::LeaveIfError( iFile.Open( CCoeEnv::Static()->FsSession(), aFileName,
|
|
328 |
EFileRead ) );
|
|
329 |
|
|
330 |
// Create a buffer to store the file content.
|
|
331 |
// Note that this method uses active object to read the file.
|
|
332 |
// So we have to call SetActive() at the end. Then we call CParser::ParseL()
|
|
333 |
// in RunL() method.
|
|
334 |
iDisplayResult->Des().Zero();
|
|
335 |
delete iBuffer;
|
|
336 |
iBuffer = 0;
|
|
337 |
iBuffer = HBufC8::NewL( KBuffer1024 );
|
|
338 |
TPtr8 bufferPtr( iBuffer->Des() );
|
|
339 |
iFile.Read( bufferPtr, KBuffer1024, iStatus );
|
|
340 |
SetActive();
|
|
341 |
|
|
342 |
// Tell the parser that we are about to parse a XML document.
|
|
343 |
iParser->ParseBeginL();
|
|
344 |
}
|
|
345 |
|
|
346 |
// -----------------------------------------------------------------------------
|
|
347 |
// CXmlHandler::OnStartDocumentL
|
|
348 |
// Callback to indicate start of the document
|
|
349 |
// -----------------------------------------------------------------------------
|
|
350 |
//
|
|
351 |
void CXmlHandler::OnStartDocumentL( const RDocumentParameters& /*aDocParam*/,
|
|
352 |
TInt aErrorCode )
|
|
353 |
{
|
|
354 |
if ( KErrNone == aErrorCode )
|
|
355 |
{
|
|
356 |
// Nothing for now
|
|
357 |
}
|
|
358 |
else
|
|
359 |
{
|
|
360 |
iObserver.OnParseCompletedL( aErrorCode, EOnStartElement );
|
|
361 |
}
|
|
362 |
}
|
|
363 |
|
|
364 |
// -----------------------------------------------------------------------------
|
|
365 |
// CXmlHandler::OnEndDocumentL
|
|
366 |
// Callback to indicate end of the document
|
|
367 |
// -----------------------------------------------------------------------------
|
|
368 |
//
|
|
369 |
void CXmlHandler::OnEndDocumentL( TInt aErrorCode )
|
|
370 |
{
|
|
371 |
if ( KErrNone == aErrorCode )
|
|
372 |
{
|
|
373 |
// Create action object
|
|
374 |
CAction *action = new(ELeave) CAction();
|
|
375 |
CleanupStack::PushL(action);
|
|
376 |
iActionList.AppendL(action);
|
|
377 |
|
|
378 |
CleanupStack::Pop(); // action
|
|
379 |
action->iType = EActionTypeEndScript;
|
|
380 |
}
|
|
381 |
iObserver.OnParseCompletedL( aErrorCode , EOnEndElement);
|
|
382 |
}
|
|
383 |
|
|
384 |
// -----------------------------------------------------------------------------
|
|
385 |
// CXmlHandler::OnStartElementL
|
|
386 |
// Callback to indicate an element has been parsed
|
|
387 |
// -----------------------------------------------------------------------------
|
|
388 |
//
|
|
389 |
void CXmlHandler::OnStartElementL( const RTagInfo& aElement,
|
|
390 |
const RAttributeArray& aAttributes, TInt aErrorCode )
|
|
391 |
{
|
|
392 |
if ( KErrNone == aErrorCode )
|
|
393 |
{
|
|
394 |
const TDesC8& name = aElement.LocalName().DesC();
|
|
395 |
|
|
396 |
iContent->Des().Zero();
|
|
397 |
|
|
398 |
TInt i;
|
|
399 |
|
|
400 |
if (name == KAction || name == KLoop)
|
|
401 |
{
|
|
402 |
// Create action object
|
|
403 |
CAction *action = new(ELeave) CAction();
|
|
404 |
CleanupStack::PushL(action);
|
|
405 |
|
|
406 |
if(name == KLoop)
|
|
407 |
{
|
|
408 |
for (i=0; i<aAttributes.Count(); i++)
|
|
409 |
{
|
|
410 |
RAttribute attrib = aAttributes[i];
|
|
411 |
const TDesC8& attribName = attrib.Attribute().LocalName().DesC();
|
|
412 |
const TDesC8& attribValue = attrib.Value().DesC();
|
|
413 |
TBuf<KBuffer256> tmp;
|
|
414 |
tmp.Copy(attribValue);
|
|
415 |
|
|
416 |
if(attribName == KCount)
|
|
417 |
{
|
|
418 |
action->iType = EActionTypeLoopStart;
|
|
419 |
if(attribValue == KInfinite)
|
|
420 |
tmp.Copy(KMinus1);
|
|
421 |
|
|
422 |
action->iParams = tmp.AllocL();
|
|
423 |
}
|
|
424 |
}
|
|
425 |
}
|
|
426 |
|
|
427 |
iActionList.AppendL(action);
|
|
428 |
|
|
429 |
CleanupStack::Pop(); // action
|
|
430 |
iAction = action;
|
|
431 |
|
|
432 |
|
|
433 |
}
|
|
434 |
else if (name == KName)
|
|
435 |
iContentType = EContentName;
|
|
436 |
else if (name == KType)
|
|
437 |
iContentType = EContentType;
|
|
438 |
else if (name == KParams)
|
|
439 |
iContentType = EContentParams;
|
|
440 |
else if (name == KPrintLog)
|
|
441 |
iContentType = EContentPrintLog;
|
|
442 |
else if (name == KKeys)
|
|
443 |
iContentType = EContentKeys;
|
|
444 |
else if (name == KScreenShot)
|
|
445 |
iContentType = EContentScreenshot;
|
|
446 |
else
|
|
447 |
{
|
|
448 |
}
|
|
449 |
}
|
|
450 |
else
|
|
451 |
{
|
|
452 |
iObserver.OnParseCompletedL( aErrorCode, EOnStartElement );
|
|
453 |
}
|
|
454 |
}
|
|
455 |
|
|
456 |
// -----------------------------------------------------------------------------
|
|
457 |
// CXmlHandler::OnEndElementL
|
|
458 |
// Callback to indicate the end of the element has been reached.
|
|
459 |
// -----------------------------------------------------------------------------
|
|
460 |
//
|
|
461 |
void CXmlHandler::OnEndElementL( const RTagInfo &aElement, TInt aErrorCode )
|
|
462 |
{
|
|
463 |
if ( KErrNone == aErrorCode )
|
|
464 |
{
|
|
465 |
// If we find the end of an element, we write it to the screen,
|
|
466 |
// for example: "</tag>"
|
|
467 |
const TDesC8& name = aElement.LocalName().DesC();
|
|
468 |
|
|
469 |
TPtr8 des(iContent->Des());
|
|
470 |
CUtils::StripSpaces(des);
|
|
471 |
|
|
472 |
HBufC *txt = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*iContent);
|
|
473 |
CleanupStack::PushL(txt);
|
|
474 |
|
|
475 |
if (name == KAction)
|
|
476 |
{
|
|
477 |
iAction = NULL;
|
|
478 |
}
|
|
479 |
else if (name == KLoop)
|
|
480 |
{
|
|
481 |
//reset the flag iLoopExists
|
|
482 |
CAction *action = new(ELeave) CAction();
|
|
483 |
CleanupStack::PushL(action);
|
|
484 |
action->iType = EActionTypeLoopEnd;
|
|
485 |
iActionList.AppendL(action);
|
|
486 |
|
|
487 |
CleanupStack::Pop(); // action
|
|
488 |
iAction = action;
|
|
489 |
}
|
|
490 |
else if (name == KType && iContentType == EContentType && iAction)
|
|
491 |
{
|
|
492 |
TLex lex(txt->Des());
|
|
493 |
lex.SkipSpace();
|
|
494 |
TPtrC token = lex.NextToken();
|
|
495 |
if (token == KParamActionsView)
|
|
496 |
iAction->iType = EActionTypeView;
|
|
497 |
else if (token == KParamActionsApp)
|
|
498 |
iAction->iType = EActionTypeApp;
|
|
499 |
else if (token == KParamActionsJavaApp)
|
|
500 |
iAction->iType = EActionTypeJavaApp;
|
|
501 |
else if (token == KParamActionsPointerEvent)
|
|
502 |
iAction->iType = EActionTypePointerEvent;
|
|
503 |
else if (token == KParamActionsWait)
|
|
504 |
iAction->iType = EActionTypeWait;
|
|
505 |
else if (token == KParamActionsOrient)
|
|
506 |
iAction->iType = EActionTypeOrientationChange;
|
|
507 |
else if (token == KParamActionsScreenReset)
|
|
508 |
iAction->iType = EActionTypeScreenReset;
|
|
509 |
else if (token == KParamActionsKeyPress)
|
|
510 |
iAction->iType = EActionTypeKeys;
|
|
511 |
else if (token == KParamCloseApp)
|
|
512 |
iAction->iType = EActionCloseApp;
|
|
513 |
}
|
|
514 |
else if (name == KParams && iContentType == EContentParams && iAction)
|
|
515 |
{
|
|
516 |
delete iAction->iParams;
|
|
517 |
iAction->iParams=NULL;
|
|
518 |
iAction->iParams = txt->Des().AllocL();
|
|
519 |
}
|
|
520 |
else if (name == KPrintLog && iContentType == EContentPrintLog && iAction)
|
|
521 |
{
|
|
522 |
delete iAction->iPrintLog;
|
|
523 |
iAction->iPrintLog=NULL;
|
|
524 |
iAction->iPrintLog = txt->Des().AllocL();
|
|
525 |
}
|
|
526 |
else if (name == KScreenShot && iContentType == EContentScreenshot && iAction)
|
|
527 |
{
|
|
528 |
delete iAction->iScreenshotTag;
|
|
529 |
iAction->iScreenshotTag = NULL;
|
|
530 |
iAction->iScreenshotTag = txt->Des().AllocL();
|
|
531 |
}
|
|
532 |
else if (name == KKeys && iContentType == EContentKeys && iAction)
|
|
533 |
{
|
|
534 |
TLex lex(txt->Des());
|
|
535 |
TBuf<KBuffer20> keyName(KN);
|
|
536 |
|
|
537 |
for (lex.SkipSpace(); !lex.Eos(); lex.SkipSpace())
|
|
538 |
{
|
|
539 |
TPtrC token = lex.NextToken();
|
|
540 |
keyName.FillZ();
|
|
541 |
keyName.Copy(token);
|
|
542 |
|
|
543 |
if(token.Compare(KLeftSoftKey) == 0 )
|
|
544 |
keyName.Copy(KF842);
|
|
545 |
else if(token.Compare(KRightSoftKey) == 0 )
|
|
546 |
keyName.Copy(KF843);
|
|
547 |
else if(token.Compare(KMiddleSoftKey) == 0 )
|
|
548 |
keyName.Copy(Ka7);
|
|
549 |
else if(token.Compare(KDownArrowKey) == 0 )
|
|
550 |
keyName.Copy(KF80A);
|
|
551 |
else if(token.Compare(KUpArrowKey) == 0 )
|
|
552 |
keyName.Copy(KF809);
|
|
553 |
else if(token.Compare(KRightArrowKey) == 0 )
|
|
554 |
keyName.Copy(KF808);
|
|
555 |
else if(token.Compare(KLeftArrowKey) == 0 )
|
|
556 |
keyName.Copy(KF807);
|
|
557 |
else if(token.Compare(KKeyBackSpace) == 0 )
|
|
558 |
keyName.Copy(K0008);
|
|
559 |
else if(token.Compare(KKeySpace) == 0 )
|
|
560 |
keyName.Copy(K0020);
|
|
561 |
else if(token.Compare(KKeyAmpersand) == 0 )
|
|
562 |
keyName.Copy(K0026);
|
|
563 |
else if(token.Compare(KKeyLessThan) == 0 )
|
|
564 |
keyName.Copy(K003C);
|
|
565 |
else if(token.Compare(KKeyGreaterThan) == 0 )
|
|
566 |
keyName.Copy(K003E);
|
|
567 |
else if(token.Compare(KKeyMenu) == 0 )
|
|
568 |
keyName.Copy(KF852);
|
|
569 |
else if(token.Compare(KKeyYes) == 0 )
|
|
570 |
keyName.Copy(KF862);
|
|
571 |
else if(token.Compare(KKeyNo) == 0 )
|
|
572 |
keyName.Copy(KF863);
|
|
573 |
else if(token.Compare(KKeyCamera) == 0 )
|
|
574 |
keyName.Copy(KF893);
|
|
575 |
else if(token.Compare(KKeyHash) == 0 )
|
|
576 |
keyName.Copy(_L("0x23"));
|
|
577 |
|
|
578 |
if (keyName.Left(2) == KHEX)
|
|
579 |
{
|
|
580 |
//Special keys
|
|
581 |
TLex lex2(keyName.Mid(2));
|
|
582 |
TUint value;
|
|
583 |
if (lex2.Val(value,EHex) == KErrNone)
|
|
584 |
iAction->iKeys.AppendL(value);
|
|
585 |
}
|
|
586 |
else
|
|
587 |
{
|
|
588 |
//alpha numeric keys and symbols
|
|
589 |
for(TInt i=0; i<token.Length(); i++)
|
|
590 |
{
|
|
591 |
TUint value = token.operator [](i);
|
|
592 |
iAction->iKeys.AppendL(value);
|
|
593 |
}
|
|
594 |
}
|
|
595 |
}
|
|
596 |
}
|
|
597 |
else
|
|
598 |
{
|
|
599 |
}
|
|
600 |
CleanupStack::PopAndDestroy(); // txt
|
|
601 |
iContentType = EContentNone;
|
|
602 |
}
|
|
603 |
else
|
|
604 |
{
|
|
605 |
iObserver.OnParseCompletedL( aErrorCode,EOnEndElement );
|
|
606 |
}
|
|
607 |
}
|
|
608 |
|
|
609 |
// -----------------------------------------------------------------------------
|
|
610 |
// CXmlHandler::OnContentL
|
|
611 |
// Callback that sends the content of the element
|
|
612 |
// -----------------------------------------------------------------------------
|
|
613 |
//
|
|
614 |
|
|
615 |
void CXmlHandler::OnContentL( const TDesC8 &aBytes, TInt aErrorCode )
|
|
616 |
{
|
|
617 |
if ( KErrNone == aErrorCode )
|
|
618 |
{
|
|
619 |
while (iContent->Des().MaxLength() < iContent->Des().Length()+aBytes.Length())
|
|
620 |
{
|
|
621 |
iContent = iContent->ReAllocL(iContent->Des().Length()*3/2);
|
|
622 |
}
|
|
623 |
iContent->Des().Append(aBytes);
|
|
624 |
}
|
|
625 |
else
|
|
626 |
{
|
|
627 |
iObserver.OnParseCompletedL( aErrorCode, EOnContent);
|
|
628 |
}
|
|
629 |
}
|
|
630 |
|
|
631 |
// -----------------------------------------------------------------------------
|
|
632 |
// CXmlHandler::OnStartPrefixMappingL
|
|
633 |
// This method is a notification of the beginning of the scope of a prefix-URI
|
|
634 |
// Namespace mapping. This method is always called before the corresponding
|
|
635 |
// OnStartElementL method.
|
|
636 |
// -----------------------------------------------------------------------------
|
|
637 |
//
|
|
638 |
|
|
639 |
void CXmlHandler::OnStartPrefixMappingL( const RString& /*aPrefix*/,
|
|
640 |
const RString& /*aUri*/, TInt aErrorCode )
|
|
641 |
{
|
|
642 |
if ( KErrNone == aErrorCode )
|
|
643 |
{
|
|
644 |
}
|
|
645 |
else
|
|
646 |
{
|
|
647 |
iObserver.OnParseCompletedL( aErrorCode,EOnStartPrefixMapping );
|
|
648 |
}
|
|
649 |
}
|
|
650 |
|
|
651 |
// -----------------------------------------------------------------------------
|
|
652 |
// CXmlHandler::OnEndPrefixMappingL
|
|
653 |
// This method is a notification of the end of the scope of a prefix-URI mapping.
|
|
654 |
// This method is called after the corresponding DoEndElementL method.
|
|
655 |
// -----------------------------------------------------------------------------
|
|
656 |
//
|
|
657 |
|
|
658 |
void CXmlHandler::OnEndPrefixMappingL( const RString& /*aPrefix*/,
|
|
659 |
TInt aErrorCode )
|
|
660 |
{
|
|
661 |
if ( KErrNone == aErrorCode )
|
|
662 |
{
|
|
663 |
}
|
|
664 |
else
|
|
665 |
{
|
|
666 |
iObserver.OnParseCompletedL( aErrorCode,EOnEndPrefixMapping );
|
|
667 |
}
|
|
668 |
}
|
|
669 |
// -----------------------------------------------------------------------------
|
|
670 |
// CXmlHandler::OnEndPrefixMappingL
|
|
671 |
// This method is a notification of ignorable whitespace in element content.
|
|
672 |
// -----------------------------------------------------------------------------
|
|
673 |
//
|
|
674 |
void CXmlHandler::OnIgnorableWhiteSpaceL( const TDesC8& /*aBytes*/,
|
|
675 |
TInt aErrorCode )
|
|
676 |
{
|
|
677 |
if ( KErrNone == aErrorCode )
|
|
678 |
{
|
|
679 |
}
|
|
680 |
else
|
|
681 |
{
|
|
682 |
iObserver.OnParseCompletedL( aErrorCode, EOnIgnorableWhiteSpace );
|
|
683 |
}
|
|
684 |
}
|
|
685 |
// -----------------------------------------------------------------------------
|
|
686 |
// CXmlHandler::OnSkippedEntityL
|
|
687 |
// This method is a notification of a skipped entity. If the parser encounters an
|
|
688 |
// external entity it does not need to expand it - it can return the entity as aName
|
|
689 |
// for the client to deal with.
|
|
690 |
// -----------------------------------------------------------------------------
|
|
691 |
//
|
|
692 |
void CXmlHandler::OnSkippedEntityL( const RString& /*aName*/,
|
|
693 |
TInt aErrorCode )
|
|
694 |
{
|
|
695 |
if ( KErrNone == aErrorCode )
|
|
696 |
{
|
|
697 |
}
|
|
698 |
else
|
|
699 |
{
|
|
700 |
iObserver.OnParseCompletedL( aErrorCode, EOnSkippedEntity );
|
|
701 |
}
|
|
702 |
}
|
|
703 |
|
|
704 |
// -----------------------------------------------------------------------------
|
|
705 |
// CXmlHandler::OnProcessingInstructionL
|
|
706 |
// This method is a receive notification of a processing instruction.
|
|
707 |
// -----------------------------------------------------------------------------
|
|
708 |
//
|
|
709 |
|
|
710 |
void CXmlHandler::OnProcessingInstructionL( const TDesC8& /*aTarget*/,
|
|
711 |
const TDesC8& /*aData*/, TInt aErrorCode )
|
|
712 |
{
|
|
713 |
if ( KErrNone == aErrorCode )
|
|
714 |
{
|
|
715 |
}
|
|
716 |
else
|
|
717 |
{
|
|
718 |
iObserver.OnParseCompletedL( aErrorCode, EOnProcessingInstruction );
|
|
719 |
}
|
|
720 |
}
|
|
721 |
|
|
722 |
// -----------------------------------------------------------------------------
|
|
723 |
// CXmlHandler::OnError
|
|
724 |
// This method indicates an error has occurred.
|
|
725 |
// -----------------------------------------------------------------------------
|
|
726 |
//
|
|
727 |
void CXmlHandler::OnError( TInt aErrorCode )
|
|
728 |
{
|
|
729 |
_LIT( KErrorMessage, "*** OnError ***\f" );
|
|
730 |
TRAPD(error, AppendTextL( KErrorMessage ));
|
|
731 |
|
|
732 |
iAction = NULL;
|
|
733 |
//reset the flag iLoopExists
|
|
734 |
for(TInt i = iActionList.Count() - 1; i >= iActionListIndex; i--)
|
|
735 |
{
|
|
736 |
CAction *action = iActionList.operator [](iActionListIndex);
|
|
737 |
if(action)
|
|
738 |
{
|
|
739 |
delete action;
|
|
740 |
action = NULL;
|
|
741 |
}
|
|
742 |
iActionList.Remove(iActionListIndex);
|
|
743 |
}
|
|
744 |
TRAPD(err, iObserver.OnParseCompletedL( aErrorCode,EOnError ));
|
|
745 |
}
|
|
746 |
|
|
747 |
// -----------------------------------------------------------------------------
|
|
748 |
// CXmlHandler::OnError
|
|
749 |
// This method obtains the interface matching the specified uid.
|
|
750 |
// -----------------------------------------------------------------------------
|
|
751 |
//
|
|
752 |
|
|
753 |
TAny* CXmlHandler::GetExtendedInterface( const TInt32 /*aUid*/ )
|
|
754 |
{
|
|
755 |
return NULL;
|
|
756 |
}
|
|
757 |
|
|
758 |
// -----------------------------------------------------------------------------
|
|
759 |
// CXmlHandler::AppendTextL
|
|
760 |
// Function to expand the actual buffer size
|
|
761 |
// -----------------------------------------------------------------------------
|
|
762 |
//
|
|
763 |
|
|
764 |
void CXmlHandler::AppendTextL( const TDesC& aText )
|
|
765 |
{
|
|
766 |
TPtr displayResultPtr( iDisplayResult->Des() );
|
|
767 |
if ( displayResultPtr.Length() + aText.Length() > displayResultPtr.MaxLength() )
|
|
768 |
{
|
|
769 |
TRAPD(err, iDisplayResult = iDisplayResult->ReAllocL( displayResultPtr.MaxLength()
|
|
770 |
+ KBuffer1024 ));
|
|
771 |
displayResultPtr.Set( iDisplayResult->Des() );
|
|
772 |
}
|
|
773 |
displayResultPtr.Append( aText );
|
|
774 |
}
|
|
775 |
|
|
776 |
// -----------------------------------------------------------------------------
|
|
777 |
// CAction::~CAction
|
|
778 |
// Destructor for the CAction class
|
|
779 |
// -----------------------------------------------------------------------------
|
|
780 |
//
|
|
781 |
CAction::~CAction()
|
|
782 |
{
|
|
783 |
delete iParams;
|
|
784 |
iParams=NULL;
|
|
785 |
delete iPrintLog;
|
|
786 |
iPrintLog = NULL;
|
|
787 |
delete iScreenshotTag;
|
|
788 |
iScreenshotTag = NULL;
|
|
789 |
iKeys.Close();
|
|
790 |
}
|
|
791 |
// End of File
|