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 
45 namespace XALAN_CPP_NAMESPACE {
46 
47 
48 
49 /**
50  * FormatterToHTML formats SAX-style events into HTML.
51  */
53 {
54 
55 public:
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  */
78  Writer& writer,
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*
90  create(
91  MemoryManager& theManager,
92  Writer& writer,
93  const XalanDOMString& encoding,
94  const XalanDOMString& mediaType,
95  const XalanDOMString& doctypeSystem,
96  const XalanDOMString& doctypePublic,
97  bool doIndent,
98  int indent,
99  bool escapeURLs,
100  bool omitMetaTag);
101  virtual
102  ~FormatterToHTML();
103 
104  // These methods are inherited from DocumentHandler ...
105 
106  virtual void
107  startDocument();
108 
109  virtual void
110  endDocument();
111 
112  virtual void
113  startElement(
114  const XMLCh* const name,
115  AttributeListType& attrs);
116 
117  virtual void
118  endElement(const XMLCh* const name);
119 
120  virtual void
121  characters(
122  const XMLCh* const chars,
123  const size_type length);
124 
125  // These methods are inherited from FormatterToXML...
126 
127  virtual bool
128  accumDefaultEntity(
129  XalanDOMChar ch,
130  bool escLF);
131 
132  // These methods are inherited from FormatterListener ...
133 
134  virtual void
135  entityReference(const XMLCh* const name);
136 
137  virtual void
138  cdata(
139  const XMLCh* const ch,
140  const size_type length);
141 
142  virtual void
143  processingInstruction(
144  const XMLCh* const target,
145  const XMLCh* const data);
146 
147 
148  bool
150  {
151  return m_escapeURLs;
152  }
153 
154  void
155  setEscapeURLs(bool flag)
156  {
157  m_escapeURLs = flag;
158  }
159 
160  struct Entity
161  {
162  enum { eMaxLength = 8 };
163 
164  XalanDOMChar m_char;
165 
167 
168  XalanDOMChar m_string[eMaxLength + 1];
169  };
170 
171 protected:
172 
173  virtual void
174  writeAttrString(
175  const XalanDOMChar* theString,
176  size_type theStringLength);
177 
178  virtual void
179  accumCommentData(const XalanDOMChar* data);
180 
181  void
182  writeCharacters(const XalanDOMString& theString);
183 
184  void
185  writeCharacters(
186  const XalanDOMChar* theString,
187  size_type theLength);
188 
189 private:
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,
234  size_type theLength);
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,
248  const XalanHTMLElementsProperties::ElementProperties& elemProperties);
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,
260  size_type theStringLength);
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
xalanc::FormatterToHTML::Entity::m_length
size_type m_length
Definition: FormatterToHTML.hpp:166
xalanc::XalanHTMLElementsProperties::ElementProperties
This class acts as a proxy for an InternalElementProperties instance.
Definition: XalanHTMLElementsProperties.hpp:152
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
FormatterToXML.hpp
xalanc::AttributeListType
xercesc::AttributeList AttributeListType
Definition: AttributeListImpl.hpp:41
xalanc::XalanVector< XalanHTMLElementsProperties::ElementProperties >
xalanc::size_type
size_t size_type
Definition: XalanMap.hpp:46
XALAN_DEFAULT_MEMMGR
#define XALAN_DEFAULT_MEMMGR
Definition: XalanMemoryManagement.hpp:516
XalanVector.hpp
xalanc::FormatterToHTML::setEscapeURLs
void setEscapeURLs(bool flag)
Definition: FormatterToHTML.hpp:155
xalanc::FormatterToHTML::getEscapeURLs
bool getEscapeURLs() const
Definition: FormatterToHTML.hpp:149
xalanc::FormatterListener::size_type
XalanSize_t size_type
Definition: FormatterListener.hpp:63
DOMStringHelper.hpp
xalanc::length
XalanDOMString::size_type length(const XalanDOMString &theString)
Get the length of a XalanDOMString.
Definition: DOMStringHelper.hpp:235
xalanc::FormatterToHTML::ElementPropertiesStackType
XalanVector< XalanHTMLElementsProperties::ElementProperties > ElementPropertiesStackType
Definition: FormatterToHTML.hpp:58
xalanc::FormatterToHTML::Entity
Definition: FormatterToHTML.hpp:160
XalanHTMLElementsProperties.hpp
xalanc::FormatterToXML
FormatterToXML formats SAX-style events into XML.
Definition: FormatterToXML.hpp:59
xalanc::FormatterToHTML::Entity::m_char
XalanDOMChar m_char
Definition: FormatterToHTML.hpp:164
xalanc::XalanDOMString
Definition: XalanDOMString.hpp:45
xalanc::FormatterToHTML
FormatterToHTML formats SAX-style events into HTML.
Definition: FormatterToHTML.hpp:52
XMLSupportDefinitions.hpp
XALAN_XMLSUPPORT_EXPORT
#define XALAN_XMLSUPPORT_EXPORT
Definition: XMLSupportDefinitions.hpp:35
xalanc::Writer
Definition: Writer.hpp:44