From: jprocter Date: Fri, 4 Feb 2011 16:10:54 +0000 (+0000) Subject: Balascz reported problems - jalview tries to write back to the URL. Fixed this so... X-Git-Tag: Release_2_7~265 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=2f3b33ed7140d07e2bb31960ce5aedfed134dfeb;p=jalview.git Balascz reported problems - jalview tries to write back to the URL. Fixed this so that Jalview will only write back to properties files, and also ensured properties are modified before potentially failing writes occur. --- diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index f80d729..75fb618 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -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); + } } }