35 #include <sys/types.h> 54 map<string, BESCatalogUtils *> BESCatalogUtils::_instances ;
57 BESCatalogUtils(
const string &n )
58 : _follow_syms( false )
60 string key =
"BES.Catalog." + n +
".RootDirectory" ;
63 if( !found || _root_dir ==
"" )
65 string s = key +
" not defined in BES configuration file" ;
68 DIR *dip = opendir( _root_dir.c_str() ) ;
71 string serr =
"BESCatalogDirectory - root directory " 72 + _root_dir +
" does not exist" ;
78 key = (string)
"BES.Catalog." + n +
".Exclude" ;
81 vector<string>::iterator ei = vals.begin() ;
82 vector<string>::iterator ee = vals.end() ;
83 for( ; ei != ee; ei++ )
85 string e_str = (*ei) ;
86 if( !e_str.empty() && e_str !=
";" )
90 key = (string)
"BES.Catalog." + n +
".Include" ;
93 vector<string>::iterator ii = vals.begin() ;
94 vector<string>::iterator ie = vals.end() ;
95 for( ; ii != ie; ii++ )
97 string i_str = (*ii) ;
98 if( !i_str.empty() && i_str !=
";" )
102 key =
"BES.Catalog." + n +
".TypeMatch" ;
103 list<string> match_list ;
106 if( !found || vals.size() == 0 )
108 string s = key +
" not defined in key file" ;
111 vector<string>::iterator vi = vals.begin() ;
112 vector<string>::iterator ve = vals.end() ;
113 for( ; vi != ve; vi++ )
118 list<string>::iterator mli = match_list.begin() ;
119 list<string>::iterator mle = match_list.end() ;
120 for( ; mli != mle; mli++ )
122 if( !((*mli).empty()) && *(mli) !=
";" )
124 list<string> amatch ;
126 if( amatch.size() != 2 )
128 string s = (string)
"Catalog type match malformed, " 129 +
"looking for type:regexp;[type:regexp;]" ;
132 list<string>::iterator ami = amatch.begin() ;
134 newval.
type = (*ami) ;
136 newval.
reg = (*ami) ;
137 _match_list.push_back( newval ) ;
141 key = (string)
"BES.Catalog." + n +
".FollowSymLinks" ;
145 if( s_str ==
"yes" || s_str ==
"on" || s_str ==
"true" )
147 _follow_syms = true ;
154 bool toInclude = false ;
159 if( _include.size() == 0 )
165 list<string>::const_iterator i_iter = _include.begin() ;
166 list<string>::const_iterator i_end = _include.end() ;
167 for( ; i_iter != i_end; i_iter++ )
169 string reg = *i_iter ;
174 Regex reg_expr( reg.c_str() ) ;
175 if( reg_expr.match( inQuestion.c_str(), inQuestion.length() ) ==
176 static_cast<int>(inQuestion.length()) )
183 string serr = (string)
"Unable to get catalog information, " 184 +
"malformed Catalog Include parameter " 185 +
"in bes configuration file around " 186 + reg +
": " + e.get_error_message() ;
192 if( toInclude ==
true )
206 list<string>::const_iterator e_iter = _exclude.begin() ;
207 list<string>::const_iterator e_end = _exclude.end() ;
208 for( ; e_iter != e_end; e_iter++ )
210 string reg = *e_iter ;
213 Regex reg_expr( reg.c_str() ) ;
214 if( reg_expr.match( inQuestion.c_str(), inQuestion.length() ) ==
215 static_cast<int>(inQuestion.length()) )
222 string serr = (string)
"Unable to get catalog information, " 223 +
"malformed Catalog Exclude parameter " 224 +
"in bes configuration file around " 225 + reg +
": " + e.get_error_message() ;
235 return _match_list.begin() ;
241 return _match_list.end() ;
248 << (
void *)
this <<
")" << endl ;
253 if( _include.size() )
257 list<string>::const_iterator i_iter = _include.begin() ;
258 list<string>::const_iterator i_end = _include.end() ;
259 for( ; i_iter != i_end; i_iter++ )
270 if( _exclude.size() )
274 list<string>::const_iterator e_iter = _exclude.begin() ;
275 list<string>::const_iterator e_end = _exclude.end() ;
276 for( ; e_iter != e_end; e_iter++ )
287 if( _match_list.size() )
293 for( ; i != ie; i++ )
297 << match.
reg << endl ;
325 BESCatalogUtils::_instances[cat_name] = utils ;
error thrown if the resource requested cannot be found
static const BESCatalogUtils * Utils(const string &name)
exception thrown if inernal error encountered
static string lowercase(const string &s)
Convert a string to all lower case.
BESCatalogUtils::match_citer match_list_end() const
error thrown if there is a user syntax error in the request or any other user error ...
vector< type_reg >::const_iterator match_citer
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
static ostream & LMarg(ostream &strm)
static void explode(char delim, const string &str, list< string > &values)
explode a string into an array given a delimiter
virtual bool include(const string &inQuestion) const
void get_value(const string &s, string &val, bool &found)
Retrieve the value of a given key, if set.
virtual bool exclude(const string &inQuestion) const
void get_values(const string &s, vector< string > &vals, bool &found)
Retrieve the values of a given key, if set.
BESCatalogUtils::match_citer match_list_begin() const
static BESKeys * TheKeys()