diff --git a/apps/susidns/src/java/src/i2p/susi/dns/BaseBean.java b/apps/susidns/src/java/src/i2p/susi/dns/BaseBean.java index e157c745a3168e84b01fb52823104c6271287c8e..a58d49602d88cd311ed07e0e30f709a7a1cb6554 100644 --- a/apps/susidns/src/java/src/i2p/susi/dns/BaseBean.java +++ b/apps/susidns/src/java/src/i2p/susi/dns/BaseBean.java @@ -49,8 +49,14 @@ public class BaseBean // Fetch theme Properties themeProps = _context.readConfigFile(THEME_CONFIG_FILE); _theme = themeProps.getProperty(PROP_THEME_NAME); - // Ensure that theme config line exists in config file - if (_theme == null) { + // Ensure that theme config line exists in config file, and theme exists + String[] themes = getThemes(); + boolean themeExists = false; + for (int i = 0; i < themes.length; i++) { + if (themes[i].equals(_theme)) + themeExists = true; + } + if (_theme == null || !themeExists) { _theme = DEFAULT_THEME; themeProps.put(PROP_THEME_NAME, _theme); _context.writeConfigFile(THEME_CONFIG_FILE, themeProps); @@ -75,4 +81,26 @@ public class BaseBean url += _theme + "/"; return url; } + + /** + * Get all themes + * @return String[] -- Array of all the themes found. + * @since 0.9.2 + */ + public String[] getThemes() { + String[] themes = null; + // "docs/themes/susidns/" + File dir = new File(_context.getBaseDir(), "docs/themes/susidns"); + FileFilter fileFilter = new FileFilter() { public boolean accept(File file) { return file.isDirectory(); } }; + // Walk the themes dir, collecting the theme names, and append them to the map + File[] dirnames = dir.listFiles(fileFilter); + if (dirnames != null) { + themes = new String[dirnames.length]; + for(int i = 0; i < dirnames.length; i++) { + themes[i] = dirnames[i].getName(); + } + } + // return the map. + return themes; + } }