2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.net.URLDecoder;
24 import java.util.Vector;
27 * Notes: this argParser does not distinguish between parameter switches,
28 * parameter values and argument text. If an argument happens to be identical to
29 * a parameter, it will be taken as such (even though it didn't have a '-'
32 * @author Andrew Waterhouse and JBP documented.
35 public class ArgsParser
38 public static final String ANNOTATIONS = "annotations";
40 public static final String COLOUR = "colour";
42 public static final String FEATURES = "features";
44 public static final String GROOVY = "groovy";
46 public static final String GROUPS = "groups";
48 public static final String HEADLESS = "headless";
50 public static final String JABAWS = "jabaws";
52 public static final String NOANNOTATION = "no-annotation";
54 public static final String NOANNOTATION2 = "noannotation"; // BH 2019.05.07
56 public static final String NODISPLAY = "nodisplay";
58 public static final String NOGUI = "nogui";
60 public static final String NONEWS = "nonews";
62 public static final String NOQUESTIONNAIRE = "noquestionnaire";
64 public static final String NOSORTBYTREE = "nosortbytree";
66 public static final String NOUSAGESTATS = "nousagestats";
68 public static final String OPEN = "open";
70 public static final String OPEN2 = "open2"; // BH added -- for applet
71 // compatibility; not fully
74 public static final String PROPS = "props";
76 public static final String QUESTIONNAIRE = "questionnaire";
78 public static final String SETPROP = "setprop";
80 public static final String SORTBYTREE = "sortbytree";
82 public static final String TREE = "tree";
84 public static final String VDOC = "vdoc";
86 public static final String VSESS = "vsess";
88 private Vector<String> vargs = null;
90 private boolean isApplet;
92 private AppletParams appletParams;
94 public boolean isApplet()
99 public ArgsParser(String[] args)
101 vargs = new Vector<>();
102 isApplet = (args.length > 0 && args[0].startsWith("<applet"));
105 appletParams = AppletParams.getAppletParams(args, vargs);
109 for (int i = 0; i < args.length; i++)
111 String arg = args[i].trim();
112 if (arg.charAt(0) == '-')
114 arg = arg.substring(1);
116 vargs.addElement(arg);
122 * check for and remove first occurence of arg+parameter in arglist.
125 * @return return the argument following the given arg if arg was in list.
127 public String getValue(String arg)
129 return getValue(arg, false);
132 public String getValue(String arg, boolean utf8decode)
134 int index = vargs.indexOf(arg);
135 String dc = null, ret = null;
138 ret = vargs.elementAt(index + 1).toString();
139 vargs.removeElementAt(index);
140 vargs.removeElementAt(index);
141 if (utf8decode && ret != null)
145 dc = URLDecoder.decode(ret, "UTF-8");
147 } catch (Exception e)
149 // TODO: log failure to decode
157 * check for and remove first occurence of arg in arglist.
160 * @return true if arg was present in argslist.
162 public boolean contains(String arg)
164 if (vargs.contains(arg))
166 vargs.removeElement(arg);
175 public String nextValue()
177 return vargs.remove(0);
185 public String getAppletValue(String key, String def)
188 return (appletParams == null ? null
189 : (value = appletParams.get(key.toLowerCase())) != null ? value