bes  Updated for version 3.17.0
BESXMLGetDataDDXCommand.cc
1 // BESXMLGetDataDDXCommand.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,2005 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 "BESXMLGetDataDDXCommand.h"
34 #include "BESDefinitionStorageList.h"
35 #include "BESDefinitionStorage.h"
36 #include "BESDefine.h"
37 #include "BESDapNames.h"
38 #include "BESResponseNames.h"
39 #include "BESXMLUtils.h"
40 #include "BESUtil.h"
41 #include "BESSyntaxUserError.h"
42 #include "BESDebug.h"
43 
44 BESXMLGetDataDDXCommand::BESXMLGetDataDDXCommand(const BESDataHandlerInterface &base_dhi) :
45  BESXMLGetCommand(base_dhi)
46 {
47 }
48 
56 {
57  string name;
58  string value;
59  map<string, string> props;
60  BESXMLUtils::GetNodeInfo(node, name, value, props);
61 
62  if (name != GET_RESPONSE) {
63  string err = "The specified command " + name + " is not a get command";
64  throw BESSyntaxUserError(err, __FILE__, __LINE__);
65  }
66 
67  string type = props["type"];
68  if (type.empty() || type != DATADDX_SERVICE) {
69  string err = name + " command: data product must be " + DATADDX_SERVICE;
70  throw BESSyntaxUserError(err, __FILE__, __LINE__);
71  }
72 
73  parse_basic_get(node, name, type, value, props);
74 
75  // Get the elements for contentStartId and mimeBoundary
76  map<string, string> cprops;
77  string cname;
78  string cval;
79  int elems = 0;
80  xmlNode *cnode = BESXMLUtils::GetFirstChild(node, cname, cval, cprops);
81  while (cnode && (elems < 2)) {
82  if (cname == "contentStartId") {
83  if (!_contentStartId.empty()) {
84  string err = name + " command: contentStartId has multiple values";
85  throw BESSyntaxUserError(err, __FILE__, __LINE__);
86  }
87  _contentStartId = cval;
88  _str_cmd += " contentStartId " + _contentStartId;
89  elems++;
90  }
91  if (cname == "mimeBoundary") {
92  if (!_mimeBoundary.empty()) {
93  string err = name + " command: mimeBoundary has multiple values";
94  throw BESSyntaxUserError(err, __FILE__, __LINE__);
95  }
96  _mimeBoundary = cval;
97  _str_cmd += " mimeBoundary " + _mimeBoundary;
98  elems++;
99  }
100  cprops.clear();
101  cnode = BESXMLUtils::GetNextChild(cnode, cname, cval, cprops);
102  }
103  if (_contentStartId.empty()) {
104  string err = name + " command: contentStartId not specified";
105  throw BESSyntaxUserError(err, __FILE__, __LINE__);
106  }
107  if (_mimeBoundary.empty()) {
108  string err = name + " command: mimeBoundary not specified";
109  throw BESSyntaxUserError(err, __FILE__, __LINE__);
110  }
111  _str_cmd += ";";
112 
113  // now that we've set the action, go get the response handler for the
114  // action
116 }
117 
124 {
126  _dhi.data[DATADDX_STARTID] = _contentStartId;
127  _dhi.data[DATADDX_BOUNDARY] = _mimeBoundary;
128 }
129 
136 void BESXMLGetDataDDXCommand::dump(ostream &strm) const
137 {
138  strm << BESIndent::LMarg << "BESXMLGetDataDDXCommand::dump - (" << (void *) this << ")" << endl;
139  BESIndent::Indent();
140  BESXMLCommand::dump(strm);
141  BESIndent::UnIndent();
142 }
143 
145 BESXMLGetDataDDXCommand::CommandBuilder(const BESDataHandlerInterface &base_dhi)
146 {
147  return new BESXMLGetDataDDXCommand(base_dhi);
148 }
149 
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
static xmlNode * GetNextChild(xmlNode *child_node, string &next_name, string &next_value, map< string, string > &next_props)
get the next element child node after the given child node
Definition: BESXMLUtils.cc:158
virtual void prep_request()
prepare the get dataddx command
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
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.
virtual void prep_request()
Prepare any information needed to execute the request of this get command.
Structure storing information used by the BES to handle the request.
virtual void parse_request(xmlNode *node)
parse a get dataddx command.
map< string, string > data
the map of string data that will be required for the current request.
virtual void dump(ostream &strm) const
dumps information about this object
virtual void dump(ostream &strm) const
dumps information about this object