|
1 /* |
|
2 * Copyright (c) 2002 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: XML syncml DTD parser |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // ------------------------------------------------------------------------------------------------ |
|
20 // Includes |
|
21 // ------------------------------------------------------------------------------------------------ |
|
22 #include "XMLSyncMLParser.h" |
|
23 #include "WBXMLParserError.h" |
|
24 |
|
25 #include "smlsyncmltags.h" |
|
26 #include "xmlelement.h" |
|
27 #include "smlmetinfdtd.h" |
|
28 #include "smldevinfdtd.h" |
|
29 |
|
30 // ------------------------------------------------------------------------------------------------ |
|
31 // CXMLSyncMLDocHandler |
|
32 // ------------------------------------------------------------------------------------------------ |
|
33 EXPORT_C CXMLSyncMLDocHandler* CXMLSyncMLDocHandler::NewL( MWBXMLSyncMLCallbacks* aCallbacks ) |
|
34 { |
|
35 CXMLSyncMLDocHandler* self = new (ELeave) CXMLSyncMLDocHandler(aCallbacks); |
|
36 CleanupStack::PushL(self); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop(); // self |
|
39 return self; |
|
40 } |
|
41 |
|
42 // ------------------------------------------------------------------------------------------------ |
|
43 EXPORT_C CXMLSyncMLDocHandler::~CXMLSyncMLDocHandler() |
|
44 { |
|
45 if(iCmdStack) |
|
46 { |
|
47 iCmdStack->Reset(); |
|
48 } |
|
49 delete iCmdStack; |
|
50 |
|
51 if(iCleanupStack) |
|
52 { |
|
53 iCleanupStack->Reset(); |
|
54 } |
|
55 delete iCleanupStack; |
|
56 } |
|
57 |
|
58 // ------------------------------------------------------------------------------------------------ |
|
59 void CXMLSyncMLDocHandler::StartDocumentL( TUint8 /*aVersion*/, TInt32 /*aPublicId*/, TUint32 /*aCharset*/ ) |
|
60 { |
|
61 } |
|
62 |
|
63 // ------------------------------------------------------------------------------------------------ |
|
64 void CXMLSyncMLDocHandler::StartDocumentL( TUint8 /*aVersion*/, const TDesC8& /*aPublicIdStr*/, TUint32 /*aCharset*/ ) |
|
65 { |
|
66 } |
|
67 |
|
68 // ------------------------------------------------------------------------------------------------ |
|
69 void CXMLSyncMLDocHandler::EndDocumentL() |
|
70 { |
|
71 } |
|
72 |
|
73 // ------------------------------------------------------------------------------------------------ |
|
74 void CXMLSyncMLDocHandler::StartElementL( TWBXMLTag aTag, const CWBXMLAttributes& /*aAttributes*/ ) |
|
75 { |
|
76 if( iCmdStack->Top() != 0 ) |
|
77 { |
|
78 AddElementL(iCmdStack->Top()->BeginElementL(aTag, TXMLElementParams(iCallbacks))); |
|
79 } |
|
80 else |
|
81 { |
|
82 if( aTag == ESyncML ) |
|
83 { |
|
84 AddElementL(new (ELeave) SmlSyncML_t()); |
|
85 } |
|
86 else |
|
87 { |
|
88 User::Leave(KWBXMLParserErrorInvalidTag); |
|
89 } |
|
90 } |
|
91 } |
|
92 |
|
93 // ------------------------------------------------------------------------------------------------ |
|
94 void CXMLSyncMLDocHandler::AddElementL( CXMLElement* aElement ) |
|
95 { |
|
96 if( aElement ) |
|
97 { |
|
98 iCmdStack->Push(aElement); |
|
99 if( aElement->NeedsCleanup() ) |
|
100 { |
|
101 iCleanupStack->Push(aElement); |
|
102 } |
|
103 } |
|
104 } |
|
105 |
|
106 // ------------------------------------------------------------------------------------------------ |
|
107 void CXMLSyncMLDocHandler::EndElementL( TWBXMLTag aTag ) |
|
108 { |
|
109 if( iCmdStack->Top() != 0 ) |
|
110 { |
|
111 CXMLElement::TAction action = iCmdStack->Top()->EndElementL(iCallbacks, aTag); |
|
112 if( action != CXMLElement::ENone ) |
|
113 { |
|
114 CXMLElement* elem = iCmdStack->Pop(); |
|
115 if( iCleanupStack->Top() == elem ) |
|
116 { |
|
117 iCleanupStack->Pop(); |
|
118 } |
|
119 if( action == CXMLElement::EPopAndDestroy ) |
|
120 { |
|
121 delete elem; |
|
122 } |
|
123 } |
|
124 } |
|
125 } |
|
126 |
|
127 // ------------------------------------------------------------------------------------------------ |
|
128 void CXMLSyncMLDocHandler::CodePageSwitchL( TUint8 aPage ) |
|
129 { |
|
130 switch( aPage ) |
|
131 { |
|
132 case 0x00: |
|
133 { |
|
134 iCmdStack->Pop(); |
|
135 break; |
|
136 } |
|
137 case 0x01: |
|
138 { |
|
139 SmlPcdataPtr_t top = (SmlPcdataPtr_t)iCmdStack->Top(); |
|
140 // If top element already contains content then push it into |
|
141 // command stack, create new otherwise. |
|
142 if( !top->content ) |
|
143 { |
|
144 top->length = 0; |
|
145 top->contentType = SML_PCDATA_EXTENSION; |
|
146 top->extension = SML_EXT_METINF; |
|
147 top->content = new (ELeave) SmlMetInfMetInf_t(); |
|
148 iCmdStack->Push(SmlMetInfMetInfPtr_t(top->content)); |
|
149 } |
|
150 else |
|
151 { |
|
152 iCmdStack->Push(SmlMetInfMetInfPtr_t(top->content)); |
|
153 } |
|
154 break; |
|
155 } |
|
156 case 0x02: |
|
157 { |
|
158 SmlPcdataPtr_t top = (SmlPcdataPtr_t)iCmdStack->Top(); |
|
159 // If top element already contains content then push it into |
|
160 // command stack, create new otherwise. |
|
161 if( !top->content ) |
|
162 { |
|
163 top->length = 0; |
|
164 top->contentType = SML_PCDATA_EXTENSION; |
|
165 top->extension = SML_EXT_DEVINFPROP; |
|
166 top->content = new (ELeave) SmlDevInfCtCap_t(); |
|
167 iCmdStack->Push((SmlDevInfCtCapPtr_t) top->content); |
|
168 } |
|
169 else |
|
170 { |
|
171 iCmdStack->Push((SmlDevInfCtCapPtr_t) top->content); |
|
172 } |
|
173 break; |
|
174 } |
|
175 default: |
|
176 User::Leave( KWBXMLParserErrorInvalidTag ); |
|
177 } |
|
178 } |
|
179 |
|
180 // ------------------------------------------------------------------------------------------------ |
|
181 void CXMLSyncMLDocHandler::CharactersL( const TDesC8& aBuffer ) |
|
182 { |
|
183 if( iCmdStack->Top() != 0 ) |
|
184 { |
|
185 iCmdStack->Top()->SetDataL(aBuffer); |
|
186 } |
|
187 else |
|
188 { |
|
189 User::Leave(KWBXMLParserErrorInvalidTag); |
|
190 } |
|
191 } |
|
192 |
|
193 // ------------------------------------------------------------------------------------------------ |
|
194 void CXMLSyncMLDocHandler::DocumentChangedL() |
|
195 { |
|
196 iCmdStack->Reset(); |
|
197 } |
|
198 |
|
199 // ------------------------------------------------------------------------------------------------ |
|
200 void CXMLSyncMLDocHandler::Ext_IL( TWBXMLTag /*aTag*/, const TDesC8& /*aData*/ ) |
|
201 { |
|
202 } |
|
203 |
|
204 // ------------------------------------------------------------------------------------------------ |
|
205 void CXMLSyncMLDocHandler::Ext_TL( TWBXMLTag /*aTag*/, TUint32 /*aData*/ ) |
|
206 { |
|
207 } |
|
208 |
|
209 // ------------------------------------------------------------------------------------------------ |
|
210 void CXMLSyncMLDocHandler::ExtL( TWBXMLTag /*aTag*/ ) |
|
211 { |
|
212 } |
|
213 |
|
214 // ------------------------------------------------------------------------------------------------ |
|
215 void CXMLSyncMLDocHandler::OpaqueL( const TDesC8& aData ) |
|
216 { |
|
217 CharactersL(aData); |
|
218 } |
|
219 |
|
220 // ------------------------------------------------------------------------------------------------ |
|
221 void CXMLSyncMLDocHandler::ConstructL() |
|
222 { |
|
223 iCmdStack = CNSmlStack<CXMLElement>::NewL(); |
|
224 iCleanupStack = CNSmlStack<CXMLElement>::NewL(); |
|
225 } |
|
226 |
|
227 // ------------------------------------------------------------------------------------------------ |
|
228 CXMLSyncMLDocHandler::CXMLSyncMLDocHandler( MWBXMLSyncMLCallbacks* aCallbacks ) : iCallbacks(aCallbacks) |
|
229 { |
|
230 } |
|
231 |