|
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 CMDXMLDocument class which |
|
15 // is the root class for a Mini-DOM tree. |
|
16 // |
|
17 // |
|
18 /** |
|
19 * @file |
|
20 * @publishedPartner |
|
21 * @released |
|
22 */ |
|
23 |
|
24 #ifndef __GMXMLDOCUMENT_H__ |
|
25 #define __GMXMLDOCUMENT_H__ |
|
26 |
|
27 #include <e32base.h> |
|
28 |
|
29 #include <e32std.h> |
|
30 #include <badesca.h> |
|
31 |
|
32 class CMDXMLElement; |
|
33 class MXMLDtd; |
|
34 |
|
35 /** |
|
36 MXMLDtd is a mixin class. If User wants to derive from MXMLDtd class , |
|
37 then one should not derive from any other class at the same time. |
|
38 i.e A class can not derive from CBase at all using MXMLDtd. |
|
39 |
|
40 Interface for DTD defintion classes. |
|
41 A class derived from this interface can be used by CMDXMLParser or CMDXMLComposer |
|
42 to check that the data conforms to a specific DTD. |
|
43 @publishedPartner |
|
44 @released |
|
45 */ |
|
46 class MXMLDtd |
|
47 |
|
48 { |
|
49 |
|
50 public: |
|
51 /** Tests if an element name is valid in the DTD. |
|
52 |
|
53 @param aElement The element name to be tested |
|
54 @return ETrue the if element name valid, else EFalse |
|
55 @leave KErrNoMemory Out of memory */ |
|
56 virtual TBool IsValidElementL(const TDesC& aElement) const = 0; |
|
57 |
|
58 /** Tests if an attribute name and value is valid in DTD. |
|
59 |
|
60 @param aElement The element to which the attributes belong |
|
61 @param aAttribute The attribute to be tested |
|
62 @param aAttributeValue The attribute value to be tested |
|
63 @return KErrNone if the name and value are valid, KXMLBadAttributeName if the |
|
64 attribute name is invalid, or KXMLBadAttributeValue if the attribute value |
|
65 is invalid |
|
66 @leave KErrNoMemory Out of memory */ |
|
67 virtual TInt IsValidAttributeForElementL(const TDesC& aElement, const TDesC& aAttribute, const TDesC& aAttributeValue) const = 0; |
|
68 |
|
69 /** Tests if the parent/child relationship is valid in DTD. |
|
70 |
|
71 @param aParentElement The name of the parent element to be tested |
|
72 @param aChildElements An array of child element names to be tested |
|
73 @return ETrue if parent/child relationship is valid |
|
74 @leave KErrNoMemory Out of memory */ |
|
75 virtual TBool AreValidChildElementsL(const TDesC& aParentElement, const CDesCArray& aChildElements) const = 0; |
|
76 |
|
77 /** Tests it is valid for a particular element to have children. |
|
78 |
|
79 @param aElement The name of the element to be tested |
|
80 @return ETrue if it is valid for the element to have children */ |
|
81 virtual TBool CanElementHaveChildren(const TDesC& aElement) const = 0; |
|
82 }; |
|
83 |
|
84 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
85 #include "gmxmldummydtd.h" |
|
86 #endif |
|
87 |
|
88 class CMDXMLDocument : public CBase |
|
89 /** An XML document. |
|
90 |
|
91 An object of this type owns the root element of a DOM tree and is not itself |
|
92 an XML node. |
|
93 @publishedPartner |
|
94 @released |
|
95 */ |
|
96 { |
|
97 public: |
|
98 |
|
99 /** |
|
100 Allocates and constructs a new CMDXMLDocument. |
|
101 @param iDtdRepresentation DTD for the document |
|
102 @return The new CMDXMLDocument object |
|
103 @leave KErrNoMemory Out of memory |
|
104 */ |
|
105 IMPORT_C static CMDXMLDocument* NewL(MXMLDtd& iDtdRepresentation); |
|
106 |
|
107 |
|
108 /** |
|
109 Allocates and constructs a new CMDXMLDocument, leaving the object on the cleanup stack. |
|
110 @param iDtdRepresentation DTD for the document |
|
111 @return The new CMDXMLDocument object |
|
112 @leave KErrNoMemory Out of memory |
|
113 */ |
|
114 IMPORT_C static CMDXMLDocument* NewLC(MXMLDtd& iDtdRepresentation); |
|
115 |
|
116 |
|
117 /** Allocates and constructs a new CMDXMLDocument, without specifying a DTD. |
|
118 |
|
119 Documents created using this function will not be able to validate the XML. |
|
120 |
|
121 @return The new CMDXMLDocument |
|
122 @leave KErrNoMemory Out of memory */ |
|
123 IMPORT_C static CMDXMLDocument* NewL(); |
|
124 |
|
125 |
|
126 /** Allocates and constructs a new CMDXMLDocument, without specifying a DTD, |
|
127 leaving the object on the cleanup stack. |
|
128 |
|
129 Documents created using this function will not be able to validate the XML. |
|
130 |
|
131 @return The new CMDXMLDocument |
|
132 @leave KErrNoMemory Out of memory */ |
|
133 IMPORT_C static CMDXMLDocument* NewLC(); |
|
134 |
|
135 |
|
136 /** Destructor. */ |
|
137 IMPORT_C virtual ~CMDXMLDocument(); |
|
138 |
|
139 /** Gets the root element of the DOM tree. |
|
140 |
|
141 @return The root element of the DOM tree */ |
|
142 inline CMDXMLElement* DocumentElement() {return iRootElement;} |
|
143 |
|
144 |
|
145 /** Sets the document's XML version processing instruction. |
|
146 |
|
147 @param aVersionTag The XML version processing instruction. This must begin |
|
148 with <?xml and end with >, for example <?xml version="1.0"?>. |
|
149 @return ETrue if successful, EFalse if the parameter format is not correct |
|
150 @leave KErrNoMemory Out of memory */ |
|
151 IMPORT_C TBool SetVersionTagL(const TDesC& aVersionTag); |
|
152 |
|
153 /** Sets the document's DOCTYPE declaration. |
|
154 |
|
155 @param aDocTypeTag The XML DOCTYPE declaration. This must begin<!DOCTYPE and |
|
156 end >. |
|
157 @return ETrue if operation succeeds, EFalse if the parameter format is not |
|
158 correct |
|
159 @leave KErrNoMemory Out of memory */ |
|
160 IMPORT_C TBool SetDocTypeTagL(const TDesC& aDocTypeTag); |
|
161 |
|
162 /** Tests whether an element name is valid for the document. |
|
163 |
|
164 @param aElement The element name to be tested |
|
165 @return True the if element name valid, else false |
|
166 @leave KErrNoMemory Out of memory */ |
|
167 IMPORT_C TBool ValidElementNameL(const TDesC& aElement) const; |
|
168 |
|
169 /** |
|
170 Tests whether it is valid for a particular element to have children. |
|
171 @param aElement the name of the element to be tested |
|
172 @return ETrue if it is valid for element to have children |
|
173 */ |
|
174 |
|
175 IMPORT_C TBool CanElementHaveChildren(const TDesC& aElement) const; |
|
176 /** Gets the document's XML version processing instruction. |
|
177 |
|
178 @return The document's XML version processing instruction. */ |
|
179 inline const TDesC& VersionTag() const {return *iVersionTag;} |
|
180 |
|
181 /** Gets the document's DOCTYPE declaration. |
|
182 |
|
183 @return The document's DOCTYPE declaration. */ |
|
184 inline const TDesC& DocTypeTag() const {return *iDocTypeTag;} |
|
185 |
|
186 /** Gets a reference to the MXMLDtd object to use for DTD validation checking. |
|
187 |
|
188 @return DTD */ |
|
189 const MXMLDtd& CMDXMLDocument::DtdRepresentation() const; |
|
190 |
|
191 |
|
192 private: |
|
193 CMDXMLDocument(MXMLDtd& aDtdRepresentation); |
|
194 CMDXMLDocument(); |
|
195 |
|
196 /* |
|
197 * sets the root elememnt of the DOM tree. |
|
198 */ |
|
199 inline void SetDocumentElement(CMDXMLElement* aRootElement) {iRootElement = aRootElement;} |
|
200 |
|
201 void ConstructL(); |
|
202 |
|
203 IMPORT_C void PlaceholderForRemovedExport1(MXMLDtd& aDtdRepresentation); |
|
204 IMPORT_C void PlaceholderForRemovedExport2(); |
|
205 |
|
206 private: |
|
207 CMDXMLElement* iRootElement; // Root element node of the DOM tree |
|
208 |
|
209 protected: |
|
210 /** XML Version text */ |
|
211 HBufC* iVersionTag; // XML Version text |
|
212 /** Document type text */ |
|
213 HBufC* iDocTypeTag; // Document type text |
|
214 |
|
215 private: |
|
216 MXMLDtd* iDtdRepresentation; |
|
217 TBool iOwnsDtd; |
|
218 }; |
|
219 |
|
220 #endif |