diff --git a/apps/susidns/src/java/src/i2p/susi/dns/AddressbookBean.java b/apps/susidns/src/java/src/i2p/susi/dns/AddressbookBean.java index 93729cad1..883184ee1 100644 --- a/apps/susidns/src/java/src/i2p/susi/dns/AddressbookBean.java +++ b/apps/susidns/src/java/src/i2p/susi/dns/AddressbookBean.java @@ -40,11 +40,10 @@ import net.i2p.data.DataHelper; import net.i2p.data.Destination; import net.i2p.util.SecureFileOutputStream; -public class AddressbookBean +public class AddressbookBean extends BaseBean { protected String book, action, serial, lastSerial, filter, search, hostname, destination; protected int beginIndex, endIndex; - protected final Properties properties; private Properties addressbook; private int trClass; protected final LinkedList deletionMarks; @@ -82,41 +81,12 @@ public class AddressbookBean public AddressbookBean() { - properties = new Properties(); + super(); deletionMarks = new LinkedList(); beginIndex = 0; endIndex = DISPLAY_SIZE - 1; } - private long configLastLoaded = 0; - private static final String PRIVATE_BOOK = "private_addressbook"; - private static final String DEFAULT_PRIVATE_BOOK = "../privatehosts.txt"; - - protected void loadConfig() - { - long currentTime = System.currentTimeMillis(); - - if( !properties.isEmpty() && currentTime - configLastLoaded < 10000 ) - return; - - FileInputStream fis = null; - try { - properties.clear(); - fis = new FileInputStream( ConfigBean.configFileName ); - properties.load( fis ); - // added in 0.5, for compatibility with 0.4 config.txt - if( properties.getProperty(PRIVATE_BOOK) == null) - properties.setProperty(PRIVATE_BOOK, DEFAULT_PRIVATE_BOOK); - configLastLoaded = currentTime; - } - catch (Exception e) { - Debug.debug( e.getClass().getName() + ": " + e.getMessage() ); - } finally { - if (fis != null) - try { fis.close(); } catch (IOException ioe) {} - } - } - public String getFileName() { loadConfig(); diff --git a/apps/susidns/src/java/src/i2p/susi/dns/BaseBean.java b/apps/susidns/src/java/src/i2p/susi/dns/BaseBean.java new file mode 100644 index 000000000..a5cc49e2d --- /dev/null +++ b/apps/susidns/src/java/src/i2p/susi/dns/BaseBean.java @@ -0,0 +1,64 @@ +package i2p.susi.dns; + +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Properties; + +/** + * Holds methods common to several Beans. + * @since 0.9.1 + */ +public class BaseBean +{ + protected final Properties properties; + + private long configLastLoaded = 0; + private static final String PRIVATE_BOOK = "private_addressbook"; + private static final String DEFAULT_PRIVATE_BOOK = "../privatehosts.txt"; + + public static final String PROP_THEME_NAME = "theme"; + public static final String DEFAULT_THEME = "light"; + public static final String BASE_THEME_PATH = "/themes/susidns/"; + + public BaseBean() + { + properties = new Properties(); + } + + protected void loadConfig() + { + long currentTime = System.currentTimeMillis(); + + if( !properties.isEmpty() && currentTime - configLastLoaded < 10000 ) + return; + + FileInputStream fis = null; + try { + properties.clear(); + fis = new FileInputStream( ConfigBean.configFileName ); + properties.load( fis ); + // added in 0.5, for compatibility with 0.4 config.txt + if( properties.getProperty(PRIVATE_BOOK) == null) + properties.setProperty(PRIVATE_BOOK, DEFAULT_PRIVATE_BOOK); + configLastLoaded = currentTime; + } + catch (Exception e) { + Debug.debug( e.getClass().getName() + ": " + e.getMessage() ); + } finally { + if (fis != null) + try { fis.close(); } catch (IOException ioe) {} + } + } + + /** + * Returns the theme path + * @since 0.9.1 + */ + public String getTheme() { + loadConfig(); + String url = BASE_THEME_PATH; + String theme = properties.getProperty(PROP_THEME_NAME, DEFAULT_THEME); + url += theme + "/"; + return url; + } +} diff --git a/apps/susidns/src/java/src/i2p/susi/dns/SubscriptionsBean.java b/apps/susidns/src/java/src/i2p/susi/dns/SubscriptionsBean.java index 69597f270..8675613c5 100644 --- a/apps/susidns/src/java/src/i2p/susi/dns/SubscriptionsBean.java +++ b/apps/susidns/src/java/src/i2p/susi/dns/SubscriptionsBean.java @@ -36,38 +36,10 @@ import java.util.Properties; import net.i2p.I2PAppContext; import net.i2p.util.SecureFileOutputStream; -public class SubscriptionsBean +public class SubscriptionsBean extends BaseBean { private String action, fileName, content, serial, lastSerial; - Properties properties; - - public SubscriptionsBean() - { - properties = new Properties(); - } - private long configLastLoaded = 0; - private void loadConfig() - { - long currentTime = System.currentTimeMillis(); - - if( !properties.isEmpty() && currentTime - configLastLoaded < 10000 ) - return; - - FileInputStream fis = null; - try { - properties.clear(); - fis = new FileInputStream( ConfigBean.configFileName ); - properties.load( fis ); - configLastLoaded = currentTime; - } - catch (Exception e) { - Debug.debug( e.getClass().getName() + ": " + e.getMessage() ); - } finally { - if (fis != null) - try { fis.close(); } catch (IOException ioe) {} - } - } public String getAction() { return action; } diff --git a/apps/susidns/src/jsp/addressbook.jsp b/apps/susidns/src/jsp/addressbook.jsp index fe9666473..61487f811 100644 --- a/apps/susidns/src/jsp/addressbook.jsp +++ b/apps/susidns/src/jsp/addressbook.jsp @@ -47,12 +47,12 @@ ${book.book} <%=intl._("address book")%> - susidns - +