Fennel: ResourceBundle Class Reference (original) (raw)

#include <[ResourceBundle.h](ResourceBundle%5F8h-source.html)>

Inheritance diagram for ResourceBundle:

List of all members.

Public Member Functions
const set< string > getKeys () const
const string & getMessage (const string &key) const
bool hasMessage (const string &key) const
const string & getBaseName () const
const Locale & getLocale () const
Static Public Member Functions
static void setGlobalResourceFileLocation (const string &location)
static RecursiveMutex & getMutex ()
Protected Member Functions
ResourceBundle (const string &baseName, const Locale &locale, const string &location)
virtual ~ResourceBundle ()
void setParent (ResourceBundle *bundle)
Private Member Functions
void loadMessages ()
Private Attributes
const string _baseName
const Locale _locale
const string _location
ResourceBundle * _parent
map< string, string > _messages
Static Private Attributes
static RecursiveMutex mutex

Detailed Description

Definition at line 38 of file ResourceBundle.h.


Constructor & Destructor Documentation

ResourceBundle::ResourceBundle ( const string & baseName,
const Locale & locale,
const string & location
) [explicit, protected]

| ResourceBundle::~ResourceBundle | ( | | ) | [protected, virtual] | | -------------------------------- | - | | - | ---------------------- |


Member Function Documentation

void ResourceBundle::setParent ( ResourceBundle * bundle ) [protected]

| const set< string > ResourceBundle::getKeys | ( | | ) | const | | ------------------------------------------- | - | | - | ----- |

Definition at line 76 of file ResourceBundle.cpp.

References _messages, _parent, and getKeys().

Referenced by getKeys().

00077 { 00078 set keys; 00079 00080 map<string, string>::const_iterator iter = _messages.begin(), 00081 end = _messages.end(); 00082 00083 while (iter != end) { 00084 keys.insert((*iter).first); 00085 iter++; 00086 } 00087 00088 if (_parent) { 00089 set parentKeys = _parent->getKeys(); 00090 00091 keys.insert(parentKeys.begin(), parentKeys.end()); 00092 } 00093 00094 return keys; 00095 }

const string & ResourceBundle::getMessage ( const string & key ) const
bool ResourceBundle::hasMessage ( const string & key ) const

| const string & ResourceBundle::getBaseName | ( | | ) | const | | ------------------------------------------ | - | | - | ----- |

| const Locale & ResourceBundle::getLocale | ( | | ) | const | | ------------------------------------------------------------ | - | | - | ----- |

void ResourceBundle::setGlobalResourceFileLocation ( const string & location ) [static]

| void ResourceBundle::loadMessages | ( | | ) | [private] | | --------------------------------- | - | | - | ----------- |

Definition at line 245 of file ResourceBundle.cpp.

References _baseName, _locale, _location, _messages, convertPropertyToBoost(), Locale::getDisplayName(), and globalResourceLocation().

Referenced by ResourceBundle().

00246 { 00247 fstream in; 00248 00249
00250 string fileName; 00251 00252 if (_locale == Locale("")) { 00253 fileName.assign(_baseName 00254 + ".properties"); 00255 } else { 00256 fileName.assign(_baseName 00257 + "_" 00258 + _locale.getDisplayName() 00259 + ".properties"); 00260 } 00261 00262
00263 bool tryGlobalLocation = true; 00264 if (_location.empty()) { 00265 string path = _location + "/" + fileName; 00266 in.open(path.c_str(), ios::in); 00267 if (in.good()) { 00268 tryGlobalLocation = false; 00269 } 00270 } 00271 00272
00273 if (tryGlobalLocation) { 00274 bool tryEnvVar = true; 00275 00276
00277
00278 if (globalResourceLocation.empty()) { 00279 string path = globalResourceLocation + "/" + fileName; 00280 in.open(path.c_str(), ios::in); 00281 if (in.good()) { 00282 tryEnvVar = false; 00283 } 00284 } 00285 00286 if (tryEnvVar) { 00287 const char *fennelHome = getenv("FENNEL_HOME"); 00288 if (fennelHome == NULL) { 00289 return; 00290 } 00291 00292 string path = string(fennelHome) + "/common/" + fileName; 00293 in.open(path.c_str(), ios::in); 00294 if (!in.good()) { 00295 return; 00296 } 00297 } 00298 } 00299 00300 string line, key, message; 00301 while (in.good()) { 00302 getline(in, line); 00303 00304 if (line.length() == 0 || line[0] == '#') { 00305
00306 continue; 00307 } 00308 00309 string::size_type pos = line.find('='); 00310 if (pos == string::npos) { 00311
00312 continue; 00313 } 00314 00315 key = line.substr(0, pos); 00316 message = line.substr(pos + 1); 00317 00318 _messages[key] = convertPropertyToBoost(message); 00319 } 00320 00321 in.close(); 00322 }


Member Data Documentation


The documentation for this class was generated from the following files:


Generated on Mon Jun 22 04:00:45 2009 for Fennel by doxygen 1.5.1