34#include <TheBESKeys.h>
38#include "BESInternalFatalError.h"
40#include "ServerAdministrator.h"
49#define prolog std::string("ServerAdministrator::").append(__func__).append("() - ")
64#define EMAIL_KEY "email"
65#define EMAIL_DEFAULT "support@opendap.org"
67#define ORGANIZATION_KEY "organization"
68#define ORGANIZATION_DEFAULT "OPeNDAP Inc."
70#define STREET_KEY "street"
71#define STREET_DEFAULT "165 NW Dean Knauss Dr."
73#define CITY_KEY "city"
74#define CITY_DEFAULT "Narragansett"
76#define REGION_KEY "region"
77#define STATE_KEY "state"
78#define REGION_DEFAULT "RI"
80#define POSTAL_CODE_KEY "postalCode"
81#define POSTAL_CODE_DEFAULT "02882"
83#define COUNTRY_KEY "country"
84#define COUNTRY_DEFAULT "US"
86#define TELEPHONE_KEY "telephone"
87#define TELEPHONE_DEFAULT "+1.401.575.4835"
89#define WEBSITE_KEY "website"
90#define WEBSITE_DEFAULT "http://www.opendap.org"
105 vector<string> admin_keys;
108 throw BESInternalFatalError(
string(
"The BES configuration must provide server administrator information using the key: '")+SERVER_ADMINISTRATOR_KEY
109 +
"'", __FILE__, __LINE__);
110 BESDEBUG(MODULE,__func__ <<
"() - ERROR! The BES configuration must provide server administrator information using the key " << SERVER_ADMINISTRATOR_KEY << endl);
115 vector<string>::iterator it;
116 for(it=admin_keys.begin(); it!=admin_keys.end(); it++){
117 string admin_info_entry = *it;
118 int index = admin_info_entry.find(
":");
120 string key = admin_info_entry.substr(0,index);
122 string value = admin_info_entry.substr(index+1);
123 BESDEBUG(MODULE, prolog <<
"key: '" << key <<
"' value: " << value << endl);
124 d_admin_info.insert( std::pair<string,string>(key,value));
129 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " << SERVER_ADMINISTRATOR_KEY <<
" was incorrectly formatted. Offending entry: " << admin_info_entry << endl);
138 bool bad_flag =
false;
140 d_organization = get(ORGANIZATION_KEY);
141 if(d_organization.empty()){
142 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
143 SERVER_ADMINISTRATOR_KEY <<
"[" << ORGANIZATION_KEY <<
"] was missing." << endl);
147 d_street = get(STREET_KEY);
148 if(d_street.empty()){
149 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
150 SERVER_ADMINISTRATOR_KEY <<
"[" << STREET_KEY <<
"] was missing." << endl);
154 d_city = get(CITY_KEY);
156 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
157 SERVER_ADMINISTRATOR_KEY <<
"[" << CITY_KEY <<
"] was missing." << endl);
161 d_region = get(REGION_KEY);
162 if(d_region.empty()){
163 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
164 SERVER_ADMINISTRATOR_KEY <<
"[" << REGION_KEY <<
"] was missing." << endl);
165 d_region = get(STATE_KEY);
167 if(d_region.empty()){
168 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
169 SERVER_ADMINISTRATOR_KEY <<
"[" << STATE_KEY <<
"] was missing." << endl);
174 d_postal_code = get(POSTAL_CODE_KEY);
175 if(d_postal_code.empty()){
176 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
177 SERVER_ADMINISTRATOR_KEY <<
"[" << POSTAL_CODE_KEY <<
"] was missing." << endl);
181 d_country = get(COUNTRY_KEY);
182 if(d_country.empty()){
183 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
184 SERVER_ADMINISTRATOR_KEY <<
"[" << COUNTRY_KEY <<
"] was missing." << endl);
188 d_telephone = get(TELEPHONE_KEY);
189 if(d_telephone.empty()){
190 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
191 SERVER_ADMINISTRATOR_KEY <<
"[" << TELEPHONE_KEY <<
"] was missing." << endl);
195 d_email = get(EMAIL_KEY);
197 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
198 SERVER_ADMINISTRATOR_KEY <<
"[" << EMAIL_KEY <<
"] was missing." << endl);
202 d_website = get(WEBSITE_KEY);
203 if(d_website.empty()){
204 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
205 SERVER_ADMINISTRATOR_KEY <<
"[" << WEBSITE_KEY <<
"] was missing." << endl);
212 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " << SERVER_ADMINISTRATOR_KEY <<
" was missing crucial information. jdump(): " << jdump(
true) << endl);
218std::string ServerAdministrator::get(
const string &key){
220 std::map<std::string,std::string>::const_iterator result = d_admin_info.find(lkey);
221 if(result == d_admin_info.end()){
224 return result->second;
231std::string ServerAdministrator::xdump()
const {
232 std::stringstream ss;
233 std::map<std::string,std::string>::const_iterator it = d_admin_info.begin();
234 ss <<
"<ServerAdministrator ";
235 for(it=d_admin_info.begin(); it!= d_admin_info.end(); it++){
236 if(it!= d_admin_info.begin())
238 ss << it->first <<
"=\"" << it->second <<
"\"";
244std::string ServerAdministrator::jdump(
bool compact)
const {
245 std::stringstream ss;
246 std::map<std::string,std::string>::const_iterator it = d_admin_info.begin();
250 ss <<
"\"ServerAdministrator\":";
254 if(!compact) ss <<
" ";
255 if(!compact) ss <<
" ";
256 for(it=d_admin_info.begin(); it!= d_admin_info.end(); it++){
257 if(it!= d_admin_info.begin())
261 ss <<
"\"" << it->first <<
"\"" <<
":";
264 ss <<
"\"" << it->second <<
"\"";
278void ServerAdministrator::mk_default() {
279 this->d_admin_info.clear();
280 d_admin_info.insert( std::pair<string,string>(EMAIL_KEY,EMAIL_DEFAULT));
281 d_admin_info.insert( std::pair<string,string>(ORGANIZATION_KEY,ORGANIZATION_DEFAULT));
282 d_admin_info.insert( std::pair<string,string>(STREET_KEY,STREET_DEFAULT));
283 d_admin_info.insert( std::pair<string,string>(CITY_KEY,CITY_DEFAULT));
284 d_admin_info.insert( std::pair<string,string>(REGION_KEY,REGION_DEFAULT));
285 d_admin_info.insert( std::pair<string,string>(POSTAL_CODE_KEY,POSTAL_CODE_DEFAULT));
286 d_admin_info.insert( std::pair<string,string>(COUNTRY_KEY,COUNTRY_DEFAULT));
287 d_admin_info.insert( std::pair<string,string>(TELEPHONE_KEY,TELEPHONE_DEFAULT));
288 d_admin_info.insert( std::pair<string,string>(WEBSITE_KEY,WEBSITE_DEFAULT));
289 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 std::string lowercase(const std::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.