OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESHTMLInfo.cc
Go to the documentation of this file.
1 // BESHTMLInfo.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 #include <sstream>
34 #include <iostream>
35 
36 using std::ostringstream ;
37 
38 #include "BESHTMLInfo.h"
39 #include "BESUtil.h"
40 
47  : BESInfo( ),
48  _header( false ),
49  _do_indent( true )
50 {
51 }
52 
61 BESHTMLInfo::BESHTMLInfo( const string &key, ostream *strm, bool strm_owned )
62  : BESInfo( key, strm, strm_owned ),
63  _header( false ),
64  _do_indent( true )
65 {
66 }
67 
69 {
70 }
71 
79 void
80 BESHTMLInfo::begin_response( const string &response_name,
82 {
83  BESInfo::begin_response( response_name, dhi ) ;
84  add_data( "<HTML>\n" ) ;
85  _indent += " " ;
86  add_data( "<HEAD>\n" ) ;
87  _indent += " " ;
88  add_data( (string)"<TITLE>" + response_name + "</TITLE>\n" ) ;
89  if( _indent.length() >= 4 )
90  _indent = _indent.substr( 0, _indent.length()-4 ) ;
91  add_data( "</HEAD>\n" ) ;
92  add_data( "<BODY>\n" ) ;
93  _indent += " " ;
94 }
95 
103 void
105 {
106  if( _indent.length() >= 4 )
107  _indent = _indent.substr( 0, _indent.length()-4 ) ;
108  add_data( "</BODY>\n" ) ;
109  if( _indent.length() >= 4 )
110  _indent = _indent.substr( 0, _indent.length()-4 ) ;
111  add_data( "</HTML>\n" ) ;
112 }
113 
120 void
121 BESHTMLInfo::add_tag( const string &tag_name,
122  const string &tag_data,
123  map<string,string> *attrs )
124 {
125  string to_add = tag_name + ": " + tag_data + "<BR />\n" ;
126  add_data( to_add ) ;
127  if( attrs )
128  {
129  map<string,string>::const_iterator i = attrs->begin() ;
130  map<string,string>::const_iterator e = attrs->end() ;
131  for( ; i != e; i++ )
132  {
133  string name = (*i).first ;
134  string val = (*i).second ;
135  BESInfo::add_data( _indent + " " + name + ": " + val + "<BR />\n" ) ;
136  }
137  }
138 }
139 
145 void
146 BESHTMLInfo::begin_tag( const string &tag_name,
147  map<string,string> *attrs )
148 {
149  BESInfo::begin_tag( tag_name ) ;
150  string to_add = tag_name + "<BR />\n" ;
151  add_data( to_add ) ;
152  _indent += " " ;
153  if( attrs )
154  {
155  map<string,string>::const_iterator i = attrs->begin() ;
156  map<string,string>::const_iterator e = attrs->end() ;
157  for( ; i != e; i++ )
158  {
159  string name = (*i).first ;
160  string val = (*i).second ;
161  BESInfo::add_data( _indent + name + ": " + val + "<BR />\n" ) ;
162  }
163  }
164 }
165 
172 void
173 BESHTMLInfo::end_tag( const string &tag_name )
174 {
175  BESInfo::end_tag( tag_name ) ;
176  if( _indent.length() >= 4 )
177  _indent = _indent.substr( 0, _indent.length()-4 ) ;
178 }
179 
184 void
185 BESHTMLInfo::add_space( unsigned long num_spaces )
186 {
187  string to_add ;
188  for( unsigned long i = 0; i < num_spaces; i++ )
189  {
190  to_add += "&nbsp;" ;
191  }
192  _do_indent = false ;
193  add_data( to_add ) ;
194 }
195 
200 void
201 BESHTMLInfo::add_break( unsigned long num_breaks )
202 {
203  string to_add ;
204  for( unsigned long i = 0; i < num_breaks; i++ )
205  {
206  to_add += "<BR />" ;
207  }
208  to_add += "\n" ;
209  _do_indent = false ;
210  add_data( to_add ) ;
211 }
212 
222 void
223 BESHTMLInfo::add_data( const string &s )
224 {
225  if( !_header && !_buffered )
226  {
228  _header = true ;
229  }
230  if( _do_indent )
231  BESInfo::add_data( _indent + s ) ;
232  else
233  BESInfo::add_data( s ) ;
234  _do_indent = true ;
235 }
236 
245 void
246 BESHTMLInfo::add_data_from_file( const string &key, const string &name )
247 {
248  string newkey = key + ".HTML" ;
249  BESInfo::add_data_from_file( newkey, name ) ;
250 }
251 
260 void
263 {
264  transmitter->send_html( *this, dhi ) ;
265 }
266 
274 void
275 BESHTMLInfo::dump( ostream &strm ) const
276 {
277  strm << BESIndent::LMarg << "BESHTMLInfo::dump - ("
278  << (void *)this << ")" << endl ;
280  strm << BESIndent::LMarg << "has header been added? " << _header << endl ;
281  strm << BESIndent::LMarg << "indentation \"" << _indent << "\"" << endl ;
282  strm << BESIndent::LMarg << "do indent? " << _do_indent << endl ;
283  BESInfo::dump( strm ) ;
285 }
286 
287 BESInfo *
288 BESHTMLInfo::BuildHTMLInfo( const string &/*info_type*/ )
289 {
290  return new BESHTMLInfo( ) ;
291 }
292 
BESHTMLInfo()
constructs an html formatted information response object.
Definition: BESHTMLInfo.cc:46
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
static BESInfo * BuildHTMLInfo(const string &info_type)
Definition: BESHTMLInfo.cc:288
virtual void end_response()
end the response
Definition: BESHTMLInfo.cc:104
virtual void dump(ostream &strm) const
Displays debug information about this object.
Definition: BESInfo.cc:299
static void Indent()
Definition: BESIndent.cc:38
virtual ~BESHTMLInfo()
Definition: BESHTMLInfo.cc:68
virtual void add_space(unsigned long num_spaces)
add a space to the informational response
Definition: BESHTMLInfo.cc:185
informational response object
Definition: BESInfo.h:68
virtual void begin_tag(const string &tag_name, map< string, string > *attrs=0)
begin a tagged part of the information, information to follow
Definition: BESHTMLInfo.cc:146
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: BESHTMLInfo.cc:121
static void set_mime_html(ostream &strm)
Generate an HTTP 1.0 response header for a html document.
Definition: BESUtil.cc:82
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(const string &s)
add data to this informational object.
Definition: BESHTMLInfo.cc:223
virtual void add_break(unsigned long num_breaks)
add a line break to the information
Definition: BESHTMLInfo.cc:201
ostream * _strm
Definition: BESInfo.h:71
virtual void end_tag(const string &tag_name)
end a tagged part of the informational response
Definition: BESHTMLInfo.cc:173
Structure storing information used by the BES to handle the request.
virtual void dump(ostream &strm) const
dumps information about this object
Definition: BESHTMLInfo.cc:275
virtual void add_data_from_file(const string &key, const string &name)
add data from a file to the informational object
Definition: BESHTMLInfo.cc:246
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
virtual void send_html(BESInfo &info, BESDataHandlerInterface &dhi)=0
static void UnIndent()
Definition: BESIndent.cc:44
bool _buffered
Definition: BESInfo.h:73
virtual void end_tag(const string &tag_name)
Definition: BESInfo.cc:149
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi)
transmit the text information as text
Definition: BESHTMLInfo.cc:261
virtual void begin_response(const string &response_name, BESDataHandlerInterface &dhi)
begin the informational response
Definition: BESHTMLInfo.cc:80