OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
ShowPathInfoResponseHandler.cc
Go to the documentation of this file.
1 // -*- mode: c++; c-basic-offset:4 -*-
2 //
3 // W10NResponseHandler.cc
4 //
5 // This file is part of BES w10n handler
6 //
7 // Copyright (c) 2015v OPeNDAP, Inc.
8 // Author: Nathan Potter <ndp@opendap.org>
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 //
24 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25 // Please read the full copyright statement in the file COPYRIGHT_URI.
26 //
27 
29 #include "W10NNames.h"
30 #include "w10n_utils.h"
31 #include "BESDebug.h"
32 
33 
34 #include "BESInfoList.h"
35 #include "BESInfo.h"
36 #include "BESRequestHandlerList.h"
37 #include "BESRequestHandler.h"
38 #include "BESNames.h"
39 #include "BESDapNames.h"
40 #include "BESDataNames.h"
41 #include "BESCatalogList.h"
42 #include "BESCatalog.h"
43 #include "BESCatalogEntry.h"
44 #include "BESCatalogUtils.h"
45 #include "BESSyntaxUserError.h"
46 #include "BESNotFoundError.h"
47 
49 {
50 }
51 
53 {
54 }
55 
67 
68  BESDEBUG(W10N_DEBUG_KEY, "ShowPathInfoResponseHandler::execute() - BEGIN ############################################################## BEGIN" << endl ) ;
69 
71  _response = info;
72 
73  string container = dhi.data[CONTAINER];
74  string catname;
75  string defcatname = BESCatalogList::TheCatalogList()->default_catalog();
77  if (!defcat) {
78  string err = (string) "Not able to find the default catalog "
79  + defcatname;
80  throw BESInternalError(err, __FILE__, __LINE__);
81  }
83 
84  // remove all of the leading slashes from the container name
85  string::size_type notslash = container.find_first_not_of("/", 0);
86  if (notslash != string::npos) {
87  container = container.substr(notslash);
88  }
89 
90  // see if there is a catalog name here. It's only a possible catalog
91  // name
92  string::size_type slash = container.find_first_of("/", 0);
93  if (slash != string::npos) {
94  catname = container.substr(0, slash);
95  } else {
96  catname = container;
97  }
98 
99  // see if this catalog exists. If it does, then remove the catalog
100  // name from the container (node)
102  catname);
103  if (catobj) {
104  if (slash != string::npos) {
105  container = container.substr(slash + 1);
106 
107  // remove repeated slashes
108  notslash = container.find_first_not_of("/", 0);
109  if (notslash != string::npos) {
110  container = container.substr(notslash);
111  }
112  } else {
113  container = "";
114  }
115  }
116 
117  if (container.empty())
118  container = "/";
119 
120 
121  BESDEBUG(W10N_DEBUG_KEY, "ShowPathInfoResponseHandler::execute() - w10n_id: " << container << endl ) ;
122 
124  //string coi = dhi.data[CATALOG_OR_INFO];
125 
126  map<string,string> pathInfoAttrs;
127  pathInfoAttrs[PATH] = container;
128 
129  info->begin_tag(PATH_INFO_RESPONSE,&pathInfoAttrs);
130 
131  string validPath, remainder;
132  bool isFile, isDir;
133 
135  container,
136  utils->get_root_dir(),
137  utils->follow_sym_links(),
138  validPath,
139  isFile,
140  isDir,
141  remainder);
142 
143 
144  // Now that we know what part of the path is actually something
145  // we can access, find out if the BES sees it as a dataset
146  bool isData = false;
147 
148  // If the valid path is an empty string then we KNOW it's not a dataset
149  if(validPath.length()!=0){
150 
151  // Get the catalog entry.
152  BESCatalogEntry *entry = 0;
153  string coi = dhi.data[CATALOG];
154  entry = defcat->show_catalog(validPath, coi, entry);
155  if (!entry) {
156  string err = (string) "Failed to find the validPath node " + validPath +
157  " this should not be possible. Some thing BAD is happening.";
158  throw BESInternalError(err, __FILE__, __LINE__);
159  }
160 
161  // Retrieve the valid services list
162  list<string> services = entry->get_service_list();
163 
164  // See if there's an OPENDAP_SERVICE available for the node.
165  if (services.size()) {
166  list<string>::const_iterator si = services.begin();
167  list<string>::const_iterator se = services.end();
168  for (; si != se; si++) {
169  if((*si) == OPENDAP_SERVICE)
170  isData = true;
171  }
172  }
173  }
174 
175 
176 
177  map<string,string> validPathAttrs;
178  validPathAttrs[IS_DATA] = isData?"true":"false";
179  validPathAttrs[IS_FILE] = isFile?"true":"false";
180  validPathAttrs[IS_DIR] = isDir?"true":"false";
181 
182  info->add_tag(VALID_PATH,validPath, &validPathAttrs);
183  info->add_tag(REMAINDER,remainder);
184 
186 
187 
188  // end the response object
189  info->end_response();
190 
191 
192  BESDEBUG(W10N_DEBUG_KEY, "ShowPathInfoResponseHandler::execute() - END ################################################################## END" << endl ) ;
193 
194 }
195 
196 
208 void
211 {
212  if( _response )
213  {
214  BESInfo *info = dynamic_cast<BESInfo *>(_response) ;
215  if( !info )
216  throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
217  info->transmit( transmitter, dhi ) ;
218  }
219 }
220 
227 void
228 ShowPathInfoResponseHandler::dump( ostream &strm ) const
229 {
230  strm << BESIndent::LMarg << "ShowPathInfoResponseHandler::dump - ("
231  << (void *)this << ")" << std::endl ;
233  BESResponseHandler::dump( strm ) ;
235 }
236 
239 {
240  return new ShowPathInfoResponseHandler( name ) ;
241 }
242 
virtual list< string > get_service_list()
virtual BESInfo * build_info()
Definition: BESInfoList.cc:77
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi)
transmit the response object built by the execute command using the specified transmitter object ...
#define PATH_INFO_RESPONSE
Definition: W10NNames.h:15
virtual void end_response()
Definition: BESInfo.cc:118
exception thrown if inernal error encountered
virtual void execute(BESDataHandlerInterface &dhi)
executes the command 'show catalog|leaves [for ];' by returning nodes or leaves at the top leve...
virtual BESCatalog * find_catalog(const string &catalog_name)
find the catalog in the list with the specified name
static BESInfoList * TheList()
Definition: BESInfoList.cc:142
#define OPENDAP_SERVICE
macros representing the default response objects handled
Definition: BESDapNames.h:52
#define PATH
Definition: W10NNames.h:16
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi)=0
transmit the informational object
virtual BESCatalogEntry * show_catalog(const string &container, const string &coi, BESCatalogEntry *entry)=0
virtual void add_tag(const string &tag_name, const string &tag_data, map< string, string > *attrs=0)=0
#define CATALOG
Definition: BESDataNames.h:72
static void Indent()
Definition: BESIndent.cc:38
BESResponseObject * _response
handler object that knows how to create a specific response object
informational response object
Definition: BESInfo.h:68
virtual string default_catalog()
#define VALID_PATH
Definition: W10NNames.h:17
virtual void begin_tag(const string &tag_name, map< string, string > *attrs=0)
Definition: BESInfo.cc:127
static ostream & LMarg(ostream &strm)
Definition: BESIndent.cc:73
bool follow_sym_links() const
#define CONTAINER
Definition: BESDataNames.h:71
void eval_resource_path(const string &w10nResourceId, const string &catalogRoot, const bool follow_sym_links, string &validPath, bool &isFile, bool &isDir, string &remainder)
Check if the specified path is valid.
Definition: w10n_utils.cc:69
#define IS_DATA(f)
Definition: freeform.h:703
virtual void dump(ostream &strm) const
dumps information about this object
#define W10N_DEBUG_KEY
Definition: W10NNames.h:4
#define SHOW_PATH_INFO_RESPONSE_STR
Definition: W10NNames.h:13
abstract base class catalog object.
Definition: BESCatalog.h:47
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.
static BESResponseHandler * ShowPathInfoResponseBuilder(const string &name)
virtual void begin_response(const string &response_name, BESDataHandlerInterface &dhi)
begin the informational response
Definition: BESInfo.cc:112
virtual string get_catalog_name()
Definition: BESCatalog.h:77
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
Definition: BESDebug.h:64
#define REMAINDER
Definition: W10NNames.h:18
static void UnIndent()
Definition: BESIndent.cc:44
static BESCatalogUtils * Utils(const string &name)
static BESCatalogList * TheCatalogList()
returns the singleton BESCatalogList instance.
#define IS_DIR
Definition: W10NNames.h:21
virtual void end_tag(const string &tag_name)
Definition: BESInfo.cc:132
virtual void dump(ostream &strm) const
dumps information about this object
const string & get_root_dir() const
#define IS_FILE(f)
Definition: freeform.h:705