BESHTMLInfo.cc

Go to the documentation of this file.
00001 // BESHTMLInfo.cc
00002 
00003 // This file is part of bes, A C++ back-end server implementation framework
00004 // for the OPeNDAP Data Access Protocol.
00005 
00006 // Copyright (c) 2004,2005 University Corporation for Atmospheric Research
00007 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 // 
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 // 
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // You can contact University Corporation for Atmospheric Research at
00024 // 3080 Center Green Drive, Boulder, CO 80301
00025  
00026 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
00027 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
00028 //
00029 // Authors:
00030 //      pwest       Patrick West <pwest@ucar.edu>
00031 //      jgarcia     Jose Garcia <jgarcia@ucar.edu>
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 
00053 BESHTMLInfo::BESHTMLInfo( )
00054     : BESInfo( ),
00055       _header( false ),
00056       _do_indent( true )
00057 {
00058 }
00059 
00068 BESHTMLInfo::BESHTMLInfo( const string &key, ostream *strm, bool strm_owned )
00069     : BESInfo( key, strm, strm_owned ),
00070       _header( false ),
00071       _do_indent( true )
00072 {
00073 }
00074 
00075 BESHTMLInfo::~BESHTMLInfo()
00076 {
00077 }
00078 
00085 void
00086 BESHTMLInfo::begin_response( const string &response_name )
00087 {
00088     BESInfo::begin_response( response_name ) ;
00089     add_data( "<HTML>\n" ) ;
00090     _indent += "    " ;
00091     add_data( "<HEAD>\n" ) ;
00092     _indent += "    " ;
00093     add_data( (string)"<TITLE>" + response_name + "</TITLE>\n" ) ;
00094     if( _indent.length() >= 4 )
00095         _indent = _indent.substr( 0, _indent.length()-4 ) ;
00096     add_data( "</HEAD>\n" ) ;
00097     add_data( "<BODY>\n" ) ;
00098     _indent += "    " ;
00099 }
00100 
00108 void
00109 BESHTMLInfo::end_response( )
00110 {
00111     if( _indent.length() >= 4 )
00112         _indent = _indent.substr( 0, _indent.length()-4 ) ;
00113     add_data( "</BODY>\n" ) ;
00114     if( _indent.length() >= 4 )
00115         _indent = _indent.substr( 0, _indent.length()-4 ) ;
00116     add_data( "</HTML>\n" ) ;
00117 }
00118 
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 
00148 void
00149 BESHTMLInfo::begin_tag( const string &tag_name,
00150                         map<string,string> *attrs )
00151 {
00152     BESInfo::begin_tag( tag_name ) ;
00153     string to_add = tag_name + "<BR />\n" ;
00154     add_data( to_add ) ;
00155     _indent += "    " ;
00156     if( attrs )
00157     {
00158         map<string,string>::const_iterator i = attrs->begin() ;
00159         map<string,string>::const_iterator e = attrs->end() ;
00160         for( ; i != e; i++ )
00161         {
00162             string name = (*i).first ;
00163             string val = (*i).second ;
00164             BESInfo::add_data( _indent + name + ": " + val + "<BR />\n" ) ;
00165         }
00166     }
00167 }
00168 
00175 void
00176 BESHTMLInfo::end_tag( const string &tag_name )
00177 {
00178     BESInfo::end_tag( tag_name ) ;
00179     if( _indent.length() >= 4 )
00180         _indent = _indent.substr( 0, _indent.length()-4 ) ;
00181 }
00182 
00187 void
00188 BESHTMLInfo::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 += "&nbsp;" ;
00194     }
00195     _do_indent = false ;
00196     add_data( to_add ) ;
00197 }
00198 
00203 void
00204 BESHTMLInfo::add_break( unsigned long num_breaks )
00205 {
00206     string to_add ;
00207     for( unsigned long i = 0; i < num_breaks; i++ )
00208     {
00209         to_add += "<BR />" ;
00210     }
00211     to_add += "\n" ;
00212     _do_indent = false ;
00213     add_data( to_add ) ;
00214 }
00215 
00225 void
00226 BESHTMLInfo::add_data( const string &s )
00227 {
00228     if( !_header && !_buffered )
00229     {
00230         BESUtil::set_mime_html( *_strm ) ;
00231         _header = true ;
00232     }
00233     if( _do_indent )
00234         BESInfo::add_data( _indent + s ) ;
00235     else
00236         BESInfo::add_data( s ) ;
00237     _do_indent = true ;
00238 }
00239 
00248 void
00249 BESHTMLInfo::add_data_from_file( const string &key, const string &name )
00250 {
00251     string newkey = key + ".HTML" ;
00252     BESInfo::add_data_from_file( newkey, name ) ;
00253 }
00254 
00263 void
00264 BESHTMLInfo::transmit( BESTransmitter *transmitter,
00265                        BESDataHandlerInterface &dhi )
00266 {
00267     transmitter->send_html( *this, dhi ) ;
00268 }
00269 
00277 void
00278 BESHTMLInfo::dump( ostream &strm ) const
00279 {
00280     strm << BESIndent::LMarg << "BESHTMLInfo::dump - ("
00281                              << (void *)this << ")" << endl ;
00282     BESIndent::Indent() ;
00283     strm << BESIndent::LMarg << "has header been added? " << _header << endl ;
00284     strm << BESIndent::LMarg << "indentation \"" << _indent << "\"" << endl ;
00285     strm << BESIndent::LMarg << "do indent? " << _do_indent << endl ;
00286     BESInfo::dump( strm ) ;
00287     BESIndent::UnIndent() ;
00288 }
00289 
00290 BESInfo *
00291 BESHTMLInfo::BuildHTMLInfo( const string &info_type )
00292 {
00293     return new BESHTMLInfo( ) ;
00294 }
00295 

Generated on Fri Nov 30 12:06:47 2007 for OPeNDAP Back End Server (BES) by  doxygen 1.5.1