4 import java.util.HashMap;
8 import jalview.gui.Preferences;
11 * Collection of all known applet tags from JalviewLite.
12 * Three cases; can be one or more of these:
14 * CASE I. args[] name and value for ArgsParser
16 * CASE II. applet parameter for JalviewJSApp
18 * CASE III. mapped to a Preference
24 @SuppressWarnings("serial")
25 public class AppletParams extends HashMap<String, Object>
28 private final static String[] params = {
30 "ANNOTATIONCOLOUR_MAX", "ANNOTATIONCOLOUR_MIN",
32 "APPLICATION_URL", "automaticScrolling", "centrecolumnlabels",
33 "debug", "defaultColour", "defaultColourNuc", "defaultColourProt",
34 "embedded", "enableSplitFrame", "externalstructureviewer", "features",
35 "file", "file2", "format", "heightScale", "hidefeaturegroups",
36 "jalviewhelpurl", "jnetfile", "jpredfile", "label", "linkLabel_",
37 "linkLabel_1", "linkURL_", "nojmol", "normaliseLogo",
38 "normaliseSequenceLogo", "oninit", "PDBFILE", "PDBSEQ",
39 "relaxedidmatch", "resolvetocodebase", "RGB", "scaleProteinAsCdna",
40 "scoreFile", "separator", "sequence", "showAnnotation", "showbutton",
41 "showConsensus", "showConsensusHistogram", "showConservation",
42 "showfeaturegroups", "showFeatureSettings", "showFullId",
43 "showGroupConsensus", "showGroupConservation", "showOccupancy",
44 "showQuality", "showSequenceLogo", "showTreeBootstraps",
45 "showTreeDistances", "showUnconserved", "showUnlinkedTreeNodes",
46 "sortBy", "sortByTree", "tree", "treeFile", "upperCase",
47 "userDefinedColour", "widthScale", "windowHeight", "windowWidth",
50 public String getParam(String param, String def)
52 Object val = get(param);
53 return (val != null ? val.toString() : def);
57 // code="jalview.bin.JalviewLite" width="140" height="35"
58 // archive="jalviewApplet.jar,JmolApplet-14.6.4_2016.10.26.jar,java-json.jar,json_simple-1.1.jar">
59 // <param name="permissions" value="sandbox"/>
60 // <param name="file" value="uniref50.fa"/>
61 // <param name="treeFile" value="ferredoxin.nw"/>
62 // <param name="userDefinedColour" value="C=yellow; R,K,H=FF5555;
64 // <param name="sortByTree" value="True"/>
65 // <param name="showSequenceLogo" value="true"/>
66 // <param name="showGroupConsensus" value="true"/>
67 // <param name="showFullId" value="false"/>
68 // <param name="linkLabel_1" value="Uniprot"/>
69 // <param name="linkUrl_1"
70 // value="http://www.uniprot.org/uniprot/$SEQUENCE_ID$"/>
71 // <param name="linkLabel_2" value="EMBL-EBI Search"/>
72 // <param name="linkUrl_2"
73 // value="http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$"/>
74 // <param name="APPLICATION_URL"
75 // value="http://www.jalview.org/services/launchApp"/>
78 public AppletParams(String outerHTML)
80 String[] tokens = outerHTML.split("<param");
81 outerHTML = tokens[0];
82 String code = getAttr(outerHTML, "code");
83 if (!code.equals("jalview.bin.JalviewLite"))
87 for (int i = tokens.length; --i > 0;)
89 String param = tokens[i];
90 String key = getAttr(param, "name");
93 String value = getAttr(param, "value");
94 System.out.println("AppletParams " + key + " = \"" + value + "\"");
98 put("_width", getAttr(outerHTML, "width"));
99 put("_height", getAttr(outerHTML, "height"));
100 put("_id", getAttr(outerHTML, "id"));
101 put("_name", getAttr(outerHTML, "name"));
102 put("_archive", getAttr(outerHTML, "archive"));
106 public AppletParams()
110 public static AppletParams getAppletParams(Map<String, Object> map,
113 AppletParams appletParams = new AppletParams();
114 String resourcePath = getString(map, "resourcePath");
115 if (resourcePath == null)
117 if (resourcePath.length() > 0 && !resourcePath.endsWith("/"))
121 for (int i = params.length; --i >= 0;)
123 String prefName = params[i];
124 Object value = map.get(prefName);
126 addParam(vargs, prefName, value, appletParams, resourcePath);
131 private static String getString(Map<String, Object> map, String key)
133 Object o = map.get(key);
134 return (o == null ? null : o.toString());
137 public static AppletParams getAppletParams(String[] args,
140 AppletParams appletParams = new AppletParams();
141 String resourcePath = "";
142 for (int i = args.length; --i > 0;) // > 0 is correct, not >=0
144 if (args[i].startsWith("name=\"Info.resourcePath\""))
146 resourcePath = getAttr(args[i], "value");
147 if (resourcePath.length() > 0 && !resourcePath.endsWith("/"))
154 for (int i = 1; i < args.length; i++)
156 String arg = args[i].trim();
157 if (arg.startsWith("name="))
159 String prefName = getAttr(arg, "name");
160 String value = getAttr(arg, "value");
161 addParam(vargs, prefName, value, appletParams, resourcePath);
167 private static void addParam(List<String> vargs, String prefName,
168 Object value, AppletParams appletParams, String resourcePath)
171 // note that Application arguments ARE case-sensitive, but
172 // Applet.getParameter() is not.
174 // prefName // CASE III
176 String argName = null; // CASE I
178 String appletName = prefName.toLowerCase(); // CASE II
180 // by nulling one or more of these names, that route will not be used.
188 value = resourcePath + value;
193 value = resourcePath + value;
196 case "hidefeaturegroups":
197 // applet parameter only
198 // setting argName to null indicates that we want
199 // JalviewJSApp to take care of this using getParameter or getParameterAsObject
200 prefName = argName = null;
204 // setting appletName to null indicates that we want
205 // Jalview.doMain to taken care of this as Jalview args
208 value = resourcePath + value;
218 prefName = argName = null;
219 value = resourcePath + value;
222 // non-loading preferences
224 case "defaultcolour":
225 prefName = Preferences.DEFAULT_COLOUR;
227 case "defaultcolournuc":
228 prefName = Preferences.DEFAULT_COLOUR_NUC;
230 case "defaultcolourprot":
231 prefName = Preferences.DEFAULT_COLOUR_PROT;
233 case "annotationcolour_max":
234 prefName = Preferences.ANNOTATIONCOLOUR_MAX;
236 case "annotationcolour_min":
237 prefName = Preferences.ANNOTATIONCOLOUR_MIN;
239 case "enablesplitframe":
240 prefName = Preferences.ENABLE_SPLIT_FRAME;
242 case "centrecolumnlabels":
243 prefName = Preferences.CENTRE_COLUMN_LABELS;
246 prefName = Preferences.SORT_ALIGNMENT; // id, etc.
248 case "normalisesequencelogo":
249 prefName = Preferences.NORMALISE_CONSENSUS_LOGO;
251 case "relaxedidmatch":
252 prefName = Preferences.RELAXEDSEQIDMATCHING;
254 case "scaleproteinascdna":
255 prefName = Preferences.SCALE_PROTEIN_TO_CDNA;
257 case "userdefinedcolour":
259 prefName = Preferences.USER_DEFINED_COLOURS;
262 prefName = Preferences.WRAP_ALIGNMENT;
266 prefName = Preferences.SORT_BY_TREE;
267 value = checkTF(value);
270 // implemented; not tested:
273 case "alignpdbfiles":
283 // TODO: probably not relevant?
286 prefName = null; // TODO no background for application?
288 case "externalstructureviewer":
290 case "application_url":
292 case "automaticscrolling":
296 case "jalviewhelpurl":
301 prefName = "linkLabel_";
304 prefName = "linkLabel_1";
307 prefName = "linkURL_";
313 case "normaliselogo":
314 case "resolvetocodebase":
327 value = checkTF(value);
329 case "showannotation":
330 prefName = Preferences.SHOW_ANNOTATIONS;
331 value = checkTF(value);
333 case "showconsensus":
334 prefName = Preferences.SHOW_CONSENSUS_LOGO;
335 value = checkTF(value);
337 case "showconsensushistogram":
338 prefName = Preferences.SHOW_CONSENSUS_HISTOGRAM;
339 value = checkTF(value);
341 case "showconservation":
342 prefName = Preferences.SHOW_CONSERVATION;
343 value = checkTF(value);
345 case "showgroupconsensus":
346 prefName = Preferences.SHOW_GROUP_CONSENSUS;
347 value = checkTF(value);
349 case "showgroupconservation":
350 prefName = Preferences.SHOW_GROUP_CONSERVATION;
351 value = checkTF(value);
353 case "showoccupancy":
354 prefName = Preferences.SHOW_OCCUPANCY;
355 value = checkTF(value);
358 prefName = Preferences.SHOW_QUALITY;
359 value = checkTF(value);
361 case "showsequencelogo":
362 prefName = Preferences.SHOW_CONSENSUS_LOGO;
363 value = checkTF(value);
365 case "showunconserved":
366 prefName = Preferences.SHOW_UNCONSERVED;
367 value = checkTF(value);
369 case "showfeaturegroups":
370 case "showfeaturesettings":
372 case "showtreebootstraps":
373 case "showtreedistances":
374 case "showunlinkedtreenodes":
375 value = checkTF(value);
378 if (appletName.startsWith("pdbfile")
379 || appletName.startsWith("sequence") && Character
380 .isDigit(appletName.charAt(appletName.length() - 1)))
382 // could be pdbFile2, for example
383 prefName = argName = null;
384 value = resourcePath + value;
387 // or one of the app preference names
391 // CASE I. args[] name and value for ArgsParser
393 // If given an argument name,
394 // put name and value into application args
395 if (value != null && argName != null)
400 vargs.add(value.toString());
404 // CASE II. applet parameter for JalviewJSApp
410 System.out.println("AppletParams propName=" + prefName + " argName="
411 + argName + " appletName=" + appletName + " value=" + value);
412 if (appletName != null)
414 appletParams.put(appletName, value);
417 // CASE III. mapped to a Preference
419 if (prefName != null)
421 Cache.setPropertyNoSave(prefName, value.toString());
426 * Check for a single-argument option.
429 * @return "true" or null
431 private static String checkTF(Object value)
433 return (("" + value).toLowerCase() == "true" ? "true" : null);
437 * Crude applet innerHTML parser
443 private static String getAttr(String tag, String attr)
445 int pt = tag.indexOf(attr + "=\"");
449 .println("AppletParams did not read " + attr + " in " + tag);
452 // <param name="sortByTree" value="True"/>
453 int pt1 = pt + attr.length() + 2;
454 int pt2 = tag.indexOf("\"", pt1);
455 return (pt < 0 ? null : tag.substring(pt1, pt2));
458 public static void main(String[] args)
460 new AppletParams("<applet\r\n"
461 + " code=\"jalview.bin.JalviewLite\" width=\"140\" height=\"35\"\r\n"
462 + " archive=\"jalviewApplet.jar,JmolApplet-14.6.4_2016.10.26.jar,java-json.jar,json_simple-1.1.jar\"> \r\n"
463 + " <param name=\"permissions\" value=\"sandbox\"/>\r\n"
464 + " <param name=\"file\" value=\"uniref50.fa\"/>\r\n"
465 + " <param name=\"treeFile\" value=\"ferredoxin.nw\"/>\r\n"
466 + " <param name=\"userDefinedColour\" value=\"C=yellow; R,K,H=FF5555; D,E=5555FF\"/>\r\n"
467 + " <param name=\"sortByTree\" value=\"True\"/>\r\n"
468 + " <param name=\"showSequenceLogo\" value=\"true\"/>\r\n"
469 + " <param name=\"showGroupConsensus\" value=\"true\"/>\r\n"
470 + " <param name=\"showFullId\" value=\"false\"/>\r\n"
471 + " <param name=\"linkLabel_1\" value=\"Uniprot\"/>\r\n"
472 + " <param name=\"linkUrl_1\" value=\"http://www.uniprot.org/uniprot/$SEQUENCE_ID$\"/>\r\n"
473 + " <param name=\"linkLabel_2\" value=\"EMBL-EBI Search\"/>\r\n"
474 + " <param name=\"linkUrl_2\" value=\"http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$\"/>\r\n"
475 + " <param name=\"APPLICATION_URL\" value=\"http://www.jalview.org/services/launchApp\"/>\r\n"