|
1 /* |
|
2 * Copyright (c) 2002-2004 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: Visitor class to modify DOM node element's data |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "xndomvisitor.h" |
|
22 #include "xnliteral.h" |
|
23 #include "xndomlist.h" |
|
24 #include "xndomproperty.h" |
|
25 #include "xndomstringpool.h" |
|
26 #include <ecom/ecom.h> |
|
27 |
|
28 // CONSTANTS |
|
29 _LIT8(KNS, "inheritpropertyvisitor"); |
|
30 |
|
31 //Function declarations |
|
32 LOCAL_C void SetPropertiesL( const TXnPropertyProxy aTable[], TInt aCount, TAny* aData ); |
|
33 LOCAL_C void SetCommonPropertiesL( TAny* aData ); |
|
34 LOCAL_C void SetElementWithTextPropertiesL( TAny* aData ); |
|
35 LOCAL_C void SetTextElementPropertiesL( TAny* aData ); |
|
36 LOCAL_C void SetGridAndListPropertiesL( TAny* aData ); |
|
37 LOCAL_C void SetDataGridAndGridPropertiesL( TAny* aData ); |
|
38 LOCAL_C void SetViewsAndViewPropertiesL( TAny* aData ); |
|
39 LOCAL_C void SetViewPropertiesL( TAny* aData ); |
|
40 |
|
41 const TXnElementVisitor KXnElementVisitorTable[]= |
|
42 { |
|
43 { (const void*)&KProperty, NULL, EEmpty}, |
|
44 { (const void*)&KXmluiml, NULL, EEmpty}, |
|
45 { (const void*)&KInclude, NULL, EEmpty}, |
|
46 { (const void*)&KViews, NULL, EEmpty}, |
|
47 { (const void*)&KView, &SetViewPropertiesL, EEmpty}, |
|
48 { (const void*)&KPanes, &SetCommonPropertiesL, EEmpty}, |
|
49 { (const void*)&KStatusPane, &SetCommonPropertiesL, EEmpty}, |
|
50 { (const void*)&KMainPane, &SetCommonPropertiesL, EEmpty}, |
|
51 { (const void*)&KControlPane, &SetCommonPropertiesL, EEmpty}, |
|
52 { (const void*)&KDialogs, &SetCommonPropertiesL, EEmpty}, |
|
53 { (const void*)&KDialog, &SetCommonPropertiesL, EEmpty}, |
|
54 { (const void*)&KNote, &SetTextElementPropertiesL, EEmpty}, |
|
55 { (const void*)&KUiDefinition, NULL, EEmpty}, |
|
56 { (const void*)&KApplication, NULL, EEmpty}, |
|
57 { (const void*)&KDesc, NULL, EPCData}, |
|
58 { (const void*)&KButton, &SetTextElementPropertiesL, EEmpty}, |
|
59 { (const void*)&KGrid, &SetDataGridAndGridPropertiesL, EEmpty}, |
|
60 { (const void*)&KListItem, &SetElementWithTextPropertiesL, EEmpty}, |
|
61 { (const void*)&KDataGrid, &SetDataGridAndGridPropertiesL, EEmpty}, |
|
62 { (const void*)&KGridCellTemplate, &SetCommonPropertiesL, EEmpty}, |
|
63 { (const void*)&KList, &SetGridAndListPropertiesL, EEmpty}, |
|
64 { (const void*)&KDataList, &SetGridAndListPropertiesL, EEmpty}, |
|
65 { (const void*)&KListRowTemplate, &SetCommonPropertiesL, EEmpty}, |
|
66 { (const void*)&KMenuBar, NULL, EEmpty}, |
|
67 { (const void*)&KMenu, NULL, EEmpty}, |
|
68 { (const void*)&KMenuItem, NULL, EEmpty}, |
|
69 { (const void*)&KText, &SetTextElementPropertiesL, EPCData}, |
|
70 { (const void*)&KImage, &SetCommonPropertiesL, EEmpty}, |
|
71 { (const void*)&KEditor, &SetElementWithTextPropertiesL, EEmpty}, |
|
72 { (const void*)&KMarquee, &SetElementWithTextPropertiesL, EPCData}, |
|
73 { (const void*)&KNewsticker, &SetElementWithTextPropertiesL, EPCData}, |
|
74 |
|
75 { (const void*)&KObject, NULL, EPCData}, |
|
76 { (const void*)&KParam, NULL, EEmpty}, |
|
77 { (const void*)&KTooltip, &SetElementWithTextPropertiesL, EEmpty}, |
|
78 |
|
79 { (const void*)&KBox, &SetCommonPropertiesL, EEmpty}, |
|
80 { (const void*)&KAction, NULL, EEmpty}, |
|
81 { (const void*)&KTrigger, NULL, EEmpty}, |
|
82 { (const void*)&KEvent, NULL, EEmpty} |
|
83 }; |
|
84 |
|
85 // ============================ LOCAL FUNCTIONS =============================== |
|
86 // ----------------------------------------------------------------------------- |
|
87 // SetPropertiesL Set properties which can inherit and doesn't exist yet. |
|
88 // Returns: On return proeprty list contains properties which can inherit |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 LOCAL_C void SetPropertiesL( |
|
92 const TXnPropertyProxy aTable[], |
|
93 TInt aItemCount, |
|
94 TAny* aData ) |
|
95 { |
|
96 CXnDomList* propertyList = reinterpret_cast<CXnDomList*>( aData ); |
|
97 CXnDomStringPool& stringPool = propertyList->StringPool(); |
|
98 |
|
99 for ( TInt i=0; i<aItemCount; i++ ) |
|
100 { |
|
101 CXnDomProperty* property = NULL; |
|
102 const TDesC8* name = |
|
103 reinterpret_cast<const TDesC8*>( aTable[i].iName ); |
|
104 |
|
105 CXnDomProperty* foundProperty = |
|
106 static_cast<CXnDomProperty*>( propertyList->FindByName( *name ) ); |
|
107 if ( aTable[i].iInherit ) |
|
108 { |
|
109 if (!foundProperty) |
|
110 { |
|
111 property = CXnDomProperty::NewL( *name, stringPool ); |
|
112 property->SetInherited( aTable[i].iInherit ); |
|
113 CleanupStack::PushL( property ); |
|
114 propertyList->AddItemL( property ); |
|
115 CleanupStack::Pop( property ); |
|
116 } |
|
117 else |
|
118 { |
|
119 foundProperty->SetInherited( aTable[i].iInherit ); |
|
120 } |
|
121 } |
|
122 } |
|
123 } |
|
124 |
|
125 LOCAL_C void SetCommonPropertiesL( TAny* aData ) |
|
126 { |
|
127 TInt count( sizeof (KXnCommonPropertyTable) / sizeof(TXnPropertyProxy) ); |
|
128 SetPropertiesL( KXnCommonPropertyTable, count, aData ); |
|
129 } |
|
130 |
|
131 LOCAL_C void SetElementWithTextPropertiesL( TAny* aData ) |
|
132 { |
|
133 SetCommonPropertiesL( aData ); |
|
134 TInt count( sizeof (KXnElementWithTextPropertyTable) / sizeof(TXnPropertyProxy) ); |
|
135 SetPropertiesL( KXnElementWithTextPropertyTable, count, aData ); |
|
136 } |
|
137 |
|
138 LOCAL_C void SetTextElementPropertiesL( TAny* aData ) |
|
139 { |
|
140 SetElementWithTextPropertiesL( aData ); |
|
141 TInt count( sizeof (KXnTextElementPropertyTable) / sizeof(TXnPropertyProxy) ); |
|
142 SetPropertiesL( KXnTextElementPropertyTable, count, aData ); |
|
143 } |
|
144 |
|
145 LOCAL_C void SetGridAndListPropertiesL( TAny* aData ) |
|
146 { |
|
147 SetCommonPropertiesL( aData ); |
|
148 TInt count( sizeof (KXnGridAndListPropertyTable) / sizeof(TXnPropertyProxy) ); |
|
149 SetPropertiesL( KXnGridAndListPropertyTable, count, aData ); |
|
150 } |
|
151 |
|
152 LOCAL_C void SetDataGridAndGridPropertiesL( TAny* aData ) |
|
153 { |
|
154 SetGridAndListPropertiesL( aData ); |
|
155 TInt count( sizeof (KXnDataGridAndGridPropertyTable) / sizeof(TXnPropertyProxy) ); |
|
156 SetPropertiesL( KXnDataGridAndGridPropertyTable, count, aData ); |
|
157 } |
|
158 |
|
159 |
|
160 LOCAL_C void SetViewsAndViewPropertiesL( TAny* aData ) |
|
161 { |
|
162 SetCommonPropertiesL( aData ); |
|
163 TInt count( sizeof (KXnViewsAndViewPropertyTable) / sizeof(TXnPropertyProxy) ); |
|
164 SetPropertiesL( KXnViewsAndViewPropertyTable, count, aData ); |
|
165 } |
|
166 |
|
167 LOCAL_C void SetViewPropertiesL( TAny* aData ) |
|
168 { |
|
169 SetViewsAndViewPropertiesL( aData ); |
|
170 TInt count( sizeof (KXnViewPropertyTable) / sizeof(TXnPropertyProxy) ); |
|
171 SetPropertiesL( KXnViewPropertyTable, count, aData ); |
|
172 } |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 // ============================ MEMBER FUNCTIONS =============================== |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // CXnDomVisitor::NewL |
|
181 // ----------------------------------------------------------------------------- |
|
182 MXnDomVisitor* CXnDomVisitor::NewL() |
|
183 { |
|
184 return new (ELeave) CXnDomVisitor(); |
|
185 } |
|
186 |
|
187 // ----------------------------------------------------------------------------- |
|
188 // CXnDomVisitor::CXnDomVisitor |
|
189 // C++ default constructor can NOT contain any code, that |
|
190 // might leave. |
|
191 // ----------------------------------------------------------------------------- |
|
192 // |
|
193 CXnDomVisitor::CXnDomVisitor() |
|
194 { |
|
195 } |
|
196 |
|
197 |
|
198 // Destructor |
|
199 CXnDomVisitor::~CXnDomVisitor() |
|
200 { |
|
201 REComSession::DestroyedImplementation( iDtorKey ); |
|
202 } |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // CXnDomVisitor::IsVersion |
|
206 // ----------------------------------------------------------------------------- |
|
207 TBool CXnDomVisitor::IsVersion( const TDesC8& aVersion ) |
|
208 { |
|
209 return (KNS().Compare( aVersion ) == 0); |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CXnDomVisitor::ModifyDataL |
|
214 // ----------------------------------------------------------------------------- |
|
215 void CXnDomVisitor::ModifyDataL( CXnDomNode& aNode ) |
|
216 { |
|
217 TInt count( sizeof(KXnElementVisitorTable) / sizeof( TXnElementVisitor ) ); |
|
218 |
|
219 TBool found = EFalse; |
|
220 for ( TInt i=0; i<count && !found; i++ ) |
|
221 { |
|
222 const TDesC8* name = |
|
223 reinterpret_cast<const TDesC8*>( KXnElementVisitorTable[i].iName ); |
|
224 |
|
225 if ( name && name->Compare( aNode.Name() ) == 0) |
|
226 { |
|
227 if ( KXnElementVisitorTable[i].iFuncPtr ) |
|
228 { |
|
229 KXnElementVisitorTable[i].iFuncPtr( &aNode.PropertyList() ); |
|
230 } |
|
231 found = ETrue; |
|
232 } |
|
233 } |
|
234 } |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // CXnDomVisitor::SetElementTypeL |
|
238 // ----------------------------------------------------------------------------- |
|
239 void CXnDomVisitor::SetElementTypeL( CXnDomNode& aNode ) |
|
240 { |
|
241 TInt count( sizeof(KXnElementVisitorTable) / sizeof( TXnElementVisitor ) ); |
|
242 |
|
243 TBool found = EFalse; |
|
244 for ( TInt i=0; i<count && !found; i++ ) |
|
245 { |
|
246 const TDesC8* name = |
|
247 reinterpret_cast<const TDesC8*>( KXnElementVisitorTable[i].iName ); |
|
248 |
|
249 if ( name && name->Compare( aNode.Name() ) == 0) |
|
250 { |
|
251 aNode.SetContentType(KXnElementVisitorTable[i].iContentType); |
|
252 found = ETrue; |
|
253 } |
|
254 } |
|
255 } |
|
256 // ----------------------------------------------------------------------------- |
|
257 // CXnDomVisitor::CreateElementL |
|
258 // ----------------------------------------------------------------------------- |
|
259 void CXnDomVisitor::SetDtorKey( const TUid aDtorKey ) |
|
260 { |
|
261 iDtorKey = aDtorKey; |
|
262 } |
|
263 |
|
264 // ----------------------------------------------------------------------------- |
|
265 // CXnDomVisitor::Release |
|
266 // ----------------------------------------------------------------------------- |
|
267 void CXnDomVisitor::Release() |
|
268 { |
|
269 delete this; |
|
270 } |
|
271 |
|
272 // End of File |