00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifdef __GNUG__
00034 #pragma implementation
00035 #endif
00036
00037 #include <sstream>
00038 #include <iostream>
00039
00040 using std::ostringstream ;
00041
00042 #include "BESTextInfo.h"
00043 #include "BESUtil.h"
00044
00054 BESTextInfo::BESTextInfo( bool ishttp )
00055 : BESInfo( ),
00056 _ishttp( ishttp ),
00057 _header( false )
00058 {
00059 }
00060
00080 BESTextInfo::BESTextInfo( const string &key, ostream *strm,
00081 bool strm_owned, bool ishttp )
00082 : BESInfo( key, strm, strm_owned ),
00083 _ishttp( ishttp ),
00084 _header( false )
00085 {
00086 }
00087
00088 BESTextInfo::~BESTextInfo()
00089 {
00090 }
00091
00098 void
00099 BESTextInfo::begin_response( const string &response_name )
00100 {
00101 BESInfo::begin_response( response_name ) ;
00102 }
00103
00110 void
00111 BESTextInfo::add_tag( const string &tag_name,
00112 const string &tag_data,
00113 map<string,string> *attrs )
00114 {
00115 add_data( _indent + tag_name + ": " + tag_data + "\n" ) ;
00116 if( attrs )
00117 {
00118 map<string,string>::const_iterator i = attrs->begin() ;
00119 map<string,string>::const_iterator e = attrs->end() ;
00120 for( ; i != e; i++ )
00121 {
00122 string name = (*i).first ;
00123 string val = (*i).second ;
00124 add_data( _indent + " " + name + ": " + val + "\n" ) ;
00125 }
00126 }
00127 }
00128
00134 void
00135 BESTextInfo::begin_tag( const string &tag_name,
00136 map<string,string> *attrs )
00137 {
00138 BESInfo::begin_tag( tag_name ) ;
00139 add_data( _indent + tag_name + "\n" ) ;
00140 _indent += " " ;
00141 if( attrs )
00142 {
00143 map<string,string>::const_iterator i = attrs->begin() ;
00144 map<string,string>::const_iterator e = attrs->end() ;
00145 for( ; i != e; i++ )
00146 {
00147 string name = (*i).first ;
00148 string val = (*i).second ;
00149 add_data( _indent + name + ": " + val + "\n" ) ;
00150 }
00151 }
00152 }
00153
00160 void
00161 BESTextInfo::end_tag( const string &tag_name )
00162 {
00163 BESInfo::end_tag( tag_name ) ;
00164 if( _indent.length() >= 4 )
00165 _indent = _indent.substr( 0, _indent.length()-4 ) ;
00166 }
00167
00172 void
00173 BESTextInfo::add_data( const string & s )
00174 {
00175 if( _ishttp && !_header && !_buffered )
00176 {
00177 BESUtil::set_mime_text( *_strm ) ;
00178 _header = true ;
00179 }
00180 BESInfo::add_data( s ) ;
00181 }
00182
00187 void
00188 BESTextInfo::add_space( unsigned long num_spaces )
00189 {
00190 string to_add ;
00191 for( unsigned long i = 0; i < num_spaces; i++ )
00192 {
00193 to_add += " " ;
00194 }
00195 add_data( to_add ) ;
00196 }
00197
00202 void
00203 BESTextInfo::add_break( unsigned long num_breaks )
00204 {
00205 string to_add ;
00206 for( unsigned long i = 0; i < num_breaks; i++ )
00207 {
00208 to_add += "\n" ;
00209 }
00210 add_data( to_add ) ;
00211 }
00212
00221 void
00222 BESTextInfo::add_data_from_file( const string &key, const string &name )
00223 {
00224 string newkey = key + ".TXT" ;
00225 BESInfo::add_data_from_file( newkey, name ) ;
00226 }
00227
00236 void
00237 BESTextInfo::transmit( BESTransmitter *transmitter,
00238 BESDataHandlerInterface &dhi )
00239 {
00240 transmitter->send_text( *this, dhi ) ;
00241 }
00242
00250 void
00251 BESTextInfo::dump( ostream &strm ) const
00252 {
00253 strm << BESIndent::LMarg << "BESTextInfo::dump - ("
00254 << (void *)this << ")" << endl ;
00255 BESIndent::Indent() ;
00256 strm << BESIndent::LMarg << "has header been added? " << _header << endl ;
00257 strm << BESIndent::LMarg << "indentation \"" << _indent << "\"" << endl ;
00258 strm << BESIndent::LMarg << "is http? " << _ishttp << endl ;
00259 BESInfo::dump( strm ) ;
00260 BESIndent::UnIndent() ;
00261 }
00262
00263 BESInfo *
00264 BESTextInfo::BuildTextInfo( const string &info_type )
00265 {
00266 return new BESTextInfo( ) ;
00267 }
00268