X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fbin%2FCache.java;h=5aab0ecb12a311d5beb9be5344b59eb87b18e939;hb=5652c334235561d2b533a292969e2fb8566d8dac;hp=6b33fea3b90b0b289b2b13f9d55058454ce46cf9;hpb=416733be19ca9e380edce9ee9b5bc0bad0092f99;p=jalview.git diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 6b33fea..5aab0ec 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -42,7 +42,9 @@ import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.Enumeration; +import java.util.HashMap; import java.util.Locale; +import java.util.Map; import java.util.Properties; import java.util.StringTokenizer; import java.util.TreeSet; @@ -310,6 +312,24 @@ public class Cache // in-memory only storage of proxy password, safer to use char array public static char[] proxyAuthPassword = null; + /** + * Session properties, set by command line, try not to affect stored + * properties! + */ + private static Map sessionProperties = new HashMap<>(); + + private static boolean bypassSessionProperties = false; + + public static void enableSessionProperties() + { + bypassSessionProperties = false; + } + + public static void disableSessionProperties() + { + bypassSessionProperties = true; + } + /** Jalview Properties */ public static Properties applicationProperties = new Properties() { @@ -712,7 +732,21 @@ public class Cache */ public static String getProperty(String key) { - String prop = applicationProperties.getProperty(key); + return getProperty(key, false); + } + + public static String getProperty(String key, + boolean skipSessionProperties) + { + String prop = null; + if (!(skipSessionProperties || bypassSessionProperties)) + { + prop = getSessionProperty(key); + } + if (prop == null) + { + prop = applicationProperties.getProperty(key); + } if (prop == null && Platform.isJS()) { prop = applicationProperties.getProperty(Platform.getUniqueAppletID() @@ -782,8 +816,16 @@ public class Cache try { oldValue = applicationProperties.setProperty(key, obj); - if (propertiesFile != null && !propsAreReadOnly) + if (propertiesFile != null && !propsAreReadOnly + // don't rewrite if new value is same as old value + && !((obj == null && oldValue == null) + || (obj != null && obj.equals(oldValue)))) { + // reset the session property too + if (sessionProperties.containsKey(key)) + { + sessionProperties.remove(key); + } FileOutputStream out = new FileOutputStream(propertiesFile); applicationProperties.store(out, "---JalviewX Properties File---"); out.close(); @@ -1694,4 +1736,17 @@ public class Cache } return bootstrapProps; } + + public static void setSessionProperty(String key, String val) + { + if (key != null) + { + sessionProperties.put(key, val); + } + } + + public static String getSessionProperty(String key) + { + return key == null ? null : sessionProperties.get(key); + } }