|
1 /* |
|
2 * Copyright (c) 2005,2006 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: Primary datatype for the entire Document Object Model. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef XN_DOM_NODE_H |
|
21 #define XN_DOM_NODE_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include <s32strm.h> |
|
26 #include "mxndomlistitem.h" |
|
27 |
|
28 // FORWARD DECLARATIONS |
|
29 enum TContentType |
|
30 { |
|
31 EEmpty = 0, |
|
32 EAny, |
|
33 EPCData |
|
34 }; |
|
35 |
|
36 class CXnDomList; |
|
37 class CXnDomStringPool; |
|
38 class CXnNode; |
|
39 |
|
40 // CLASS DECLARATION |
|
41 |
|
42 /** |
|
43 * @ingroup group_domdocument |
|
44 * Class represents a single node in the document tree. |
|
45 * |
|
46 * @lib xndomdocument.lib |
|
47 * @since Series 60 3.1 |
|
48 */ |
|
49 class CXnDomNode : public CBase, public MXnDomListItem |
|
50 { |
|
51 |
|
52 public: // Constructors and destructor |
|
53 |
|
54 /** |
|
55 * Two-phased constructor. |
|
56 */ |
|
57 static CXnDomNode* NewL( |
|
58 const TDesC8& aName, |
|
59 const TDesC8& aNS, |
|
60 CXnDomStringPool& aStringPool ); |
|
61 |
|
62 /** |
|
63 * Two-phased stream constructor. |
|
64 */ |
|
65 static CXnDomNode* NewL( RReadStream& aStream, CXnDomStringPool& aStringPool ); |
|
66 |
|
67 /** |
|
68 * Destructor. |
|
69 */ |
|
70 virtual ~CXnDomNode(); |
|
71 |
|
72 public: // New functions |
|
73 /** |
|
74 * Makes a clone from this node and it's child nodes. |
|
75 * @since Series 60 3.1 |
|
76 * @param aStringPool. A new string pool. |
|
77 * @return Pointer to a clone node. Caller has the ownership. |
|
78 */ |
|
79 IMPORT_C CXnDomNode* CloneL( CXnDomStringPool& aStringPool ); |
|
80 |
|
81 /** |
|
82 * Makes a clone only from this node. |
|
83 * @since Series 60 3.1 |
|
84 * @param aStringPool. A new string pool. |
|
85 * @return Pointer to a clone node. Caller has the ownership. |
|
86 */ |
|
87 IMPORT_C CXnDomNode* CloneWithoutKidsL( CXnDomStringPool& aStringPool ); |
|
88 |
|
89 /** |
|
90 * Contructs a ref node from this node and its child's. |
|
91 * @since Series 60 3.1 |
|
92 * @return Pointer to a ref node. Caller has the ownership. |
|
93 */ |
|
94 IMPORT_C CXnDomNode* CreateRefNodeL(); |
|
95 |
|
96 /** |
|
97 * Get the namespace of this node. |
|
98 * @since Series 60 3.1 |
|
99 * @return Pointer to the namespace buffer |
|
100 */ |
|
101 IMPORT_C const TDesC8& Namespace(); |
|
102 |
|
103 /** |
|
104 * Node's attributes exist in a list. |
|
105 * @since Series 60 3.1 |
|
106 * @return Reference to a attribute list. |
|
107 */ |
|
108 IMPORT_C CXnDomList& AttributeList()const; |
|
109 |
|
110 /** |
|
111 * Node's properties exist in a list. |
|
112 * @since Series 60 3.1 |
|
113 * @return Reference to a property list. |
|
114 */ |
|
115 IMPORT_C CXnDomList& PropertyList(); |
|
116 |
|
117 /** |
|
118 * Node need to know it's parent. |
|
119 * @since Series 60 3.1 |
|
120 * @param aParent Pointer to this node parent |
|
121 */ |
|
122 IMPORT_C void SetParent( CXnDomNode* aParent ); |
|
123 |
|
124 /** |
|
125 * Node's parent is enquered e.g to traverse the document. |
|
126 * @since Series 60 3.1 |
|
127 * @return Pointer to a parent node |
|
128 */ |
|
129 IMPORT_C CXnDomNode* Parent() const; |
|
130 |
|
131 /** |
|
132 * Node id is for a uiengine use. |
|
133 * @since Series 60 3.1 |
|
134 * @param aNodeId Unique identifier |
|
135 */ |
|
136 IMPORT_C void SetNodeId( const TInt aNodeId ); |
|
137 |
|
138 /** |
|
139 * Get the node unique identifier. |
|
140 * @since Series 60 3.1 |
|
141 * @return Node unique identifier |
|
142 */ |
|
143 IMPORT_C TInt NodeId() const; |
|
144 |
|
145 /** |
|
146 * Get the node unique identifier. |
|
147 * @since Series 60 3.1 |
|
148 * @return Node unique identifier |
|
149 */ |
|
150 IMPORT_C TInt ItemIndex( const MXnDomListItem& aItem )const; |
|
151 |
|
152 /** |
|
153 * Access to child nodes. |
|
154 * @since Series 60 3.1 |
|
155 * @return Pointer to a list of child nodes |
|
156 */ |
|
157 IMPORT_C CXnDomList& ChildNodes(); |
|
158 |
|
159 /** |
|
160 * Child nodes of this node are needed to be able to |
|
161 * traverse the document. |
|
162 * @since Series 60 3.1 |
|
163 * @param aNode Node owns it's childs |
|
164 */ |
|
165 IMPORT_C void AddChildL( CXnDomNode* aNode ); |
|
166 |
|
167 /** |
|
168 * Child nodes of this node are needed to be able to |
|
169 * traverse the document. |
|
170 * @since Series 60 3.1 |
|
171 * @param aNode Node owns it's childs |
|
172 * @param aIndex Index in list where the node is added |
|
173 */ |
|
174 IMPORT_C void AddChildL( CXnDomNode* aNode, TInt aIndex ); |
|
175 |
|
176 /** |
|
177 * Removes node from the child list and frees memory allocated |
|
178 * for a child node and it descendants. |
|
179 * @since Series 60 3.1 |
|
180 * @param aNode Node to be released |
|
181 */ |
|
182 IMPORT_C void DeleteChild( CXnDomNode* aNode ); |
|
183 |
|
184 /** |
|
185 * Replaces a child node with the other node. Memory allocated for |
|
186 * the node is freed. |
|
187 * @since Series 60 3.1 |
|
188 * @param aNode Node to be replaced |
|
189 * @param aNewNode New node |
|
190 */ |
|
191 IMPORT_C void ReplaceChildL( CXnDomNode* aNode, CXnDomNode* aNewNode ); |
|
192 |
|
193 /** |
|
194 * Get the character data |
|
195 * @since Series 60 3.1 |
|
196 * @return Reference to a buffer |
|
197 */ |
|
198 IMPORT_C const TDesC8& PCData(); |
|
199 |
|
200 /** |
|
201 * Append PCData into node. Thus it is possible to have |
|
202 * "<root>a <first/> c <second/> e </root>" PCData. |
|
203 * @since Series 60 3.1 |
|
204 * @param aPCData UTF-8 encoded parsed character data |
|
205 */ |
|
206 IMPORT_C void AppendPCDataL( const TDesC8& aPCData ); |
|
207 |
|
208 /** |
|
209 * Set parsed character data. |
|
210 * @since Series 60 3.1 |
|
211 * @param aPCData UTF-8 encoded parsed character data |
|
212 */ |
|
213 IMPORT_C void SetPCDataL( const TDesC8& aPCData ); |
|
214 |
|
215 /** |
|
216 * Set content type |
|
217 * @since Series 60 3.1 |
|
218 * @return content type |
|
219 */ |
|
220 IMPORT_C const TContentType& ContentType(); |
|
221 |
|
222 /** |
|
223 * Get content type |
|
224 * @since Series 60 3.1 |
|
225 * @param aContentType content type |
|
226 */ |
|
227 IMPORT_C void SetContentType( const TContentType& aContentType ); |
|
228 |
|
229 /** |
|
230 * Recursive function to count all child nodes belonging |
|
231 * to this node. |
|
232 * @since Series 60 3.1 |
|
233 * @return This node and it's all childs count |
|
234 */ |
|
235 IMPORT_C TInt DescendantCount() const; |
|
236 |
|
237 /** |
|
238 * Get reference to the dom's string pool. |
|
239 * @since Series 60 3.1 |
|
240 * @return Reference to string pool |
|
241 */ |
|
242 IMPORT_C CXnDomStringPool& StringPool() const; |
|
243 |
|
244 /** |
|
245 * Mark this node as a reference node. |
|
246 * @since Series 60 3.1 |
|
247 * @param aRefNode ETrue if node is a reference node |
|
248 */ |
|
249 IMPORT_C void SetRefNode( TBool aRefNode=ETrue ); |
|
250 |
|
251 /** |
|
252 * Check if this node is referring to some global node. |
|
253 * @since Series 60 3.1 |
|
254 * @return ETrue if this is a reference node. |
|
255 */ |
|
256 IMPORT_C TBool IsRefNode() const; |
|
257 |
|
258 /** |
|
259 * Deletes attributes when they are not needed anymore. |
|
260 * I.e. UIEngine has copied them into property list. |
|
261 * @since Series 60 3.1 |
|
262 */ |
|
263 IMPORT_C void DeleteAttributeList(); |
|
264 |
|
265 /** |
|
266 * Returns value of given attribute |
|
267 * @param aAttribute Name of the attribute |
|
268 * @since S60 3.1 |
|
269 * @return Value of an attribute |
|
270 */ |
|
271 IMPORT_C const TDesC8& AttributeValue(const TDesC8& aAttribute) const; |
|
272 |
|
273 public: //From MXnDomListItem |
|
274 |
|
275 |
|
276 /** |
|
277 * Documented in CXnDomListItem::Size |
|
278 */ |
|
279 TInt Size() const; |
|
280 |
|
281 /** |
|
282 * Documented in CXnDomListItem::ExternalizeL |
|
283 * NOTE: This function is not implemented yet! |
|
284 */ |
|
285 void ExternalizeL( RWriteStream& aStream ) const; |
|
286 |
|
287 /** |
|
288 * Documented in CXnDomListItem::InternalizeL |
|
289 */ |
|
290 void InternalizeL( RReadStream& aStream ); |
|
291 |
|
292 /** |
|
293 * Similar to InternalizeL, but does not expect dedicated odt document |
|
294 */ |
|
295 void ReadL( RReadStream& aStream ); |
|
296 |
|
297 |
|
298 /** |
|
299 * Documented in CXnDomListItem::Name |
|
300 */ |
|
301 IMPORT_C const TDesC8& Name(); |
|
302 |
|
303 |
|
304 public: |
|
305 |
|
306 /** |
|
307 * Sets pointer to associated layout node |
|
308 * @since S60 3.1 |
|
309 * @param aNode Pointer to associated layout node |
|
310 */ |
|
311 IMPORT_C void SetLayoutNode(CXnNode* aNode); |
|
312 |
|
313 /** |
|
314 * Returns pointer to associated layout node |
|
315 * @since S60 3.1 |
|
316 * @return Pointer to associated layout node |
|
317 */ |
|
318 IMPORT_C CXnNode* LayoutNode(); |
|
319 |
|
320 /** |
|
321 * Set the namespace for this node. |
|
322 * @since Series 60 3.1 |
|
323 * @param aNS New namespace |
|
324 */ |
|
325 IMPORT_C void SetNamespaceL(const TDesC8& aNS); |
|
326 |
|
327 /** |
|
328 * Makes a clone from this node and it's child nodes. Sets new namespace. |
|
329 * @since Series 60 3.1 |
|
330 * @param aStringPool. A new string pool. |
|
331 * @param aNS. A new namespace. |
|
332 * @return Pointer to a clone node. Caller has the ownership. |
|
333 */ |
|
334 IMPORT_C CXnDomNode* CloneL( CXnDomStringPool& aStringPool, const TDesC8& aNS ); |
|
335 |
|
336 /** |
|
337 * Set ownership of node and its children |
|
338 * @since Series 60 5.1 |
|
339 * @param aNS. A new namespace. |
|
340 * @return void |
|
341 */ |
|
342 IMPORT_C void SetOwnershipL( const TDesC8& aNS ); |
|
343 |
|
344 private: |
|
345 /** |
|
346 * C++ default constructor. |
|
347 */ |
|
348 CXnDomNode( CXnDomStringPool& aStringPool ); |
|
349 |
|
350 /** |
|
351 * By default Symbian 2nd phase constructor is private. |
|
352 */ |
|
353 void ConstructL( const TDesC8& aName, const TDesC8& aNS ); |
|
354 |
|
355 private: // Data |
|
356 |
|
357 //iNameRef refers to a name string in a string pool |
|
358 TInt iNameRef; |
|
359 |
|
360 //iNSRef refers to a namespace string in a string pool |
|
361 TInt iNSRef; |
|
362 |
|
363 //iStringPool is used to resolve strings based on references |
|
364 CXnDomStringPool& iStringPool; |
|
365 |
|
366 //Type of the elements content |
|
367 TContentType iContentType; |
|
368 |
|
369 //Parsed character data |
|
370 HBufC8* iPCData; |
|
371 |
|
372 //Node's parent pointer |
|
373 CXnDomNode* iParentNode; |
|
374 |
|
375 //Node unique identifier |
|
376 TInt iNodeId; |
|
377 |
|
378 //Node's childs are collected into a list. Childs are owned by node |
|
379 CXnDomList* iChildList; |
|
380 |
|
381 //Node is the owner of the attributes |
|
382 CXnDomList* iAttributeList; |
|
383 |
|
384 //Node is the owner of the properties |
|
385 CXnDomList* iPropertyList; |
|
386 |
|
387 //Flag is set if this node is reference node |
|
388 TBool iRefNode; |
|
389 |
|
390 // Not owned |
|
391 CXnNode* iLayoutNode; |
|
392 }; |
|
393 |
|
394 #endif // XN_DOM_NODE_H |
|
395 |
|
396 // End of File |