|
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 // MDXMLDocument.CPP |
|
15 // @file |
|
16 // This file contains the implementation of the CMDXMLDocument class which |
|
17 // is the root class for a Mini-DOM tree. |
|
18 // |
|
19 // |
|
20 |
|
21 #include <gmxmldomconstants.h> |
|
22 #include <gmxmlnode.h> |
|
23 #include <gmxmlelement.h> |
|
24 #include <gmxmldocument.h> |
|
25 #include <gmxmldocumentelement.h> |
|
26 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
27 #include "gmxmldummydtd.h" |
|
28 #endif |
|
29 // |
|
30 // Global functions // |
|
31 // |
|
32 |
|
33 |
|
34 CMDXMLDocument::CMDXMLDocument(MXMLDtd& aDtdRepresentation) : iDtdRepresentation(&aDtdRepresentation) |
|
35 // |
|
36 // Constructor |
|
37 // |
|
38 { |
|
39 } |
|
40 |
|
41 CMDXMLDocument::CMDXMLDocument() |
|
42 // |
|
43 // Constructor |
|
44 // |
|
45 { |
|
46 } |
|
47 |
|
48 |
|
49 EXPORT_C CMDXMLDocument::~CMDXMLDocument() |
|
50 { |
|
51 delete iRootElement; |
|
52 delete iVersionTag; |
|
53 delete iDocTypeTag; |
|
54 |
|
55 if (iOwnsDtd) |
|
56 // If the DTD is a dummy DTD created by this document then it should be deleted. |
|
57 { |
|
58 delete iDtdRepresentation; |
|
59 } |
|
60 } |
|
61 |
|
62 EXPORT_C CMDXMLDocument* CMDXMLDocument::NewL(MXMLDtd& aDtdRepresentation) |
|
63 // |
|
64 // Factory function |
|
65 // @return Returns the created CMDXMLDocument |
|
66 // @leave Can Leave due to OOM |
|
67 // |
|
68 { |
|
69 CMDXMLDocument* self = CMDXMLDocument::NewLC(aDtdRepresentation); |
|
70 CleanupStack::Pop(self); |
|
71 return self; |
|
72 } |
|
73 |
|
74 |
|
75 EXPORT_C CMDXMLDocument* CMDXMLDocument::NewLC(MXMLDtd& aDtdRepresentation) |
|
76 // |
|
77 // Factory function |
|
78 // @return Returns the created CMDXMLDocument |
|
79 // @leave Can Leave due to OOM |
|
80 // |
|
81 { |
|
82 CMDXMLDocument* self = new(ELeave) CMDXMLDocument(aDtdRepresentation); |
|
83 CleanupStack::PushL(self); |
|
84 self->ConstructL(); |
|
85 return self; |
|
86 } |
|
87 |
|
88 /** |
|
89 * Factory function - Without taking a DTD |
|
90 * Documents created using this function will not be able to validate the XML. |
|
91 * @return Returns the created CMDXMLDocument |
|
92 * @leave Can Leave due to OOM |
|
93 */ |
|
94 EXPORT_C CMDXMLDocument* CMDXMLDocument::NewL() |
|
95 { |
|
96 CMDXMLDocument* self = CMDXMLDocument::NewLC(); |
|
97 CleanupStack::Pop(self); |
|
98 return self; |
|
99 } |
|
100 |
|
101 |
|
102 /** |
|
103 * Factory function - Without taking a DTD |
|
104 * Documents created using this function will not be able to validate the XML. |
|
105 * @return Returns the created CMDXMLDocument |
|
106 * @leave Can Leave due to OOM |
|
107 */ |
|
108 EXPORT_C CMDXMLDocument* CMDXMLDocument::NewLC() |
|
109 { |
|
110 CMDXMLDocument* self = new(ELeave) CMDXMLDocument(); |
|
111 CleanupStack::PushL(self); |
|
112 self->ConstructL(); |
|
113 return self; |
|
114 } |
|
115 |
|
116 |
|
117 void CMDXMLDocument::ConstructL() |
|
118 { |
|
119 // Default XML Version & Doc tags being set |
|
120 // Can be reset externally |
|
121 iVersionTag = TPtrC(KXMLDefaultVersionTag).AllocL(); |
|
122 iDocTypeTag = TPtrC(KXMLDefaultDocTypeTag).AllocL(); |
|
123 |
|
124 iRootElement = CMDXMLDocumentElement::NewL(this); |
|
125 |
|
126 if (iDtdRepresentation == NULL) |
|
127 // If no DTD has been provided then use the dummy DTD |
|
128 { |
|
129 iDtdRepresentation = new (ELeave) CMDXMLDummyDtd; |
|
130 iOwnsDtd = ETrue; |
|
131 } |
|
132 } |
|
133 |
|
134 |
|
135 EXPORT_C TBool CMDXMLDocument::SetVersionTagL(const TDesC& aVersionTag) |
|
136 // |
|
137 // @param replacement tag, this must be complete, starting <?xml and finishing > |
|
138 // @return ETrue if operation succeeds, EFalse if formal parameter does not |
|
139 // begin with <?xml or does not end with an > |
|
140 // @leave can Leave due to OOM |
|
141 // |
|
142 { |
|
143 TBool returnValue = EFalse; |
|
144 |
|
145 // if correct tag frame |
|
146 if(aVersionTag.Left(TPtrC(KXMLVersion).Length()) == KXMLVersion |
|
147 && aVersionTag.Right(TPtrC(KXMLEndTag).Length()) == KXMLEndTag) |
|
148 { |
|
149 delete iVersionTag; |
|
150 iVersionTag = NULL; |
|
151 iVersionTag = aVersionTag.AllocL(); |
|
152 returnValue = ETrue; |
|
153 } |
|
154 |
|
155 return returnValue; |
|
156 } |
|
157 |
|
158 EXPORT_C TBool CMDXMLDocument::SetDocTypeTagL(const TDesC& aDocTypeTag) |
|
159 // |
|
160 // @param replacement tag, this must be complete, starting <!DOCTYPE and finishing > |
|
161 // @return ETrue if operation succeeds, EFalse if formal parameter does not |
|
162 // begin with <!DOCTYPE or does not end with an angle bracket |
|
163 // @leave can Leave due to OOM |
|
164 // |
|
165 { |
|
166 TBool returnValue = EFalse; |
|
167 |
|
168 // if correct tag frame |
|
169 if(aDocTypeTag.Left(TPtrC(KXMLDocumentTypes).Length()) == KXMLDocumentTypes |
|
170 && aDocTypeTag.Right(TPtrC(KXMLEndTag).Length()) == KXMLEndTag) |
|
171 { |
|
172 delete iDocTypeTag; |
|
173 iDocTypeTag = NULL; |
|
174 iDocTypeTag = aDocTypeTag.AllocL(); |
|
175 returnValue = ETrue; |
|
176 } |
|
177 |
|
178 return returnValue; |
|
179 } |
|
180 |
|
181 |
|
182 |
|
183 EXPORT_C TBool CMDXMLDocument::ValidElementNameL(const TDesC& aElement) const |
|
184 // |
|
185 // Function to determine whether an Element name is valid for Document |
|
186 // @return ETrue the if element name valid - else EFalse |
|
187 // @param aElement the element name to be tested |
|
188 // @leave can leave due to OOM |
|
189 // |
|
190 { |
|
191 return iDtdRepresentation->IsValidElementL(aElement); |
|
192 } |
|
193 |
|
194 |
|
195 EXPORT_C TBool CMDXMLDocument::CanElementHaveChildren(const TDesC& aElement) const |
|
196 { |
|
197 return iDtdRepresentation->CanElementHaveChildren(aElement); |
|
198 } |
|
199 |
|
200 EXPORT_C void CMDXMLDocument::PlaceholderForRemovedExport1(MXMLDtd& /*aDtdRepresentation*/) |
|
201 { |
|
202 User::Panic(KLDRIMPORT, KLdrImportedOrdinalDoesNotExist); |
|
203 } |
|
204 |
|
205 EXPORT_C void CMDXMLDocument::PlaceholderForRemovedExport2() |
|
206 { |
|
207 User::Panic(KLDRIMPORT, KLdrImportedOrdinalDoesNotExist); |
|
208 } |
|
209 |
|
210 const MXMLDtd& CMDXMLDocument::DtdRepresentation() const |
|
211 // Returns a reference to the dtd class responsible for validation |
|
212 // @return Returns a reference to MXMLDtd class that should be used for Dtd validation checking |
|
213 { |
|
214 return *iDtdRepresentation; |
|
215 } |
|
216 |
|
217 |
|
218 TBool CMDXMLDummyDtd::IsValidElementL(const TDesC& /*aElement*/) const |
|
219 { |
|
220 return ETrue; |
|
221 } |
|
222 |
|
223 TInt CMDXMLDummyDtd::IsValidAttributeForElementL(const TDesC& /*aElement*/, const TDesC& /*aAttribute*/, const TDesC& /*aAttributeValue*/) const |
|
224 { |
|
225 return KErrNone; |
|
226 } |
|
227 |
|
228 TBool CMDXMLDummyDtd::AreValidChildElementsL(const TDesC& /*aParentElement*/, const CDesCArray& /*aChildElements*/) const |
|
229 { |
|
230 return ETrue; |
|
231 } |
|
232 |
|
233 TBool CMDXMLDummyDtd::CanElementHaveChildren(const TDesC& /*aElement*/) const |
|
234 { |
|
235 return ETrue; |
|
236 } |
|
237 |
|
238 // End Of File |