bes  Updated for version 3.20.5
BESWWWTransmit.cc
1 // BESWWWTransmit.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,2005 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 <BESDapTransmit.h>
34 #if 0
35 #include <DODSFilter.h>
36 #endif
37 #include <BESWWWTransmit.h>
38 // #include <DODSFilter.h>
39 #include <BESContainer.h>
40 #include <BESDapNames.h>
41 #include <BESWWWNames.h>
42 #include <mime_util.h>
43 #include <BESWWW.h>
44 #include <util.h>
45 #include <InternalErr.h>
46 #include <BESError.h>
47 #include <BESDapError.h>
48 #include <BESInternalFatalError.h>
49 #include <BESServiceRegistry.h>
50 
51 #include <BESDebug.h>
52 
53 #include "get_html_form.h"
54 
55 using namespace dap_html_form;
56 
57 void BESWWWTransmit::send_basic_form(BESResponseObject * obj, BESDataHandlerInterface & dhi)
58 {
59  dhi.first_container();
60  try {
61  BESDEBUG("www", "converting dds to www dds" << endl);
62 
63  DDS *dds = dynamic_cast<BESWWW &>(*obj).get_dds()->get_dds();
64  if (!dds) throw BESInternalFatalError("Expected a DDS instance", __FILE__, __LINE__);
65 
66  DDS *wwwdds = dds_to_www_dds(dds);
67 
68  BESDEBUG("www", "writing form" << endl);
69 
70  string url = dhi.data[WWW_URL];
71 
72  // Look for the netcdf format in the dap service. If present
73  // then have the interface make a button for it.
74  BESServiceRegistry *registry = BESServiceRegistry::TheRegistry();
75  bool netcdf3_file_response = registry->service_available(OPENDAP_SERVICE, DATA_SERVICE, "netcdf");
76  // TODO change this so that it actually tests for the netcdf4 capability. I'm
77  // not sure how to do that, so just assume the handler has it. jhrg 9/23/13
78  bool netcdf4_file_response = registry->service_available(OPENDAP_SERVICE, DATA_SERVICE, "netcdf");
79  write_html_form_interface(dhi.get_output_stream(), wwwdds, url, false /*send mime headers*/,
80  netcdf3_file_response, netcdf4_file_response);
81 
82  BESDEBUG("www", "done transmitting form" << endl);
83 
84  delete wwwdds;
85  }
86  catch (InternalErr &e) {
87  string err = "Failed to write html form: " + e.get_error_message();
88  throw BESDapError(err, true, e.get_error_code(), __FILE__, __LINE__);
89  }
90  catch (Error &e) {
91  string err = "Failed to write html form: " + e.get_error_message();
92  throw BESDapError(err, false, e.get_error_code(), __FILE__, __LINE__);
93  }
94  catch (BESError &e) {
95  throw;
96  }
97  catch (...) {
98  string err = "Failed to write html form: Unknown exception caught";
99  throw BESInternalFatalError(err, __FILE__, __LINE__);
100  }
101 }
102 
103 void BESWWWTransmit::send_http_form(BESResponseObject * obj, BESDataHandlerInterface & dhi)
104 {
105  set_mime_text(dhi.get_output_stream(), unknown_type, x_plain);
106  BESWWWTransmit::send_basic_form(obj, dhi);
107 }
108 
exception thrown if an internal error is found and is fatal to the BES
The service registry allows modules to register services with the BES that they provide.
Abstract exception class for the BES with basic string message.
Definition: BESError.h:58
error object created from libdap error objects and can handle those errors
Definition: BESDapError.h:59
Structure storing information used by the BES to handle the request.
map< string, string > data
the map of string data that will be required for the current request.
void first_container()
set the container pointer to the first container in the containers list
virtual bool service_available(const string &name, const string &cmd="", const string &format="")
Determines if a service and, optionally, a command and a return format, is available.
Abstract base class representing a specific set of information in response to a request to the BES.