|
1 /* |
|
2 * Copyright (c) 2005-2007 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: Parser class for Voice Commands XML |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef VCXMLPARSER_H |
|
20 #define VCXMLPARSER_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32base.h> |
|
24 #include <contenthandler.h> |
|
25 #include <parser.h> |
|
26 |
|
27 // DATA TYPES |
|
28 |
|
29 // Enumeration that is used when saving information |
|
30 // of last found xml tag |
|
31 enum TVcXmlTagNesting |
|
32 { |
|
33 EXmlStarted = 0, |
|
34 EXmlDocument, |
|
35 EXmlFolder, |
|
36 EXmlVCommand, |
|
37 EXmlSpoken, |
|
38 EXmlWritten, |
|
39 EXmlExecutes, |
|
40 EXmlCmdlineparams, |
|
41 EXmlIcon, |
|
42 EXmlTooltip |
|
43 }; |
|
44 |
|
45 // FORWARD DECLARATIONS |
|
46 class CVcResource; |
|
47 |
|
48 // CLASS DECLARATION |
|
49 |
|
50 /** |
|
51 * Observer mixin class for Voice Commands XML parser |
|
52 * |
|
53 * @lib nssvcommandmanager.exe |
|
54 * |
|
55 */ |
|
56 NONSHARABLE_CLASS( MVcXmlParserObserver ) |
|
57 { |
|
58 public: // New functions |
|
59 |
|
60 /** |
|
61 * Callback when voice command data has been completely resolved. |
|
62 * |
|
63 * @param aWrittenText Voice Command text in written form |
|
64 * @param aSpokenText Voice Command text in spoken form |
|
65 * @param aTooltipText Tooltip text |
|
66 * @param aFolder Folder where Voice Command should be placed |
|
67 * in the UI |
|
68 * @param aFolderTitle String which is used in folder title pane |
|
69 * @param aParameters Command line parameters for the application |
|
70 * which is started |
|
71 * @param aIcon Icon which is used when showing the voice command |
|
72 * @param aAppId UID of the application which will be started |
|
73 * @param aAppName Name of the application which will be started |
|
74 * @param aStartImmediately ETrue if no TTS verification is needed when |
|
75 * command has been recognized |
|
76 * @param aUserCanModify ETrue if user can modify the command |
|
77 * @param aFolderIconFile Full path to the MBM file where to get the folder icon from |
|
78 * or KNullDesC if not defined |
|
79 * @param aFolderIconIndex Index of the folder icon in the aFolderIconFile. |
|
80 * or -1 if not defined |
|
81 */ |
|
82 virtual void MvcxpoVoiceCommandFound( const TDesC& aWrittenText, |
|
83 const TDesC& aSpokenText, |
|
84 const TDesC& aTooltipText, |
|
85 const TDesC& aFolder, |
|
86 const TDesC& aFolderTitle, |
|
87 const TDesC& aParameters, |
|
88 TUid aIcon, |
|
89 TUid aAppId, |
|
90 const TDesC& aAppName, |
|
91 TBool aStartImmediately, |
|
92 TBool aUserCanModify, |
|
93 const TDesC& aFolderIconFile, |
|
94 TInt aFolderIconIndex |
|
95 ) = 0; |
|
96 |
|
97 }; |
|
98 |
|
99 |
|
100 /** |
|
101 * Parser class for Voice Commands XML |
|
102 * |
|
103 * @lib nssvcommandmanager.exe |
|
104 * |
|
105 */ |
|
106 NONSHARABLE_CLASS( CVcXmlParser ) : public CBase, public Xml::MContentHandler |
|
107 { |
|
108 public: // Constructors and destructor |
|
109 |
|
110 /** |
|
111 * Two-phased constructor. |
|
112 */ |
|
113 static CVcXmlParser* NewL( RFs& aRFs, MVcXmlParserObserver& aObserver ); |
|
114 |
|
115 /** |
|
116 * Destructor. |
|
117 */ |
|
118 virtual ~CVcXmlParser(); |
|
119 |
|
120 public: // New functions |
|
121 |
|
122 /** |
|
123 * Parses one XML file |
|
124 * |
|
125 * @param aFileName XML file name |
|
126 */ |
|
127 void ParseFileL( const TFileName& aFileName ); |
|
128 |
|
129 |
|
130 |
|
131 public: // From Xml::MContentHandler |
|
132 |
|
133 /** |
|
134 This method is a callback to indicate the start of the document. |
|
135 @param aDocParam Specifies the various parameters of the document. |
|
136 @param aDocParam.iCharacterSetName The character encoding of the document. |
|
137 @param aErrorCode is the error code. |
|
138 If this is not KErrNone then special action may be required. |
|
139 */ |
|
140 void OnStartDocumentL( const Xml::RDocumentParameters& aDocParam, |
|
141 TInt aErrorCode ); |
|
142 |
|
143 /** |
|
144 This method is a callback to indicate the end of the document. |
|
145 @param aErrorCode is the error code. |
|
146 If this is not KErrNone then special action may be required. |
|
147 */ |
|
148 void OnEndDocumentL( TInt aErrorCode ); |
|
149 |
|
150 /** |
|
151 This method is a callback to indicate an element has been parsed. |
|
152 @param aElement is a handle to the element's details. |
|
153 @param aAttributes contains the attributes for the element. |
|
154 @param aErrorCode is the error code. |
|
155 If this is not KErrNone then special action may be required. |
|
156 */ |
|
157 void OnStartElementL( const Xml::RTagInfo& aElement, |
|
158 const Xml::RAttributeArray& aAttributes, |
|
159 TInt aErrorCode ); |
|
160 |
|
161 /** |
|
162 This method is a callback to indicate the end of the element has been reached. |
|
163 @param aElement is a handle to the element's details. |
|
164 @param aErrorCode is the error code. |
|
165 If this is not KErrNone then special action may be required. |
|
166 */ |
|
167 void OnEndElementL( const Xml::RTagInfo& aElement, TInt aErrorCode ); |
|
168 |
|
169 /** |
|
170 This method is a callback that sends the content of the element. |
|
171 Not all the content may be returned in one go. The data may be sent in chunks. |
|
172 When an OnEndElementL is received this means there is no more content to be sent. |
|
173 @param aBytes is the raw content data for the element. |
|
174 The client is responsible for converting the data to the |
|
175 required character set if necessary. |
|
176 In some instances the content may be binary and must not be converted. |
|
177 @param aErrorCode is the error code. |
|
178 If this is not KErrNone then special action may be required. |
|
179 */ |
|
180 void OnContentL( const TDesC8& aBytes, TInt aErrorCode ); |
|
181 |
|
182 /** |
|
183 This method is a notification of the beginning of the scope of a prefix-URI Namespace mapping. |
|
184 This method is always called before the corresponding OnStartElementL method. |
|
185 @param aPrefix is the Namespace prefix being declared. |
|
186 @param aUri is the Namespace URI the prefix is mapped to. |
|
187 @param aErrorCode is the error code. |
|
188 If this is not KErrNone then special action may be required. |
|
189 */ |
|
190 void OnStartPrefixMappingL( const RString& aPrefix, |
|
191 const RString& aUri, |
|
192 TInt aErrorCode ); |
|
193 |
|
194 /** |
|
195 This method is a notification of the end of the scope of a prefix-URI mapping. |
|
196 This method is called after the corresponding DoEndElementL method. |
|
197 @param aPrefix is the Namespace prefix that was mapped. |
|
198 @param aErrorCode is the error code. |
|
199 If this is not KErrNone then special action may be required. |
|
200 */ |
|
201 void OnEndPrefixMappingL( const RString& aPrefix, TInt aErrorCode ); |
|
202 |
|
203 /** |
|
204 This method is a notification of ignorable whitespace in element content. |
|
205 @param aBytes are the ignored bytes from the document being parsed. |
|
206 @param aErrorCode is the error code. |
|
207 If this is not KErrNone then special action may be required. |
|
208 */ |
|
209 void OnIgnorableWhiteSpaceL( const TDesC8& aBytes, TInt aErrorCode ); |
|
210 |
|
211 /** |
|
212 This method is a notification of a skipped entity. If the parser encounters an |
|
213 external entity it does not need to expand it - it can return the entity as aName |
|
214 for the client to deal with. |
|
215 @param aName is the name of the skipped entity. |
|
216 @param aErrorCode is the error code. |
|
217 If this is not KErrNone then special action may be required. |
|
218 */ |
|
219 void OnSkippedEntityL( const RString& aName, TInt aErrorCode ); |
|
220 |
|
221 /** |
|
222 This method is a receive notification of a processing instruction. |
|
223 @param aTarget is the processing instruction target. |
|
224 @param aData is the processing instruction data. If empty none was supplied. |
|
225 @param aErrorCode is the error code. |
|
226 If this is not KErrNone then special action may be required. |
|
227 */ |
|
228 void OnProcessingInstructionL( const TDesC8& aTarget, |
|
229 const TDesC8& aData, |
|
230 TInt aErrorCode ); |
|
231 |
|
232 /** |
|
233 This method indicates an error has occurred. |
|
234 @param aError is the error code |
|
235 */ |
|
236 void OnError( TInt aErrorCode ); |
|
237 |
|
238 /** |
|
239 This method obtains the interface matching the specified uid. |
|
240 @return 0 if no interface matching the uid is found. |
|
241 Otherwise, the this pointer cast to that interface. |
|
242 @param aUid the uid identifying the required interface. |
|
243 */ |
|
244 TAny* GetExtendedInterface( const TInt32 aUid ); |
|
245 |
|
246 |
|
247 private: |
|
248 |
|
249 /** |
|
250 * C++ default constructor. |
|
251 */ |
|
252 CVcXmlParser( RFs& aRFs, MVcXmlParserObserver& aObserver ); |
|
253 |
|
254 /** |
|
255 * By default Symbian 2nd phase constructor is private. |
|
256 */ |
|
257 void ConstructL(); |
|
258 |
|
259 /** |
|
260 * Checks if attribute value equals to the expected. If no value is given, just |
|
261 * checks that the attribute exists. |
|
262 * |
|
263 * @param aAttributes List of attributes |
|
264 * @param aAttribute Name of the attribute which is searched |
|
265 * @param aValue Needed value. |
|
266 * @return ETrue if attribute was found, EFalse otherwise |
|
267 */ |
|
268 TBool CheckAttributeL( const Xml::RAttributeArray& aAttributes, |
|
269 const TDesC8& aAttribute, const TDesC8& aValue = KNullDesC8 ); |
|
270 |
|
271 |
|
272 /** |
|
273 * Resolves content of <nssvcommands> element. |
|
274 * |
|
275 * @param aName Element name |
|
276 * @param aAttributes Attribute list |
|
277 * @return ETrue if document tag was resolved |
|
278 */ |
|
279 TBool ResolveDocumentTagL( const TDesC8& aName, |
|
280 const Xml::RAttributeArray& aAttributes ); |
|
281 |
|
282 /** |
|
283 * Resolves content of <vcommandfolder> element. |
|
284 * |
|
285 * @param aName Element name |
|
286 * @param aAttributes Attribute list |
|
287 * @return ETrue if folder tag was resolved |
|
288 */ |
|
289 TBool ResolveFolderTagL( const TDesC8& aName, |
|
290 const Xml::RAttributeArray& aAttributes ); |
|
291 |
|
292 /** |
|
293 * Resolves content of <vcommand> element. |
|
294 * |
|
295 * @param aName Element name |
|
296 * @param aAttributes Attribute list |
|
297 * @return ETrue if vcommand tag was resolved |
|
298 */ |
|
299 TBool ResolveVCommandTagL( const TDesC8& aName, |
|
300 const Xml::RAttributeArray& aAttributes ); |
|
301 |
|
302 /** |
|
303 * Resolves content of <spoken> element. |
|
304 * |
|
305 * @param aName Element name |
|
306 * @param aAttributes Attribute list |
|
307 * @return ETrue if spoken tag was resolved |
|
308 */ |
|
309 TBool ResolveSpokenTagL( const TDesC8& aName, |
|
310 const Xml::RAttributeArray& aAttributes ); |
|
311 |
|
312 /** |
|
313 * Resolves content of <written> element. |
|
314 * |
|
315 * @param aName Element name |
|
316 * @param aAttributes Attribute list |
|
317 * @return ETrue if written tag was resolved |
|
318 */ |
|
319 TBool ResolveWrittenTagL( const TDesC8& aName, |
|
320 const Xml::RAttributeArray& aAttributes ); |
|
321 |
|
322 /** |
|
323 * Resolves content of <tooltip> element. |
|
324 * |
|
325 * @param aName Element name |
|
326 * @param aAttributes Attribute list |
|
327 * @return Error code |
|
328 */ |
|
329 TBool ResolveTooltipTagL( const TDesC8& aName, |
|
330 const Xml::RAttributeArray& aAttributes ); |
|
331 |
|
332 /** |
|
333 * Resolves content of <executes> element. |
|
334 * |
|
335 * @param aName Element name |
|
336 * @param aAttributes Attribute list |
|
337 * @return Error code |
|
338 */ |
|
339 TBool ResolveExecutesTagL( const TDesC8& aName, |
|
340 const Xml::RAttributeArray& aAttributes ); |
|
341 |
|
342 /** |
|
343 * Resolves content of <cmdlineparams> element. |
|
344 * |
|
345 * @param aName Element name |
|
346 * @param aAttributes Attribute list |
|
347 * @return ETrue if commandline parameters were found correctly |
|
348 */ |
|
349 TBool ResolveCmdlineparamsTag( const TDesC8& aName, |
|
350 const Xml::RAttributeArray& aAttributes ); |
|
351 |
|
352 /** |
|
353 * Resolves content of <icon> element. |
|
354 * |
|
355 * @param aName Element name |
|
356 * @param aAttributes Attribute list |
|
357 * @return ETrue if icon element was found |
|
358 */ |
|
359 TBool ResolveIconTagL( const TDesC8& aName, |
|
360 const Xml::RAttributeArray& aAttributes ); |
|
361 |
|
362 /** |
|
363 * Destroys the data of one voice command folder. |
|
364 */ |
|
365 void ResetVCommandFolder(); |
|
366 |
|
367 /** |
|
368 * Destroys the data of one voice command. |
|
369 */ |
|
370 void ResetVCommandInfo(); |
|
371 |
|
372 /** |
|
373 * Checks that all mandatory data is found for one voice command. |
|
374 */ |
|
375 void CheckVoiceCommmandData(); |
|
376 |
|
377 /** |
|
378 * Reads localized string from loc file based on locindex attribute |
|
379 * |
|
380 * @param aAttributes Attribute list |
|
381 * @param aAttributeName Name of the loc index attribute |
|
382 * @return Error code |
|
383 */ |
|
384 TBool GetLocalizedStringL( const Xml::RAttributeArray& aAttributes, |
|
385 const TDesC8& aAttributeName ); |
|
386 |
|
387 /** |
|
388 * Reads uid attribute and constructs TUid |
|
389 * |
|
390 * @params aAttributes List of XML attributes |
|
391 * @return Parsed UID |
|
392 */ |
|
393 TUid ResolveUidL( const Xml::RAttributeArray& aAttributes ); |
|
394 |
|
395 /** |
|
396 * Reads exe attribute and constructs exe file name |
|
397 * |
|
398 * @params aAttributes List of XML attributes |
|
399 * @return Error code |
|
400 */ |
|
401 TBool ResolveExeL( const Xml::RAttributeArray& aAttributes ); |
|
402 |
|
403 /** |
|
404 * Reads the iconfile attribute and constructs the file name or |
|
405 * sets it to NULL |
|
406 * |
|
407 * @params aAttributes List of XML attributes |
|
408 * @return ETrue if resolved successfully, EFalse otherwise |
|
409 */ |
|
410 TBool ResolveFolderIconFileL( const Xml::RAttributeArray& aAttributes ); |
|
411 |
|
412 /** |
|
413 * Reads the iconindex attribute and stores the index or sets it to 0 |
|
414 * |
|
415 * @params aAttributes List of XML attributes |
|
416 * @return parsed index if any. -1 if there is no icon index |
|
417 */ |
|
418 TInt ResolveFolderIconIndexL( const Xml::RAttributeArray& aAttributes ); |
|
419 |
|
420 /** |
|
421 * Common function to resolve content of all elements which contain localized data. |
|
422 * |
|
423 * @param aName Element name |
|
424 * @param aAttributes Attribute list |
|
425 * @param aExpectedName Expected element name |
|
426 * @param aTagEnum Enum value equal to tag name |
|
427 * @param aAttributeName name of the attribute which contains loc index |
|
428 * @return Error code |
|
429 */ |
|
430 TBool ResolveLocalizedTagL( const TDesC8& aName, const Xml::RAttributeArray& aAttributes, |
|
431 const TDesC8& aExpectedName, TVcXmlTagNesting aTagEnum ); |
|
432 |
|
433 |
|
434 |
|
435 /** |
|
436 * Tries to find matching element name from the attribute list. |
|
437 * |
|
438 * @param aName Element name |
|
439 * @param aAttributes Attribute list |
|
440 * @return Found attribute as a 16-bit descriptor |
|
441 */ |
|
442 const TDesC& Find16ValueL( const TDesC8& aName, |
|
443 const Xml::RAttributeArray& aAttributes ); |
|
444 |
|
445 /** |
|
446 * Tries to find matching element name from the attribute list. |
|
447 * |
|
448 * @param aName Element name |
|
449 * @param aAttributes Attribute list |
|
450 * @return Found attribute as a 8-bit descriptor |
|
451 */ |
|
452 const TDesC8& Find8ValueL( const TDesC8& aName, |
|
453 const Xml::RAttributeArray& aAttributes ); |
|
454 |
|
455 /** |
|
456 * Converts given string to lowercase |
|
457 * |
|
458 * @param aString String to convert |
|
459 * @return Converted string |
|
460 */ |
|
461 HBufC8* ToLowercaseLC( const TDesC8& aString ); |
|
462 |
|
463 /** |
|
464 * Pops the last element from XML stack if aTagName and aExpectedTag are equal |
|
465 * |
|
466 * @param aTagName Tag name which was found in XML file |
|
467 * @param aExpectedTag Tag which was expected |
|
468 */ |
|
469 void PopFromStackIfFoundL( const TDesC8& aTagName, const TDesC8& aExpectedTag ); |
|
470 |
|
471 private: // Data |
|
472 |
|
473 // Callback observer |
|
474 MVcXmlParserObserver& iObserver; |
|
475 |
|
476 // Currently open localization resource file |
|
477 CVcResource* iResource; |
|
478 |
|
479 // String read from localization resource file |
|
480 HBufC* iCurrentLocalizedString; |
|
481 |
|
482 // Stack of XML elements |
|
483 RArray<TVcXmlTagNesting> iXmlNesting; |
|
484 |
|
485 // Data for one Voice Command |
|
486 // Text shown on screen |
|
487 HBufC* iWrittenText; |
|
488 |
|
489 // Text which will be trained, if KNullDesC then iWrittenText will be trained |
|
490 HBufC* iSpokenText; |
|
491 |
|
492 // Icon |
|
493 TUid iIcon; |
|
494 |
|
495 // Text of the tooltip |
|
496 HBufC* iTooltipText; |
|
497 |
|
498 // Folder name, if it does not exist, then it will be created |
|
499 // If NULL then "root" will be used |
|
500 HBufC* iFolder; |
|
501 |
|
502 // Title pane text for folder |
|
503 HBufC* iFolderTitle; |
|
504 |
|
505 HBufC* iFolderIconFile; |
|
506 |
|
507 TInt iFolderIconIndex; |
|
508 |
|
509 // UID of the application which will be started when this voice command has been recognized |
|
510 TUid iAppId; |
|
511 |
|
512 // Name of the application which will be started when this voice command has been recognized |
|
513 HBufC* iAppName; |
|
514 |
|
515 // Command line parameters for the application which will be started |
|
516 HBufC* iParameters; |
|
517 HBufC8* iParameters8; |
|
518 |
|
519 // TTS feedback & adaptation of the recognition result on/off |
|
520 TBool iStartImmediately; |
|
521 |
|
522 // Can user modify? |
|
523 TBool iUserCanModify; |
|
524 |
|
525 // Value for attribute |
|
526 HBufC* iAttributeValue; |
|
527 |
|
528 // XML Parser |
|
529 Xml::CParser* iParser; |
|
530 |
|
531 // File system handle |
|
532 RFs& iRFs; |
|
533 }; |
|
534 |
|
535 #endif // VCXMLPARSER_H |
|
536 |
|
537 // End of File |