bes  Updated for version 3.19.1
SampleSayXMLCommand.cc
1 // SampleSayXMLCommand.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 "BESXMLUtils.h"
36 #include "BESUtil.h"
37 #include "BESSyntaxUserError.h"
38 #include "BESDebug.h"
39 
40 #include "SampleSayXMLCommand.h"
41 #include "SampleResponseNames.h"
42 
43 SampleSayXMLCommand::SampleSayXMLCommand(const BESDataHandlerInterface &base_dhi) :
44  BESXMLCommand(base_dhi)
45 {
46 }
47 
55 {
56  string name;
57  string value;
58  map<string, string> props;
59  BESXMLUtils::GetNodeInfo(node, name, value, props);
60  if (name != SAY_RESPONSE) {
61  string err = "The specified command " + name + " is not a say command";
62  throw BESSyntaxUserError(err, __FILE__, __LINE__);
63  }
64 
65  if (!value.empty()) {
66  string err = name + " command: should not have xml element values";
67  throw BESSyntaxUserError(err, __FILE__, __LINE__);
68  }
69 
70  string child_name;
71  string child_value;
72  map<string, string> child_props;
73  xmlNode *child_node = BESXMLUtils::GetFirstChild(node, child_name, child_value, child_props);
74  if (child_node) {
75  string err = name + " command: should not have child elements";
76  throw BESSyntaxUserError(err, __FILE__, __LINE__);
77  }
78 
79  d_xmlcmd_dhi.data[SAY_WHAT] = props["what"];
80  if (d_xmlcmd_dhi.data[SAY_WHAT].empty()) {
81  string err = name + " command: Must specify to whom to say";
82  throw BESSyntaxUserError(err, __FILE__, __LINE__);
83  }
84 
85  d_xmlcmd_dhi.data[SAY_TO] = props["to"];
86  if (d_xmlcmd_dhi.data[SAY_WHAT].empty()) {
87  string err = name + " command: Must specify what to say";
88  throw BESSyntaxUserError(err, __FILE__, __LINE__);
89  }
90 
91  d_xmlcmd_dhi.action = SAY_RESPONSE;
92 
93  // now that we've set the action, go get the response handler for the
94  // action
96 }
97 
99 {
100 }
101 
108 void SampleSayXMLCommand::dump(ostream &strm) const
109 {
110  strm << BESIndent::LMarg << "SampleSayXMLCommand::dump - (" << (void *) this << ")" << endl;
111  BESIndent::Indent();
112  BESXMLCommand::dump(strm);
113  BESIndent::UnIndent();
114 }
115 
117 SampleSayXMLCommand::CommandBuilder(const BESDataHandlerInterface &base_dhi)
118 {
119  return new SampleSayXMLCommand(base_dhi);
120 }
121 
static xmlNode * GetFirstChild(xmlNode *node, string &child_name, string &child_value, map< string, string > &child_props)
get the first element child node for the given node
Definition: BESXMLUtils.cc:133
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 dump(ostream &strm) const
dumps information about this object
error thrown if there is a user syntax error in the request or any other user error
virtual void prep_request()
Prepare any information needed to execute the request of this command.
virtual void set_response()
The request has been parsed, use the command action name to set the response handler.
Structure storing information used by the BES to handle the request.
map< string, string > data
the map of string data that will be required for the current request.
virtual void parse_request(xmlNode *node)
parse a show command. No properties or children elements
string action
the response object requested, e.g. das, dds