org.apache.tapestry5.internal.services
public class: MessagesSourceImpl [javadoc |
source]
java.lang.Object
org.apache.tapestry5.internal.event.InvalidationEventHubImpl
org.apache.tapestry5.internal.services.MessagesSourceImpl
All Implemented Interfaces:
MessagesSource, InvalidationEventHub
A utility class that encapsulates all the logic for reading properties files and assembling
Messages from
them, in accordance with extension rules and locale. This represents code that was refactored out of
ComponentMessagesSourceImpl . This class can be used as a base class, though the existing code base uses it as a
utility. Composition trumps inheritance!
The message catalog for a component is the combination of all appropriate properties files for the component, plus
any keys inherited form base components and, ultimately, the application global message catalog. At some point we
should add support for per-library message catalogs.
Message catalogs are read using the UTF-8 character set. This is tricky in JDK 1.5; we read the file into memory then
feed that bytestream to Properties.load().
| Methods from java.lang.Object: |
|---|
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from org.apache.tapestry5.internal.services.MessagesSourceImpl Detail: |
public void checkForUpdates() {
if (tracker.containsChanges())
{
messagesByBundleIdAndLocale.clear();
cookedProperties.clear();
rawProperties.clear();
tracker.clear();
fireInvalidationEvent();
}
}
|
public Messages getMessages(MessagesBundle bundle,
Locale locale) {
MultiKey key = new MultiKey(bundle.getId(), locale);
Messages result = messagesByBundleIdAndLocale.get(key);
if (result == null)
{
result = buildMessages(bundle, locale);
messagesByBundleIdAndLocale.put(key, result);
}
return result;
}
|
static Map<String, String> readPropertiesFromStream(InputStream propertiesFileStream) throws IOException {
Map< String, String > result = CollectionFactory.newCaseInsensitiveMap();
Properties p = new Properties();
InputStream is = null;
try
{
is = readUTFStreamToEscapedASCII(propertiesFileStream);
// Ok, now we have the content read into memory as UTF-8, not ASCII.
p.load(is);
is.close();
is = null;
}
finally
{
InternalUtils.close(is);
}
for (Map.Entry e : p.entrySet())
{
String key = e.getKey().toString();
String value = p.getProperty(key);
result.put(key, value);
}
return result;
}
|