bes  Updated for version 3.20.10
ShowBesKeyCommand.cc
1 // -*- mode: c++; c-basic-offset:4 -*-
2 //
3 // ShowBesKeyCommand.cc
4 //
5 // This file is part of the BES default command set
6 //
7 // Copyright (c) 2018 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 
26 
27 #include "config.h"
28 
29 #include "ShowBesKeyCommand.h"
30 #include "BESDataNames.h"
31 #include "BESDebug.h"
32 #include "BESError.h"
33 #include "BESUtil.h"
34 #include "BESXMLUtils.h"
35 #include "BESSyntaxUserError.h"
36 
37 using std::endl;
38 using std::ostream;
39 using std::string;
40 using std::map;
41 
42 ShowBesKeyCommand::ShowBesKeyCommand(const BESDataHandlerInterface &base_dhi) :
43  BESXMLCommand(base_dhi)
44 {
45 
46 }
47 
57 {
58  string name;
59  string value;
60  map<string, string> props;
61  BESXMLUtils::GetNodeInfo(node, name, value, props);
62  if (name != SHOW_BES_KEY_RESPONSE_STR) {
63  string err = "The specified command " + name + " is not a " + SHOW_BES_KEY_RESPONSE_STR + " command";
64  throw BESSyntaxUserError(err, __FILE__, __LINE__);
65  }
66 
67  // the action is to show the requested BES key value info response
68  d_xmlcmd_dhi.action = SHOW_BES_KEY_RESPONSE;
69  d_xmlcmd_dhi.data[SHOW_BES_KEY_RESPONSE] = SHOW_BES_KEY_RESPONSE;
70  d_cmd_log_info = "show besKey";
71 
72  // key is a required property, so it MAY NOT be the empty string
73 
74  string requested_bes_key = props["key"];
75 
76  if(requested_bes_key.empty())
77  throw BESError("Ouch! A Key name was not submitted with the request for a Key value from BESKeys", BES_SYNTAX_USER_ERROR, __FILE__, __LINE__);
78 
79  d_xmlcmd_dhi.data[BES_KEY] = requested_bes_key;
80 
81  if (!d_xmlcmd_dhi.data[BES_KEY].empty()) {
82  d_cmd_log_info += " for " + d_xmlcmd_dhi.data[BES_KEY];
83  }
84  d_cmd_log_info += ";";
85 
86  BESDEBUG(SBK_DEBUG_KEY, "Built BES Command: '" << d_cmd_log_info << "'"<< endl );
87 
88  // Given that we've set the action above, set the response handler for the
89  // action by calling set_response() in our parent class
91 }
92 
99 void ShowBesKeyCommand::dump(ostream &strm) const
100 {
101  strm << BESIndent::LMarg << "ShowBesKeyCommand::dump - (" << (void *) this << ")" << endl;
102  BESIndent::Indent();
103  BESXMLCommand::dump(strm);
104  BESIndent::UnIndent();
105 }
106 
108 ShowBesKeyCommand::CommandBuilder(const BESDataHandlerInterface &base_dhi)
109 {
110  return new ShowBesKeyCommand(base_dhi);
111 }
112 
113 
114 
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.
std::string action
the response object requested, e.g. das, dds
Abstract exception class for the BES with basic string message.
Definition: BESError.h:58
error thrown if there is a user syntax error in the request or any other user error
Base class for the BES's commands.
Definition: BESXMLCommand.h:63
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual void set_response()
The request has been parsed, use the command action name to set the response handler.
std::string d_cmd_log_info
Used only for the log.
Definition: BESXMLCommand.h:74
static void GetNodeInfo(xmlNode *node, std::string &name, std::string &value, std::map< std::string, std::string > &props)
get the name, value if any, and any properties for the specified node
Definition: BESXMLUtils.cc:109
virtual void parse_request(xmlNode *node)
parse a show command. No properties or children elements
virtual void dump(std::ostream &strm) const
dumps information about this object