adds static declaration of AJAX-readable domains
[jalview.git] / src / jalview / bin / Cache.java
index dc50843..6d23bd0 100755 (executable)
@@ -28,8 +28,6 @@ import jalview.schemes.UserColourScheme;
 import jalview.structure.StructureImportSettings;
 import jalview.urls.IdOrgSettings;
 import jalview.util.ColorUtils;
-import jalview.ws.dbsources.das.api.DasSourceRegistryI;
-import jalview.ws.dbsources.das.datamodel.DasSourceRegistry;
 import jalview.ws.sifts.SiftsSettings;
 
 import java.awt.Color;
@@ -281,14 +279,15 @@ public class Cache
     @Override
     public synchronized Enumeration<Object> keys()
     {
-      return Collections.enumeration(new TreeSet<Object>(super.keySet()));
+      return Collections.enumeration(new TreeSet<>(super.keySet()));
     }
   };
 
   /** Default file is ~/.jalview_properties */
   static String propertiesFile;
 
-  private static boolean propsAreReadOnly = false;
+  private static boolean propsAreReadOnly = /** @j2sNative true || */
+          false;
 
   public static void initLogger()
   {
@@ -334,7 +333,10 @@ public class Cache
     }
   }
 
-  /** Called when Jalview is started */
+  /**
+   * Loads properties from the given properties file. Any existing properties
+   * are first cleared.
+   */
   public static void loadProperties(String propsFile)
   {
     propertiesFile = propsFile;
@@ -369,6 +371,7 @@ public class Cache
       {
         fis = new FileInputStream(propertiesFile);
       }
+      applicationProperties.clear();
       applicationProperties.load(fis);
 
       // remove any old build properties
@@ -395,7 +398,8 @@ public class Cache
     // LOAD THE AUTHORS FROM THE authors.props file
     try
     {
-      String authorDetails = "jar:"
+      String authorDetails = /** @j2sNative "xxx" || */
+              "jar:"
               .concat(Cache.class.getProtectionDomain().getCodeSource()
                       .getLocation().toString().concat("!/authors.props"));
 
@@ -417,7 +421,8 @@ public class Cache
     // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
     try
     {
-      String buildDetails = "jar:".concat(Cache.class.getProtectionDomain()
+      String buildDetails = /** @j2sNative "xxx" || */
+              "jar:".concat(Cache.class.getProtectionDomain()
               .getCodeSource().getLocation().toString()
               .concat("!/.build_properties"));
 
@@ -599,18 +604,13 @@ public class Cache
   }
 
   /**
-   * These methods are used when checking if the saved preference is different
-   * to the default setting
+   * Answers the value of the given property, or the supplied default value if
+   * the property is not set
    */
   public static String getDefault(String property, String def)
   {
-    String string = getProperty(property);
-    if (string != null)
-    {
-      return string;
-    }
-
-    return def;
+    String value = getProperty(property);
+    return value == null ? def : value;
   }
 
   /**
@@ -621,14 +621,14 @@ public class Cache
    * @param obj
    *          String value of property
    * 
-   * @return String value of property
+   * @return previous value of property (or null)
    */
-  public static String setProperty(String key, String obj)
+  public static Object setProperty(String key, String obj)
   {
-
+    Object oldValue = null;
     try
     {
-      applicationProperties.setProperty(key, obj);
+      oldValue = applicationProperties.setProperty(key, obj);
       if (!propsAreReadOnly)
       {
         FileOutputStream out = new FileOutputStream(propertiesFile);
@@ -640,7 +640,7 @@ public class Cache
       System.out.println(
               "Error setting property: " + key + " " + obj + "\n" + ex);
     }
-    return obj;
+    return oldValue;
   }
 
   /**
@@ -978,22 +978,6 @@ public class Cache
     return null;
   }
 
-  private static DasSourceRegistryI sourceRegistry = null;
-
-  /**
-   * initialise and ..
-   * 
-   * @return instance of the das source registry
-   */
-  public static DasSourceRegistryI getDasSourceRegistry()
-  {
-    if (sourceRegistry == null)
-    {
-      sourceRegistry = new DasSourceRegistry();
-    }
-    return sourceRegistry;
-  }
-
   /**
    * Set the specified value, or remove it if null or empty. Does not save the
    * properties file.
@@ -1068,4 +1052,19 @@ public class Cache
       }
     }
   }
+
+       /**
+        * Add a known domain that implements access-control-allow-origin:* bh 2018
+        * 
+        * @param defaultUniprotDomain
+        */
+       public static void addJ2SDirectDatabaseCall(String domain) 
+       {
+
+               /**
+                * @j2sNative
+                * 
+                *                      J2S.addDirectDatabaseCall(domain);
+                */
+       }
 }