JAL-1760 JAL-1641 Serialisation of Hidden Seqs and Cols in JSON output. Added ability...
[jalview.git] / src / jalview / io / BioJsHTMLOutput.java
index 3a3b665..a026c57 100644 (file)
@@ -29,16 +29,18 @@ public class BioJsHTMLOutput
 
   private static TreeMap<String, File> bioJsMSAVersions;
 
+  public static final String DEFAULT_DIR = System.getProperty("user.home")
+          + File.separatorChar + ".biojs_templates" + File.separatorChar;
+
   public static final String BJS_TEMPLATES_LOCAL_DIRECTORY = jalview.bin.Cache
-          .getDefault("biojs_template_directory", "/biojs_templates/");
+          .getDefault("biojs_template_directory", DEFAULT_DIR);
 
   public static final String BJS_TEMPLATE_GIT_REPO = jalview.bin.Cache
           .getDefault(
                   "biojs_template_git_repo",
-                  "https://raw.githubusercontent.com/tcofoegbu/bjs-template/master/package.json");;
+                  "https://raw.githubusercontent.com/tcofoegbu/bjs-template/master/package.json");
 
-  public BioJsHTMLOutput(AlignmentPanel ap,
-          FeatureRenderer fr1)
+  public BioJsHTMLOutput(AlignmentPanel ap, FeatureRenderer fr1)
   {
     if (ap != null)
     {
@@ -146,11 +148,10 @@ public class BioJsHTMLOutput
     return sb.toString();
   }
 
-  public void refreshBioJSVersionsInfo(String dirName)
+  public static void refreshBioJSVersionsInfo(String dirName)
           throws URISyntaxException
   {
-    URL url = getClass().getResource(dirName);
-    File directory = new File(url.toURI());
+    File directory = new File(BJS_TEMPLATES_LOCAL_DIRECTORY);
     Objects.requireNonNull(dirName, "dirName MUST not be null!");
     Objects.requireNonNull(directory, "directory MUST not be null!");
     TreeMap<String, File> versionFileMap = new TreeMap<String, File>();
@@ -180,23 +181,31 @@ public class BioJsHTMLOutput
     setBioJsMSAVersions(versionFileMap);
   }
 
-  public void updateBioJS()
+  public static void updateBioJS()
   {
-    try
-    {
-      String gitRepoPkgJson = getURLContentAsString(BJS_TEMPLATE_GIT_REPO);
-      BioJSRepositoryPojo release = new BioJSRepositoryPojo(gitRepoPkgJson);
-      syncUpdates(BJS_TEMPLATES_LOCAL_DIRECTORY, release);
-      refreshBioJSVersionsInfo(BJS_TEMPLATES_LOCAL_DIRECTORY);
-    } catch (URISyntaxException e)
+    Thread updateThread = new Thread()
     {
-      e.printStackTrace();
-    }
+      public void run()
+      {
+        try
+        {
+          String gitRepoPkgJson = getURLContentAsString(BJS_TEMPLATE_GIT_REPO);
+          BioJSRepositoryPojo release = new BioJSRepositoryPojo(
+                  gitRepoPkgJson);
+          syncUpdates(BJS_TEMPLATES_LOCAL_DIRECTORY, release);
+          refreshBioJSVersionsInfo(BJS_TEMPLATES_LOCAL_DIRECTORY);
+        } catch (URISyntaxException e)
+        {
+          e.printStackTrace();
+        }
+      }
+    };
+    updateThread.start();
+
   }
 
 
-  public void syncUpdates(String localDir, BioJSRepositoryPojo repo)
-          throws URISyntaxException
+  public static void syncUpdates(String localDir, BioJSRepositoryPojo repo)
   {
     for (BioJSReleasePojo bjsRelease : repo.getReleases())
     {
@@ -207,23 +216,22 @@ public class BioJsHTMLOutput
       {
         releaseFile = "Latest_BioJsMSA_" + releaseVersion + ".txt";
       }
-      File file = null;
-      URL url = getClass().getResource(
-              BJS_TEMPLATES_LOCAL_DIRECTORY + releaseFile);
-      if (url == null)
-      {
-        String path = getClass().getResource(BJS_TEMPLATES_LOCAL_DIRECTORY)
-                .getPath();
-        System.out.println("------> " + path);
-        file = new File(path + releaseFile);
-      }
-      else
+
+      File biojsDirectory = new File(BJS_TEMPLATES_LOCAL_DIRECTORY);
+      if (!biojsDirectory.exists())
       {
-        file = new File(url.toURI());
+        if (!biojsDirectory.mkdirs())
+        {
+          System.out.println("Couldn't create local directory : "
+                  + BJS_TEMPLATES_LOCAL_DIRECTORY);
+          return;
+        }
       }
 
+      File file = new File(BJS_TEMPLATES_LOCAL_DIRECTORY + releaseFile);
       if (!file.exists())
       {
+
         PrintWriter out = null;
         try
         {