1 martin 1.3 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.4 //
|
3 martin 1.3 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.4 //
|
10 martin 1.3 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.4 //
|
17 martin 1.3 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.4 //
|
20 martin 1.3 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.4 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.3 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.4 //
|
28 martin 1.3 //////////////////////////////////////////////////////////////////////////
|
29 kumpf 1.1 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #ifndef Pegasus_XmlGenerator_h
33 #define Pegasus_XmlGenerator_h
34
35 #include <iostream>
36 #include <Pegasus/Common/Config.h>
37 #include <Pegasus/Common/Linkage.h>
38 #include <Pegasus/Common/ArrayInternal.h>
39 #include <Pegasus/Common/String.h>
40 #include <Pegasus/Common/CIMName.h>
41 #include <Pegasus/Common/Buffer.h>
42 #include <Pegasus/Common/AcceptLanguageList.h>
43 #include <Pegasus/Common/ContentLanguageList.h>
44 #include <Pegasus/Common/XmlParser.h>
45
46 PEGASUS_NAMESPACE_BEGIN
47
48 class PEGASUS_COMMON_LINKAGE XmlGenerator
49 {
50 kumpf 1.1 public:
51
52 static void append(Buffer& out, char x)
53 {
54 out.append(x);
55 }
56
57 static void append(Buffer& out, const Char16& x);
58 static void append(Buffer& out, Boolean x);
59 static void append(Buffer& out, Uint32 x);
60 static void append(Buffer& out, Sint32 x);
61 static void append(Buffer& out, Uint64 x);
62 static void append(Buffer& out, Sint64 x);
63 static void append(Buffer& out, Real32 x);
64 static void append(Buffer& out, Real64 x);
65 static void append(Buffer& out, const char* str);
66 static void append(Buffer& out, const String& str);
67
68 static void appendSpecial(Buffer& out, const Char16& x);
69 static void appendSpecial(Buffer& out, char x);
70 static void appendSpecial(Buffer& out, const char* str);
71 kumpf 1.1 static void appendSpecial(Buffer& out, const String& str);
72
|
73 thilo.boehm 1.6 static void appendSpecial(Buffer& out, const char* str, Uint32 size);
74
|
75 kumpf 1.1 static String encodeURICharacters(const Buffer& uriString);
76 static String encodeURICharacters(const String& uriString);
|
77 kumpf 1.5
|
78 kumpf 1.1 static void indentedPrint(
79 PEGASUS_STD(ostream)& os,
80 const char* text,
81 Uint32 indentChars = 2);
82
|
83 thilo.boehm 1.6 static StrLit xmlWriterTypeStrings(CIMType type)
84 {
85 return _XmlWriterTypeStrings[type];
86 }
87
88 static StrLit xmlWriterKeyTypeStrings(CIMType type)
89 {
90 return _XmlWriterKeyTypeStrings[type];
91 }
92
|
93 kumpf 1.1 private:
94
|
95 kumpf 1.5 static void _appendChar(Buffer& out, const Char16& c);
|
96 kumpf 1.1 static void _appendSpecialChar7(Buffer& out, char c);
97 static void _appendSpecialChar(Buffer& out, const Char16& c);
98 static void _appendSpecialChar(PEGASUS_STD(ostream)& os, char c);
99 static void _appendSurrogatePair(
100 Buffer& out, Uint16 high, Uint16 low);
101 static void _appendSpecial(
102 PEGASUS_STD(ostream)& os, const char* str);
103 #ifdef PEGASUS_OS_TYPE_WINDOWS
104 static void _normalizeRealValueString(char *str);
105 #endif
106
107 static void _encodeURIChar(String& outString, Sint8 char8);
108
109 static void _printAttributes(
110 PEGASUS_STD(ostream)& os,
111 const XmlAttribute* attributes,
112 Uint32 attributeCount);
113
114 static void _indent(
115 PEGASUS_STD(ostream)& os,
116 Uint32 level,
117 kumpf 1.1 Uint32 indentChars);
118
119 XmlGenerator();
|
120 thilo.boehm 1.6
121 static const StrLit _XmlWriterTypeStrings[17];
122 static const StrLit _XmlWriterKeyTypeStrings[17];
|
123 kumpf 1.1 };
124
125 PEGASUS_COMMON_LINKAGE Buffer& operator<<(
126 Buffer& out,
127 const char* x);
128
129 inline Buffer& operator<<(Buffer& out, char x)
130 {
131 out.append(x);
132 return out;
133 }
134
135 inline Buffer& operator<<(Buffer& out, const char* s)
136 {
137 out.append(s, (Uint32)strlen(s));
138 return out;
139 }
140
141 PEGASUS_COMMON_LINKAGE Buffer& operator<<(
|
142 kumpf 1.5 Buffer& out,
|
143 kumpf 1.1 const AcceptLanguageList& al);
144
145 PEGASUS_COMMON_LINKAGE Buffer& operator<<(
|
146 kumpf 1.5 Buffer& out,
|
147 kumpf 1.1 const ContentLanguageList& cl);
148
149 PEGASUS_COMMON_LINKAGE Buffer& operator<<(Buffer& out, const Char16& x);
150
151 PEGASUS_COMMON_LINKAGE Buffer& operator<<(
152 Buffer& out,
153 const String& x);
154
155 PEGASUS_COMMON_LINKAGE Buffer& operator<<(
156 Buffer& out,
157 const Buffer& x);
158
159 PEGASUS_COMMON_LINKAGE Buffer& operator<<(
160 Buffer& out,
161 Uint32 x);
162
163 PEGASUS_COMMON_LINKAGE Buffer& operator<<(
164 Buffer& out,
165 const CIMName& name);
166
167 // This is a shortcut macro for outputing content length. This
168 kumpf 1.1 // pads the output number to the max characters representing a Uint32 number
169 // so that it can be overwritten easily with a transfer encoding line later
170 // on in HTTPConnection if required. This is strictly for performance since
171 // messages can be very large. This overwriting shortcut allows us to NOT have
172 // to repackage a large message later.
173
174 #define OUTPUT_CONTENTLENGTH(out, contentLength) \
175 { \
176 char contentLengthP[11]; \
|
177 kumpf 1.2 int n = sprintf(contentLengthP,"%.10u", (unsigned int)contentLength); \
|
178 kumpf 1.1 out << STRLIT("content-length: "); \
179 out.append(contentLengthP, n); \
180 out << STRLIT("\r\n"); \
181 }
182
183 PEGASUS_NAMESPACE_END
184
185 #endif /* Pegasus_XmlGenerator_h */
|