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 "BESHTMLInfo.h"
00043 #include "BESUtil.h"
00044
00050 BESHTMLInfo::BESHTMLInfo( )
00051 : BESInfo( ),
00052 _header( false ),
00053 _do_indent( true )
00054 {
00055 }
00056
00065 BESHTMLInfo::BESHTMLInfo( const string &key, ostream *strm, bool strm_owned )
00066 : BESInfo( key, strm, strm_owned ),
00067 _header( false ),
00068 _do_indent( true )
00069 {
00070 }
00071
00072 BESHTMLInfo::~BESHTMLInfo()
00073 {
00074 }
00075
00082 void
00083 BESHTMLInfo::begin_response( const string &response_name )
00084 {
00085 BESInfo::begin_response( response_name ) ;
00086 add_data( "<HTML>\n" ) ;
00087 _indent += " " ;
00088 add_data( "<HEAD>\n" ) ;
00089 _indent += " " ;
00090 add_data( (string)"<TITLE>" + response_name + "</TITLE>\n" ) ;
00091 if( _indent.length() >= 4 )
00092 _indent = _indent.substr( 0, _indent.length()-4 ) ;
00093 add_data( "</HEAD>\n" ) ;
00094 add_data( "<BODY>\n" ) ;
00095 _indent += " " ;
00096 }
00097
00105 void
00106 BESHTMLInfo::end_response( )
00107 {
00108 if( _indent.length() >= 4 )
00109 _indent = _indent.substr( 0, _indent.length()-4 ) ;
00110 add_data( "</BODY>\n" ) ;
00111 if( _indent.length() >= 4 )
00112 _indent = _indent.substr( 0, _indent.length()-4 ) ;
00113 add_data( "</HTML>\n" ) ;
00114 }
00115
00122 void
00123 BESHTMLInfo::add_tag( const string &tag_name,
00124 const string &tag_data,
00125 map<string,string> *attrs )
00126 {
00127 string to_add = tag_name + ": " + tag_data + "<BR />\n" ;
00128 add_data( to_add ) ;
00129 if( attrs )
00130 {
00131 map<string,string>::const_iterator i = attrs->begin() ;
00132 map<string,string>::const_iterator e = attrs->end() ;
00133 for( ; i != e; i++ )
00134 {
00135 string name = (*i).first ;
00136 string val = (*i).second ;
00137 BESInfo::add_data( _indent + " " + name + ": " + val + "<BR />\n" ) ;
00138 }
00139 }
00140 }
00141
00147 void
00148 BESHTMLInfo::begin_tag( const string &tag_name,
00149 map<string,string> *attrs )
00150 {
00151 BESInfo::begin_tag( tag_name ) ;
00152 string to_add = tag_name + "<BR />\n" ;
00153 add_data( to_add ) ;
00154 _indent += " " ;
00155 if( attrs )
00156 {
00157 map<string,string>::const_iterator i = attrs->begin() ;
00158 map<string,string>::const_iterator e = attrs->end() ;
00159 for( ; i != e; i++ )
00160 {
00161 string name = (*i).first ;
00162 string val = (*i).second ;
00163 BESInfo::add_data( _indent + name + ": " + val + "<BR />\n" ) ;
00164 }
00165 }
00166 }
00167
00174 void
00175 BESHTMLInfo::end_tag( const string &tag_name )
00176 {
00177 BESInfo::end_tag( tag_name ) ;
00178 if( _indent.length() >= 4 )
00179 _indent = _indent.substr( 0, _indent.length()-4 ) ;
00180 }
00181
00186 void
00187 BESHTMLInfo::add_space( unsigned long num_spaces )
00188 {
00189 string to_add ;
00190 for( unsigned long i = 0; i < num_spaces; i++ )
00191 {
00192 to_add += " " ;
00193 }
00194 _do_indent = false ;
00195 add_data( to_add ) ;
00196 }
00197
00202 void
00203 BESHTMLInfo::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 += "<BR />" ;
00209 }
00210 to_add += "\n" ;
00211 _do_indent = false ;
00212 add_data( to_add ) ;
00213 }
00214
00224 void
00225 BESHTMLInfo::add_data( const string &s )
00226 {
00227 if( !_header && !_buffered )
00228 {
00229 BESUtil::set_mime_html( *_strm ) ;
00230 _header = true ;
00231 }
00232 if( _do_indent )
00233 BESInfo::add_data( _indent + s ) ;
00234 else
00235 BESInfo::add_data( s ) ;
00236 _do_indent = true ;
00237 }
00238
00247 void
00248 BESHTMLInfo::add_data_from_file( const string &key, const string &name )
00249 {
00250 string newkey = key + ".HTML" ;
00251 BESInfo::add_data_from_file( newkey, name ) ;
00252 }
00253
00262 void
00263 BESHTMLInfo::transmit( BESTransmitter *transmitter,
00264 BESDataHandlerInterface &dhi )
00265 {
00266 transmitter->send_html( *this, dhi ) ;
00267 }
00268
00276 void
00277 BESHTMLInfo::dump( ostream &strm ) const
00278 {
00279 strm << BESIndent::LMarg << "BESHTMLInfo::dump - ("
00280 << (void *)this << ")" << endl ;
00281 BESIndent::Indent() ;
00282 strm << BESIndent::LMarg << "has header been added? " << _header << endl ;
00283 strm << BESIndent::LMarg << "indentation \"" << _indent << "\"" << endl ;
00284 strm << BESIndent::LMarg << "do indent? " << _do_indent << endl ;
00285 BESInfo::dump( strm ) ;
00286 BESIndent::UnIndent() ;
00287 }
00288
00289 BESInfo *
00290 BESHTMLInfo::BuildHTMLInfo( const string &info_type )
00291 {
00292 return new BESHTMLInfo( ) ;
00293 }
00294