|
1 /* |
|
2 * Copyright (c) 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 "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: CXdmXmlParser |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <hal.h> |
|
23 #include <parser.h> |
|
24 #include <f32file.h> |
|
25 #include <flogger.h> |
|
26 #include <parserfeature.h> |
|
27 #include <XdmNodeAttribute.h> |
|
28 #include <XdmDocument.h> |
|
29 #include <xdmlogwriter.h> |
|
30 #include <XdmDocumentNode.h> |
|
31 #include "XdmXmlParser.h" |
|
32 #include "XmlFormatter.h" |
|
33 #include "XmlParserDefines.h" |
|
34 #include "XdmXmlContentHandler.h" |
|
35 |
|
36 // ---------------------------------------------------------- |
|
37 // CXdmXmlParser::CXdmXmlParser |
|
38 // |
|
39 // ---------------------------------------------------------- |
|
40 // |
|
41 CXdmXmlParser::CXdmXmlParser() : iDumpIndex( 1 ), |
|
42 iXmlDocument( ( TText8* )"", 0, 0 ) |
|
43 { |
|
44 } |
|
45 |
|
46 // ---------------------------------------------------------- |
|
47 // CXdmXmlParser::NewL |
|
48 // |
|
49 // ---------------------------------------------------------- |
|
50 // |
|
51 EXPORT_C CXdmXmlParser* CXdmXmlParser::NewL() |
|
52 { |
|
53 CXdmXmlParser* self = new ( ELeave ) CXdmXmlParser(); |
|
54 CleanupStack::PushL( self ); |
|
55 self->ConstructL(); |
|
56 CleanupStack::Pop(); |
|
57 return self; |
|
58 } |
|
59 |
|
60 // ---------------------------------------------------------- |
|
61 // CXdmXmlParser::ConstructL |
|
62 // |
|
63 // ---------------------------------------------------------- |
|
64 // |
|
65 void CXdmXmlParser::ConstructL() |
|
66 { |
|
67 #ifdef _DEBUG |
|
68 iLogWriter = CXdmLogWriter::NewL( KParserLogFile ); |
|
69 WriteToLog( _L8( "CXdmXmlParser::ConstructL()" ) ); |
|
70 #endif |
|
71 iXmlFormatter = CXmlFormatter::NewL( *this ); |
|
72 iContentHandler = CXdmXmlContentHandler::NewL( *this ); |
|
73 iXmlParser = CParser::NewL( KDefaultMimeType, *iContentHandler ); |
|
74 } |
|
75 |
|
76 // ---------------------------------------------------- |
|
77 // CXdmXmlParser::~CXdmXmlParser |
|
78 // |
|
79 // ---------------------------------------------------- |
|
80 // |
|
81 CXdmXmlParser::~CXdmXmlParser() |
|
82 { |
|
83 #ifdef _DEBUG |
|
84 WriteToLog( _L8( "CXdmXmlParser::~CXdmXmlParser()" ) ); |
|
85 #endif |
|
86 delete iXmlParser; |
|
87 delete iLogWriter; |
|
88 delete iXmlFormatter; |
|
89 delete iContentHandler; |
|
90 } |
|
91 |
|
92 // ---------------------------------------------------------- |
|
93 // CXdmXmlParser::ParseDocumentL |
|
94 // |
|
95 // ---------------------------------------------------------- |
|
96 // |
|
97 EXPORT_C void CXdmXmlParser::ParseDocumentL( CXdmDocument* aDocument, |
|
98 const TDesC8& aXmlDocument ) |
|
99 { |
|
100 #ifdef _DEBUG |
|
101 TInt start = CXdmXmlParser::TimeL(); |
|
102 #endif |
|
103 CXdmDocumentNode* root = aDocument->DocumentRoot(); |
|
104 if( root == NULL ) |
|
105 aDocument->CreateRootL(); |
|
106 User::LeaveIfError( iXmlParser->EnableFeature( EReportNamespaceMapping ) ); |
|
107 iContentHandler->SetTarget( *aDocument ); |
|
108 Xml::ParseL( *iXmlParser, aXmlDocument ); |
|
109 iContentHandler->Reset(); |
|
110 //self->ParseL( aDocument, aXmlDocument ); |
|
111 #ifdef _DEBUG |
|
112 TInt finish = CXdmXmlParser::TimeL(); |
|
113 WriteToLog( _L8( "CXdmXmlParser::ParseDocumentL() - Parsing took %d milliseconds" ), finish - start ); |
|
114 #endif |
|
115 } |
|
116 |
|
117 // ---------------------------------------------------------- |
|
118 // CXdmXmlParser::ParseDocumentL |
|
119 // |
|
120 // ---------------------------------------------------------- |
|
121 // |
|
122 EXPORT_C void CXdmXmlParser::ParseDocumentL( const TDesC8& aXmlDocument, |
|
123 CXdmDocumentNode* aDocumentRoot ) |
|
124 { |
|
125 #ifdef _DEBUG |
|
126 TInt start = CXdmXmlParser::TimeL(); |
|
127 #endif |
|
128 User::LeaveIfError( iXmlParser->EnableFeature( EReportNamespaceMapping ) ); |
|
129 iContentHandler->SetTarget( *aDocumentRoot ); |
|
130 Xml::ParseL( *iXmlParser, aXmlDocument ); |
|
131 iContentHandler->Reset(); |
|
132 //self->ParseL( aXmlDocument, aDocumentRoot ); |
|
133 #ifdef _DEBUG |
|
134 TInt finish = CXdmXmlParser::TimeL(); |
|
135 WriteToLog( _L8( "CXdmXmlParser::ParseDocumentL() - Parsing took %d milliseconds" ), finish - start ); |
|
136 #endif |
|
137 } |
|
138 |
|
139 // ---------------------------------------------------------- |
|
140 // CXdmXmlParser::ParseDocumentL |
|
141 // |
|
142 // ---------------------------------------------------------- |
|
143 // |
|
144 EXPORT_C void CXdmXmlParser::ParseDocumentL( CXdmDocument* aDocument, |
|
145 const TDesC8& aXmlDocument, |
|
146 CXdmDocumentNode* aDocumentSubset ) |
|
147 { |
|
148 #ifdef _DEBUG |
|
149 TInt start = CXdmXmlParser::TimeL(); |
|
150 #endif |
|
151 User::LeaveIfError( iXmlParser->EnableFeature( EReportNamespaces ) ); |
|
152 User::LeaveIfError( iXmlParser->EnableFeature( EReportNamespaceMapping ) ); |
|
153 User::LeaveIfError( iXmlParser->EnableFeature( EReportNamespacePrefixes ) ); |
|
154 iContentHandler->SetTargetL( *aDocument, *aDocumentSubset ); |
|
155 Xml::ParseL( *iXmlParser, aXmlDocument ); |
|
156 iContentHandler->Reset(); |
|
157 //self->ParseL( aDocument, aXmlDocument, aDocumentSubset ); |
|
158 #ifdef _DEBUG |
|
159 TInt finish = CXdmXmlParser::TimeL(); |
|
160 CXdmXmlParser::WriteToLog( _L8( |
|
161 "CXdmXmlParser::ParseDocumentL() - Parsing took %d milliseconds" ), finish - start ); |
|
162 #endif |
|
163 } |
|
164 |
|
165 // ---------------------------------------------------------- |
|
166 // CXdmXmlParser::FormatToXmlLC |
|
167 // |
|
168 // ---------------------------------------------------------- |
|
169 // |
|
170 EXPORT_C HBufC8* CXdmXmlParser::FormatToXmlLC( TBool aIsWholeDocument, |
|
171 const CXdmDocument* aDocument, |
|
172 const CXdmDocumentNode* aRootNode ) |
|
173 { |
|
174 #ifdef _DEBUG |
|
175 WriteToLog( _L8( "CXdmXmlParser::FormatToXmlLC" ) ); |
|
176 TInt start = CXdmXmlParser::TimeL(); |
|
177 #endif |
|
178 HBufC8* ret = iXmlFormatter->FormatLC( aIsWholeDocument, aDocument, aRootNode ); |
|
179 #ifdef _DEBUG |
|
180 DumpDocumentL( ret ); |
|
181 TInt finish = CXdmXmlParser::TimeL(); |
|
182 CXdmXmlParser::WriteToLog( _L8( |
|
183 "CXdmXmlParser::FormatToXmlLC() - Formatting took %d milliseconds" ), finish - start ); |
|
184 #endif |
|
185 return ret; |
|
186 } |
|
187 |
|
188 // ---------------------------------------------------------- |
|
189 // CXdmXmlParser::FormatToXmlLC |
|
190 // |
|
191 // ---------------------------------------------------------- |
|
192 // |
|
193 EXPORT_C HBufC8* CXdmXmlParser::FormatToXmlLC( const TDesC8& aXmlFragment, |
|
194 const CXdmDocument* aDocument, |
|
195 const CXdmDocumentNode* aTargetNode ) |
|
196 { |
|
197 #ifdef _DEBUG |
|
198 TInt start = CXdmXmlParser::TimeL(); |
|
199 #endif |
|
200 //HBufC8* ret = self->FormatLC( aXmlFragment, aDocument, aTargetNode ); |
|
201 HBufC8* ret = iXmlFormatter->FormatLC( aXmlFragment, aDocument, aTargetNode ); |
|
202 #ifdef _DEBUG |
|
203 DumpDocumentL( ret ); |
|
204 TInt finish = CXdmXmlParser::TimeL(); |
|
205 CXdmXmlParser::WriteToLog( _L8( |
|
206 "CXdmXmlParser::FormatToXmlLC() - Formatting took %d milliseconds" ), finish - start ); |
|
207 #endif |
|
208 return ret; |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------- |
|
212 // CXdmXmlParser::FinishParsing |
|
213 // |
|
214 // --------------------------------------------------------- |
|
215 // |
|
216 void CXdmXmlParser::FinishParsingL() |
|
217 { |
|
218 #ifdef _DEBUG |
|
219 WriteToLog( _L8( "CXdmXmlParser::FinishParsing()" ) ); |
|
220 #endif |
|
221 iXmlParser->ParseEndL(); |
|
222 } |
|
223 |
|
224 #ifdef _DEBUG |
|
225 |
|
226 // --------------------------------------------------------- |
|
227 // CXcapPartDocOperation::DumpDocumentL |
|
228 // |
|
229 // --------------------------------------------------------- |
|
230 // |
|
231 void CXdmXmlParser::DumpDocumentL( HBufC8* aDocData ) |
|
232 { |
|
233 if( aDocData ) |
|
234 { |
|
235 RFile file; |
|
236 RFs session; |
|
237 TPtr8 pointer( aDocData->Des() ); |
|
238 _LIT( KXmlFileExtension, ".xml" ); |
|
239 TBuf<128> nameBuf( _L( "C:\\logs\\XDM\\request" ) ); |
|
240 nameBuf.AppendNum( iDumpIndex ); |
|
241 nameBuf.Append( KXmlFileExtension ); |
|
242 User::LeaveIfError( session.Connect() ); |
|
243 TInt error( file.Replace( session, nameBuf, EFileWrite ) ); |
|
244 if( error == KErrNone ) |
|
245 { |
|
246 file.Write( pointer ); |
|
247 file.Close(); |
|
248 iDumpIndex++; |
|
249 } |
|
250 session.Close(); |
|
251 } |
|
252 } |
|
253 |
|
254 // ---------------------------------------------------------- |
|
255 // CXdmXmlParser::TimeL |
|
256 // |
|
257 // ---------------------------------------------------------- |
|
258 // |
|
259 TInt CXdmXmlParser::TimeL() |
|
260 { |
|
261 TInt period = 0; |
|
262 User::LeaveIfError( HAL::Get( HALData::ESystemTickPeriod, period ) ); |
|
263 TInt millisecsPerTick = period / 1000; |
|
264 return User::TickCount() * millisecsPerTick; |
|
265 } |
|
266 |
|
267 // ---------------------------------------------------------- |
|
268 // CXdmXmlParser::WriteToLog |
|
269 // |
|
270 // ---------------------------------------------------------- |
|
271 // |
|
272 void CXdmXmlParser::WriteToLog( TRefByValue<const TDesC8> aFmt,... ) const |
|
273 { |
|
274 VA_LIST list; |
|
275 VA_START( list, aFmt ); |
|
276 TBuf8<KLogBufferMaxSize> buf; |
|
277 buf.FormatList( aFmt, list ); |
|
278 iLogWriter->WriteToLog( buf ); |
|
279 } |
|
280 |
|
281 #endif |
|
282 |
|
283 |
|
284 |
|
285 |