Refactoring of Jalview, JalviewAppLoader, JalviewApp, various
[jalview.git] / src / jalview / bin / ArgsParser.java
index 91c8838..55e760f 100644 (file)
  */
 package jalview.bin;
 
+import jalview.util.Platform;
+
 import java.net.URLDecoder;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * Notes: this argParser does not distinguish between parameter switches,
@@ -96,7 +99,7 @@ public class ArgsParser
 
   public static final String VSESS = "vsess";
 
-  private Vector<String> vargs = null;
+  private List<String> vargs = null;
 
   private boolean isApplet;
 
@@ -109,12 +112,18 @@ public class ArgsParser
 
   public ArgsParser(String[] args)
   {
-    vargs = new Vector<>();
+    vargs = new ArrayList<>();
     isApplet = (args.length > 0 && args[0].startsWith("<applet"));
     if (isApplet)
     {
       appletParams = AppletParams.getAppletParams(args, vargs);
     }
+    else if (Platform.isJS() && args.length == 0)
+    {
+      isApplet = true;
+      appletParams = AppletParams
+              .getAppletParams(Platform.getAppletInfoAsMap(), vargs);
+    }
     else
     {
       for (int i = 0; i < args.length; i++)
@@ -124,7 +133,7 @@ public class ArgsParser
         {
           arg = arg.substring(1);
         }
-        vargs.addElement(arg);
+        vargs.add(arg);
       }
     }
   }
@@ -146,9 +155,9 @@ public class ArgsParser
     String dc = null, ret = null;
     if (index != -1)
     {
-      ret = vargs.elementAt(index + 1).toString();
-      vargs.removeElementAt(index);
-      vargs.removeElementAt(index);
+      ret = vargs.get(index + 1).toString();
+      vargs.remove(index);
+      vargs.remove(index);
       if (utf8decode && ret != null)
       {
         try
@@ -174,7 +183,7 @@ public class ArgsParser
   {
     if (vargs.contains(arg))
     {
-      vargs.removeElement(arg);
+      vargs.remove(arg);
       return true;
     }
     else
@@ -193,12 +202,13 @@ public class ArgsParser
     return vargs.size();
   }
 
-  public String getAppletValue(String key, String def)
+  public Object getAppletValue(String key, String def, boolean asString)
   {
-    String value;
+    Object value;
     return (appletParams == null ? null
-            : (value = appletParams.get(key.toLowerCase())) != null ? value
-                    : def);
+            : (value = appletParams.get(key.toLowerCase())) == null
+                    ? def : asString ? value.toString()
+                    : value);
   }
 
 }