JAL-2418 source formatting
[jalview.git] / src / jalview / ws / rest / params / Alignment.java
index 08a242d..4426c5f 100644 (file)
@@ -23,6 +23,7 @@ package jalview.ws.rest.params;
 import jalview.datamodel.AlignmentI;
 import jalview.io.FileFormat;
 import jalview.io.FileFormatI;
+import jalview.io.FileFormats;
 import jalview.io.FormatAdapter;
 import jalview.ws.params.OptionI;
 import jalview.ws.params.simple.BooleanOption;
@@ -78,11 +79,11 @@ public class Alignment extends InputType
       try
       {
         File fa = File.createTempFile("jvmime", ".fa");
-        PrintWriter pw = new PrintWriter(
-                new OutputStreamWriter(new BufferedOutputStream(
-                        new FileOutputStream(fa)), "UTF-8"));
-        pw.append(new FormatAdapter().formatSequences(format,
-                alignment, jvsuffix));
+        PrintWriter pw = new PrintWriter(new OutputStreamWriter(
+                new BufferedOutputStream(new FileOutputStream(fa)),
+                "UTF-8"));
+        pw.append(new FormatAdapter().formatSequences(format, alignment,
+                jvsuffix));
         pw.close();
         return new FileBody(fa, "text/plain");
       } catch (Exception ex)
@@ -107,8 +108,8 @@ public class Alignment extends InputType
   @Override
   public List<String> getURLEncodedParameter()
   {
-    ArrayList<String> prms = new ArrayList<String>();
-    prms.add("format='" + format + "'");
+    List<String> prms = new ArrayList<String>();
+    prms.add("format='" + format.getName() + "'");
     if (type != null)
     {
       prms.add("type='" + type.toString() + "'");
@@ -147,22 +148,19 @@ public class Alignment extends InputType
 
     if (tok.startsWith("format"))
     {
-      for (FileFormatI fmt : FileFormat.values())
+      for (FileFormatI fmt : FileFormats.getInstance().getFormats())
       {
-        if (fmt.isWritable() && val.equalsIgnoreCase(fmt.toString()))
+        if (fmt.isWritable() && val.equalsIgnoreCase(fmt.getName()))
         {
           format = fmt;
           return true;
         }
       }
-      warnings.append("Invalid alignment format '" + val
-              + "'. Must be one of (");
-      for (FileFormatI fmt : FileFormat.values())
+      warnings.append(
+              "Invalid alignment format '" + val + "'. Must be one of (");
+      for (String fmt : FileFormats.getInstance().getWritableFormats(true))
       {
-        if (fmt.isWritable())
-        {
-          warnings.append(" " + fmt).toString();
-        }
+        warnings.append(" ").append(fmt);
       }
       warnings.append(")\n");
     }
@@ -174,8 +172,8 @@ public class Alignment extends InputType
         return true;
       } catch (Exception x)
       {
-        warnings.append("Invalid molecule type '" + val
-                + "'. Must be one of (");
+        warnings.append(
+                "Invalid molecule type '" + val + "'. Must be one of (");
         for (molType v : molType.values())
         {
           warnings.append(" " + v);
@@ -197,28 +195,14 @@ public class Alignment extends InputType
             "Append jalview style /start-end suffix to ID", false, false,
             writeAsFile, null));
 
+    List<String> writable = FileFormats.getInstance()
+            .getWritableFormats(true);
     lst.add(new Option("format", "Alignment upload format", true,
-            FileFormat.Fasta.toString(), format.toString(), getWritableFormats(),
+            FileFormat.Fasta.toString(), format.getName(), writable, null));
+    lst.add(createMolTypeOption("type", "Sequence type", false, type,
             null));
-    lst.add(createMolTypeOption("type", "Sequence type", false, type, null));
 
     return lst;
   }
 
-  /**
-   * @return
-   */
-  protected List<String> getWritableFormats()
-  {
-    List<String> formats = new ArrayList<String>();
-    for (FileFormatI ff : FileFormat.values())
-    {
-      if (ff.isWritable())
-      {
-        formats.add(ff.toString());
-      }
-    }
-    return formats;
-  }
-
 }