|
1 /* |
|
2 * Copyright (c) 2002 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 generator |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __XMLGENERATOR_H__ |
|
20 #define __XMLGENERATOR_H__ |
|
21 |
|
22 // ------------------------------------------------------------------------------------------------ |
|
23 // Includes |
|
24 // ------------------------------------------------------------------------------------------------ |
|
25 #include <e32base.h> |
|
26 |
|
27 #include "WBXMLAttributes.h" |
|
28 |
|
29 // ------------------------------------------------------------------------------------------------ |
|
30 // Class forwards |
|
31 // ------------------------------------------------------------------------------------------------ |
|
32 |
|
33 class CXMLWorkspace; |
|
34 |
|
35 // ------------------------------------------------------------------------------------------------ |
|
36 // TXMLContentFormat |
|
37 // ------------------------------------------------------------------------------------------------ |
|
38 enum TXMLContentFormat |
|
39 { |
|
40 EXMLContentFormatOpaque, |
|
41 EXMLContentFormatInlineString |
|
42 }; |
|
43 |
|
44 // ------------------------------------------------------------------------------------------------ |
|
45 // CXMLGenerator |
|
46 // ------------------------------------------------------------------------------------------------ |
|
47 class CXMLGenerator : public CBase |
|
48 { |
|
49 public: |
|
50 IMPORT_C TPtrC8 Document(); |
|
51 IMPORT_C void Reset(); |
|
52 IMPORT_C CXMLWorkspace* Workspace() const; |
|
53 IMPORT_C void SetWorkspace( CXMLWorkspace* aBuffer, TBool aTakeOwnership = EFalse ); |
|
54 IMPORT_C TInt IndentLevel() const; |
|
55 IMPORT_C void SetIndentLevel( TInt aLevel ); |
|
56 |
|
57 protected: |
|
58 enum TNSmlNamespaceAppendType |
|
59 { |
|
60 EAppendToEveryElement, |
|
61 EAppendToFirstElementOnly |
|
62 }; |
|
63 |
|
64 IMPORT_C CXMLGenerator(); |
|
65 IMPORT_C virtual ~CXMLGenerator(); |
|
66 |
|
67 IMPORT_C void CreateStaticWorkspaceL( TInt aBufferSize ); |
|
68 IMPORT_C void CreateDynamicWorkspaceL(); |
|
69 |
|
70 // XML |
|
71 IMPORT_C void BeginDocumentL( TUint8 aVersion, TInt32 aPublicId, TUint32 aCharset, const TDesC8& aStringTbl = TPtrC8() ); // Negative PublicId = offset to string table |
|
72 |
|
73 IMPORT_C void BeginElementL( TUint8 aElement, TBool aHasContent = EFalse, TBool aHasAttributes = EFalse ); |
|
74 IMPORT_C void EndElementL(); |
|
75 |
|
76 IMPORT_C void AddElementL( TUint8 aElement, const TDesC8& aContent, const TXMLContentFormat aFormat = EXMLContentFormatOpaque ); |
|
77 IMPORT_C void AddElementL( TUint8 aElement, const TDesC8& aContent, const CWBXMLAttributes& aAttributes, const TXMLContentFormat aFormat = EXMLContentFormatOpaque ); |
|
78 |
|
79 IMPORT_C void AddEntityL( TUint32 aEntity ); |
|
80 |
|
81 IMPORT_C void AddExt_IL( TInt aExtNum, const TDesC8& aContent ); |
|
82 IMPORT_C void AddExt_TL( TInt aExtNum, TUint32 aContent ); |
|
83 IMPORT_C void AddExtL( TInt aExtNum ); |
|
84 |
|
85 IMPORT_C void SwitchCodePageL( TUint8 aNewCodePage ); |
|
86 |
|
87 IMPORT_C TInt HandleResult( TInt aResult, TInt aTreshold = 0 ); |
|
88 |
|
89 IMPORT_C void SetTranslateTableL( const TDesC8& aTable ); |
|
90 IMPORT_C void SetNamespaceNameL( const TDesC8& aName, TNSmlNamespaceAppendType aAppendType = EAppendToFirstElementOnly ); |
|
91 |
|
92 private: |
|
93 TPtrC8 TranslateElement( TUint8 aElement ); |
|
94 void WriteMUint32L( TUint32 aValue ); |
|
95 void WriteOpaqueDataL( const TDesC8& aData ); |
|
96 void WriteInlineStringL( const TDesC8& aData ); |
|
97 void FreeWorkspace(); |
|
98 void ConstructL( const TDesC8& aElements ); |
|
99 void IndentL(); |
|
100 |
|
101 private: |
|
102 RArray<TUint8> iElemStack; |
|
103 HBufC8* iTable; |
|
104 HBufC8* iNSName; |
|
105 CXMLWorkspace* iWorkspace; |
|
106 TBool iOwnsWorkspace; |
|
107 TBool iNSAppended; |
|
108 TBool iDontNewLine; |
|
109 TBool iDontIndent; |
|
110 TNSmlNamespaceAppendType iNSAppendType; |
|
111 TInt iInitialIndentLevel; |
|
112 }; |
|
113 |
|
114 #endif // __XMLGENERATOR_H__ |