Go to the documentation of this file.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
00083 void
00084 BESHTMLInfo::begin_response( const string &response_name,
00085 BESDataHandlerInterface &dhi )
00086 {
00087 BESInfo::begin_response( response_name, dhi ) ;
00088 add_data( "<HTML>\n" ) ;
00089 _indent += " " ;
00090 add_data( "<HEAD>\n" ) ;
00091 _indent += " " ;
00092 add_data( (string)"<TITLE>" + response_name + "</TITLE>\n" ) ;
00093 if( _indent.length() >= 4 )
00094 _indent = _indent.substr( 0, _indent.length()-4 ) ;
00095 add_data( "</HEAD>\n" ) ;
00096 add_data( "<BODY>\n" ) ;
00097 _indent += " " ;
00098 }
00099
00107 void
00108 BESHTMLInfo::end_response( )
00109 {
00110 if( _indent.length() >= 4 )
00111 _indent = _indent.substr( 0, _indent.length()-4 ) ;
00112 add_data( "</BODY>\n" ) ;
00113 if( _indent.length() >= 4 )
00114 _indent = _indent.substr( 0, _indent.length()-4 ) ;
00115 add_data( "</HTML>\n" ) ;
00116 }
00117
00124 void
00125 BESHTMLInfo::add_tag( const string &tag_name,
00126 const string &tag_data,
00127 map<string,string> *attrs )
00128 {
00129 string to_add = tag_name + ": " + tag_data + "<BR />\n" ;
00130 add_data( to_add ) ;
00131 if( attrs )
00132 {
00133 map<string,string>::const_iterator i = attrs->begin() ;
00134 map<string,string>::const_iterator e = attrs->end() ;
00135 for( ; i != e; i++ )
00136 {
00137 string name = (*i).first ;
00138 string val = (*i).second ;
00139 BESInfo::add_data( _indent + " " + name + ": " + val + "<BR />\n" ) ;
00140 }
00141 }
00142 }
00143
00149 void
00150 BESHTMLInfo::begin_tag( const string &tag_name,
00151 map<string,string> *attrs )
00152 {
00153 BESInfo::begin_tag( tag_name ) ;
00154 string to_add = tag_name + "<BR />\n" ;
00155 add_data( to_add ) ;
00156 _indent += " " ;
00157 if( attrs )
00158 {
00159 map<string,string>::const_iterator i = attrs->begin() ;
00160 map<string,string>::const_iterator e = attrs->end() ;
00161 for( ; i != e; i++ )
00162 {
00163 string name = (*i).first ;
00164 string val = (*i).second ;
00165 BESInfo::add_data( _indent + name + ": " + val + "<BR />\n" ) ;
00166 }
00167 }
00168 }
00169
00176 void
00177 BESHTMLInfo::end_tag( const string &tag_name )
00178 {
00179 BESInfo::end_tag( tag_name ) ;
00180 if( _indent.length() >= 4 )
00181 _indent = _indent.substr( 0, _indent.length()-4 ) ;
00182 }
00183
00188 void
00189 BESHTMLInfo::add_space( unsigned long num_spaces )
00190 {
00191 string to_add ;
00192 for( unsigned long i = 0; i < num_spaces; i++ )
00193 {
00194 to_add += " " ;
00195 }
00196 _do_indent = false ;
00197 add_data( to_add ) ;
00198 }
00199
00204 void
00205 BESHTMLInfo::add_break( unsigned long num_breaks )
00206 {
00207 string to_add ;
00208 for( unsigned long i = 0; i < num_breaks; i++ )
00209 {
00210 to_add += "<BR />" ;
00211 }
00212 to_add += "\n" ;
00213 _do_indent = false ;
00214 add_data( to_add ) ;
00215 }
00216
00226 void
00227 BESHTMLInfo::add_data( const string &s )
00228 {
00229 if( !_header && !_buffered )
00230 {
00231 BESUtil::set_mime_html( *_strm ) ;
00232 _header = true ;
00233 }
00234 if( _do_indent )
00235 BESInfo::add_data( _indent + s ) ;
00236 else
00237 BESInfo::add_data( s ) ;
00238 _do_indent = true ;
00239 }
00240
00249 void
00250 BESHTMLInfo::add_data_from_file( const string &key, const string &name )
00251 {
00252 string newkey = key + ".HTML" ;
00253 BESInfo::add_data_from_file( newkey, name ) ;
00254 }
00255
00264 void
00265 BESHTMLInfo::transmit( BESTransmitter *transmitter,
00266 BESDataHandlerInterface &dhi )
00267 {
00268 transmitter->send_html( *this, dhi ) ;
00269 }
00270
00278 void
00279 BESHTMLInfo::dump( ostream &strm ) const
00280 {
00281 strm << BESIndent::LMarg << "BESHTMLInfo::dump - ("
00282 << (void *)this << ")" << endl ;
00283 BESIndent::Indent() ;
00284 strm << BESIndent::LMarg << "has header been added? " << _header << endl ;
00285 strm << BESIndent::LMarg << "indentation \"" << _indent << "\"" << endl ;
00286 strm << BESIndent::LMarg << "do indent? " << _do_indent << endl ;
00287 BESInfo::dump( strm ) ;
00288 BESIndent::UnIndent() ;
00289 }
00290
00291 BESInfo *
00292 BESHTMLInfo::BuildHTMLInfo( const string &info_type )
00293 {
00294 return new BESHTMLInfo( ) ;
00295 }
00296