bes  Updated for version 3.20.6
SiteMapCommand.cc
1 // SiteMapCommand.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) 2018 OPeNDAP, Inc.
7 // Author: James Gallagher <jgallagher@opendap.org>
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 OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24 
25 #include "config.h"
26 
27 #include <string>
28 #include <fstream>
29 #include <memory>
30 
31 #include "BESDataHandlerInterface.h"
32 #include "BESCatalog.h"
33 #include "BESCatalogList.h"
34 
35 #include "BESXMLUtils.h"
36 #include "BESSyntaxUserError.h"
37 #include "BESDebug.h"
38 #include "BESNames.h"
39 
40 #include "SiteMapCommand.h"
41 
42 using namespace std;
43 
44 SiteMapCommand::SiteMapCommand(const BESDataHandlerInterface &base_dhi) :
45  BESXMLCommand(base_dhi)
46 {
47 }
48 
59 void SiteMapCommand::parse_request(xmlNode *node)
60 {
61  string name;
62  string value;
63  map<string, string> props;
64  BESXMLUtils::GetNodeInfo(node, name, value, props);
65  if (name != SITE_MAP_RESPONSE_STR) {
66  throw BESSyntaxUserError(string("The specified command ") + name + " is not a build site map command", __FILE__, __LINE__);
67  }
68 
69  d_xmlcmd_dhi.data[SITE_MAP_RESPONSE] = SITE_MAP_RESPONSE;
70 
71  if (props[PREFIX].empty() || (props[NODE_SUFFIX].empty() && props[LEAF_SUFFIX].empty()))
72  throw BESSyntaxUserError("Build site map must include the prefix and at least one of the nodeSuffix or leafSuffix attributes.", __FILE__, __LINE__);
73 
74  d_xmlcmd_dhi.data[PREFIX] = props[PREFIX];
75  d_xmlcmd_dhi.data[NODE_SUFFIX] = props[NODE_SUFFIX];
76  d_xmlcmd_dhi.data[LEAF_SUFFIX] = props[LEAF_SUFFIX];
77 
78  d_xmlcmd_dhi.data[CATALOG] = props[CATALOG];
79 
80  // if CATALOG is not given, then return a site map for all the catalogs. See
81  // SiteMapResponseHandler.
82  if (props[CATALOG].empty())
83  d_cmd_log_info = string("show siteMap: build site map for all catalogs.");
84  else
85  d_cmd_log_info = string("show siteMap: build site map for catalog '").append(props[CATALOG]).append("'.");
86 
87  // These values control the ResponseHandler set in the set_response() call below.
88  // jhrg 11/26/18
89  d_xmlcmd_dhi.action_name = SITE_MAP_RESPONSE_STR;
90  d_xmlcmd_dhi.action = SITE_MAP_RESPONSE;
91 
92  // Set the response handler for the action in the command's DHI using the value of
93  // the DHI.action field. And, as a bonus, copy the d_cmd_log_info into DHI.data[LOG_INFO]
94  // and if VERBOSE logging is on, log that the command has been parsed.
96 }
97 
105 void SiteMapCommand::dump(ostream &strm) const
106 {
107  strm << BESIndent::LMarg << "SiteMapCommand::dump - (" << (void *) this << ")" << endl;
108  BESIndent::Indent();
109  BESXMLCommand::dump(strm);
110  BESIndent::UnIndent();
111 }
112 
121 {
122  return new SiteMapCommand(base_dhi);
123 }
124 
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
SiteMapCommand::CommandBuilder
static BESXMLCommand * CommandBuilder(const BESDataHandlerInterface &base_dhi)
Factory for the SiteMapCommand.
Definition: SiteMapCommand.cc:120
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
SiteMapCommand::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: SiteMapCommand.cc:105
BESXMLCommand::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESXMLCommand.cc:119
BESSyntaxUserError
error thrown if there is a user syntax error in the request or any other user error
Definition: BESSyntaxUserError.h:41
SiteMapCommand::parse_request
virtual void parse_request(xmlNode *node)
Parse the build site map command.
Definition: SiteMapCommand.cc:59
BESXMLCommand
Base class for the BES's commands.
Definition: BESXMLCommand.h:63
SiteMapCommand
Build a site map.
Definition: SiteMapCommand.h:57
BESDataHandlerInterface
Structure storing information used by the BES to handle the request.
Definition: BESDataHandlerInterface.h:56