00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one 00003 * or more contributor license agreements. See the NOTICE file 00004 * distributed with this work for additional information 00005 * regarding copyright ownership. The ASF licenses this file 00006 * to you under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 #if !defined(FORMATTERTOHTML_HEADER_GUARD_1357924680) 00019 #define FORMATTERTOHTML_HEADER_GUARD_1357924680 00020 00021 00022 00023 // Base include file. Must be first. 00024 #include <xalanc/XMLSupport/XMLSupportDefinitions.hpp> 00025 00026 00027 00028 #include <xalanc/Include/XalanVector.hpp> 00029 00030 00031 00032 // Base class header file. 00033 #include <xalanc/XMLSupport/FormatterToXML.hpp> 00034 00035 00036 00037 #include <xalanc/PlatformSupport/DOMStringHelper.hpp> 00038 00039 00040 00041 #include <xalanc/XMLSupport/XalanHTMLElementsProperties.hpp> 00042 00043 00044 00045 XALAN_CPP_NAMESPACE_BEGIN 00046 00047 00048 00049 /** 00050 * FormatterToHTML formats SAX-style events into HTML. 00051 */ 00052 class XALAN_XMLSUPPORT_EXPORT FormatterToHTML : public FormatterToXML 00053 { 00054 00055 public: 00056 00057 00058 typedef XalanVector<XalanHTMLElementsProperties::ElementProperties> ElementPropertiesStackType; 00059 00060 00061 enum 00062 { 00063 eDefaultIndentAmount = 0 00064 }; 00065 00066 /** 00067 * Constructor for customized encoding and doctype. 00068 * @param writer The character output stream to use. 00069 * @param encoding The character encoding in use by writer. 00070 * @param doctypeSystem The system ID for the DOCTYPE. 00071 * @param doctypePublic The public ID for the DOCTYPE. 00072 * @param doIndent true if indenting should be enabled 00073 * @param indent Number of spaces to indent at each nesting level. 00074 * @param escapeURLs Whether or not to escape URLs according to the recommendation. The default is true. 00075 * @param omitMetaTag Whether or not to output a META TAG according to the recommendation. The default is false. 00076 */ 00077 FormatterToHTML( 00078 Writer& writer, 00079 const XalanDOMString& encoding = XalanDOMString(XalanMemMgrs::getDummyMemMgr()), 00080 const XalanDOMString& mediaType = XalanDOMString(XalanMemMgrs::getDummyMemMgr()), 00081 const XalanDOMString& doctypeSystem = XalanDOMString(XalanMemMgrs::getDummyMemMgr()), 00082 const XalanDOMString& doctypePublic = XalanDOMString(XalanMemMgrs::getDummyMemMgr()), 00083 bool doIndent = true, 00084 int indent = eDefaultIndentAmount, 00085 bool escapeURLs = true, 00086 bool omitMetaTag = false, 00087 MemoryManager& theManager XALAN_DEFAULT_MEMMGR); 00088 00089 static FormatterToHTML* 00090 create( 00091 MemoryManager& theManager, 00092 Writer& writer, 00093 const XalanDOMString& encoding, 00094 const XalanDOMString& mediaType, 00095 const XalanDOMString& doctypeSystem, 00096 const XalanDOMString& doctypePublic, 00097 bool doIndent, 00098 int indent, 00099 bool escapeURLs, 00100 bool omitMetaTag); 00101 virtual 00102 ~FormatterToHTML(); 00103 00104 // These methods are inherited from DocumentHandler ... 00105 00106 virtual void 00107 startDocument(); 00108 00109 virtual void 00110 endDocument(); 00111 00112 virtual void 00113 startElement( 00114 const XMLCh* const name, 00115 AttributeListType& attrs); 00116 00117 virtual void 00118 endElement(const XMLCh* const name); 00119 00120 virtual void 00121 characters( 00122 const XMLCh* const chars, 00123 const size_type length); 00124 00125 // These methods are inherited from FormatterToXML... 00126 00127 virtual bool 00128 accumDefaultEntity( 00129 XalanDOMChar ch, 00130 bool escLF); 00131 00132 // These methods are inherited from FormatterListener ... 00133 00134 virtual void 00135 entityReference(const XMLCh* const name); 00136 00137 virtual void 00138 cdata( 00139 const XMLCh* const ch, 00140 const size_type length); 00141 00142 virtual void 00143 processingInstruction( 00144 const XMLCh* const target, 00145 const XMLCh* const data); 00146 00147 00148 bool 00149 getEscapeURLs() const 00150 { 00151 return m_escapeURLs; 00152 } 00153 00154 void 00155 setEscapeURLs(bool flag) 00156 { 00157 m_escapeURLs = flag; 00158 } 00159 00160 struct Entity 00161 { 00162 enum { eMaxLength = 8 }; 00163 00164 XalanDOMChar m_char; 00165 00166 size_type m_length; 00167 00168 XalanDOMChar m_string[eMaxLength + 1]; 00169 }; 00170 00171 protected: 00172 00173 virtual void 00174 writeAttrString( 00175 const XalanDOMChar* theString, 00176 size_type theStringLength); 00177 00178 virtual void 00179 accumCommentData(const XalanDOMChar* data); 00180 00181 void 00182 writeCharacters(const XalanDOMString& theString); 00183 00184 void 00185 writeCharacters( 00186 const XalanDOMChar* theString, 00187 size_type theLength); 00188 00189 private: 00190 00191 /** 00192 * The string "<!DOCTYPE HTML". 00193 */ 00194 static const XalanDOMChar s_doctypeHeaderStartString[]; 00195 00196 static const size_type s_doctypeHeaderStartStringLength; 00197 00198 /** 00199 * The string " PUBLIC \"". 00200 */ 00201 static const XalanDOMChar s_doctypeHeaderPublicString[]; 00202 00203 static const size_type s_doctypeHeaderPublicStringLength; 00204 00205 /** 00206 * The string " SYSTEM". 00207 */ 00208 static const XalanDOMChar s_doctypeHeaderSystemString[]; 00209 00210 static const size_type s_doctypeHeaderSystemStringLength; 00211 00212 /** 00213 * The string "<META http-equiv=\"Content-Type\" content=\"text/html; charset=". 00214 */ 00215 static const XalanDOMChar s_metaString[]; 00216 00217 static const size_type s_metaStringLength; 00218 00219 /** 00220 * Set the attribute characters what will require special mapping. 00221 */ 00222 void 00223 initAttrCharsMap(); 00224 00225 /** 00226 * Set the output characters what will require special mapping. 00227 */ 00228 void 00229 initCharsMap(); 00230 00231 void 00232 copyEntityIntoBuffer( 00233 const XalanDOMChar* s, 00234 size_type theLength); 00235 00236 void 00237 copyEntityIntoBuffer(const XalanDOMString& s); 00238 00239 /** 00240 * Process an attribute. 00241 * @param name The name of the attribute. 00242 * @param value The value of the attribute. 00243 */ 00244 virtual void 00245 processAttribute( 00246 const XalanDOMChar* name, 00247 const XalanDOMChar* value, 00248 const XalanHTMLElementsProperties::ElementProperties& elemProperties); 00249 00250 /** 00251 * Write the specified string after substituting non ASCII characters, 00252 * with %HH, where HH is the hex of the byte value. 00253 * 00254 * @param theString String to convert to HTML format. 00255 * @param theStringLength The length of the string. 00256 */ 00257 void 00258 writeAttrURI( 00259 const XalanDOMChar* theString, 00260 size_type theStringLength); 00261 00262 /** 00263 * Accumulate the specified character by converting its numeric value to 00264 * a hex string, making sure that any string of length 1 are written with 00265 * a '0' before the number. 00266 * 00267 * @param theChar The character to accumulate 00268 */ 00269 void 00270 accumHexNumber(XalanDOMChar theChar); 00271 00272 bool 00273 popHasNamespace() 00274 { 00275 return m_prefixResolver == 0 ? 00276 false : 00277 doPopHasNamespace(); 00278 } 00279 00280 bool 00281 pushHasNamespace(const XalanDOMChar* theElementName) 00282 { 00283 return m_prefixResolver == 0 ? 00284 false : 00285 doPushHasNamespace(theElementName); 00286 } 00287 00288 bool 00289 doPopHasNamespace(); 00290 00291 bool 00292 doPushHasNamespace(const XalanDOMChar* theElementName); 00293 00294 // Data members... 00295 XalanDOMString m_currentElementName; 00296 00297 bool m_inBlockElem; 00298 00299 BoolStackType m_isRawStack; 00300 00301 bool m_isScriptOrStyleElem; 00302 00303 BoolStackType m_inScriptElemStack; 00304 00305 bool m_escapeURLs; 00306 00307 /** 00308 * A flag so we know whether or not we've put out the first 00309 * element. 00310 */ 00311 bool m_isFirstElement; 00312 00313 /** 00314 * A counter so we can tell if we're inside the document element. 00315 */ 00316 int m_elementLevel; 00317 00318 /** 00319 * A stack to determine if the current element has 00320 * a namespace. 00321 */ 00322 BoolStackType m_hasNamespaceStack; 00323 00324 /** 00325 * This is set to true if we should omit the META tag in HTML output (the default is false) 00326 */ 00327 bool m_omitMetaTag; 00328 00329 ElementPropertiesStackType m_elementPropertiesStack; 00330 00331 static const XalanDOMString s_emptyString; 00332 00333 static const Entity s_entities[]; 00334 00335 static const Entity* const s_lastEntity; 00336 }; 00337 00338 00339 00340 XALAN_CPP_NAMESPACE_END 00341 00342 00343 00344 #endif // FORMATTERTOHTML_HEADER_GUARD_1357924680
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
Xalan-C++ XSLT Processor Version 1.11 |
|