114
|
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: Represents the entire xmluiml specific xml and css data.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
// INCLUDE FILES
|
|
21 |
#include "hspsdomdocument.h"
|
|
22 |
#include "hspsdomnode.h"
|
|
23 |
#include "hspsdomlist.h"
|
|
24 |
#include "hspsdomstringpool.h"
|
|
25 |
#include <s32mem.h>
|
|
26 |
|
|
27 |
|
|
28 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
29 |
// -----------------------------------------------------------------------------
|
|
30 |
// ChspsDomDocument::CloneL()
|
|
31 |
// -----------------------------------------------------------------------------
|
|
32 |
//
|
|
33 |
EXPORT_C ChspsDomDocument* ChspsDomDocument::CloneL()
|
|
34 |
{
|
|
35 |
ChspsDomDocument* clone = new (ELeave) ChspsDomDocument;
|
|
36 |
CleanupStack::PushL( clone );
|
|
37 |
|
|
38 |
clone->iDomStringPool = iDomStringPool->CloneL();
|
|
39 |
if ( iRootNode )
|
|
40 |
{
|
|
41 |
clone->iRootNode = iRootNode->CloneL( *clone->iDomStringPool, ETrue );
|
|
42 |
}
|
|
43 |
|
|
44 |
CleanupStack::Pop( clone );
|
|
45 |
return clone;
|
|
46 |
}
|
|
47 |
|
|
48 |
// -----------------------------------------------------------------------------
|
|
49 |
// ChspsDomDocument::CreateElementNSL
|
|
50 |
// -----------------------------------------------------------------------------
|
|
51 |
//
|
|
52 |
EXPORT_C ChspsDomNode* ChspsDomDocument::CreateElementNSL(
|
|
53 |
const TDesC8& aName,
|
|
54 |
const TDesC8& aNamespace )
|
|
55 |
{
|
|
56 |
return ChspsDomNode::NewL( aName, aNamespace, *iDomStringPool );
|
|
57 |
}
|
|
58 |
// -----------------------------------------------------------------------------
|
|
59 |
// ChspsDomDocument::ChspsDomDocument
|
|
60 |
// C++ default constructor can NOT contain any code, that
|
|
61 |
// might leave.
|
|
62 |
// -----------------------------------------------------------------------------
|
|
63 |
//
|
|
64 |
ChspsDomDocument::ChspsDomDocument()
|
|
65 |
{
|
|
66 |
}
|
|
67 |
|
|
68 |
// -----------------------------------------------------------------------------
|
|
69 |
// ChspsDomDocument::ConstructL
|
|
70 |
// Symbian 2nd phase constructor can leave.
|
|
71 |
// -----------------------------------------------------------------------------
|
|
72 |
//
|
|
73 |
void ChspsDomDocument::ConstructL()
|
|
74 |
{
|
|
75 |
iDomStringPool = ChspsDomStringPool::NewL();
|
|
76 |
}
|
|
77 |
|
|
78 |
// -----------------------------------------------------------------------------
|
|
79 |
// ChspsDomDocument::NewL
|
|
80 |
// Two-phased constructor.
|
|
81 |
// -----------------------------------------------------------------------------
|
|
82 |
//
|
|
83 |
EXPORT_C ChspsDomDocument* ChspsDomDocument::NewL()
|
|
84 |
{
|
|
85 |
ChspsDomDocument* self = new( ELeave ) ChspsDomDocument;
|
|
86 |
|
|
87 |
CleanupStack::PushL( self );
|
|
88 |
self->ConstructL();
|
|
89 |
CleanupStack::Pop(self);
|
|
90 |
|
|
91 |
return self;
|
|
92 |
}
|
|
93 |
// -----------------------------------------------------------------------------
|
|
94 |
// ChspsDomDocument::NewL
|
|
95 |
// Two-phased constructor.
|
|
96 |
// -----------------------------------------------------------------------------
|
|
97 |
//
|
|
98 |
EXPORT_C ChspsDomDocument* ChspsDomDocument::NewL(
|
|
99 |
RReadStream& aStream )
|
|
100 |
{
|
|
101 |
ChspsDomDocument* self = new( ELeave ) ChspsDomDocument;
|
|
102 |
|
|
103 |
CleanupStack::PushL( self );
|
|
104 |
self->ConstructL();
|
|
105 |
aStream >> *self;
|
|
106 |
CleanupStack::Pop(self);
|
|
107 |
|
|
108 |
return self;
|
|
109 |
}
|
|
110 |
// -----------------------------------------------------------------------------
|
|
111 |
// ChspsDomDocument::NewL
|
|
112 |
// Constructs ChspsDomDocument from streamed HBufC8.
|
|
113 |
// -----------------------------------------------------------------------------
|
|
114 |
//
|
|
115 |
EXPORT_C ChspsDomDocument* ChspsDomDocument::NewL(
|
|
116 |
const HBufC8* aBufStream )
|
|
117 |
{
|
|
118 |
RDesReadStream readStream( *aBufStream );
|
|
119 |
CleanupClosePushL( readStream );
|
|
120 |
ChspsDomDocument* self = ChspsDomDocument::NewL( readStream );
|
|
121 |
CleanupStack::PopAndDestroy( &readStream );
|
|
122 |
return self;
|
|
123 |
}
|
|
124 |
|
|
125 |
// Destructor
|
|
126 |
EXPORT_C ChspsDomDocument::~ChspsDomDocument()
|
|
127 |
{
|
|
128 |
if ( iRootNode )
|
|
129 |
{
|
|
130 |
delete iRootNode;
|
|
131 |
}
|
|
132 |
|
|
133 |
if ( iDomStringPool )
|
|
134 |
{
|
|
135 |
delete iDomStringPool;
|
|
136 |
}
|
|
137 |
}
|
|
138 |
|
|
139 |
// -----------------------------------------------------------------------------
|
|
140 |
// ChspsDomDocument::DomNodeCount
|
|
141 |
// -----------------------------------------------------------------------------
|
|
142 |
//
|
|
143 |
EXPORT_C TInt ChspsDomDocument::DomNodeCount() const
|
|
144 |
{
|
|
145 |
TInt count( 0 );
|
|
146 |
if ( iRootNode )
|
|
147 |
{
|
|
148 |
count = iRootNode->DescendantCount();
|
|
149 |
}
|
|
150 |
return count;
|
|
151 |
}
|
|
152 |
|
|
153 |
// -----------------------------------------------------------------------------
|
|
154 |
// ChspsDomDocument::ExternalizeL
|
|
155 |
// -----------------------------------------------------------------------------
|
|
156 |
//
|
|
157 |
EXPORT_C void ChspsDomDocument::ExternalizeL( RWriteStream& aStream ) const
|
|
158 |
{
|
|
159 |
aStream << *iDomStringPool;
|
|
160 |
|
|
161 |
if ( iRootNode )
|
|
162 |
{
|
|
163 |
aStream.WriteInt8L( ETrue ); //Root node exist
|
|
164 |
aStream << *iRootNode;
|
|
165 |
}
|
|
166 |
else
|
|
167 |
{
|
|
168 |
aStream.WriteInt8L( EFalse );
|
|
169 |
}
|
|
170 |
}
|
|
171 |
|
|
172 |
// -----------------------------------------------------------------------------
|
|
173 |
// ChspsDomDocument::InternalizeL
|
|
174 |
// -----------------------------------------------------------------------------
|
|
175 |
//
|
|
176 |
EXPORT_C void ChspsDomDocument::InternalizeL( RReadStream& aStream )
|
|
177 |
{
|
|
178 |
iDomStringPool->Reset();
|
|
179 |
iDomStringPool->InternalizeL( aStream );
|
|
180 |
|
|
181 |
if ( iRootNode )
|
|
182 |
{
|
|
183 |
delete iRootNode;
|
|
184 |
iRootNode = NULL;
|
|
185 |
}
|
|
186 |
|
|
187 |
TBool rootNodeExist( aStream.ReadInt8L() );
|
|
188 |
if ( rootNodeExist )
|
|
189 |
{
|
|
190 |
iRootNode = ChspsDomNode::NewL( aStream, *iDomStringPool );
|
|
191 |
}
|
|
192 |
}
|
|
193 |
|
|
194 |
// -----------------------------------------------------------------------------
|
|
195 |
// ChspsDomDocument::SetRootNode
|
|
196 |
// -----------------------------------------------------------------------------
|
|
197 |
//
|
|
198 |
EXPORT_C void ChspsDomDocument::SetRootNode( ChspsDomNode* aRootNode )
|
|
199 |
{
|
|
200 |
iRootNode = aRootNode;
|
|
201 |
iRootNode->SetParent( NULL );
|
|
202 |
}
|
|
203 |
|
|
204 |
// -----------------------------------------------------------------------------
|
|
205 |
// ChspsDomDocument::RootNode
|
|
206 |
// -----------------------------------------------------------------------------
|
|
207 |
//
|
|
208 |
EXPORT_C ChspsDomNode* ChspsDomDocument::RootNode() const
|
|
209 |
{
|
|
210 |
return iRootNode;
|
|
211 |
}
|
|
212 |
|
|
213 |
// -----------------------------------------------------------------------------
|
|
214 |
// ChspsDomDocument::LastNode
|
|
215 |
// -----------------------------------------------------------------------------
|
|
216 |
//
|
|
217 |
EXPORT_C ChspsDomNode* ChspsDomDocument::LastNode() const
|
|
218 |
{
|
|
219 |
ChspsDomNode* last = NULL;
|
|
220 |
if ( iRootNode )
|
|
221 |
{
|
|
222 |
last = iRootNode;
|
|
223 |
ChspsDomNode* tmp = iRootNode;
|
|
224 |
while( tmp )
|
|
225 |
{
|
|
226 |
last = tmp;
|
|
227 |
tmp = static_cast<ChspsDomNode*>( last->ChildNodes().Last() );
|
|
228 |
}
|
|
229 |
}
|
|
230 |
return last;
|
|
231 |
}
|
|
232 |
|
|
233 |
// -----------------------------------------------------------------------------
|
|
234 |
// ChspsDomDocument::Size
|
|
235 |
// -----------------------------------------------------------------------------
|
|
236 |
//
|
|
237 |
EXPORT_C TInt ChspsDomDocument::Size() const
|
|
238 |
{
|
|
239 |
TInt size( 1 ); //Root node information takes one byte
|
|
240 |
size += iDomStringPool->Size();
|
|
241 |
|
|
242 |
if ( iRootNode )
|
|
243 |
{
|
|
244 |
|
|
245 |
size += iRootNode->Size();
|
|
246 |
}
|
|
247 |
|
|
248 |
return size;
|
|
249 |
}
|
|
250 |
|
|
251 |
// -----------------------------------------------------------------------------
|
|
252 |
// ChspsDomDocument::MarshallL
|
|
253 |
// -----------------------------------------------------------------------------
|
|
254 |
//
|
|
255 |
EXPORT_C HBufC8* ChspsDomDocument::MarshallL()
|
|
256 |
{
|
|
257 |
TInt dataLength = Size();
|
|
258 |
HBufC8* writeBuf = HBufC8::NewLC( dataLength );
|
|
259 |
TPtr8 p( writeBuf->Des() );
|
|
260 |
RDesWriteStream writeStream( p ); //stream over the buffer
|
|
261 |
CleanupClosePushL( writeStream );
|
|
262 |
writeStream << *this; //Stream object
|
|
263 |
CleanupStack::PopAndDestroy( &writeStream );
|
|
264 |
CleanupStack::Pop( writeBuf );
|
|
265 |
return writeBuf;
|
|
266 |
}
|
|
267 |
|
|
268 |
// -----------------------------------------------------------------------------
|
|
269 |
// ChspsDomDocument::StringPool
|
|
270 |
// -----------------------------------------------------------------------------
|
|
271 |
//
|
|
272 |
EXPORT_C ChspsDomStringPool& ChspsDomDocument::StringPool() const
|
|
273 |
{
|
|
274 |
return *iDomStringPool;
|
|
275 |
}
|
|
276 |
|
|
277 |
// End of File
|