BESTextInfo.cc

Go to the documentation of this file.
00001 // BESTextInfo.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 Atmostpheric 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 
00039 using std::ostringstream ;
00040 
00041 #include "BESTextInfo.h"
00042 #include "BESUtil.h"
00043 
00053 BESTextInfo::BESTextInfo( bool ishttp )
00054     : BESInfo( ),
00055       _ishttp( ishttp ),
00056       _header( false )
00057 {
00058 }
00059 
00072 BESTextInfo::BESTextInfo( const string &key, bool ishttp )
00073     : BESInfo( key ),
00074       _ishttp( ishttp ),
00075       _header( false )
00076 {
00077 }
00078 
00079 BESTextInfo::~BESTextInfo()
00080 {
00081 }
00082 
00089 void
00090 BESTextInfo::begin_response( const string &response_name )
00091 {
00092     BESInfo::begin_response( response_name ) ;
00093 }
00094 
00100 void
00101 BESTextInfo::add_tag( const string &tag_name,
00102                       const string &tag_data,
00103                       map<string,string> *attrs )
00104 {
00105     add_data( _indent + tag_name + ": " + tag_data + "\n" ) ;
00106     if( attrs )
00107     {
00108         map<string,string>::const_iterator i = attrs->begin() ;
00109         map<string,string>::const_iterator e = attrs->end() ;
00110         for( ; i != e; i++ )
00111         {
00112             string name = (*i).first ;
00113             string val = (*i).second ;
00114             add_data( _indent + "    " + name + ": " + val + "\n" ) ;
00115         }
00116     }
00117 }
00118 
00123 void
00124 BESTextInfo::begin_tag( const string &tag_name,
00125                         map<string,string> *attrs )
00126 {
00127     BESInfo::begin_tag( tag_name ) ;
00128     add_data( _indent + tag_name + "\n" ) ;
00129     _indent += "    " ;
00130     if( attrs )
00131     {
00132         map<string,string>::const_iterator i = attrs->begin() ;
00133         map<string,string>::const_iterator e = attrs->end() ;
00134         for( ; i != e; i++ )
00135         {
00136             string name = (*i).first ;
00137             string val = (*i).second ;
00138             add_data( _indent + name + ": " + val + "\n" ) ;
00139         }
00140     }
00141 }
00142 
00149 void
00150 BESTextInfo::end_tag( const string &tag_name )
00151 {
00152     BESInfo::end_tag( tag_name ) ;
00153     if( _indent.length() >= 4 )
00154         _indent = _indent.substr( 0, _indent.length()-4 ) ;
00155 }
00156 
00161 void
00162 BESTextInfo::add_data( const string & s )
00163 {
00164     if( _ishttp && !_header && !_buffered )
00165     {
00166         BESUtil::set_mime_text( stdout ) ;
00167         _header = true ;
00168     }
00169     BESInfo::add_data( s ) ;
00170 }
00171 
00176 void
00177 BESTextInfo::add_space( unsigned long num_spaces )
00178 {
00179     string to_add ;
00180     for( unsigned long i = 0; i < num_spaces; i++ )
00181     {
00182         to_add += " " ;
00183     }
00184     add_data( to_add ) ;
00185 }
00186 
00191 void
00192 BESTextInfo::add_break( unsigned long num_breaks )
00193 {
00194     string to_add ;
00195     for( unsigned long i = 0; i < num_breaks; i++ )
00196     {
00197         to_add += "\n" ;
00198     }
00199     add_data( to_add ) ;
00200 }
00201 
00210 void
00211 BESTextInfo::add_data_from_file( const string &key, const string &name )
00212 {
00213     string newkey = key + ".TXT" ;
00214     BESInfo::add_data_from_file( newkey, name ) ;
00215 }
00216 
00225 void
00226 BESTextInfo::transmit( BESTransmitter *transmitter,
00227                        BESDataHandlerInterface &dhi )
00228 {
00229     transmitter->send_text( *this, dhi ) ;
00230 }
00231 
00239 void
00240 BESTextInfo::dump( ostream &strm ) const
00241 {
00242     strm << BESIndent::LMarg << "BESTextInfo::dump - ("
00243                              << (void *)this << ")" << endl ;
00244     BESIndent::Indent() ;
00245     strm << BESIndent::LMarg << "has header been added? " << _header << endl ;
00246     strm << BESIndent::LMarg << "indentation \"" << _indent << "\"" << endl ;
00247     strm << BESIndent::LMarg << "is http? " << _ishttp << endl ;
00248     BESInfo::dump( strm ) ;
00249     BESIndent::UnIndent() ;
00250 }
00251 
00252 BESInfo *
00253 BESTextInfo::BuildTextInfo( const string &info_type )
00254 {
00255     return new BESTextInfo( ) ;
00256 }
00257 

Generated on Wed Aug 29 03:14:16 2007 for OPeNDAP Back End Server (BES) by  doxygen 1.5.2