Xalan-C++ API Reference 1.12.0
FormatterToHTML.hpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18#if !defined(FORMATTERTOHTML_HEADER_GUARD_1357924680)
19#define FORMATTERTOHTML_HEADER_GUARD_1357924680
20
21
22
23// Base include file. Must be first.
25
26
27
29
30
31
32// Base class header file.
34
35
36
38
39
40
42
43
44
45namespace XALAN_CPP_NAMESPACE {
46
47
48
49/**
50 * FormatterToHTML formats SAX-style events into HTML.
51 */
53{
54
55public:
56
57
59
60
61 enum
62 {
63 eDefaultIndentAmount = 0
64 };
65
66 /**
67 * Constructor for customized encoding and doctype.
68 * @param writer The character output stream to use.
69 * @param encoding The character encoding in use by writer.
70 * @param doctypeSystem The system ID for the DOCTYPE.
71 * @param doctypePublic The public ID for the DOCTYPE.
72 * @param doIndent true if indenting should be enabled
73 * @param indent Number of spaces to indent at each nesting level.
74 * @param escapeURLs Whether or not to escape URLs according to the recommendation. The default is true.
75 * @param omitMetaTag Whether or not to output a META TAG according to the recommendation. The default is false.
76 */
79 const XalanDOMString& encoding = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
80 const XalanDOMString& mediaType = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
81 const XalanDOMString& doctypeSystem = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
82 const XalanDOMString& doctypePublic = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
83 bool doIndent = true,
84 int indent = eDefaultIndentAmount,
85 bool escapeURLs = true,
86 bool omitMetaTag = false,
87 MemoryManager& theManager XALAN_DEFAULT_MEMMGR);
88
89 static FormatterToHTML*
91 MemoryManager& theManager,
97 bool doIndent,
98 int indent,
99 bool escapeURLs,
100 bool omitMetaTag);
101 virtual
103
104 // These methods are inherited from DocumentHandler ...
105
106 virtual void
108
109 virtual void
111
112 virtual void
114 const XMLCh* const name,
116
117 virtual void
118 endElement(const XMLCh* const name);
119
120 virtual void
122 const XMLCh* const chars,
123 const size_type length);
124
125 // These methods are inherited from FormatterToXML...
126
127 virtual bool
130 bool escLF);
131
132 // These methods are inherited from FormatterListener ...
133
134 virtual void
136
137 virtual void
139 const XMLCh* const ch,
140 const size_type length);
141
142 virtual void
144 const XMLCh* const target,
145 const XMLCh* const data);
146
147
148 bool
150 {
151 return m_escapeURLs;
152 }
153
154 void
156 {
157 m_escapeURLs = flag;
158 }
159
160 struct Entity
161 {
162 enum { eMaxLength = 8 };
163
165
167
168 XalanDOMChar m_string[eMaxLength + 1];
169 };
170
171protected:
172
173 virtual void
175 const XalanDOMChar* theString,
177
178 virtual void
180
181 void
183
184 void
186 const XalanDOMChar* theString,
188
189private:
190
191 /**
192 * The string "<!DOCTYPE HTML".
193 */
194 static const XalanDOMChar s_doctypeHeaderStartString[];
195
196 static const size_type s_doctypeHeaderStartStringLength;
197
198 /**
199 * The string " PUBLIC \"".
200 */
201 static const XalanDOMChar s_doctypeHeaderPublicString[];
202
203 static const size_type s_doctypeHeaderPublicStringLength;
204
205 /**
206 * The string " SYSTEM".
207 */
208 static const XalanDOMChar s_doctypeHeaderSystemString[];
209
210 static const size_type s_doctypeHeaderSystemStringLength;
211
212 /**
213 * The string "<META http-equiv=\"Content-Type\" content=\"text/html; charset=".
214 */
215 static const XalanDOMChar s_metaString[];
216
217 static const size_type s_metaStringLength;
218
219 /**
220 * Set the attribute characters what will require special mapping.
221 */
222 void
223 initAttrCharsMap();
224
225 /**
226 * Set the output characters what will require special mapping.
227 */
228 void
229 initCharsMap();
230
231 void
232 copyEntityIntoBuffer(
233 const XalanDOMChar* s,
235
236 void
237 copyEntityIntoBuffer(const XalanDOMString& s);
238
239 /**
240 * Process an attribute.
241 * @param name The name of the attribute.
242 * @param value The value of the attribute.
243 */
244 virtual void
245 processAttribute(
246 const XalanDOMChar* name,
247 const XalanDOMChar* value,
249
250 /**
251 * Write the specified string after substituting non ASCII characters,
252 * with %HH, where HH is the hex of the byte value.
253 *
254 * @param theString String to convert to HTML format.
255 * @param theStringLength The length of the string.
256 */
257 void
258 writeAttrURI(
259 const XalanDOMChar* theString,
261
262 /**
263 * Accumulate the specified character by converting its numeric value to
264 * a hex string, making sure that any string of length 1 are written with
265 * a '0' before the number.
266 *
267 * @param theChar The character to accumulate
268 */
269 void
270 accumHexNumber(XalanDOMChar theChar);
271
272 bool
273 popHasNamespace()
274 {
275 return m_prefixResolver == 0 ?
276 false :
277 doPopHasNamespace();
278 }
279
280 bool
281 pushHasNamespace(const XalanDOMChar* theElementName)
282 {
283 return m_prefixResolver == 0 ?
284 false :
285 doPushHasNamespace(theElementName);
286 }
287
288 bool
289 doPopHasNamespace();
290
291 bool
292 doPushHasNamespace(const XalanDOMChar* theElementName);
293
294 // Data members...
295 XalanDOMString m_currentElementName;
296
297 bool m_inBlockElem;
298
299 BoolStackType m_isRawStack;
300
301 bool m_isScriptOrStyleElem;
302
303 BoolStackType m_inScriptElemStack;
304
305 bool m_escapeURLs;
306
307 /**
308 * A flag so we know whether or not we've put out the first
309 * element.
310 */
311 bool m_isFirstElement;
312
313 /**
314 * A counter so we can tell if we're inside the document element.
315 */
316 int m_elementLevel;
317
318 /**
319 * A stack to determine if the current element has
320 * a namespace.
321 */
322 BoolStackType m_hasNamespaceStack;
323
324 /**
325 * This is set to true if we should omit the META tag in HTML output (the default is false)
326 */
327 bool m_omitMetaTag;
328
329 ElementPropertiesStackType m_elementPropertiesStack;
330
331 static const XalanDOMString s_emptyString;
332
333 static const Entity s_entities[];
334
335 static const Entity* const s_lastEntity;
336};
337
338
339
340}
341
342
343
344#endif // FORMATTERTOHTML_HEADER_GUARD_1357924680
#define XALAN_XMLSUPPORT_EXPORT
#define XALAN_DEFAULT_MEMMGR
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
FormatterToHTML formats SAX-style events into HTML.
void writeCharacters(const XalanDOMString &theString)
virtual bool accumDefaultEntity(XalanDOMChar ch, bool escLF)
Handle one of the default entities, return false if it is not a default entity.
virtual void characters(const XMLCh *const chars, const size_type length)
virtual void startElement(const XMLCh *const name, AttributeListType &attrs)
virtual void entityReference(const XMLCh *const name)
Receive notification of a entityReference.
virtual void cdata(const XMLCh *const ch, const size_type length)
FormatterToHTML(Writer &writer, const XalanDOMString &encoding=XalanDOMString(XalanMemMgrs::getDummyMemMgr()), const XalanDOMString &mediaType=XalanDOMString(XalanMemMgrs::getDummyMemMgr()), const XalanDOMString &doctypeSystem=XalanDOMString(XalanMemMgrs::getDummyMemMgr()), const XalanDOMString &doctypePublic=XalanDOMString(XalanMemMgrs::getDummyMemMgr()), bool doIndent=true, int indent=eDefaultIndentAmount, bool escapeURLs=true, bool omitMetaTag=false, MemoryManager &theManager XALAN_DEFAULT_MEMMGR)
Constructor for customized encoding and doctype.
virtual void endElement(const XMLCh *const name)
virtual void endDocument()
static FormatterToHTML * create(MemoryManager &theManager, Writer &writer, const XalanDOMString &encoding, const XalanDOMString &mediaType, const XalanDOMString &doctypeSystem, const XalanDOMString &doctypePublic, bool doIndent, int indent, bool escapeURLs, bool omitMetaTag)
virtual void accumCommentData(const XalanDOMChar *data)
Write the data for a comment.
XalanVector< XalanHTMLElementsProperties::ElementProperties > ElementPropertiesStackType
virtual void writeAttrString(const XalanDOMChar *theString, size_type theStringLength)
Write an attribute string.
virtual void processingInstruction(const XMLCh *const target, const XMLCh *const data)
void writeCharacters(const XalanDOMChar *theString, size_type theLength)
virtual void startDocument()
FormatterToXML formats SAX-style events into XML.
This class acts as a proxy for an InternalElementProperties instance.
size_t size_type
Definition XalanMap.hpp:46
xercesc::AttributeList AttributeListType