bes  Updated for version 3.20.8
BESDapResponse.cc
1 // BESDapResponse.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 "config.h"
34 
35 #include "BESDapResponse.h"
36 #include "BESContextManager.h"
37 #include "BESConstraintFuncs.h"
38 #include "BESDataNames.h"
39 #include "BESError.h"
40 #include "BESDebug.h"
41 
42 using std::endl;
43 using std::string;
44 using std::ostream;
45 
46 #define MODULE "dap"
47 #define prolog std::string("BESDapResponse::").append(__func__).append("() - ")
48 
65 {
66  bool found = false;
67  string context_key;
68  string context_value;
69  BESDEBUG(MODULE,prolog << "BEGIN" << endl);
70 
71  // d_explicit_containers is false by default
72  context_key = "dap_explicit_containers";
73  context_value = BESContextManager::TheManager()->get_context(context_key, found);
74  //BESDEBUG(MODULE,prolog << context_key << ": \"" << context_value << "\" found: " << found << endl);
75  if (found) {
76  if (context_value == "yes")
77  d_explicit_containers = true;
78  else if (context_value == "no")
79  d_explicit_containers = false;
80  else
81  throw BESError("dap_explicit_containers must be yes or no",
82  BES_SYNTAX_USER_ERROR, __FILE__, __LINE__);
83  }
84  else {
85  context_key = "dap_format";
86  context_value = BESContextManager::TheManager()->get_context(context_key, found);
87  //BESDEBUG(MODULE,prolog << context_key << ": \"" << context_value << "\" found: " << found << endl);
88  if (found) {
89  if (context_value == "dap2")
90  d_explicit_containers = false;
91  else
92  d_explicit_containers = true;
93  }
94  }
95  BESDEBUG(MODULE,prolog << "d_explicit_containers: " << (d_explicit_containers?"true":"false") << endl);
96 
97  context_key = "xdap_accept";
98  context_value = BESContextManager::TheManager()->get_context(context_key, found);
99  //BESDEBUG(MODULE,prolog << context_key << ": \"" << context_value << "\" found: " << found << endl);
100  if (found) d_dap_client_protocol = context_value;
101  BESDEBUG(MODULE,prolog << "d_dap_client_protocol: " << d_dap_client_protocol << endl);
102 
103  context_key = "xml:base";
104  context_value = BESContextManager::TheManager()->get_context(context_key, found);
105  //BESDEBUG(MODULE,prolog << context_key << ": \"" << context_value << "\" found: " << found << endl);
106  if (found) d_request_xml_base = context_value;
107  BESDEBUG(MODULE,prolog << "d_request_xml_base: " << d_request_xml_base << endl);
108 
109  BESDEBUG(MODULE,prolog << "END" << endl);
110 }
111 
120 {
121  return !d_explicit_containers;
122 }
123 
135 {
136  if (dhi.container) {
137  if (is_dap2()) {
138  dhi.data[POST_CONSTRAINT] = dhi.container->get_constraint();
139  }
140  else {
141  BESConstraintFuncs::post_append(dhi);
142  }
143  }
144 }
145 
157 {
158  if (dhi.container) {
159  dhi.data[DAP4_CONSTRAINT] = dhi.container->get_dap4_constraint();
160  }
161 }
162 
174 {
175  if (dhi.container) {
176  dhi.data[DAP4_FUNCTION] = dhi.container->get_dap4_function();
177  }
178 }
179 
187 void BESDapResponse::dump(ostream &strm) const
188 {
189  strm << BESIndent::LMarg << "BESDapResponse::dump - (" << (void *) this << ")" << endl;
190  BESIndent::Indent();
191  strm << BESIndent::LMarg << "d_explicit_containers: " << d_explicit_containers << endl;
192  strm << BESIndent::LMarg << "d_dap_client_protocol: " << d_dap_client_protocol << endl;
193  BESIndent::UnIndent();
194 
195  BESIndent::UnIndent();
196 }
197 
std::string get_dap4_constraint() const
retrieve the constraint expression for this container
Definition: BESContainer.h:203
std::string get_dap4_function() const
retrieve the constraint expression for this container
Definition: BESContainer.h:212
std::string get_constraint() const
retrieve the constraint expression for this container
Definition: BESContainer.h:194
virtual std::string get_context(const std::string &name, bool &found)
retrieve the value of the specified context from the BES
void read_contexts()
Extract the dap protocol from the setContext information This method checks four contexts: dap_explic...
virtual void set_dap4_function(BESDataHandlerInterface &dhi)
set the constraint depending on the context
virtual void set_dap4_constraint(BESDataHandlerInterface &dhi)
set the constraint depending on the context
virtual void set_constraint(BESDataHandlerInterface &dhi)
set the constraint depending on the context
virtual void dump(std::ostream &strm) const
dumps information about this object
bool is_dap2()
See get_explicit_containers()
Structure storing information used by the BES to handle the request.
std::map< std::string, std::string > data
the map of string data that will be required for the current request.
BESContainer * container
pointer to current container in this interface
Abstract exception class for the BES with basic string message.
Definition: BESError.h:58