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"
101 vector<string> admin_keys;
104 throw BESInternalFatalError(
string(
"The BES configuration must provide server administrator information using the key: '")+SERVER_ADMINISTRATOR_KEY
105 +
"'", __FILE__, __LINE__);
106 BESDEBUG(MODULE,__func__ <<
"() - ERROR! The BES configuration must provide server administrator information using the key " << SERVER_ADMINISTRATOR_KEY << endl);
111 vector<string>::iterator it;
112 for(it=admin_keys.begin(); it!=admin_keys.end(); it++){
113 string admin_info_entry = *it;
114 int index = admin_info_entry.find(
":");
116 string key = admin_info_entry.substr(0,index);
118 string value = admin_info_entry.substr(index+1);
119 BESDEBUG(MODULE, prolog <<
"key: '" << key <<
"' value: " << value << endl);
120 d_admin_info.insert( std::pair<string,string>(key,value));
125 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " << SERVER_ADMINISTRATOR_KEY <<
" was incorrectly formatted. Offending entry: " << admin_info_entry << endl);
130 bool bad_flag =
false;
132 d_organization = get(ORGANIZATION_KEY);
133 if(d_organization.empty()){
134 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
135 SERVER_ADMINISTRATOR_KEY <<
"[" << ORGANIZATION_KEY <<
"] was missing." << endl);
139 d_street = get(STREET_KEY);
140 if(d_street.empty()){
141 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
142 SERVER_ADMINISTRATOR_KEY <<
"[" << STREET_KEY <<
"] was missing." << endl);
146 d_city = get(CITY_KEY);
148 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
149 SERVER_ADMINISTRATOR_KEY <<
"[" << CITY_KEY <<
"] was missing." << endl);
153 d_region = get(REGION_KEY);
154 if(d_region.empty()){
155 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
156 SERVER_ADMINISTRATOR_KEY <<
"[" << REGION_KEY <<
"] was missing." << endl);
157 d_region = get(STATE_KEY);
159 if(d_region.empty()){
160 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
161 SERVER_ADMINISTRATOR_KEY <<
"[" << STATE_KEY <<
"] was missing." << endl);
166 d_postal_code = get(POSTAL_CODE_KEY);
167 if(d_postal_code.empty()){
168 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
169 SERVER_ADMINISTRATOR_KEY <<
"[" << POSTAL_CODE_KEY <<
"] was missing." << endl);
173 d_country = get(COUNTRY_KEY);
174 if(d_country.empty()){
175 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
176 SERVER_ADMINISTRATOR_KEY <<
"[" << COUNTRY_KEY <<
"] was missing." << endl);
180 d_telephone = get(TELEPHONE_KEY);
181 if(d_telephone.empty()){
182 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
183 SERVER_ADMINISTRATOR_KEY <<
"[" << TELEPHONE_KEY <<
"] was missing." << endl);
187 d_email = get(EMAIL_KEY);
189 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
190 SERVER_ADMINISTRATOR_KEY <<
"[" << EMAIL_KEY <<
"] was missing." << endl);
194 d_website = get(WEBSITE_KEY);
195 if(d_website.empty()){
196 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " <<
197 SERVER_ADMINISTRATOR_KEY <<
"[" << WEBSITE_KEY <<
"] was missing." << endl);
204 BESDEBUG(MODULE,__func__ <<
"() - The configuration entry for the " << SERVER_ADMINISTRATOR_KEY <<
" was missing crucial information. jdump(): " << jdump(
true) << endl);
210 std::string ServerAdministrator::get(
const string &key){
212 std::map<std::string,std::string>::const_iterator result = d_admin_info.find(lkey);
213 if(result == d_admin_info.end()){
216 return result->second;
223 std::string ServerAdministrator::xdump()
const {
224 std::stringstream ss;
225 std::map<std::string,std::string>::const_iterator it = d_admin_info.begin();
226 ss <<
"<ServerAdministrator ";
227 for(it=d_admin_info.begin(); it!= d_admin_info.end(); it++){
228 if(it!= d_admin_info.begin())
230 ss << it->first <<
"=\"" << it->second <<
"\"";
236 std::string ServerAdministrator::jdump(
bool compact)
const {
237 std::stringstream ss;
238 std::map<std::string,std::string>::const_iterator it = d_admin_info.begin();
242 ss <<
"\"ServerAdministrator\":";
246 if(!compact) ss <<
" ";
247 if(!compact) ss <<
" ";
248 for(it=d_admin_info.begin(); it!= d_admin_info.end(); it++){
249 if(it!= d_admin_info.begin())
253 ss <<
"\"" << it->first <<
"\"" <<
":";
256 ss <<
"\"" << it->second <<
"\"";
270 void ServerAdministrator::mk_default() {
271 this->d_admin_info.clear();
272 d_admin_info.insert( std::pair<string,string>(EMAIL_KEY,EMAIL_DEFAULT));
273 d_admin_info.insert( std::pair<string,string>(ORGANIZATION_KEY,ORGANIZATION_DEFAULT));
274 d_admin_info.insert( std::pair<string,string>(STREET_KEY,STREET_DEFAULT));
275 d_admin_info.insert( std::pair<string,string>(CITY_KEY,CITY_DEFAULT));
276 d_admin_info.insert( std::pair<string,string>(REGION_KEY,REGION_DEFAULT));
277 d_admin_info.insert( std::pair<string,string>(POSTAL_CODE_KEY,POSTAL_CODE_DEFAULT));
278 d_admin_info.insert( std::pair<string,string>(COUNTRY_KEY,COUNTRY_DEFAULT));
279 d_admin_info.insert( std::pair<string,string>(TELEPHONE_KEY,TELEPHONE_DEFAULT));
280 d_admin_info.insert( std::pair<string,string>(WEBSITE_KEY,WEBSITE_DEFAULT));
281 BESDEBUG(MODULE,__func__ <<
"() - ServerAdministrator values have been set to the defaults: " << jdump(
true) << endl);