bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
BESTextInfo.cc
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., 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#include <map>
36
37using std::ostringstream;
38using std::endl;
39using std::map;
40using std::string;
41using std::ostream;
42
43#include "BESTextInfo.h"
44#include "BESUtil.h"
45
56 BESInfo(), _ishttp(ishttp), _header(false)
57{
58}
59
79BESTextInfo::BESTextInfo(const string &key, ostream *strm, bool strm_owned, bool ishttp) :
80 BESInfo(key, strm, strm_owned), _ishttp(ishttp), _header(false)
81{
82}
83
84BESTextInfo::~BESTextInfo()
85{
86}
87
95void BESTextInfo::begin_response(const string &response_name, BESDataHandlerInterface &dhi)
96{
97 BESInfo::begin_response(response_name, dhi);
98}
99
106void BESTextInfo::add_tag(const string &tag_name, const string &tag_data, map<string, string, std::less<>> *attrs)
107{
108 add_data(_indent + tag_name + ": " + tag_data + "\n");
109 if (attrs) {
110 map<string, string>::const_iterator i = attrs->begin();
112 for (; i != e; i++) {
113 string name = (*i).first;
114 string val = (*i).second;
115 add_data(_indent + " " + name + ": " + val + "\n");
116 }
117 }
118}
119
125void BESTextInfo::begin_tag(const string &tag_name, map<string, string, std::less<>> *attrs)
126{
127 BESInfo::begin_tag(tag_name);
128 add_data(_indent + tag_name + "\n");
129 _indent += " ";
130 if (attrs) {
131 map<string, string>::const_iterator i = attrs->begin();
133 for (; i != e; i++) {
134 string name = (*i).first;
135 string val = (*i).second;
136 add_data(_indent + name + ": " + val + "\n");
137 }
138 }
139}
140
147void BESTextInfo::end_tag(const string &tag_name)
148{
149 BESInfo::end_tag(tag_name);
150 if (_indent.size() >= 4) _indent = _indent.substr(0, _indent.size() - 4);
151}
152
157void BESTextInfo::add_data(const string & s)
158{
159 if (_ishttp && !_header && !_buffered) {
161 _header = true;
162 }
164}
165
170void BESTextInfo::add_space(unsigned long num_spaces)
171{
172 string to_add;
173 for (unsigned long i = 0; i < num_spaces; i++) {
174 to_add += " ";
175 }
176 add_data(to_add);
177}
178
183void BESTextInfo::add_break(unsigned long num_breaks)
184{
185 string to_add;
186 for (unsigned long i = 0; i < num_breaks; i++) {
187 to_add += "\n";
188 }
189 add_data(to_add);
190}
191
200void BESTextInfo::add_data_from_file(const string &key, const string &name)
201{
202 string newkey = key + ".TXT";
203 BESInfo::add_data_from_file(newkey, name);
204}
205
215{
216 transmitter->send_text(*this, dhi);
217}
218
226void BESTextInfo::dump(ostream &strm) const
227{
228 strm << BESIndent::LMarg << "BESTextInfo::dump - (" << (void *) this << ")" << endl;
229 BESIndent::Indent();
230 strm << BESIndent::LMarg << "has header been added? " << _header << endl;
231 strm << BESIndent::LMarg << "indentation \"" << _indent << "\"" << endl;
232 strm << BESIndent::LMarg << "is http? " << _ishttp << endl;
233 BESInfo::dump(strm);
234 BESIndent::UnIndent();
235}
236
237BESInfo *
238BESTextInfo::BuildTextInfo(const string &/*info_type*/)
239{
240 return new BESTextInfo();
241}
242
Structure storing information used by the BES to handle the request.
informational response object
Definition BESInfo.h:63
virtual void add_data(const std::string &s)
add data to this informational object. If buffering is not set then the information is output directl...
Definition BESInfo.cc:151
BESInfo()
constructs a BESInfo object
Definition BESInfo.cc:52
virtual void begin_response(const std::string &response_name, BESDataHandlerInterface &dhi)
begin the informational response
Definition BESInfo.cc:120
virtual void dump(std::ostream &strm) const
Displays debug information about this object.
Definition BESInfo.cc:262
virtual void add_data_from_file(const std::string &key, const std::string &name)
add data from a file to the informational object.
Definition BESInfo.cc:172
void add_data_from_file(const std::string &key, const std::string &name) override
add data from a file to the informational object
void begin_tag(const std::string &tag_name, std::map< std::string, std::string, std::less<> > *attrs=nullptr) override
begin a tagged part of the information, information to follow
BESTextInfo(bool ishttp=false)
constructs a basic text information response object.
void add_space(unsigned long num_spaces) override
add a space to the informational response
void add_tag(const std::string &tag_name, const std::string &tag_data, std::map< std::string, std::string, std::less<> > *attrs=nullptr) override
add tagged information to the inforamtional response
void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi) override
transmit the text information as text
void dump(std::ostream &strm) const override
dumps information about this object
void add_data(const std::string &s) override
add string data to the informational response
void end_tag(const std::string &tag_name) override
end a tagged part of the informational response
void add_break(unsigned long num_breaks) override
add a line break to the information
void begin_response(const std::string &response_name, BESDataHandlerInterface &dhi) override
begin the informational response
static void set_mime_text(std::ostream &strm)
Generate an HTTP 1.0 response header for a text document.
Definition BESUtil.cc:139
STL iterator class.