|
1 /* |
|
2 * Copyright (c) 2003-2005 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 the License "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: Wrapper to XML parser interface. Loads the inline and external XML metadata |
|
15 * and populates the service provider metadata information. This class |
|
16 * uses Symbian SAX parser to load the metadata information. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 #ifndef LIW_XMLHANDLER_H |
|
27 #define LIW_XMLHANDLER_H |
|
28 |
|
29 #include <SenXmlReader.h> |
|
30 #include <MSenContentHandlerClient.h> |
|
31 #include <xml/ContentHandler.h> |
|
32 #include <e32capability.h> |
|
33 |
|
34 // CONSTANTS |
|
35 const TInt KMaxBufLen = 255; |
|
36 |
|
37 // MACROS |
|
38 |
|
39 // DATA TYPES |
|
40 |
|
41 // FUNCTION PROTOTYPES |
|
42 |
|
43 // FORWARD DECLARATIONS |
|
44 class CLiwServiceData; |
|
45 class CLiwList; |
|
46 |
|
47 /** |
|
48 * Wrapper class for XML parser. This class is used to parse inline |
|
49 * and file-based external metadata definitions. SAX (Simple API for XML) |
|
50 * parser is used to parse the XML content. |
|
51 * |
|
52 * @lib ServiceHandler.lib |
|
53 * |
|
54 * @see MSenContentHandlerClient |
|
55 * @see CSenXmlReader |
|
56 * @see CLiwServiceData |
|
57 **/ |
|
58 class CLiwXmlHandler : public CBase, public MSenContentHandlerClient |
|
59 { |
|
60 public: |
|
61 |
|
62 /* |
|
63 * Creates and returns an instance of \c CLiwXmlHandler |
|
64 * |
|
65 * @return an instance of \c CLiwXmlHandler |
|
66 */ |
|
67 static CLiwXmlHandler* NewL(); |
|
68 |
|
69 /* |
|
70 * Creates and returns an instance of \c CLiwXmlHandler |
|
71 * Leaves the created instance in the cleanupstack. |
|
72 * |
|
73 * @return an instance of \c CLiwXmlHandler |
|
74 */ |
|
75 static CLiwXmlHandler* NewLC(); |
|
76 |
|
77 /* |
|
78 * Destructor |
|
79 */ |
|
80 virtual ~CLiwXmlHandler(); |
|
81 |
|
82 /** |
|
83 * Receive notification of the beginning of a document. |
|
84 * @return KErrNone or some of the system-wide Symbian error codes. |
|
85 */ |
|
86 virtual TInt StartDocument(); |
|
87 |
|
88 /** |
|
89 * Receive notification of the end of a document. |
|
90 * @return KErrNone or some of the system-wide Symbian error codes. |
|
91 */ |
|
92 virtual TInt EndDocument(); |
|
93 |
|
94 /** |
|
95 * Receive notification of the start of an element. |
|
96 * @return KErrNone or some of the system-wide Symbian error codes. |
|
97 */ |
|
98 virtual TInt StartElement( const TDesC8& /*aURI*/, |
|
99 const TDesC8& /*aLocalName*/, |
|
100 const TDesC8& /*aName*/, |
|
101 const RAttributeArray& /* apAttrs */); |
|
102 |
|
103 /** |
|
104 * Receive notification of the end of an element. |
|
105 * @return KErrNone or some of the system-wide Symbian error codes. |
|
106 */ |
|
107 virtual TInt EndElement( const TDesC8& /*aURI*/, |
|
108 const TDesC8& /*aLocalName*/, |
|
109 const TDesC8& /*aName*/); |
|
110 /** |
|
111 * Receive notification of the character data found in the XML document. |
|
112 * @return KErrNone or some of the system-wide Symbian error codes. |
|
113 */ |
|
114 virtual TInt Characters(const TDesC8& /*aBuf*/, |
|
115 const TInt /*aStart*/, |
|
116 const TInt /*aLength*/); |
|
117 |
|
118 /** |
|
119 * Called when there is an error in parsing. |
|
120 * @return KErrNone or some of the system-wide Symbian error codes. |
|
121 */ |
|
122 inline virtual TInt Error(TInt /*aErrorCode*/); |
|
123 |
|
124 /** |
|
125 * Loads service data from an external file specified |
|
126 * in aFileToParse parameter. |
|
127 * |
|
128 * @param aFileToParse a valid well defined XML file having metadata definition |
|
129 * @param aServiceData service data to be populated with service provider information. |
|
130 * The caller should pass a properly instantiated pointer to CLiwServiceData instance |
|
131 * |
|
132 * @return KErrNone if the loading of service data is successful |
|
133 KSrvDataLoadFailed if the loading of XML file failed |
|
134 */ |
|
135 TInt LoadServiceData(const TDesC& aFileToParse, CLiwServiceData* aServiceData); |
|
136 |
|
137 /** |
|
138 * Loads service data from a XML data buffer. The passed XML data buffer |
|
139 * should be well defined and well formatted valid XML content. |
|
140 * |
|
141 * @param aXmlBuffer a valid well defined and well formatted XML data content |
|
142 * @param aServiceData service data to be populated with service provider information. |
|
143 * The caller should pass a properly instantiated pointer to CLiwServiceData instance |
|
144 * |
|
145 * @return KErrNone if the loading of service data is successful |
|
146 KSrvDataLoadFailed if the loading of XML buffer content failed |
|
147 */ |
|
148 TInt LoadServiceData(const TDesC8& aXmlBuffer, CLiwServiceData* aServiceData); |
|
149 |
|
150 /* |
|
151 * Enumeration IDs corresponding to XML parsing status |
|
152 */ |
|
153 enum TLiwXmlParseStatus |
|
154 { |
|
155 ESrvDataLoadSuccess=0, |
|
156 ESrvDataLoadFailed, //General failures other than below |
|
157 ESrvDataFileNotFnd, |
|
158 ESrvDataInvalidFile, //Parse error |
|
159 ESrvDataCapNotSpecified |
|
160 }; |
|
161 |
|
162 private: |
|
163 |
|
164 //private default constructor |
|
165 CLiwXmlHandler(); |
|
166 |
|
167 //second phase constructor |
|
168 void ConstructL(); |
|
169 |
|
170 //the SAX parser instance |
|
171 CSenXmlReader* iXmlHandler; |
|
172 |
|
173 //the service data instance to be populated with metadata information |
|
174 CLiwServiceData* iServiceData; |
|
175 |
|
176 HBufC8* iBuffer; |
|
177 TBuf8<KMaxBufLen> startBuf; |
|
178 }; |
|
179 |
|
180 #endif |
|
181 |
|
182 // End of File |
|
183 |
|
184 |