17
|
1 |
// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// This file contains the declaration of the CMDXMLNode class which
|
|
15 |
// is the base class for the Mini-DOM.
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
/**
|
|
20 |
@file
|
|
21 |
*/
|
|
22 |
|
|
23 |
#ifndef __GMXMLNODE_H__
|
|
24 |
#define __GMXMLNODE_H__
|
|
25 |
|
|
26 |
#include <e32base.h>
|
|
27 |
#ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
|
|
28 |
#include <gmxmldocument.h>
|
|
29 |
#endif
|
|
30 |
|
|
31 |
// forward references
|
|
32 |
class CMDXMLComposer;
|
|
33 |
class CMDXMLDocument;
|
|
34 |
class CMDXMLEntityConverter;
|
|
35 |
|
|
36 |
class CMDXMLNode : public CBase
|
|
37 |
/** Abstract base class for DOM node classes.
|
|
38 |
|
|
39 |
It stores the node type and name, and manages a list of child nodes. The node
|
|
40 |
name and type are set in the derived class's constructor and cannot be changed.
|
|
41 |
|
|
42 |
The list of child nodes is managed as a doubly-linked list, not an array
|
|
43 |
or similar structure.
|
|
44 |
|
|
45 |
Derived classes that are not allowed children override the operations to manipulate
|
|
46 |
the child list.
|
|
47 |
@publishedPartner
|
|
48 |
@released
|
|
49 |
*/
|
|
50 |
{
|
|
51 |
public:
|
|
52 |
// XML DOM Node Types - The actual values are taken from the DOM definition but we only use some of them.
|
|
53 |
/** XML DOM node types.
|
|
54 |
|
|
55 |
The values are taken from the DOM definition, but only some of them are used
|
|
56 |
for the SMIL API.
|
|
57 |
@publishedPartner
|
|
58 |
@released
|
|
59 |
*/
|
|
60 |
enum TDOMNodeType
|
|
61 |
{
|
|
62 |
EElementNode=1, //< Element
|
|
63 |
ETextNode=3, //< Text
|
|
64 |
ECDATASectionNode=4, //< CDATA Section
|
|
65 |
EProcessingInstructionNode=7, //< Processing Instruction
|
|
66 |
ECommentNode=8, //< Comment
|
|
67 |
EDocumentNode=9 //< Document
|
|
68 |
};
|
|
69 |
|
|
70 |
/** Destructor.
|
|
71 |
|
|
72 |
When a node is deleted, it:
|
|
73 |
|
|
74 |
1. links its previous and next siblings
|
|
75 |
|
|
76 |
2. deletes all its children
|
|
77 |
|
|
78 |
3. corrects its parents first and last child pointers if necessary */
|
|
79 |
IMPORT_C virtual ~CMDXMLNode();
|
|
80 |
|
|
81 |
/** Gets the node type of the node.
|
|
82 |
|
|
83 |
@return The node type of the node */
|
|
84 |
inline TDOMNodeType NodeType() {return iNodeType;}
|
|
85 |
|
|
86 |
/** Gets the name of the node.
|
|
87 |
|
|
88 |
@return The name of the node */
|
|
89 |
IMPORT_C TPtrC NodeName();
|
|
90 |
|
|
91 |
/** Tests if the node can have child nodes.
|
|
92 |
|
|
93 |
@return True if the node can have child nodes, false otherwise */
|
|
94 |
inline TBool CanHaveChildNodes() {return iCanHaveChildren;}
|
|
95 |
|
|
96 |
/** Tests if the node has any child nodes.
|
|
97 |
|
|
98 |
@return True if the node has any child nodes, false otherwise */
|
|
99 |
inline TBool HasChildNodes() {return (iFirstChildPtr != NULL);}
|
|
100 |
|
|
101 |
/** Gets a pointer to the document which is the owner of the DOM tree.
|
|
102 |
|
|
103 |
@return A pointer to the document which is the owner of the DOM tree */
|
|
104 |
inline CMDXMLDocument* OwnerDocument() {return (CMDXMLDocument*)iOwnerDocument;}
|
|
105 |
|
|
106 |
/** Gets a pointer to the first child node, if any.
|
|
107 |
|
|
108 |
@return A pointer to the first child node if any, otherwise NULL */
|
|
109 |
inline CMDXMLNode* FirstChild() {return iFirstChildPtr;}
|
|
110 |
|
|
111 |
/** Gets a pointer to the last child node, if any.
|
|
112 |
|
|
113 |
@return A pointer to the last child node if any, otherwise NULL */
|
|
114 |
inline CMDXMLNode* LastChild() {return iLastChildPtr;}
|
|
115 |
|
|
116 |
/** Gets a pointer to the next sibling node, if any.
|
|
117 |
|
|
118 |
@return A pointer to the next sibling node if any, otherwise NULL */
|
|
119 |
inline CMDXMLNode* NextSibling() {return iNextSiblingPtr;}
|
|
120 |
|
|
121 |
/** Gets a pointer to the previous sibling node, if any.
|
|
122 |
|
|
123 |
@return A pointer to the previous sibling node if any, otherwise NULL */
|
|
124 |
inline CMDXMLNode* PreviousSibling() {return iPrevSiblingPtr;}
|
|
125 |
|
|
126 |
/** Gets a pointer to the parent node, if any.
|
|
127 |
|
|
128 |
@return A pointer to the parent node if any, otherwise NULL (only at root
|
|
129 |
of tree) */
|
|
130 |
inline CMDXMLNode* ParentNode() {return iParentPtr;}
|
|
131 |
|
|
132 |
/** Gets the element type as an enumerated value.
|
|
133 |
|
|
134 |
This function is quicker to use than NodeName().
|
|
135 |
|
|
136 |
@return A CMDXMLNode::TDomNodeType value identifying the node type */
|
|
137 |
inline TInt ElementType() {return iElementType;}
|
|
138 |
|
|
139 |
/** Removes a child from the list of child nodes.
|
|
140 |
|
|
141 |
The child node is not deleted: that is the responsibility of the caller.
|
|
142 |
|
|
143 |
@param aChildToRemove Pointer to child to remove from the list
|
|
144 |
@return KErrNone if sucessful or KErrNotFound if the referenced child node
|
|
145 |
is not found */
|
|
146 |
IMPORT_C TInt RemoveChild(CMDXMLNode* aChildToRemove);
|
|
147 |
|
|
148 |
/** Inserts a new child node at a specific point in the child list.
|
|
149 |
|
|
150 |
@param aInsertBeforeChild Pointer to the element before which the new child
|
|
151 |
should be inserted. UseNULL to insert at the start of the list.
|
|
152 |
@param aChildToInsert Pointer to the new child node to insert
|
|
153 |
@return KErrNone if successful, KErrNotSupported if the node cannot have children
|
|
154 |
or KErrNotFound if it cannot find the child before which to insert */
|
|
155 |
IMPORT_C TInt InsertBefore(CMDXMLNode* aInsertBeforeChild, CMDXMLNode* aChildToInsert);
|
|
156 |
|
|
157 |
/** Appends a new child at the end of the child list.
|
|
158 |
|
|
159 |
@param aChildToInsert Pointer to the new child node to append.
|
|
160 |
@return KErrNone if successful or KErrNotSupported if the node cannot have
|
|
161 |
children */
|
|
162 |
IMPORT_C TInt AppendChild(CMDXMLNode* aChildToInsert);
|
|
163 |
|
|
164 |
/** Inserts a new child node while removing an existing one.
|
|
165 |
|
|
166 |
The old child is not deleted.
|
|
167 |
|
|
168 |
@param aChildToInsert Pointer to the new child node to insert
|
|
169 |
@param aChildToReplace Pointer to the child node to be replaced
|
|
170 |
@return KErrNone if successful, KErrNotSupported if the node cannot have children
|
|
171 |
or KErrNotFound if it cannot find the child to replace. */
|
|
172 |
IMPORT_C TInt ReplaceChild(CMDXMLNode* aChildToInsert, CMDXMLNode* aChildToReplace);
|
|
173 |
|
|
174 |
|
|
175 |
/** Checks the children of this node for validity.
|
|
176 |
|
|
177 |
@return True if the children are valid according to the DTD. */
|
|
178 |
IMPORT_C virtual TBool CheckChildren()=0;
|
|
179 |
|
|
180 |
protected:
|
|
181 |
/*
|
|
182 |
* The node type will normally be hard-wired in any derived class constructor.
|
|
183 |
* The node name and HaveChildren flag will normally be hard-wired in a derived class constructor unless it
|
|
184 |
* covers a generic element.
|
|
185 |
* @param aNodeType The tpe of node to be created
|
|
186 |
* @param aCanHaveChildren Flag to indicate if the node represents a node which is allowed children
|
|
187 |
* @param aOwnerDocument Pointer to the document at the root of the DOM tree - if NULL then assume this is the root
|
|
188 |
*/
|
|
189 |
CMDXMLNode( TDOMNodeType aNodeType, TBool aCanHaveChildren, CMDXMLDocument* aOwnerDocument );
|
|
190 |
|
|
191 |
// make these public? sjr
|
|
192 |
/**
|
|
193 |
* Gets a pointer to the previous sibling node of the same type if any,
|
|
194 |
* otherwise returns NULL
|
|
195 |
* @return Previous sibling node
|
|
196 |
*/
|
|
197 |
IMPORT_C CMDXMLNode* PreviousSameTypeSibling();
|
|
198 |
|
|
199 |
/**
|
|
200 |
* Gets a pointer to the next sibling node of the same type if any,
|
|
201 |
* otherwise returns NULL
|
|
202 |
* @return Next sibling node
|
|
203 |
*/
|
|
204 |
IMPORT_C CMDXMLNode* NextSameTypeSibling();
|
|
205 |
|
|
206 |
/**
|
|
207 |
* Set the node name - normally on creation
|
|
208 |
* @param aNodeName The node name - commonly an element tag name - _not_ any unique identifier
|
|
209 |
* @leave Can Leave due to OOM
|
|
210 |
*/
|
|
211 |
IMPORT_C void SetNodeNameL(const TDesC& aNodeName);
|
|
212 |
|
|
213 |
/**
|
|
214 |
* Sets the enumerated element type (same information as node name but faster to access)
|
|
215 |
*/
|
|
216 |
inline void SetElementType( TInt aElementType ) {iElementType = aElementType;}
|
|
217 |
|
|
218 |
protected:
|
|
219 |
CMDXMLDocument* iOwnerDocument; //< Pointer to owning document
|
|
220 |
|
|
221 |
|
|
222 |
private:
|
|
223 |
TInt iElementType; // Enumerated element type
|
|
224 |
TDOMNodeType iNodeType; // Node type
|
|
225 |
HBufC* iNodeName; // Name of the node, e.g. element tag name - not unique id
|
|
226 |
CMDXMLNode* iParentPtr; // Pointer to parent node if any
|
|
227 |
CMDXMLNode* iFirstChildPtr; // Pointer to first child node if any
|
|
228 |
CMDXMLNode* iLastChildPtr; // Pointer to last child node if any
|
|
229 |
CMDXMLNode* iNextSiblingPtr; // Pointer to next sibling if any
|
|
230 |
CMDXMLNode* iPrevSiblingPtr; // Pointer to previous sibling if any
|
|
231 |
TBool iCanHaveChildren; // true if this node is allowed to have children
|
|
232 |
};
|
|
233 |
|
|
234 |
#endif
|
|
235 |
// End Of File
|