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