34 #include <TheBESKeys.h> 38 #include "BESInternalFatalError.h" 40 #include "ServerAdministrator.h" 46 #define prolog std::string("ServerAdministrator::").append(__func__).append("() - ") 61 #define EMAIL_KEY "email" 62 #define EMAIL_DEFAULT "support@opendap.org" 64 #define ORGANIZATION_KEY "organization" 65 #define ORGANIZATION_DEFAULT "OPeNDAP Inc." 67 #define STREET_KEY "street" 68 #define STREET_DEFAULT "165 NW Dean Knauss Dr." 70 #define CITY_KEY "city" 71 #define CITY_DEFAULT "Narragansett" 73 #define REGION_KEY "region" 74 #define STATE_KEY "state" 75 #define REGION_DEFAULT "RI" 77 #define POSTAL_CODE_KEY "postalCode" 78 #define POSTAL_CODE_DEFAULT "02882" 80 #define COUNTRY_KEY "country" 81 #define COUNTRY_DEFAULT "US" 83 #define TELEPHONE_KEY "telephone" 84 #define TELEPHONE_DEFAULT "+1.401.575.4835" 86 #define WEBSITE_KEY "website" 87 #define WEBSITE_DEFAULT "http://www.opendap.org" 98 vector<string> admin_keys;
101 throw BESInternalFatalError(
string(
"The BES configuration must provide server administrator information using the key: '")+SERVER_ADMINISTRATOR_KEY
102 +
"'", __FILE__, __LINE__);
103 BESDEBUG(MODULE,__func__ <<
"() - ERROR! The BES configuration must provide server administrator information using the key " << SERVER_ADMINISTRATOR_KEY << endl);
108 vector<string>::iterator it;
109 for(it=admin_keys.begin(); it!=admin_keys.end(); it++){
110 string admin_info_entry = *it;
111 int index = admin_info_entry.find(
":");
113 string key = admin_info_entry.substr(0,index);
115 string value = admin_info_entry.substr(index+1);
116 BESDEBUG(MODULE, prolog <<
"key: '" << key <<
"' value: " << value << endl);
117 d_admin_info.insert( std::pair<string,string>(key,value));
122 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " << SERVER_ADMINISTRATOR_KEY <<
" was incorrectly formatted. Offending entry: " << admin_info_entry << endl);
127 bool bad_flag =
false;
129 d_organization = get(ORGANIZATION_KEY);
130 if(d_organization.empty()){
131 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
132 SERVER_ADMINISTRATOR_KEY <<
"[" << ORGANIZATION_KEY <<
"] was missing." << endl);
136 d_street = get(STREET_KEY);
137 if(d_street.empty()){
138 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
139 SERVER_ADMINISTRATOR_KEY <<
"[" << STREET_KEY <<
"] was missing." << endl);
143 d_city = get(CITY_KEY);
145 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
146 SERVER_ADMINISTRATOR_KEY <<
"[" << CITY_KEY <<
"] was missing." << endl);
150 d_region = get(REGION_KEY);
151 if(d_region.empty()){
152 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
153 SERVER_ADMINISTRATOR_KEY <<
"[" << REGION_KEY <<
"] was missing." << endl);
154 d_region = get(STATE_KEY);
156 if(d_region.empty()){
157 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
158 SERVER_ADMINISTRATOR_KEY <<
"[" << STATE_KEY <<
"] was missing." << endl);
163 d_postal_code = get(POSTAL_CODE_KEY);
164 if(d_postal_code.empty()){
165 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
166 SERVER_ADMINISTRATOR_KEY <<
"[" << POSTAL_CODE_KEY <<
"] was missing." << endl);
170 d_country = get(COUNTRY_KEY);
171 if(d_country.empty()){
172 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
173 SERVER_ADMINISTRATOR_KEY <<
"[" << COUNTRY_KEY <<
"] was missing." << endl);
177 d_telephone = get(TELEPHONE_KEY);
178 if(d_telephone.empty()){
179 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
180 SERVER_ADMINISTRATOR_KEY <<
"[" << TELEPHONE_KEY <<
"] was missing." << endl);
184 d_email = get(EMAIL_KEY);
186 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
187 SERVER_ADMINISTRATOR_KEY <<
"[" << EMAIL_KEY <<
"] was missing." << endl);
191 d_website = get(WEBSITE_KEY);
192 if(d_website.empty()){
193 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
194 SERVER_ADMINISTRATOR_KEY <<
"[" << WEBSITE_KEY <<
"] was missing." << endl);
201 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " << SERVER_ADMINISTRATOR_KEY <<
" was missing crucial information. jdump(): " << jdump(
true) << endl);
207 std::string ServerAdministrator::get(
const string &key){
209 std::map<std::string,std::string>::const_iterator result = d_admin_info.find(lkey);
210 if(result == d_admin_info.end()){
213 return result->second;
220 std::string ServerAdministrator::xdump()
const {
221 std::stringstream ss;
222 std::map<std::string,std::string>::const_iterator it = d_admin_info.begin();
223 ss <<
"<ServerAdministrator ";
224 for(it=d_admin_info.begin(); it!= d_admin_info.end(); it++){
225 if(it!= d_admin_info.begin())
227 ss << it->first <<
"=\"" << it->second <<
"\"";
233 std::string ServerAdministrator::jdump(
bool compact)
const {
234 std::stringstream ss;
235 std::map<std::string,std::string>::const_iterator it = d_admin_info.begin();
239 ss <<
"\"ServerAdministrator\":";
243 if(!compact) ss <<
" ";
244 if(!compact) ss <<
" ";
245 for(it=d_admin_info.begin(); it!= d_admin_info.end(); it++){
246 if(it!= d_admin_info.begin())
250 ss <<
"\"" << it->first <<
"\"" <<
":";
253 ss <<
"\"" << it->second <<
"\"";
267 void ServerAdministrator::mk_default() {
268 this->d_admin_info.clear();
269 d_admin_info.insert( std::pair<string,string>(EMAIL_KEY,EMAIL_DEFAULT));
270 d_admin_info.insert( std::pair<string,string>(ORGANIZATION_KEY,ORGANIZATION_DEFAULT));
271 d_admin_info.insert( std::pair<string,string>(STREET_KEY,STREET_DEFAULT));
272 d_admin_info.insert( std::pair<string,string>(CITY_KEY,CITY_DEFAULT));
273 d_admin_info.insert( std::pair<string,string>(REGION_KEY,REGION_DEFAULT));
274 d_admin_info.insert( std::pair<string,string>(POSTAL_CODE_KEY,POSTAL_CODE_DEFAULT));
275 d_admin_info.insert( std::pair<string,string>(COUNTRY_KEY,COUNTRY_DEFAULT));
276 d_admin_info.insert( std::pair<string,string>(TELEPHONE_KEY,TELEPHONE_DEFAULT));
277 d_admin_info.insert( std::pair<string,string>(WEBSITE_KEY,WEBSITE_DEFAULT));
278 BESDEBUG(MODULE,__func__ <<
"() - ServerAdministrator values have been set to the defaults: " << jdump(
true) << endl);
exception thrown if an internal error is found and is fatal to the BES
static string lowercase(const string &s)
static TheBESKeys * TheKeys()
void get_values(const std::string &s, std::vector< std::string > &vals, bool &found)
Retrieve the values of a given key, if set.