1 /* |
|
2 * Copyright (c) 2010 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef CREATORSCRIPTPARSER_H_ |
|
22 #define CREATORSCRIPTPARSER_H_ |
|
23 |
|
24 #include <e32base.h> |
|
25 #include <xml/contenthandler.h> |
|
26 #include <xml/parser.h> |
|
27 |
|
28 using namespace Xml; |
|
29 |
|
30 class CCreatorScriptElement; |
|
31 class CCreatorEngine; |
|
32 class CCreatorScriptElementCache; |
|
33 |
|
34 class TCreatorScriptElementInfo |
|
35 { |
|
36 public: |
|
37 enum TElementStatus |
|
38 { |
|
39 EStatusUndefined, // undefined |
|
40 EStatusParsing, // currently being parsed |
|
41 EStatusParsed // parsed |
|
42 }; |
|
43 TCreatorScriptElementInfo() |
|
44 { |
|
45 iStatus = EStatusUndefined; |
|
46 iElement = 0; |
|
47 } |
|
48 TCreatorScriptElementInfo(TElementStatus aStatus, CCreatorScriptElement* aElement) |
|
49 { |
|
50 iStatus = aStatus; |
|
51 iElement = aElement; |
|
52 }; |
|
53 |
|
54 TElementStatus iStatus; |
|
55 CCreatorScriptElement* iElement; |
|
56 }; |
|
57 |
|
58 class CCreatorScriptParser : public CBase, public MContentHandler |
|
59 { |
|
60 public: |
|
61 |
|
62 virtual ~CCreatorScriptParser(); |
|
63 static CCreatorScriptParser* NewL(CCreatorEngine* aEngine); |
|
64 static CCreatorScriptParser* NewLC(CCreatorEngine* aEngine); |
|
65 void ParseL(const TDesC& aFileName); |
|
66 void ParseL(RFile& aFile); |
|
67 |
|
68 TInt GetError() const; |
|
69 |
|
70 private: |
|
71 |
|
72 CCreatorScriptParser(); |
|
73 void ConstructL(CCreatorEngine* aEngine); |
|
74 |
|
75 /** |
|
76 * Converts 8 bit descriptor to 16 bit descriptor |
|
77 * @param aDes 8 bit descriptor to be converted |
|
78 * @return Pointer to the new 16 bit descriptor |
|
79 */ |
|
80 HBufC* Convert8BitTo16BitLC(const TDesC8& aInput); |
|
81 const TCreatorScriptElementInfo& LastElementInfo() const; |
|
82 void GetTextFileMode(RFile& aFile, TInt& aFileSize); |
|
83 |
|
84 |
|
85 public: |
|
86 // From MContentHandler: |
|
87 void OnStartDocumentL(const RDocumentParameters &aDocParam, TInt aErrorCode); |
|
88 void OnEndDocumentL(TInt aErrorCode); |
|
89 void OnStartElementL( const RTagInfo& aElement, |
|
90 const RAttributeArray& aAttributes, |
|
91 TInt aErrorCode); |
|
92 void OnEndElementL(const RTagInfo& aElement, TInt aErrorCode); |
|
93 void OnContentL(const TDesC8& aBytes, TInt aErrorCode); |
|
94 void OnStartPrefixMappingL( const RString& aPrefix, |
|
95 const RString& aUri, |
|
96 TInt aErrorCode); |
|
97 void OnEndPrefixMappingL(const RString& aPrefix, TInt aErrorCode); |
|
98 void OnIgnorableWhiteSpaceL(const TDesC8& aBytes, TInt aErrorCode); |
|
99 void OnSkippedEntityL(const RString& aName, TInt aErrorCode); |
|
100 void OnProcessingInstructionL( const TDesC8& aTarget, |
|
101 const TDesC8& aData, |
|
102 TInt aErrorCode); |
|
103 void OnError(TInt aErrorCode); |
|
104 TAny* GetExtendedInterface(const TInt32 aUid); |
|
105 |
|
106 private: |
|
107 |
|
108 enum TFileFormat |
|
109 { |
|
110 EFormatANSIASCII, |
|
111 EFormatUTF8, |
|
112 EFormatUTF16LE, |
|
113 EFormatUTF16BE |
|
114 }; |
|
115 // XML parser |
|
116 CParser* iParser; |
|
117 |
|
118 /** |
|
119 * Element stack holding the elements that are currently being parsed. |
|
120 */ |
|
121 RArray<TCreatorScriptElementInfo> iElementStack; |
|
122 |
|
123 /** |
|
124 * Cache object containig the elements that are referred in future and thus should |
|
125 * not be deleted after parsing. |
|
126 */ |
|
127 CCreatorScriptElementCache* iElementCache; |
|
128 |
|
129 /** |
|
130 * Pointer to the engine |
|
131 */ |
|
132 CCreatorEngine* iEngine; |
|
133 |
|
134 TCreatorScriptElementInfo iDefaultElement; |
|
135 |
|
136 TFileFormat iScriptTextFormat; |
|
137 TInt iLastError; |
|
138 }; |
|
139 |
|
140 #endif /*CREATORSCRIPTPARSER_H_*/ |
|