3 import java.util.HashMap;
5 import java.util.Vector;
8 * Collection of all known applet tags from JalviewLite
13 @SuppressWarnings("serial")
14 public class AppletParams extends HashMap<String, String>
17 private final static String[] params = { "alignpdbfiles",
18 "ANNOTATIONCOLOUR_MAX", "ANNOTATIONCOLOUR_MIN", "annotations",
19 "APPLICATION_URL", "automaticScrolling", "centrecolumnlabels",
20 "debug", "defaultColour", "defaultColourNuc", "defaultColourProt",
21 "embedded", "enableSplitFrame", "externalstructureviewer", "features",
22 "file", "file2", "format", "heightScale", "hidefeaturegroups",
23 "jalviewhelpurl", "jnetfile", "jpredfile", "label", "linkLabel_",
24 "linkLabel_1", "linkURL_", "nojmol", "normaliseLogo",
25 "normaliseSequenceLogo", "oninit", "PDBFILE", "PDBSEQ",
26 "relaxedidmatch", "resolvetocodebase", "RGB", "scaleProteinAsCdna",
27 "scoreFile", "separator", "sequence", "showAnnotation", "showbutton",
28 "showConsensus", "showConsensusHistogram", "showConservation",
29 "showfeaturegroups", "showFeatureSettings", "showFullId",
30 "showGroupConsensus", "showGroupConservation", "showOccupancy",
31 "showQuality", "showSequenceLogo", "showTreeBootstraps",
32 "showTreeDistances", "showUnconserved", "showUnlinkedTreeNodes",
33 "sortBy", "sortByTree", "tree", "treeFile", "upperCase",
34 "userDefinedColour", "widthScale", "windowHeight", "windowWidth",
37 public AppletParams(Map<String, String> info)
39 for (int i = params.length; --i >= 0;)
41 put(params[i], info.get(params[i]));
45 public String getParam(String param, String def)
47 String val = get(param);
48 return (val != null ? val : def);
52 // code="jalview.bin.JalviewLite" width="140" height="35"
53 // archive="jalviewApplet.jar,JmolApplet-14.6.4_2016.10.26.jar,java-json.jar,json_simple-1.1.jar">
54 // <param name="permissions" value="sandbox"/>
55 // <param name="file" value="uniref50.fa"/>
56 // <param name="treeFile" value="ferredoxin.nw"/>
57 // <param name="userDefinedColour" value="C=yellow; R,K,H=FF5555;
59 // <param name="sortByTree" value="True"/>
60 // <param name="showSequenceLogo" value="true"/>
61 // <param name="showGroupConsensus" value="true"/>
62 // <param name="showFullId" value="false"/>
63 // <param name="linkLabel_1" value="Uniprot"/>
64 // <param name="linkUrl_1"
65 // value="http://www.uniprot.org/uniprot/$SEQUENCE_ID$"/>
66 // <param name="linkLabel_2" value="EMBL-EBI Search"/>
67 // <param name="linkUrl_2"
68 // value="http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$"/>
69 // <param name="APPLICATION_URL"
70 // value="http://www.jalview.org/services/launchApp"/>
73 public AppletParams(String outerHTML)
75 String[] tokens = outerHTML.split("<param");
76 outerHTML = tokens[0];
77 String code = getAttr(outerHTML, "code");
78 if (!code.equals("jalview.bin.JalviewLite"))
82 for (int i = tokens.length; --i > 0;)
84 String param = tokens[i];
85 String key = getAttr(param, "name");
88 String value = getAttr(param, "value");
89 System.out.println("AppletParams " + key + " = \"" + value + "\"");
93 put("_width", getAttr(outerHTML, "width"));
94 put("_height", getAttr(outerHTML, "height"));
95 put("_id", getAttr(outerHTML, "id"));
96 put("_name", getAttr(outerHTML, "name"));
97 put("_archive", getAttr(outerHTML, "archive"));
101 public AppletParams()
103 // TODO Auto-generated constructor stub
106 public static AppletParams getAppletParams(String[] args,
107 Vector<String> vargs)
109 AppletParams appletParams = new AppletParams();
110 String resourcePath = null;
111 for (int i = args.length; --i > 0;) // > 0 is correct, not >=0
113 if (args[i].startsWith("name=\"Info.resourcePath\""))
115 resourcePath = getAttr(args[i], "value");
116 if (resourcePath.length() > 0 && !resourcePath.endsWith("/"))
123 for (int i = 1; i < args.length; i++)
125 String arg = args[i].trim();
126 if (arg.startsWith("name="))
128 String appName = getAttr(arg, "name");
129 String value = getAttr(arg, "value");
130 String appletName = appName.toLowerCase();
132 // note that Application arguments ARE case-sensitive, but
133 // Applet.getParameter() is not.
139 value = resourcePath + value;
143 value = resourcePath + value;
147 value = resourcePath + value;
152 value = resourcePath + value;
158 value = resourcePath + value;
159 appletName = null; // taken care of by Jalview
161 // implemented; not tested:
163 value = resourcePath + value;
166 case "defaultcolour":
167 appName = "DEFAULT_COLOUR"; // defaultColour
169 case "defaultcolournuc":
170 appName = "DEFAULT_COLOUR_NUC";// defaultColourNuc
172 case "defaultcolourprot":
173 appName = "DEFAULT_COLOUR_PROT";// defaultColourProt";
175 case "annotationcolour_max":
176 appName = "ANNOTATIONCOLOUR_MAX";
178 case "annotationcolour_min":
179 appName = "ANNOTATIONCOLOUR_MIN";
181 case "centrecolumnlabels":
184 case "enablesplitframe":
185 appName = "enableSplitFrame";
187 case "externalstructureviewer":
189 case "alignpdbfiles":
191 case "application_url":
192 appName = "APPLICATION_URL";
194 case "automaticscrolling":
195 appName = "automaticScrolling";
198 appName = "heightScale";
200 case "hidefeaturegroups":
202 case "jalviewhelpurl":
207 appName = "linkLabel_";
210 appName = "linkLabel_1";
213 appName = "linkURL_";
217 case "normaliselogo":
218 appName = "normaliseLogo";
220 case "normalisesequencelogo":
221 appName = "normaliseSequenceLogo";
228 case "relaxedidmatch":
230 case "resolvetocodebase":
235 case "scaleproteinascdna":
236 appName = "scaleProteinAsCdna";
245 value = checkTF(value);
246 appletName = null; // taken care of by Jalview
251 appName = "scoreFile";
252 value = resourcePath + value;
255 appName = "upperCase";
257 case "userdefinedcolour":
261 appName = "widthScale";
264 appName = "windowHeight";
267 appName = "windowWidth";
272 // cases not handled in doc/parameters.xlsx
274 value = checkTF(value);
278 value = resourcePath + value;
281 value = resourcePath + value;
284 value = checkTF(value);
286 case "showannotation":
287 appName = "SHOW_ANNOTATIONS";
288 value = checkTF(value);
291 value = checkTF(value);
293 case "showconsensus":
294 appName = "SHOW_CONSENSUS_LOGO";
295 value = checkTF(value);
297 case "showconsensushistogram":
298 appName = "SHOW_CONSENSUS_HISTOGRAM";
299 value = checkTF(value);
301 case "showconservation":
302 appName = "SHOW_CONSERVATION";
303 value = checkTF(value);
305 case "showfeaturegroups":
306 value = checkTF(value);
308 case "showfeaturesettings":
309 appName = "showFeatureSettings";
310 value = checkTF(value);
313 appName = "showFullId";
314 value = checkTF(value);
316 case "showgroupconsensus":
317 appName = "SHOW_GROUP_CONSENSUS";
318 value = checkTF(value);
320 case "showgroupconservation":
321 appName = "SHOW_GROUP_CONSERVATION";
322 value = checkTF(value);
324 case "showoccupancy":
325 appName = "SHOW_OCCUPANCY";
326 value = checkTF(value);
329 appName = "SHOW_QUALITY";
330 value = checkTF(value);
332 case "showsequencelogo":
333 appName = "showSequenceLogo";
334 value = checkTF(value);
336 case "showtreebootstraps":
337 appName = "showTreeBootstraps";
338 value = checkTF(value);
340 case "showtreedistances":
341 appName = "showTreeDistances";
342 value = checkTF(value);
344 case "showunconserved":
345 appName = "showUnconserved";
346 value = checkTF(value);
348 case "showunlinkedtreenodes":
349 appName = "showUnlinkedTreeNodes";
350 value = checkTF(value);
367 System.out.println("AppletParams appName=" + appName + "appletName="
368 + appletName + " value=" + value);
369 Cache.setPropertyNoSave(appName, value);
370 if (appletName != null)
372 appletParams.put(appletName, value);
380 * Check for a single-argument option.
383 * @return "true" or null
385 private static String checkTF(String value)
387 return (value.toLowerCase() == "true" ? "true" : null);
391 * Crude applet innerHTML parser
397 private static String getAttr(String tag, String attr)
399 int pt = tag.indexOf(attr + "=\"");
403 .println("AppletParams did not read " + attr + " in " + tag);
406 // <param name="sortByTree" value="True"/>
407 int pt1 = pt + attr.length() + 2;
408 int pt2 = tag.indexOf("\"", pt1);
409 return (pt < 0 ? null : tag.substring(pt1, pt2));
412 public static void main(String[] args)
414 new AppletParams("<applet\r\n"
415 + " code=\"jalview.bin.JalviewLite\" width=\"140\" height=\"35\"\r\n"
416 + " archive=\"jalviewApplet.jar,JmolApplet-14.6.4_2016.10.26.jar,java-json.jar,json_simple-1.1.jar\"> \r\n"
417 + " <param name=\"permissions\" value=\"sandbox\"/>\r\n"
418 + " <param name=\"file\" value=\"uniref50.fa\"/>\r\n"
419 + " <param name=\"treeFile\" value=\"ferredoxin.nw\"/>\r\n"
420 + " <param name=\"userDefinedColour\" value=\"C=yellow; R,K,H=FF5555; D,E=5555FF\"/>\r\n"
421 + " <param name=\"sortByTree\" value=\"True\"/>\r\n"
422 + " <param name=\"showSequenceLogo\" value=\"true\"/>\r\n"
423 + " <param name=\"showGroupConsensus\" value=\"true\"/>\r\n"
424 + " <param name=\"showFullId\" value=\"false\"/>\r\n"
425 + " <param name=\"linkLabel_1\" value=\"Uniprot\"/>\r\n"
426 + " <param name=\"linkUrl_1\" value=\"http://www.uniprot.org/uniprot/$SEQUENCE_ID$\"/>\r\n"
427 + " <param name=\"linkLabel_2\" value=\"EMBL-EBI Search\"/>\r\n"
428 + " <param name=\"linkUrl_2\" value=\"http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$\"/>\r\n"
429 + " <param name=\"APPLICATION_URL\" value=\"http://www.jalview.org/services/launchApp\"/>\r\n"