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(XALANIDENTWRITER_HEADER_GUARD_1357924680) 00019 #define XALANIDENTWRITER_HEADER_GUARD_1357924680 00020 00021 00022 // Base include file. Must be first. 00023 #include <xalanc/XMLSupport/XMLSupportDefinitions.hpp> 00024 00025 #include <xalanc/Include/XalanVector.hpp> 00026 00027 #include <xalanc/PlatformSupport/FormatterListener.hpp> 00028 #include <xalanc/PlatformSupport/Writer.hpp> 00029 00030 00031 XALAN_CPP_NAMESPACE_BEGIN 00032 00033 00034 template< 00035 class WhiteSpaceWriter, 00036 class NewLineWriter> 00037 class XalanIndentWriter 00038 { 00039 public: 00040 00041 typedef FormatterListener::size_type size_type; 00042 typedef XalanVector<bool> BoolStackType; 00043 typedef typename WhiteSpaceWriter::writer_type writer_type; 00044 00045 XalanIndentWriter( 00046 writer_type& writer, 00047 size_type ident) : 00048 m_whiteSpaceWriter(writer), 00049 m_newLineWriter(writer), 00050 m_indent(ident), 00051 m_currentIndent(0), 00052 m_startNewLine(false), 00053 m_ispreserve(false), 00054 m_isprevtext(false), 00055 m_preserves(writer.getMemoryManager(), 5) 00056 { 00057 assert( m_indent != -1); 00058 } 00059 00060 ~XalanIndentWriter() 00061 { 00062 } 00063 00064 00065 void 00066 setIndent(size_type value) 00067 { 00068 m_indent = value; 00069 } 00070 00071 size_type 00072 getIndent()const 00073 { 00074 return m_indent; 00075 } 00076 00077 void 00078 indent() 00079 { 00080 if( shouldIndent() ) 00081 { 00082 if(m_startNewLine == true) 00083 { 00084 m_newLineWriter(); 00085 } 00086 00087 m_whiteSpaceWriter(m_currentIndent); 00088 00089 } 00090 } 00091 00092 void 00093 increaseIndent() 00094 { 00095 m_currentIndent += m_indent; 00096 } 00097 00098 void 00099 decreaseIndent() 00100 { 00101 assert( m_currentIndent >= m_indent); 00102 00103 m_currentIndent -= m_indent; 00104 } 00105 00106 void 00107 setStartNewLine(bool value) 00108 { 00109 m_startNewLine = value; 00110 } 00111 00112 /** 00113 * Output a line break. 00114 */ 00115 void 00116 outputLineSep() 00117 { 00118 m_newLineWriter(); 00119 } 00120 00121 void 00122 setPrevText(bool value) 00123 { 00124 m_isprevtext = value; 00125 } 00126 00127 void 00128 setPreserve(bool value) 00129 { 00130 m_ispreserve = value; 00131 } 00132 00133 void 00134 pop_preserve() 00135 { 00136 if ( m_preserves.empty() ) 00137 { 00138 m_ispreserve = false; 00139 } 00140 else 00141 { 00142 m_ispreserve = m_preserves.back(); 00143 00144 m_preserves.pop_back(); 00145 } 00146 } 00147 00148 void 00149 push_preserve() 00150 { 00151 m_preserves.push_back(m_ispreserve); 00152 } 00153 00154 private: 00155 bool 00156 shouldIndent() const 00157 { 00158 return (!m_ispreserve && !m_isprevtext); 00159 // return true; 00160 } 00161 00162 private: 00163 00164 //data members 00165 00166 WhiteSpaceWriter m_whiteSpaceWriter; 00167 00168 NewLineWriter m_newLineWriter; 00169 00170 /** 00171 * Amount to indent. 00172 */ 00173 size_type m_indent; 00174 00175 /** 00176 * Flag to keep track of the indent amount. 00177 */ 00178 size_type m_currentIndent; 00179 00180 /** 00181 * Flag to signal that a newline should be added. 00182 */ 00183 bool m_startNewLine; 00184 00185 /** 00186 * State flag to tell if preservation of whitespace 00187 * is important. 00188 */ 00189 bool m_ispreserve; 00190 00191 /** 00192 * State flag that tells if the previous node processed 00193 * was text, so we can tell if we should preserve whitespace. 00194 */ 00195 bool m_isprevtext; 00196 00197 /** 00198 * Stack to keep track of whether or not we need to 00199 * preserve whitespace. 00200 */ 00201 BoolStackType m_preserves; 00202 }; 00203 00204 XALAN_CPP_NAMESPACE_END 00205 00206 00207 00208 #endif // XALANIDENTWRITER_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 |
|