From: hansonr Date: Sun, 24 Mar 2019 10:56:05 +0000 (-0500) Subject: app-specific property caching X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=5d4f312f392e448a128138404fc4bc72762f072a;p=jalview.git app-specific property caching --- diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index b018f9c..3e5d583 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -289,6 +289,8 @@ public class Cache private static boolean propsAreReadOnly = Platform.isJS(); + private static String JS_PROPERTY_PREFIX = "jalview_"; + public static void initLogger() { if (log != null) @@ -351,7 +353,10 @@ public class Cache propsAreReadOnly = true; } - if (propertiesFile != null) { + if (propertiesFile == null) + { // BH 2019 + Platform.readInfoProperties(JS_PROPERTY_PREFIX , applicationProperties); + } else { try { InputStream fis; @@ -593,7 +598,14 @@ public class Cache */ public static String getProperty(String key) { - return applicationProperties.getProperty(key); + + String prop = applicationProperties.getProperty(key); + if (prop == null && Platform.isJS()) + { + prop = applicationProperties.getProperty(Platform.getUniqueAppletID() + "_" + JS_PROPERTY_PREFIX + key); + } + + return prop; } /** diff --git a/src/jalview/util/Platform.java b/src/jalview/util/Platform.java index 0a788d9..7b318ba 100644 --- a/src/jalview/util/Platform.java +++ b/src/jalview/util/Platform.java @@ -23,6 +23,7 @@ package jalview.util; import java.awt.Toolkit; import java.awt.event.MouseEvent; import java.io.File; +import java.util.Properties; import javax.swing.SwingUtilities; @@ -223,7 +224,8 @@ public class Platform } } -public static void cacheFileData(String path, byte[] data) { + public static void cacheFileData(String path, byte[] data) + { if (!isJS()) return; /** @@ -232,22 +234,26 @@ public static void cacheFileData(String path, byte[] data) { * swingjs.JSUtil.cacheFileData$S$O(path, data); * */ -} + } -public static byte[] getFileBytes(File f) { + public static byte[] getFileBytes(File f) + { return /** @j2sNative f && f._bytes || */null; -} + } -public static byte[] getFileAsBytes(String fileStr) { + public static byte[] getFileAsBytes(String fileStr) + { // BH 2018 hack for no support for access-origin - return /** @j2sNative swingjs.JSUtil.getFileAsBytes$O(fileStr) || */ null; -} + return /** @j2sNative swingjs.JSUtil.getFileAsBytes$O(fileStr) || */ null; + } -public static String getFileAsString(String data) { + public static String getFileAsString(String data) + { return /** @j2sNative swingjs.JSUtil.getFileAsString$S(data) || */ null; -} + } -public static boolean setFileBytes(File f, String urlstring) { + public static boolean setFileBytes(File f, String urlstring) + { if (!isJS()) return false; @SuppressWarnings("unused") @@ -256,30 +262,30 @@ public static boolean setFileBytes(File f, String urlstring) { * f._bytes = bytes; */ return true; -} + } -public static void addJ2SBinaryType(String ext) -{ - ext = "." + ext + "?"; - + public static void addJ2SBinaryType(String ext) + { /** * @j2sNative * - * J2S._binaryTypes.push(ext); + * J2S._binaryTypes.push("." + ext + "?"); * */ -} + } -public static String encodeURI(String value) { + public static String encodeURI(String value) + { /** * @j2sNative * return encodeURIComponent(value); */ return value; -} + } -public static boolean openURL(String url) { + public static boolean openURL(String url) + { if (!isJS()) return false; /** @@ -289,7 +295,49 @@ public static boolean openURL(String url) { * window.open(url); */ return true; -} + } + + public static String getUniqueAppletID() { + @SuppressWarnings("unused") + ThreadGroup g = Thread.currentThread().getThreadGroup(); + /** + * @j2sNative return g.html5Applet._uniqueId; + * + */ + return null; + + } + /** + * Read the Info block for this applet. + * + * @param prefix "jalview_" + * @param p + * @return unique id for this applet + */ + public static void readInfoProperties(String prefix, Properties p) + { + @SuppressWarnings("unused") + ThreadGroup g = Thread.currentThread().getThreadGroup(); + String id = getUniqueAppletID(); + String key = "", value = ""; + /** + * @j2sNative + var info = g.html5Applet.__Info || {}; + for (var key in info) { + if (key.indexOf(prefix) == 0) { + value = "" + info[key]; + */ + + p.put(id + "_" + key, value); + + /** + * @j2sNative + + + } + } + */ + } }