OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESTextInfo.cc
Go to the documentation of this file.
1 // BESTextInfo.cc
2 
3 // This file is part of bes, A C++ back-end server implementation framework
4 // for the OPeNDAP Data Access Protocol.
5 
6 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 //
23 // You can contact University Corporation for Atmospheric Research at
24 // 3080 Center Green Drive, Boulder, CO 80301
25 
26 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
28 //
29 // Authors:
30 // pwest Patrick West <pwest@ucar.edu>
31 // jgarcia Jose Garcia <jgarcia@ucar.edu>
32 
33 #ifdef __GNUG__
34 #pragma implementation
35 #endif
36 
37 #include <sstream>
38 #include <iostream>
39 
40 using std::ostringstream ;
41 
42 #include "BESTextInfo.h"
43 #include "BESUtil.h"
44 
55  : BESInfo( ),
56  _ishttp( ishttp ),
57  _header( false )
58 {
59 }
60 
80 BESTextInfo::BESTextInfo( const string &key, ostream *strm,
81  bool strm_owned, bool ishttp )
82  : BESInfo( key, strm, strm_owned ),
83  _ishttp( ishttp ),
84  _header( false )
85 {
86 }
87 
89 {
90 }
91 
99 void
100 BESTextInfo::begin_response( const string &response_name,
102 {
103  BESInfo::begin_response( response_name, dhi ) ;
104 }
105 
112 void
113 BESTextInfo::add_tag( const string &tag_name,
114  const string &tag_data,
115  map<string,string> *attrs )
116 {
117  add_data( _indent + tag_name + ": " + tag_data + "\n" ) ;
118  if( attrs )
119  {
120  map<string,string>::const_iterator i = attrs->begin() ;
121  map<string,string>::const_iterator e = attrs->end() ;
122  for( ; i != e; i++ )
123  {
124  string name = (*i).first ;
125  string val = (*i).second ;
126  add_data( _indent + " " + name + ": " + val + "\n" ) ;
127  }
128  }
129 }
130 
136 void
137 BESTextInfo::begin_tag( const string &tag_name,
138  map<string,string> *attrs )
139 {
140  BESInfo::begin_tag( tag_name ) ;
141  add_data( _indent + tag_name + "\n" ) ;
142  _indent += " " ;
143  if( attrs )
144  {
145  map<string,string>::const_iterator i = attrs->begin() ;
146  map<string,string>::const_iterator e = attrs->end() ;
147  for( ; i != e; i++ )
148  {
149  string name = (*i).first ;
150  string val = (*i).second ;
151  add_data( _indent + name + ": " + val + "\n" ) ;
152  }
153  }
154 }
155 
162 void
163 BESTextInfo::end_tag( const string &tag_name )
164 {
165  BESInfo::end_tag( tag_name ) ;
166  if( _indent.length() >= 4 )
167  _indent = _indent.substr( 0, _indent.length()-4 ) ;
168 }
169 
174 void
175 BESTextInfo::add_data( const string & s )
176 {
177  if( _ishttp && !_header && !_buffered )
178  {
180  _header = true ;
181  }
182  BESInfo::add_data( s ) ;
183 }
184 
189 void
190 BESTextInfo::add_space( unsigned long num_spaces )
191 {
192  string to_add ;
193  for( unsigned long i = 0; i < num_spaces; i++ )
194  {
195  to_add += " " ;
196  }
197  add_data( to_add ) ;
198 }
199 
204 void
205 BESTextInfo::add_break( unsigned long num_breaks )
206 {
207  string to_add ;
208  for( unsigned long i = 0; i < num_breaks; i++ )
209  {
210  to_add += "\n" ;
211  }
212  add_data( to_add ) ;
213 }
214 
223 void
224 BESTextInfo::add_data_from_file( const string &key, const string &name )
225 {
226  string newkey = key + ".TXT" ;
227  BESInfo::add_data_from_file( newkey, name ) ;
228 }
229 
238 void
241 {
242  transmitter->send_text( *this, dhi ) ;
243 }
244 
252 void
253 BESTextInfo::dump( ostream &strm ) const
254 {
255  strm << BESIndent::LMarg << "BESTextInfo::dump - ("
256  << (void *)this << ")" << endl ;
258  strm << BESIndent::LMarg << "has header been added? " << _header << endl ;
259  strm << BESIndent::LMarg << "indentation \"" << _indent << "\"" << endl ;
260  strm << BESIndent::LMarg << "is http? " << _ishttp << endl ;
261  BESInfo::dump( strm ) ;
263 }
264 
265 BESInfo *
266 BESTextInfo::BuildTextInfo( const string &info_type )
267 {
268  return new BESTextInfo( ) ;
269 }
270 
virtual void begin_response(const string &response_name, BESDataHandlerInterface &dhi)
begin the informational response
Definition: BESTextInfo.cc:100
virtual void add_space(unsigned long num_spaces)
add a space to the informational response
Definition: BESTextInfo.cc:190
virtual void dump(ostream &strm) const
Displays debug information about this object.
Definition: BESInfo.cc:299
virtual void begin_tag(const string &tag_name, map< string, string > *attrs=0)
begin a tagged part of the information, information to follow
Definition: BESTextInfo.cc:137
virtual void add_data_from_file(const string &key, const string &name)
add data from a file to the informational object.
Definition: BESInfo.cc:192
virtual void dump(ostream &strm) const
dumps information about this object
Definition: BESTextInfo.cc:253
static BESInfo * BuildTextInfo(const string &info_type)
Definition: BESTextInfo.cc:266
static void Indent()
Definition: BESIndent.cc:38
informational response object
Definition: BESInfo.h:68
virtual void begin_tag(const string &tag_name, map< string, string > *attrs=0)
Definition: BESInfo.cc:142
static ostream & LMarg(ostream &strm)
Definition: BESIndent.cc:73
virtual void add_data_from_file(const string &key, const string &name)
add data from a file to the informational object
Definition: BESTextInfo.cc:224
static void set_mime_text(ostream &strm)
Generate an HTTP 1.0 response header for a text document.
Definition: BESUtil.cc:65
virtual void add_tag(const string &tag_name, const string &tag_data, map< string, string > *attrs=0)
add tagged information to the inforamtional response
Definition: BESTextInfo.cc:113
BESTextInfo(bool ishttp=false)
constructs a basic text information response object.
Definition: BESTextInfo.cc:54
virtual void send_text(BESInfo &info, BESDataHandlerInterface &dhi)=0
virtual void end_tag(const string &tag_name)
end a tagged part of the informational response
Definition: BESTextInfo.cc:163
virtual void add_break(unsigned long num_breaks)
add a line break to the information
Definition: BESTextInfo.cc:205
ostream * _strm
Definition: BESInfo.h:71
Structure storing information used by the BES to handle the request.
virtual ~BESTextInfo()
Definition: BESTextInfo.cc:88
virtual void begin_response(const string &response_name, BESDataHandlerInterface &dhi)
begin the informational response
Definition: BESInfo.cc:123
virtual void add_data(const string &s)
add data to this informational object.
Definition: BESInfo.cc:169
static void UnIndent()
Definition: BESIndent.cc:44
bool _buffered
Definition: BESInfo.h:73
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi)
transmit the text information as text
Definition: BESTextInfo.cc:239
virtual void end_tag(const string &tag_name)
Definition: BESInfo.cc:149
virtual void add_data(const string &s)
add string data to the informational response
Definition: BESTextInfo.cc:175