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 jalview.util.Platform;
25 import java.net.URLDecoder;
26 import java.util.ArrayList;
27 import java.util.List;
30 * Notes: this argParser does not distinguish between parameter switches,
31 * parameter values and argument text. If an argument happens to be identical to
32 * a parameter, it will be taken as such (even though it didn't have a '-'
35 * @author Andrew Waterhouse and JBP documented.
38 public class ArgsParser
43 public static final String NOCALCULATION = "nocalculation";
45 public static final String NOMENUBAR = "nomenubar";
47 public static final String NOSTATUS = "nostatus";
49 public static final String SHOWOVERVIEW = "showoverview";
52 public static final String ANNOTATIONS = "annotations";
54 public static final String COLOUR = "colour";
56 public static final String FEATURES = "features";
58 public static final String GROOVY = "groovy";
60 public static final String GROUPS = "groups";
62 public static final String HEADLESS = "headless";
64 public static final String JABAWS = "jabaws";
66 public static final String NOANNOTATION = "no-annotation";
68 public static final String NOANNOTATION2 = "noannotation"; // BH 2019.05.07
70 public static final String NODISPLAY = "nodisplay";
72 public static final String NOGUI = "nogui";
74 public static final String NONEWS = "nonews";
76 public static final String NOQUESTIONNAIRE = "noquestionnaire";
78 public static final String NOSORTBYTREE = "nosortbytree";
80 public static final String NOUSAGESTATS = "nousagestats";
82 public static final String OPEN = "open";
84 public static final String OPEN2 = "open2"; // BH added -- for applet
85 // compatibility; not fully
88 public static final String PROPS = "props";
90 public static final String QUESTIONNAIRE = "questionnaire";
92 public static final String SETPROP = "setprop";
94 public static final String SORTBYTREE = "sortbytree";
96 public static final String TREE = "tree";
98 public static final String VDOC = "vdoc";
100 public static final String VSESS = "vsess";
102 private List<String> vargs = null;
104 private boolean isApplet;
106 private AppletParams appletParams;
108 public boolean isApplet()
113 public ArgsParser(String[] args)
115 vargs = new ArrayList<>();
116 isApplet = (args.length > 0 && args[0].startsWith("<applet"));
119 appletParams = AppletParams.getAppletParams(args, vargs);
127 appletParams = AppletParams
128 .getAppletParams(Platform.getAppletInfoAsMap(), vargs);
130 for (int i = 0; i < args.length; i++)
132 String arg = args[i].trim();
133 if (arg.charAt(0) == '-')
135 arg = arg.substring(1);
143 * check for and remove first occurence of arg+parameter in arglist.
146 * @return return the argument following the given arg if arg was in list.
148 public String getValue(String arg)
150 return getValue(arg, false);
153 public String getValue(String arg, boolean utf8decode)
155 int index = vargs.indexOf(arg);
156 String dc = null, ret = null;
159 ret = vargs.get(index + 1).toString();
162 if (utf8decode && ret != null)
166 dc = URLDecoder.decode(ret, "UTF-8");
168 } catch (Exception e)
170 // TODO: log failure to decode
178 * check for and remove first occurence of arg in arglist.
181 * @return true if arg was present in argslist.
183 public boolean contains(String arg)
185 if (vargs.contains(arg))
196 public String nextValue()
198 return vargs.remove(0);
206 public Object getAppletValue(String key, String def, boolean asString)
209 return (appletParams == null ? null
210 : (value = appletParams.get(key.toLowerCase())) == null
211 ? def : asString ? "" + value