Jalview-JS/JAL-3253-applet JAL-3192 secondary core files
[jalview.git] / src / jalview / bin / JalviewAppLoader.java
index 5d60cf9..39e7c21 100644 (file)
@@ -29,7 +29,7 @@ import java.util.Vector;
 public class JalviewAppLoader
 {
 
-  private JalviewApp app;
+  private JalviewApp app; // Jalview or JalviewJS or JalviewLite
 
   private boolean debug;
 
@@ -65,6 +65,7 @@ public class JalviewAppLoader
     loadAnnotations();
     loadJnetFile();
     loadPdbFiles();
+    callInitCallback();
   }
 
   /**
@@ -93,7 +94,6 @@ public class JalviewAppLoader
      * <param name="PDBfile3" value="1q0o Q45135_9MICO">
      */
 
-    int pdbFileCount = 0;
     // Accumulate pdbs here if they are heading for the same view (if
     // alignPdbStructures is true)
     Vector<Object[]> pdbs = new Vector<>();
@@ -105,6 +105,7 @@ public class JalviewAppLoader
                                     .getSequencesArray())
                     : null;
 
+    int pdbFileCount = 0;
     String param;
     do
     {
@@ -167,9 +168,9 @@ public class JalviewAppLoader
             chains = tmp2.toArray(new String[tmp2.size()]);
           }
         }
+        pdb.setId(param);
         ret[0] = param;
-        DataSourceType protocol = resolveFileProtocol(app,
-                ret);
+        DataSourceType protocol = resolveFileProtocol(app, ret);
         // TODO check JAL-357 for files in a jar (CLASSLOADER)
         pdb.setFile(ret[0]);
 
@@ -253,14 +254,13 @@ public class JalviewAppLoader
       try
       {
         ret[0] = param;
-        DataSourceType protocol = resolveFileProtocol(app,
-                ret);
+        DataSourceType protocol = resolveFileProtocol(app, ret);
         JPredFile predictions = new JPredFile(ret[0], protocol);
         JnetAnnotationMaker.add_annotation(predictions,
                 app.getViewport().getAlignment(), 0, false);
         // false == do not add sequence profile from concise output
         app.getViewport().getAlignment().setupJPredAlignment();
-        app.updateForLoader();
+        app.updateForAnnotations();
         result = true;
       } catch (Exception ex)
       {
@@ -284,13 +284,12 @@ public class JalviewAppLoader
     if (param != null)
     {
       ret[0] = param;
-      DataSourceType protocol = resolveFileProtocol(app,
-              ret);
+      DataSourceType protocol = resolveFileProtocol(app, ret);
       param = ret[0];
       if (new AnnotationFile().annotateAlignmentView(app.getViewport(),
               param, protocol))
       {
-        app.updateForLoader();
+        app.updateForAnnotations();
         result = true;
       }
       else
@@ -323,8 +322,8 @@ public class JalviewAppLoader
     String param = app.getParameter("hidefeaturegroups");
     if (param != null)
     {
-      app.setFeatureGroupState(
-              separatorListToArray(param, separator), false);
+      app.setFeatureGroupState(separatorListToArray(param, separator),
+              false);
       // app.setFeatureGroupStateOn(newAlignFrame, param, false);
     }
     // show specific groups
@@ -340,10 +339,9 @@ public class JalviewAppLoader
     if (param != null)
     {
       ret[0] = param;
-      DataSourceType protocol = resolveFileProtocol(app,
-              ret);
+      DataSourceType protocol = resolveFileProtocol(app, ret);
 
-      result = app.parseFeaturesFile(param, protocol);
+      result = app.parseFeaturesFile(ret[0], protocol);
     }
 
     param = app.getParameter("showFeatureSettings");
@@ -390,6 +388,7 @@ public class JalviewAppLoader
   }
 
   String[] ret = new String[1];
+
   /**
    * Load a tree for the alignment if specified by parameter. Returns true if a
    * tree was loaded, else false.
@@ -428,7 +427,8 @@ public class JalviewAppLoader
         {
           if (debug)
           {
-            System.out.println("Tree parameter did not resolve to a valid tree.");
+            System.out.println(
+                    "Tree parameter did not resolve to a valid tree.");
           }
         }
       } catch (Exception ex)
@@ -462,7 +462,7 @@ public class JalviewAppLoader
               codebase.length() - localfile.length()) + targetPath;
       return resolvedPath;
     }
-  
+
     /*
      * get URL path and strip off any trailing file e.g.
      * www.jalview.org/examples/index.html#applets?a=b is trimmed to
@@ -475,7 +475,7 @@ public class JalviewAppLoader
     {
       directoryPath = directoryPath.substring(0, lastSeparator + 1);
     }
-  
+
     if (targetPath.startsWith("/"))
     {
       /*
@@ -491,11 +491,11 @@ public class JalviewAppLoader
     {
       resolvedPath = directoryPath + targetPath;
     }
-    if (JalviewLite.debug)
-    {
-      System.err.println(
-              "resolveUrlForLocalOrAbsolute returning " + resolvedPath);
-    }
+    // if (debug)
+    // {
+    // System.err.println(
+    // "resolveUrlForLocalOrAbsolute returning " + resolvedPath);
+    // }
     return resolvedPath;
   }
 
@@ -568,7 +568,7 @@ public class JalviewAppLoader
       retPath[0] = path.substring(5);
       return DataSourceType.PASTE;
     }
-  
+
     /*
      * is it a URL?
      */
@@ -576,13 +576,12 @@ public class JalviewAppLoader
     {
       return DataSourceType.URL;
     }
-  
+
     /*
      * try relative to document root
      */
     URL documentBase = app.getDocumentBase();
-    String withDocBase = resolveUrlForLocalOrAbsolute(path,
-            documentBase);
+    String withDocBase = resolveUrlForLocalOrAbsolute(path, documentBase);
     if (HttpUtils.isValidUrl(withDocBase))
     {
       // if (debug)
@@ -593,13 +592,12 @@ public class JalviewAppLoader
       retPath[0] = withDocBase;
       return DataSourceType.URL;
     }
-  
+
     /*
      * try relative to codebase (if different to document base)
      */
     URL codeBase = app.getCodeBase();
-    String withCodeBase = resolveUrlForLocalOrAbsolute(path,
-            codeBase);
+    String withCodeBase = resolveUrlForLocalOrAbsolute(path, codeBase);
     if (!withCodeBase.equals(withDocBase)
             && HttpUtils.isValidUrl(withCodeBase))
     {
@@ -650,4 +648,86 @@ public class JalviewAppLoader
     }
   }
 
-}
+  public void callInitCallback()
+  {
+    String initjscallback = app.getParameter("oninit");
+    if (initjscallback == null)
+    {
+      return;
+    }
+    initjscallback = initjscallback.trim();
+    if (initjscallback.length() > 0)
+    {
+      // TODO
+    }
+  }
+
+  /**
+   * read sequence1...sequenceN as a raw alignment
+   * 
+   * @param jalviewApp
+   * @return
+   */
+  public String getPastedSequence(JalviewApp jalviewApp)
+  {
+    StringBuffer data = new StringBuffer("PASTE");
+    int i = 1;
+    String file = null;
+    while ((file = app.getParameter("sequence" + i)) != null)
+    {
+      data.append(file.toString() + "\n");
+      i++;
+    }
+    if (data.length() > 5)
+    {
+      file = data.toString();
+    }
+    return file;
+  }
+
+  /**
+   * concatenate the list with separator
+   * 
+   * @param list
+   * @param separator
+   * @return concatenated string
+   */
+  public static String arrayToSeparatorList(String[] list, String separator)
+  {
+    // TODO use StringUtils version
+    StringBuffer v = new StringBuffer();
+    if (list != null && list.length > 0)
+    {
+      for (int i = 0, iSize = list.length; i < iSize; i++)
+      {
+        if (list[i] != null)
+        {
+          if (i > 0)
+          {
+            v.append(separator);
+          }
+          v.append(list[i]);
+        }
+      }
+      // if (debug)
+      // {
+      // System.err
+      // .println("Returning '" + separator + "' separated List:\n");
+      // System.err.println(v);
+      // }
+      return v.toString();
+    }
+    // if (debug)
+    // {
+    // System.err.println(
+    // "Returning empty '" + separator + "' separated List\n");
+    // }
+    return "" + separator;
+  }
+
+  public String arrayToSeparatorList(String[] array)
+  {
+    return arrayToSeparatorList(array, separator);
+  }
+
+}
\ No newline at end of file