Balascz reported problems - jalview tries to write back to the URL. Fixed this so...
authorjprocter <Jim Procter>
Fri, 4 Feb 2011 16:10:54 +0000 (16:10 +0000)
committerjprocter <Jim Procter>
Fri, 4 Feb 2011 16:10:54 +0000 (16:10 +0000)
src/jalview/bin/Cache.java

index f80d729..75fb618 100755 (executable)
@@ -173,6 +173,8 @@ public class Cache
   /** Default file is ~/.jalview_properties */
   static String propertiesFile;
 
+  private static boolean propsAreReadOnly=false;
+
   public static void initLogger()
   {
     if (log != null)
@@ -230,11 +232,21 @@ public class Cache
     try
     {
       InputStream fis;
-      try {
+      try
+      {
         fis = new java.net.URL(propertiesFile).openStream();
-        System.out.println("Loading jalview properties from : "+propertiesFile);
-      } catch (Exception ex) {fis=null;}
-      if (fis==null) {
+        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.load(fis);
@@ -424,12 +436,16 @@ public class Cache
    */
   public static String setProperty(String key, String obj)
   {
+
     try
     {
-      FileOutputStream out = new FileOutputStream(propertiesFile);
       applicationProperties.setProperty(key, obj);
-      applicationProperties.store(out, "---JalviewX Properties File---");
-      out.close();
+      if (!propsAreReadOnly)
+      {
+        FileOutputStream out = new FileOutputStream(propertiesFile);
+        applicationProperties.store(out, "---JalviewX Properties File---");
+        out.close();
+      }
     } catch (Exception ex)
     {
       System.out.println("Error setting property: " + key + " " + obj
@@ -454,14 +470,17 @@ public class Cache
    */
   public static void saveProperties()
   {
-    try
-    {
-      FileOutputStream out = new FileOutputStream(propertiesFile);
-      applicationProperties.store(out, "---JalviewX Properties File---");
-      out.close();
-    } catch (Exception ex)
+    if (!propsAreReadOnly)
     {
-      System.out.println("Error saving properties: " + ex);
+      try
+      {
+        FileOutputStream out = new FileOutputStream(propertiesFile);
+        applicationProperties.store(out, "---JalviewX Properties File---");
+        out.close();
+      } catch (Exception ex)
+      {
+        System.out.println("Error saving properties: " + ex);
+      }
     }
   }