Jalview-JS/JAL-3253-applet JAL-3192 secondary core files
[jalview.git] / src / jalview / bin / JalviewAppLoader.java
index dbb3611..39e7c21 100644 (file)
@@ -254,8 +254,7 @@ 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);
@@ -285,8 +284,7 @@ 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))
@@ -324,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
@@ -341,8 +339,7 @@ public class JalviewAppLoader
     if (param != null)
     {
       ret[0] = param;
-      DataSourceType protocol = resolveFileProtocol(app,
-              ret);
+      DataSourceType protocol = resolveFileProtocol(app, ret);
 
       result = app.parseFeaturesFile(ret[0], protocol);
     }
@@ -391,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.
@@ -429,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)
@@ -463,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
@@ -476,7 +475,7 @@ public class JalviewAppLoader
     {
       directoryPath = directoryPath.substring(0, lastSeparator + 1);
     }
-  
+
     if (targetPath.startsWith("/"))
     {
       /*
@@ -492,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;
   }
 
@@ -569,7 +568,7 @@ public class JalviewAppLoader
       retPath[0] = path.substring(5);
       return DataSourceType.PASTE;
     }
-  
+
     /*
      * is it a URL?
      */
@@ -577,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)
@@ -594,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))
     {
@@ -665,4 +662,72 @@ public class JalviewAppLoader
     }
   }
 
-}
+  /**
+   * 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