|
1 /* |
|
2 * Copyright (c) 2004 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: XML Serializer implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef __CPENGXMLSERIALIZER_H__ |
|
19 #define __CPENGXMLSERIALIZER_H__ |
|
20 |
|
21 // INCLUDES |
|
22 #include <e32base.h> |
|
23 #include <e32std.h> |
|
24 #include <badesca.h> |
|
25 |
|
26 #include "MPEngXmlSerializer.h" |
|
27 #include "TPEngWriter.h" |
|
28 |
|
29 |
|
30 |
|
31 //MODULE DATA STRUCTURES |
|
32 /** |
|
33 * Enumeration defining different |
|
34 * serializer states. |
|
35 */ |
|
36 enum TPEngSerializerState |
|
37 { |
|
38 EPEngInRoot = 0, ///< Initial state. No start tag or element open (ready to accept start tags or content). |
|
39 EPEngInStartTag, ///< Start tag's start written (ready to accept XML attributes). |
|
40 EPEngInElement, ///< Start tag closed, in element (ready to accept content). |
|
41 }; |
|
42 |
|
43 |
|
44 /** |
|
45 * Container for serializer state specific data. |
|
46 * |
|
47 * Data holded by this structure is |
|
48 * used when rolling back the serializer |
|
49 * state. |
|
50 */ |
|
51 struct TPEngSerializerStateData |
|
52 { |
|
53 TInt iWriterLength; ///< Length of produced XML in the writer. |
|
54 TPEngSerializerState iState; ///< Serializer state enumeration. |
|
55 #ifdef __SERIALIZER_TAG_NAME_ASSERT |
|
56 TInt iAssertionStackCount; ///< Count of elements there in the element stack. |
|
57 #endif |
|
58 }; |
|
59 |
|
60 |
|
61 |
|
62 //FORWARD DECLARATION |
|
63 class CPEngTagAssertionStack; |
|
64 |
|
65 |
|
66 |
|
67 // CLASS DECLARATION |
|
68 /** |
|
69 * XML Serializer implementation. |
|
70 * |
|
71 * @lib PEngParser.lib |
|
72 * @since 2.1 |
|
73 */ |
|
74 class CPEngXmlSerializer : public CBase, |
|
75 public MPEngXMLSerializer |
|
76 { |
|
77 public: // Two-phased constructors and destructor |
|
78 |
|
79 /** |
|
80 * Two-phased constructor. |
|
81 * |
|
82 * @since 2.1 |
|
83 */ |
|
84 IMPORT_C static CPEngXmlSerializer* NewL( TDes8& aBuffer ); |
|
85 IMPORT_C static CPEngXmlSerializer* NewLC( TDes8& aBuffer ); |
|
86 |
|
87 |
|
88 /** |
|
89 * Destructor. |
|
90 */ |
|
91 ~CPEngXmlSerializer(); |
|
92 |
|
93 private: |
|
94 |
|
95 /** |
|
96 * C++ constructor. |
|
97 */ |
|
98 CPEngXmlSerializer( TDes8& aBuffer ); |
|
99 |
|
100 /** |
|
101 * Symbian OS constructor. |
|
102 */ |
|
103 void ConstructL(); |
|
104 |
|
105 public: // XML Serialization methods from MPEngXmlSerializer |
|
106 |
|
107 |
|
108 void Close(); |
|
109 |
|
110 MPEngXMLSerializer& StartTagL( const TDesC8& aName ); |
|
111 MPEngXMLSerializer& AttributeL( const TDesC8& aName, const TDesC8& aValue ); |
|
112 MPEngXMLSerializer& EndTagL( const TDesC8& aName ); |
|
113 |
|
114 |
|
115 MPEngXMLSerializer& RawValueL( const TDesC8& aValue ); |
|
116 MPEngXMLSerializer& NarrowTextL( const TDesC8& aText ); |
|
117 MPEngXMLSerializer& UnicodeTextL( const TDesC16& aText ); |
|
118 MPEngXMLSerializer& WvAddressL( const TDesC16& aAddress ); |
|
119 MPEngXMLSerializer& Base64DataL( const TDesC8& aData ); |
|
120 |
|
121 |
|
122 |
|
123 public: //Serializer state handling support |
|
124 |
|
125 /** |
|
126 * @see MPEngXmlSerializer |
|
127 * |
|
128 * @since 2.1 |
|
129 */ |
|
130 void PushSerializerStateL(); |
|
131 |
|
132 /** |
|
133 * @see MPEngXmlSerializer |
|
134 * |
|
135 * @since 2.1 |
|
136 */ |
|
137 void CommitState(); |
|
138 |
|
139 /** |
|
140 * @see MPEngXmlSerializer |
|
141 * |
|
142 * @since 2.1 |
|
143 */ |
|
144 void RollbackState(); |
|
145 |
|
146 /** |
|
147 * @see MPEngXmlSerializer |
|
148 * |
|
149 * @since 2.1 |
|
150 */ |
|
151 TInt PushedStateCount(); |
|
152 |
|
153 |
|
154 protected: //Private helpers |
|
155 |
|
156 |
|
157 void CheckAndCloseOpenStartTagL(); |
|
158 TInt EncodeWvAddressChars( TDes16& aEncodedAddress, |
|
159 const TDesC16& aUnicodeAddress ); |
|
160 |
|
161 void WriteXmlEscapedL( const TDesC8& aString, |
|
162 TBool aEscapeQuotes ); |
|
163 |
|
164 void WriteXmlEscapedL( TUint8 aCharacter, |
|
165 TBool aEscapeQuotes ); |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 protected: //Assertion helpers |
|
172 |
|
173 void __AssertNoXmlEscapedCharsL( const TDesC8& aString ); |
|
174 |
|
175 void __AssertSerializerStateL( TBool aInCorrectState, |
|
176 TPEngSerializerPanics aPanicReason ); |
|
177 |
|
178 void __AssertNotEmptyL( const TDesC8& aString ); |
|
179 |
|
180 |
|
181 #ifdef __SERIALIZER_TAG_NAME_ASSERT |
|
182 void __AssertEndTagName( const TDesC8& aEndTagName ); |
|
183 #endif // __SERIALIZER_TAG_NAME_ASSERT |
|
184 |
|
185 |
|
186 private: // Data |
|
187 |
|
188 //OWN: serializer state |
|
189 TPEngSerializerState iState; |
|
190 |
|
191 //OWN: Content writer |
|
192 TPEngWriter iWriter; |
|
193 |
|
194 //OWN: Start tag count |
|
195 TInt iStartTagCount; |
|
196 |
|
197 //OWN: Pushed states |
|
198 RArray< TPEngSerializerStateData > iStateStack; |
|
199 |
|
200 #ifdef __SERIALIZER_TAG_NAME_ASSERT |
|
201 //OWN: Start tag assertion stack |
|
202 CPEngTagAssertionStack* iAssertionStack; |
|
203 #endif // __SERIALIZER_TAG_NAME_ASSERT |
|
204 }; |
|
205 |
|
206 #endif // __CPENGXMLSERIALIZER_H__ |
|
207 |
|
208 |
|
209 // End of File |