bes  Updated for version 3.20.6
W10nJsonRequestHandler.cc
1 // -*- mode: c++; c-basic-offset:4 -*-
2 //
3 // FoJsonRequestHandler.cc
4 //
5 // This file is part of BES JSON File Out Module
6 //
7 // Copyright (c) 2014 OPeNDAP, Inc.
8 // Author: Nathan Potter <ndp@opendap.org>
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 //
24 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25 // (c) COPYRIGHT URI/MIT 1995-1999
26 // Please read the full copyright statement in the file COPYRIGHT_URI.
27 //
28 
29 #include "W10nJsonRequestHandler.h"
30 #include <BESResponseHandler.h>
31 #include <BESResponseNames.h>
32 #include <BESVersionInfo.h>
33 #include <BESDataNames.h>
34 #include <BESDataNames.h>
35 #include <TheBESKeys.h>
36 #include "config.h"
37 
38 using std::endl;
39 using std::ostream;
40 using std::string;
41 using std::map;
42 
52  : BESRequestHandler( name )
53 {
56 }
57 
61 {
62 }
63 
75 bool
77 {
78  BESResponseObject *response = dhi.response_handler->get_response_object() ;
79  BESInfo *info = dynamic_cast < BESInfo * >(response) ;
80  if( !info )
81  throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
82 
83  bool found = false ;
84  string key = "W10n.Reference" ;
85  string ref ;
86  TheBESKeys::TheKeys()->get_value( key, ref, found ) ;
87  if( ref.empty() )
88  ref = "http://docs.opendap.org/index.php/BES_-_Modules_-_w10n_JSON" ;
89  map<string,string> attrs ;
90  attrs["name"] = MODULE_NAME ;
91  attrs["version"] = MODULE_VERSION ;
92 #if 0
93  attrs["name"] = PACKAGE_NAME;
94  attrs["version"] = PACKAGE_VERSION;
95 #endif
96  attrs["reference"] = ref ;
97  info->begin_tag( "module", &attrs ) ;
98  info->end_tag( "module" ) ;
99 
100  return true ;
101 }
102 
110 bool
112 {
113  BESResponseObject *response = dhi.response_handler->get_response_object() ;
114  BESVersionInfo *info = dynamic_cast < BESVersionInfo * >(response) ;
115  if( !info )
116  throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
117 
118 #if 0
119  info->add_module(PACKAGE_NAME, PACKAGE_VERSION);
120 #endif
121  info->add_module(MODULE_NAME, MODULE_VERSION);
122 
123  return true ;
124 }
125 
132 void
133 W10nJsonRequestHandler::dump( ostream &strm ) const
134 {
135  strm << BESIndent::LMarg << "W10nJsonRequestHandler::dump - ("
136  << (void *)this << ")" << endl ;
137  BESIndent::Indent() ;
138  BESRequestHandler::dump( strm ) ;
139  BESIndent::UnIndent() ;
140 }
141 
BESRequestHandler
Represents a specific data type request handler.
Definition: BESRequestHandler.h:74
W10nJsonRequestHandler::build_version
static bool build_version(BESDataHandlerInterface &dhi)
add version information to a version response
Definition: W10nJsonRequestHandler.cc:111
BESInfo
informational response object
Definition: BESInfo.h:63
W10nJsonRequestHandler::build_help
static bool build_help(BESDataHandlerInterface &dhi)
adds help information for FileOut NetCDF to a help request
Definition: W10nJsonRequestHandler.cc:76
BESRequestHandler::add_method
virtual bool add_method(const std::string &name, p_request_handler_method method)
add a handler method to the request handler that knows how to fill in a specific response object
Definition: BESRequestHandler.cc:58
TheBESKeys::TheKeys
static TheBESKeys * TheKeys()
Definition: TheBESKeys.cc:62
BESResponseHandler::get_response_object
virtual BESResponseObject * get_response_object()
return the current response object
Definition: BESResponseHandler.cc:82
BESVersionInfo
Definition: BESVersionInfo.h:47
W10nJsonRequestHandler::W10nJsonRequestHandler
W10nJsonRequestHandler(const std::string &name)
Constructor for FileOut NetCDF module.
Definition: W10nJsonRequestHandler.cc:51
W10nJsonRequestHandler::~W10nJsonRequestHandler
virtual ~W10nJsonRequestHandler(void)
Any cleanup that needs to take place.
Definition: W10nJsonRequestHandler.cc:60
BESInternalError
exception thrown if internal error encountered
Definition: BESInternalError.h:43
TheBESKeys::get_value
void get_value(const std::string &s, std::string &val, bool &found)
Retrieve the value of a given key, if set.
Definition: TheBESKeys.cc:272
BESRequestHandler::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESRequestHandler.cc:163
W10nJsonRequestHandler::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: W10nJsonRequestHandler.cc:133
BESDataHandlerInterface
Structure storing information used by the BES to handle the request.
Definition: BESDataHandlerInterface.h:56
BESResponseObject
Abstract base class representing a specific set of information in response to a request to the BES.
Definition: BESResponseObject.h:45