bes  Updated for version 3.20.5
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 "ShowBesKeyCommand.h"
28 #include "BESDataNames.h"
29 #include "BESDebug.h"
30 #include "BESError.h"
31 #include "BESUtil.h"
32 #include "BESXMLUtils.h"
33 #include "BESSyntaxUserError.h"
34 
35 ShowBesKeyCommand::ShowBesKeyCommand(const BESDataHandlerInterface &base_dhi) :
36  BESXMLCommand(base_dhi)
37 {
38 
39 }
40 
50 {
51  string name;
52  string value;
53  map<string, string> props;
54  BESXMLUtils::GetNodeInfo(node, name, value, props);
55  if (name != SHOW_BES_KEY_RESPONSE_STR) {
56  string err = "The specified command " + name + " is not a " + SHOW_BES_KEY_RESPONSE_STR + " command";
57  throw BESSyntaxUserError(err, __FILE__, __LINE__);
58  }
59 
60  // the action is to show the requested BES key value info response
61  d_xmlcmd_dhi.action = SHOW_BES_KEY_RESPONSE;
62  d_xmlcmd_dhi.data[SHOW_BES_KEY_RESPONSE] = SHOW_BES_KEY_RESPONSE;
63  d_cmd_log_info = "show besKey";
64 
65  // key is a required property, so it MAY NOT be the empty string
66 
67  string requested_bes_key = props["key"];
68 
69  if(requested_bes_key.empty())
70  throw BESError("Ouch! A Key name was not submitted with the request for a Key value from BESKeys", BES_SYNTAX_USER_ERROR, __FILE__, __LINE__);
71 
72  d_xmlcmd_dhi.data[BES_KEY] = requested_bes_key;
73 
74  if (!d_xmlcmd_dhi.data[BES_KEY].empty()) {
75  d_cmd_log_info += " for " + d_xmlcmd_dhi.data[BES_KEY];
76  }
77  d_cmd_log_info += ";";
78 
79  BESDEBUG(SBK_DEBUG_KEY, "Built BES Command: '" << d_cmd_log_info << "'"<< endl );
80 
81  // Given that we've set the action above, set the response handler for the
82  // action by calling set_response() in our parent class
84 }
85 
92 void ShowBesKeyCommand::dump(ostream &strm) const
93 {
94  strm << BESIndent::LMarg << "ShowBesKeyCommand::dump - (" << (void *) this << ")" << endl;
95  BESIndent::Indent();
96  BESXMLCommand::dump(strm);
97  BESIndent::UnIndent();
98 }
99 
101 ShowBesKeyCommand::CommandBuilder(const BESDataHandlerInterface &base_dhi)
102 {
103  return new ShowBesKeyCommand(base_dhi);
104 }
105 
106 
107 
virtual void dump(ostream &strm) const
dumps information about this object
virtual void dump(ostream &strm) const
dumps information about this object
static void GetNodeInfo(xmlNode *node, string &name, string &value, map< string, string > &props)
get the name, value if any, and any properties for the specified node
Definition: BESXMLUtils.cc:101
virtual void parse_request(xmlNode *node)
parse a show command. No properties or children elements
error thrown if there is a user syntax error in the request or any other user error
virtual void set_response()
The request has been parsed, use the command action name to set the response handler.
Abstract exception class for the BES with basic string message.
Definition: BESError.h:58
Structure storing information used by the BES to handle the request.
Base class for the BES's commands.
Definition: BESXMLCommand.h:63