bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
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
42using namespace std;
43
44SiteMapCommand::SiteMapCommand(const BESDataHandlerInterface &base_dhi) :
45 BESXMLCommand(base_dhi)
46{
47}
48
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
105void SiteMapCommand::dump(ostream &strm) const
106{
107 strm << BESIndent::LMarg << "SiteMapCommand::dump - (" << (void *) this << ")" << endl;
108 BESIndent::Indent();
110 BESIndent::UnIndent();
111}
112
121{
122 return new SiteMapCommand(base_dhi);
123}
124
Structure storing information used by the BES to handle the request.
error thrown if there is a user syntax error in the request or any other user error
Base class for the BES's commands.
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual void set_response()
The request has been parsed, use the command action name to set the response handler.
std::string d_cmd_log_info
Used only for the log.
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
virtual void parse_request(xmlNode *node)
Parse the build site map command.
virtual void dump(std::ostream &strm) const
dumps information about this object
static BESXMLCommand * CommandBuilder(const BESDataHandlerInterface &base_dhi)
Factory for the SiteMapCommand.