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., 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 "BESHTMLInfo.h"
43 #include "BESUtil.h"
44 
51  : BESInfo( ),
52  _header( false ),
53  _do_indent( true )
54 {
55 }
56 
65 BESHTMLInfo::BESHTMLInfo( const string &key, ostream *strm, bool strm_owned )
66  : BESInfo( key, strm, strm_owned ),
67  _header( false ),
68  _do_indent( true )
69 {
70 }
71 
73 {
74 }
75 
83 void
84 BESHTMLInfo::begin_response( const string &response_name,
86 {
87  BESInfo::begin_response( response_name, dhi ) ;
88  add_data( "<HTML>\n" ) ;
89  _indent += " " ;
90  add_data( "<HEAD>\n" ) ;
91  _indent += " " ;
92  add_data( (string)"<TITLE>" + response_name + "</TITLE>\n" ) ;
93  if( _indent.length() >= 4 )
94  _indent = _indent.substr( 0, _indent.length()-4 ) ;
95  add_data( "</HEAD>\n" ) ;
96  add_data( "<BODY>\n" ) ;
97  _indent += " " ;
98 }
99 
107 void
109 {
110  if( _indent.length() >= 4 )
111  _indent = _indent.substr( 0, _indent.length()-4 ) ;
112  add_data( "</BODY>\n" ) ;
113  if( _indent.length() >= 4 )
114  _indent = _indent.substr( 0, _indent.length()-4 ) ;
115  add_data( "</HTML>\n" ) ;
116 }
117 
124 void
125 BESHTMLInfo::add_tag( const string &tag_name,
126  const string &tag_data,
127  map<string,string> *attrs )
128 {
129  string to_add = tag_name + ": " + tag_data + "<BR />\n" ;
130  add_data( to_add ) ;
131  if( attrs )
132  {
133  map<string,string>::const_iterator i = attrs->begin() ;
134  map<string,string>::const_iterator e = attrs->end() ;
135  for( ; i != e; i++ )
136  {
137  string name = (*i).first ;
138  string val = (*i).second ;
139  BESInfo::add_data( _indent + " " + name + ": " + val + "<BR />\n" ) ;
140  }
141  }
142 }
143 
149 void
150 BESHTMLInfo::begin_tag( const string &tag_name,
151  map<string,string> *attrs )
152 {
153  BESInfo::begin_tag( tag_name ) ;
154  string to_add = tag_name + "<BR />\n" ;
155  add_data( to_add ) ;
156  _indent += " " ;
157  if( attrs )
158  {
159  map<string,string>::const_iterator i = attrs->begin() ;
160  map<string,string>::const_iterator e = attrs->end() ;
161  for( ; i != e; i++ )
162  {
163  string name = (*i).first ;
164  string val = (*i).second ;
165  BESInfo::add_data( _indent + name + ": " + val + "<BR />\n" ) ;
166  }
167  }
168 }
169 
176 void
177 BESHTMLInfo::end_tag( const string &tag_name )
178 {
179  BESInfo::end_tag( tag_name ) ;
180  if( _indent.length() >= 4 )
181  _indent = _indent.substr( 0, _indent.length()-4 ) ;
182 }
183 
188 void
189 BESHTMLInfo::add_space( unsigned long num_spaces )
190 {
191  string to_add ;
192  for( unsigned long i = 0; i < num_spaces; i++ )
193  {
194  to_add += "&nbsp;" ;
195  }
196  _do_indent = false ;
197  add_data( to_add ) ;
198 }
199 
204 void
205 BESHTMLInfo::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 += "<BR />" ;
211  }
212  to_add += "\n" ;
213  _do_indent = false ;
214  add_data( to_add ) ;
215 }
216 
226 void
227 BESHTMLInfo::add_data( const string &s )
228 {
229  if( !_header && !_buffered )
230  {
232  _header = true ;
233  }
234  if( _do_indent )
235  BESInfo::add_data( _indent + s ) ;
236  else
237  BESInfo::add_data( s ) ;
238  _do_indent = true ;
239 }
240 
249 void
250 BESHTMLInfo::add_data_from_file( const string &key, const string &name )
251 {
252  string newkey = key + ".HTML" ;
253  BESInfo::add_data_from_file( newkey, name ) ;
254 }
255 
264 void
267 {
268  transmitter->send_html( *this, dhi ) ;
269 }
270 
278 void
279 BESHTMLInfo::dump( ostream &strm ) const
280 {
281  strm << BESIndent::LMarg << "BESHTMLInfo::dump - ("
282  << (void *)this << ")" << endl ;
284  strm << BESIndent::LMarg << "has header been added? " << _header << endl ;
285  strm << BESIndent::LMarg << "indentation \"" << _indent << "\"" << endl ;
286  strm << BESIndent::LMarg << "do indent? " << _do_indent << endl ;
287  BESInfo::dump( strm ) ;
289 }
290 
291 BESInfo *
292 BESHTMLInfo::BuildHTMLInfo( const string &info_type )
293 {
294  return new BESHTMLInfo( ) ;
295 }
296 
virtual void dump(ostream &strm) const
dumps information about this object
Definition: BESHTMLInfo.cc:279
virtual void dump(ostream &strm) const
Displays debug information about this object.
Definition: BESInfo.cc:299
BESHTMLInfo()
constructs an html formatted information response object.
Definition: BESHTMLInfo.cc:50
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:292
virtual void end_response()
end the response
Definition: BESHTMLInfo.cc:108
static void Indent()
Definition: BESIndent.cc:38
virtual ~BESHTMLInfo()
Definition: BESHTMLInfo.cc:72
virtual void add_space(unsigned long num_spaces)
add a space to the informational response
Definition: BESHTMLInfo.cc:189
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:150
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:125
static void set_mime_html(ostream &strm)
Generate an HTTP 1.0 response header for a html document.
Definition: BESUtil.cc:85
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:227
virtual void add_break(unsigned long num_breaks)
add a line break to the information
Definition: BESHTMLInfo.cc:205
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:177
Structure storing information used by the BES to handle the request.
virtual void add_data_from_file(const string &key, const string &name)
add data from a file to the informational object
Definition: BESHTMLInfo.cc:250
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:265
virtual void begin_response(const string &response_name, BESDataHandlerInterface &dhi)
begin the informational response
Definition: BESHTMLInfo.cc:84