j2sNative references moved to Platform
[jalview.git] / src / jalview / bin / Cache.java
index 6d23bd0..b018f9c 100755 (executable)
@@ -28,6 +28,7 @@ import jalview.schemes.UserColourScheme;
 import jalview.structure.StructureImportSettings;
 import jalview.urls.IdOrgSettings;
 import jalview.util.ColorUtils;
+import jalview.util.Platform;
 import jalview.ws.sifts.SiftsSettings;
 
 import java.awt.Color;
@@ -286,8 +287,7 @@ public class Cache
   /** Default file is ~/.jalview_properties */
   static String propertiesFile;
 
-  private static boolean propsAreReadOnly = /** @j2sNative true || */
-          false;
+  private static boolean propsAreReadOnly = Platform.isJS();
 
   public static void initLogger()
   {
@@ -340,7 +340,7 @@ public class Cache
   public static void loadProperties(String propsFile)
   {
     propertiesFile = propsFile;
-    if (propsFile == null)
+    if (propsFile == null && !propsAreReadOnly)
     {
       propertiesFile = System.getProperty("user.home") + File.separatorChar
               + ".jalview_properties";
@@ -351,38 +351,39 @@ public class Cache
       propsAreReadOnly = true;
     }
 
-    try
-    {
-      InputStream fis;
-      try
-      {
-        fis = new java.net.URL(propertiesFile).openStream();
-        System.out.println(
-                "Loading jalview properties from : " + propertiesFile);
-        System.out.println(
-                "Disabling Jalview writing to user's local properties file.");
-        propsAreReadOnly = true;
-
-      } catch (Exception ex)
-      {
-        fis = null;
-      }
-      if (fis == null)
-      {
-        fis = new FileInputStream(propertiesFile);
-      }
-      applicationProperties.clear();
-      applicationProperties.load(fis);
-
-      // remove any old build properties
-
-      deleteBuildProperties();
-      fis.close();
-    } catch (Exception ex)
-    {
-      System.out.println("Error reading properties file: " + ex);
+    if (propertiesFile != null) {
+           try
+           {
+             InputStream fis;
+             try
+             {
+               fis = new java.net.URL(propertiesFile).openStream();
+               System.out.println(
+                       "Loading jalview properties from : " + propertiesFile);
+               System.out.println(
+                       "Disabling Jalview writing to user's local properties file.");
+               propsAreReadOnly = true;
+       
+             } catch (Exception ex)
+             {
+               fis = null;
+             }
+             if (fis == null)
+             {
+               fis = new FileInputStream(propertiesFile);
+             }
+             applicationProperties.clear();
+             applicationProperties.load(fis);
+       
+             // remove any old build properties
+       
+             deleteBuildProperties();
+             fis.close();
+           } catch (Exception ex)
+           {
+             System.out.println("Error reading properties file: " + ex);
+           }
     }
-
     if (getDefault("USE_PROXY", false))
     {
       String proxyServer = getDefault("PROXY_SERVER", ""),
@@ -396,47 +397,55 @@ public class Cache
     }
 
     // LOAD THE AUTHORS FROM THE authors.props file
+    String authorDetails = (Platform.isJS() ? null :
+            "jar:"
+            .concat(Cache.class.getProtectionDomain().getCodeSource()
+                    .getLocation().toString().concat("!/authors.props")));
+
     try
     {
-      String authorDetails = /** @j2sNative "xxx" || */
-              "jar:"
-              .concat(Cache.class.getProtectionDomain().getCodeSource()
-                      .getLocation().toString().concat("!/authors.props"));
-
-      java.net.URL localJarFileURL = new java.net.URL(authorDetails);
-
-      InputStream in = localJarFileURL.openStream();
-      applicationProperties.load(in);
-      in.close();
-    } catch (Exception ex)
+      if (authorDetails != null) {
+         java.net.URL localJarFileURL = new java.net.URL(authorDetails);
+         InputStream in = localJarFileURL.openStream();
+         applicationProperties.load(in);
+         in.close();
+      }
+    } catch (Exception ex) {
+    System.out.println("Error reading author details: " + ex);
+       authorDetails = null;
+    }
+    if (authorDetails == null) 
     {
-      System.out.println("Error reading author details: " + ex);
-      applicationProperties.remove("AUTHORS");
-      applicationProperties.remove("AUTHORFNAMES");
-      applicationProperties.remove("YEAR");
+        applicationProperties.remove("AUTHORS");
+        applicationProperties.remove("AUTHORFNAMES");
+        applicationProperties.remove("YEAR");
     }
 
     // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
     // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
     // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
-    try
+    String buildDetails = (Platform.isJS() ? null :
+            "jar:".concat(Cache.class.getProtectionDomain()
+            .getCodeSource().getLocation().toString()
+            .concat("!/.build_properties")));
+    if (buildDetails != null) 
     {
-      String buildDetails = /** @j2sNative "xxx" || */
-              "jar:".concat(Cache.class.getProtectionDomain()
-              .getCodeSource().getLocation().toString()
-              .concat("!/.build_properties"));
-
-      java.net.URL localJarFileURL = new java.net.URL(buildDetails);
-
-      InputStream in = localJarFileURL.openStream();
-      applicationProperties.load(in);
-      in.close();
-    } catch (Exception ex)
+           try
+           {
+             java.net.URL localJarFileURL = new java.net.URL(buildDetails);
+             InputStream in = localJarFileURL.openStream();
+             applicationProperties.load(in);
+             in.close();
+           } catch (Exception ex)
+           {
+             System.out.println("Error reading build details: " + ex);
+             buildDetails = null;
+           }
+    }
+    if (buildDetails == null) 
     {
-      System.out.println("Error reading build details: " + ex);
-      applicationProperties.remove("VERSION");
+             applicationProperties.remove("VERSION");
     }
-
     String jnlpVersion = System.getProperty("jalview.version");
     String codeVersion = getProperty("VERSION");
     String codeInstallation = getProperty("INSTALLATION");