|
1 /* |
|
2 * Copyright (c) 2002-2007 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: Class used for encoding xml landmark content. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef CPOSLMXMLENCODER_H |
|
20 #define CPOSLMXMLENCODER_H |
|
21 |
|
22 #include <EPos_CPosLandmarkEncoder.h> |
|
23 #include "EPos_LmConverter.h" |
|
24 |
|
25 class CPosLmOutput; |
|
26 |
|
27 /** |
|
28 * Class used for encoding xml landmark content. |
|
29 * |
|
30 * Output is written either to a buffer or to a file. |
|
31 * |
|
32 * The basic protocol for encoding is to 1) define where to write the |
|
33 * output to by calling @ref SetUseOutputBufferL or @ref SetOutputFileL, 2) |
|
34 * optionally add collection data using @ref AddCollectionDataL, 3) add |
|
35 * landmark data to encode by using functions in @ref CPosLandmarkEncoder |
|
36 * and/or @ref CPosLandmarkDatabase::ExportLandmarksL and 4) finalize the |
|
37 * encoding by calling @ref FinalizeEncodingL. If this protocol is not followed |
|
38 * the client is panicked with code @p EPosLmProtocolBreak. Encoding can be |
|
39 * performed multiple times using the same encoder object. |
|
40 * |
|
41 */ |
|
42 class CPosLmXmlEncoder : public CPosLandmarkEncoder |
|
43 { |
|
44 public: |
|
45 |
|
46 /** |
|
47 * Destructor. |
|
48 */ |
|
49 ~CPosLmXmlEncoder(); |
|
50 |
|
51 public: // From CPosLandmarkEncoder |
|
52 |
|
53 CBufBase* SetUseOutputBufferL(); |
|
54 |
|
55 void SetOutputFileL( const TDesC& aOutputFile ); |
|
56 |
|
57 void AddCollectionDataL( |
|
58 TPosLmCollectionDataId aDataId, |
|
59 const TDesC& aCollectionData ); |
|
60 |
|
61 void AddLandmarkL( const CPosLandmark& aLandmark ); |
|
62 |
|
63 void AddCategoryForLatestLandmarkL( const CPosLandmarkCategory& aCategory ); |
|
64 |
|
65 CPosLmOperation* FinalizeEncodingL(); |
|
66 |
|
67 protected: |
|
68 |
|
69 /** Writes start tags. At least root tag should be written */ |
|
70 virtual void WriteStartTagsL() = 0; |
|
71 |
|
72 /** Writes collection name and description, if supported */ |
|
73 virtual void WriteCollectionDataL( |
|
74 const HBufC* aCollectionName, |
|
75 const HBufC* aCollectionDescription ) = 0; |
|
76 |
|
77 /** Writes landmark with categories */ |
|
78 virtual void WriteLandmarkL( |
|
79 const CPosLandmark& aLandmark, |
|
80 const RPointerArray<const CPosLandmarkCategory>& aCategories ) = 0; |
|
81 |
|
82 /** Writes end tags. At least root tag closure should be written, but also |
|
83 * any other tag added in WriteStartTagsL should be closed */ |
|
84 virtual void WriteFinalTagsL() = 0; |
|
85 |
|
86 /** Returns string of tag name for given tag type */ |
|
87 virtual TPtrC TagNameL( TPosXmlTagType aTagType ) = 0; |
|
88 |
|
89 protected: |
|
90 |
|
91 /** |
|
92 * Checks if the specified tag type is a leaf or a branch. |
|
93 * |
|
94 * @param aXmlTagType The tag type. |
|
95 * @return ETrue if the tag type is a leaf, |
|
96 * EFalse if the tag type is a branch. |
|
97 */ |
|
98 TBool IsTagLeaf( TPosXmlTagType aXmlTagType ); |
|
99 |
|
100 /** Writes XML prolog */ |
|
101 void WritePrologL(); |
|
102 |
|
103 /** Writes start of XML tag with attributes string */ |
|
104 void WriteSTagL( TPosXmlTagType aTagType, const TDesC& aAttributes ); |
|
105 |
|
106 /** Writes end of XML tag */ |
|
107 void WriteETagL( TPosXmlTagType aTagType ); |
|
108 |
|
109 /** Writes full leaf tag with string value |
|
110 * @param aDes tag value |
|
111 * @param aTagType tag type */ |
|
112 void WriteStringWithTagsL( const TDesC16& aDes, TPosXmlTagType aTagType ); |
|
113 |
|
114 /** Writes full leaf tag with real value |
|
115 * @param aValue tag value |
|
116 * @param aTagType tag type */ |
|
117 void WriteTRealWithTagsL( TReal aValue, TPosXmlTagType aTagType ); |
|
118 |
|
119 /** Writes string value escaping prohibited characters |
|
120 * @param aDes tag value */ |
|
121 void WriteEscapedStringL( const TDesC& aDes ); |
|
122 |
|
123 private: |
|
124 |
|
125 CBufBase* CreateOutPutBufferLC(); |
|
126 |
|
127 void CreateOutputFileL( const TDesC& aOutputFile ); |
|
128 |
|
129 /** Starts encoding. Writes prolog string. */ |
|
130 void InitializeEncodingL(); |
|
131 |
|
132 void ResetEncoderL(); |
|
133 |
|
134 HBufC16* IndentationLC(); |
|
135 void ResetIndentation(); |
|
136 |
|
137 /** |
|
138 * Get the prolog string. |
|
139 * Caller takes ownership of the returned string. |
|
140 * |
|
141 * @return The prolog string. |
|
142 */ |
|
143 static HBufC16* PrologStringLC(); |
|
144 |
|
145 /** |
|
146 * Get the start tag for the specified tag type. |
|
147 * Caller takes ownership of the returned string. |
|
148 * |
|
149 * @param aTagType The tag type. |
|
150 * @param aAttributes String of attributes if any needed. |
|
151 * @return The start tag. |
|
152 */ |
|
153 HBufC16* STagStringLC( TPosXmlTagType aTagType, const TDesC& aAttributes ); |
|
154 |
|
155 /** |
|
156 * Get the end tag for the specified tag type. |
|
157 * Caller takes ownership of the returned string. |
|
158 * |
|
159 * @param aTagType The tag type. |
|
160 * @return The end tag. |
|
161 */ |
|
162 HBufC16* ETagStringLC( TPosXmlTagType aTagType ); |
|
163 |
|
164 /** Dumps last added landmark with categories */ |
|
165 void WriteLastLandmarkL(); |
|
166 |
|
167 protected: |
|
168 CPosLmXmlEncoder(); |
|
169 |
|
170 private: |
|
171 // Prohibit copy constructor |
|
172 CPosLmXmlEncoder( const CPosLmXmlEncoder& ); |
|
173 // Prohibit assigment operator |
|
174 CPosLmXmlEncoder& operator= ( const CPosLmXmlEncoder& ); |
|
175 |
|
176 protected: |
|
177 CPosLandmark* iLastLandmark; |
|
178 RPointerArray<const CPosLandmarkCategory> iCategories; |
|
179 |
|
180 private: // Data |
|
181 |
|
182 enum TPosEncoderStatus |
|
183 { |
|
184 EPosUninitialized = 0, |
|
185 EPosInitialized, |
|
186 EPosCollectionInfoAdded, |
|
187 EPosLmInfoAdded |
|
188 }; |
|
189 |
|
190 TPosEncoderStatus iEncoderStatus; |
|
191 |
|
192 CPosLmOutput* iOutput; |
|
193 |
|
194 HBufC* iCollectionDataName; |
|
195 HBufC* iCollectionDataDescription; |
|
196 |
|
197 TInt iIndentationDepth; |
|
198 }; |
|
199 |
|
200 #endif // CPOSLMXMLENCODER_H |