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
00078 BESTextInfo::BESTextInfo( const string &key, ostream *strm,
00079 bool strm_owned, bool ishttp )
00080 : BESInfo( key, strm, strm_owned ),
00081 _ishttp( ishttp ),
00082 _header( false )
00083 {
00084 }
00085
00086 BESTextInfo::~BESTextInfo()
00087 {
00088 }
00089
00096 void
00097 BESTextInfo::begin_response( const string &response_name )
00098 {
00099 BESInfo::begin_response( response_name ) ;
00100 }
00101
00107 void
00108 BESTextInfo::add_tag( const string &tag_name,
00109 const string &tag_data,
00110 map<string,string> *attrs )
00111 {
00112 add_data( _indent + tag_name + ": " + tag_data + "\n" ) ;
00113 if( attrs )
00114 {
00115 map<string,string>::const_iterator i = attrs->begin() ;
00116 map<string,string>::const_iterator e = attrs->end() ;
00117 for( ; i != e; i++ )
00118 {
00119 string name = (*i).first ;
00120 string val = (*i).second ;
00121 add_data( _indent + " " + name + ": " + val + "\n" ) ;
00122 }
00123 }
00124 }
00125
00130 void
00131 BESTextInfo::begin_tag( const string &tag_name,
00132 map<string,string> *attrs )
00133 {
00134 BESInfo::begin_tag( tag_name ) ;
00135 add_data( _indent + tag_name + "\n" ) ;
00136 _indent += " " ;
00137 if( attrs )
00138 {
00139 map<string,string>::const_iterator i = attrs->begin() ;
00140 map<string,string>::const_iterator e = attrs->end() ;
00141 for( ; i != e; i++ )
00142 {
00143 string name = (*i).first ;
00144 string val = (*i).second ;
00145 add_data( _indent + name + ": " + val + "\n" ) ;
00146 }
00147 }
00148 }
00149
00156 void
00157 BESTextInfo::end_tag( const string &tag_name )
00158 {
00159 BESInfo::end_tag( tag_name ) ;
00160 if( _indent.length() >= 4 )
00161 _indent = _indent.substr( 0, _indent.length()-4 ) ;
00162 }
00163
00168 void
00169 BESTextInfo::add_data( const string & s )
00170 {
00171 if( _ishttp && !_header && !_buffered )
00172 {
00173 BESUtil::set_mime_text( *_strm ) ;
00174 _header = true ;
00175 }
00176 BESInfo::add_data( s ) ;
00177 }
00178
00183 void
00184 BESTextInfo::add_space( unsigned long num_spaces )
00185 {
00186 string to_add ;
00187 for( unsigned long i = 0; i < num_spaces; i++ )
00188 {
00189 to_add += " " ;
00190 }
00191 add_data( to_add ) ;
00192 }
00193
00198 void
00199 BESTextInfo::add_break( unsigned long num_breaks )
00200 {
00201 string to_add ;
00202 for( unsigned long i = 0; i < num_breaks; i++ )
00203 {
00204 to_add += "\n" ;
00205 }
00206 add_data( to_add ) ;
00207 }
00208
00217 void
00218 BESTextInfo::add_data_from_file( const string &key, const string &name )
00219 {
00220 string newkey = key + ".TXT" ;
00221 BESInfo::add_data_from_file( newkey, name ) ;
00222 }
00223
00232 void
00233 BESTextInfo::transmit( BESTransmitter *transmitter,
00234 BESDataHandlerInterface &dhi )
00235 {
00236 transmitter->send_text( *this, dhi ) ;
00237 }
00238
00246 void
00247 BESTextInfo::dump( ostream &strm ) const
00248 {
00249 strm << BESIndent::LMarg << "BESTextInfo::dump - ("
00250 << (void *)this << ")" << endl ;
00251 BESIndent::Indent() ;
00252 strm << BESIndent::LMarg << "has header been added? " << _header << endl ;
00253 strm << BESIndent::LMarg << "indentation \"" << _indent << "\"" << endl ;
00254 strm << BESIndent::LMarg << "is http? " << _ishttp << endl ;
00255 BESInfo::dump( strm ) ;
00256 BESIndent::UnIndent() ;
00257 }
00258
00259 BESInfo *
00260 BESTextInfo::BuildTextInfo( const string &info_type )
00261 {
00262 return new BESTextInfo( ) ;
00263 }
00264