bes  Updated for version 3.17.4
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 "SampleSayXMLCommand.h"
34 #include "BESXMLUtils.h"
35 #include "BESUtil.h"
36 #include "BESSyntaxUserError.h"
37 #include "BESDebug.h"
38 #include "SampleResponseNames.h"
39 
40 SampleSayXMLCommand::SampleSayXMLCommand( const BESDataHandlerInterface &base_dhi )
41  : BESXMLCommand( base_dhi )
42 {
43 }
44 
51 void
53 {
54  string name ;
55  string value ;
56  map<string, string> props ;
57  BESXMLUtils::GetNodeInfo( node, name, value, props ) ;
58  if( name != SAY_RESPONSE )
59  {
60  string err = "The specified command " + name
61  + " is not a say command" ;
62  throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
63  }
64 
65  if( !value.empty() )
66  {
67  string err = name + " command: should not have xml element values" ;
68  throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
69  }
70 
71  string child_name ;
72  string child_value ;
73  map<string,string> child_props ;
74  xmlNode *child_node =
75  BESXMLUtils::GetFirstChild( node, child_name, child_value, child_props);
76  if( child_node )
77  {
78  string err = name + " command: should not have child elements" ;
79  throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
80  }
81 
82  _dhi.data[SAY_WHAT] = props["what"] ;
83  if( _dhi.data[SAY_WHAT].empty() )
84  {
85  string err = name + " command: Must specify to whom to say" ;
86  throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
87  }
88 
89  _dhi.data[SAY_TO] = props["to"] ;
90  if( _dhi.data[SAY_WHAT].empty() )
91  {
92  string err = name + " command: Must specify what to say" ;
93  throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
94  }
95 
96  _dhi.action = SAY_RESPONSE ;
97 
98  // now that we've set the action, go get the response handler for the
99  // action
101 }
102 
103 void
105 {
106 }
107 
114 void
115 SampleSayXMLCommand::dump( ostream &strm ) const
116 {
117  strm << BESIndent::LMarg << "SampleSayXMLCommand::dump - ("
118  << (void *)this << ")" << endl ;
119  BESIndent::Indent() ;
120  BESXMLCommand::dump( strm ) ;
121  BESIndent::UnIndent() ;
122 }
123 
125 SampleSayXMLCommand::CommandBuilder( const BESDataHandlerInterface &base_dhi )
126 {
127  return new SampleSayXMLCommand( base_dhi ) ;
128 }
129 
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:131
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:99
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