Add new getMessages() method to Theme interface.

This commit is contained in:
Stan Silvert 2015-09-08 13:28:17 -04:00
parent cee2d69718
commit e455cbf319
4 changed files with 37 additions and 3 deletions

View file

@ -224,10 +224,15 @@ public class ExtendingThemeManager implements ThemeProvider {
@Override
public Properties getMessages(Locale locale) throws IOException {
return getMessages("messages", locale);
}
@Override
public Properties getMessages(String baseBundlename, Locale locale) throws IOException {
Properties messages = new Properties();
ListIterator<Theme> itr = themes.listIterator(themes.size());
while (itr.hasPrevious()) {
Properties m = itr.previous().getMessages(locale);
Properties m = itr.previous().getMessages(baseBundlename, locale);
if (m != null) {
messages.putAll(m);
}

View file

@ -29,8 +29,27 @@ public interface Theme {
public InputStream getResourceAsStream(String path) throws IOException;
/**
* Same as getMessages(baseBundlename, locale), but uses a default baseBundlename
* such as "messages".
*
* @param locale The locale of the desired message bundle.
* @return The localized messages from the bundle.
* @throws IOException If bundle can not be read.
*/
public Properties getMessages(Locale locale) throws IOException;
/**
* Retrieve localized messages from a message bundle.
*
* @param baseBundlename The base name of the bundle, such as "messages" in
* messages_en.properties.
* @param locale The locale of the desired message bundle.
* @return The localized messages from the bundle.
* @throws IOException If bundle can not be read.
*/
public Properties getMessages(String baseBundlename, Locale locale) throws IOException;
public Properties getProperties() throws IOException;
}

View file

@ -100,12 +100,17 @@ public class ClassLoaderTheme implements Theme {
@Override
public Properties getMessages(Locale locale) throws IOException {
return getMessages("messages", locale);
}
@Override
public Properties getMessages(String baseBundlename, Locale locale) throws IOException {
if(locale == null){
return null;
}
Properties m = new Properties();
URL url = classLoader.getResource(this.messageRoot + "messages_" + locale.toString() + ".properties");
URL url = classLoader.getResource(this.messageRoot + baseBundlename + "_" + locale.toString() + ".properties");
if (url != null) {
m.load(url.openStream());
}

View file

@ -93,13 +93,18 @@ public class FolderTheme implements Theme {
@Override
public Properties getMessages(Locale locale) throws IOException {
return getMessages("messages", locale);
}
@Override
public Properties getMessages(String baseBundlename, Locale locale) throws IOException {
if(locale == null){
return null;
}
Properties m = new Properties();
File file = new File(themeDir, "messages" + File.separator + "messages_" + locale.toString() + ".properties");
File file = new File(themeDir, "messages" + File.separator + baseBundlename + "_" + locale.toString() + ".properties");
if (file.isFile()) {
m.load(new FileInputStream(file));
}