Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 14:43:25 GMT
  2. Package jalview.bin

File AppletParams.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
60% of files have more coverage

Code metrics

46
249
10
1
479
367
105
0.42
24.9
10
10.5

Classes

Class Line # Actions
AppletParams 25 249 105
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1   
2    package jalview.bin;
3   
4    import java.util.HashMap;
5    import java.util.List;
6    import java.util.Map;
7   
8    import jalview.gui.Preferences;
9   
10    /**
11    * Collection of all known applet tags from JalviewLite.
12    * Three cases; can be one or more of these:
13    *
14    * CASE I. args[] name and value for ArgsParser
15    *
16    * CASE II. applet parameter for JalviewJSApp
17    *
18    * CASE III. mapped to a Preference
19    *
20    *
21    * @author hansonr
22    *
23    */
24    @SuppressWarnings("serial")
 
25    public class AppletParams extends HashMap<String, Object>
26    {
27   
28    private final static String[] params = {
29    "alignpdbfiles",
30    "ANNOTATIONCOLOUR_MAX", "ANNOTATIONCOLOUR_MIN",
31    "annotations",
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",
48    "wrap", };
49   
 
50  0 toggle public String getParam(String param, String def)
51    {
52  0 Object val = get(param);
53  0 return (val != null ? val.toString() : def);
54    }
55   
56    // <applet
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;
63    // D,E=5555FF"/>
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"/>
76    // </applet>
77    //
 
78  0 toggle public AppletParams(String outerHTML)
79    {
80  0 String[] tokens = outerHTML.split("<param");
81  0 outerHTML = tokens[0];
82  0 String code = getAttr(outerHTML, "code");
83  0 if (!code.equals("jalview.bin.JalviewLite"))
84    {
85  0 return;
86    }
87  0 for (int i = tokens.length; --i > 0;)
88    {
89  0 String param = tokens[i];
90  0 String key = getAttr(param, "name");
91  0 if (key != null)
92    {
93  0 String value = getAttr(param, "value");
94  0 System.out.println("AppletParams " + key + " = \"" + value + "\"");
95  0 put(key, value);
96    }
97    }
98  0 put("_width", getAttr(outerHTML, "width"));
99  0 put("_height", getAttr(outerHTML, "height"));
100  0 put("_id", getAttr(outerHTML, "id"));
101  0 put("_name", getAttr(outerHTML, "name"));
102  0 put("_archive", getAttr(outerHTML, "archive"));
103  0 put("_code", code);
104    }
105   
 
106  0 toggle public AppletParams()
107    {
108    }
109   
 
110  0 toggle public static AppletParams getAppletParams(Map<String, Object> map,
111    List<String> vargs)
112    {
113  0 AppletParams appletParams = new AppletParams();
114  0 String resourcePath = getString(map, "resourcePath");
115  0 if (resourcePath == null)
116  0 resourcePath = "";
117  0 if (resourcePath.length() > 0 && !resourcePath.endsWith("/"))
118    {
119  0 resourcePath += "/";
120    }
121  0 for (int i = params.length; --i >= 0;)
122    {
123  0 String prefName = params[i];
124  0 Object value = map.get(prefName);
125  0 if (value != null)
126  0 addParam(vargs, prefName, value, appletParams, resourcePath);
127    }
128  0 return appletParams;
129    }
130   
 
131  0 toggle private static String getString(Map<String, Object> map, String key)
132    {
133  0 Object o = map.get(key);
134  0 return (o == null ? null : o.toString());
135    }
136   
 
137  0 toggle public static AppletParams getAppletParams(String[] args,
138    List<String> vargs)
139    {
140  0 AppletParams appletParams = new AppletParams();
141  0 String resourcePath = "";
142  0 for (int i = args.length; --i > 0;) // > 0 is correct, not >=0
143    {
144  0 if (args[i].startsWith("name=\"Info.resourcePath\""))
145    {
146  0 resourcePath = getAttr(args[i], "value");
147  0 if (resourcePath.length() > 0 && !resourcePath.endsWith("/"))
148    {
149  0 resourcePath += "/";
150    }
151  0 break;
152    }
153    }
154  0 for (int i = 1; i < args.length; i++)
155    {
156  0 String arg = args[i].trim();
157  0 if (arg.startsWith("name="))
158    {
159  0 String prefName = getAttr(arg, "name");
160  0 String value = getAttr(arg, "value");
161  0 addParam(vargs, prefName, value, appletParams, resourcePath);
162    }
163    }
164  0 return appletParams;
165    }
166   
 
167  0 toggle private static void addParam(List<String> vargs, String prefName,
168    Object value, AppletParams appletParams, String resourcePath)
169    {
170   
171    // note that Application arguments ARE case-sensitive, but
172    // Applet.getParameter() is not.
173   
174    // prefName // CASE III
175   
176  0 String argName = null; // CASE I
177   
178  0 String appletName = prefName.toLowerCase(); // CASE II
179   
180    // by nulling one or more of these names, that route will not be used.
181   
182  0 switch (appletName)
183    {
184   
185  0 case "file":
186  0 argName = "open";
187  0 prefName = null;
188  0 value = resourcePath + value;
189  0 break;
190  0 case "file2":
191  0 argName = "open2";
192  0 prefName = null;
193  0 value = resourcePath + value;
194  0 break;
195  0 case "oninit":
196  0 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  0 prefName = argName = null;
201  0 break;
202  0 case "tree":
203  0 case "treefile":
204    // setting appletName to null indicates that we want
205    // Jalview.doMain to taken care of this as Jalview args
206  0 argName = "tree";
207  0 prefName = null;
208  0 value = resourcePath + value;
209  0 break;
210   
211  0 case "features":
212  0 case "jnetfile":
213  0 case "jpredfile":
214  0 case "pdbfile":
215  0 case "scorefile":
216  0 case "sequence":
217  0 case "annotations":
218  0 prefName = argName = null;
219  0 value = resourcePath + value;
220  0 break;
221   
222    // non-loading preferences
223   
224  0 case "defaultcolour":
225  0 prefName = Preferences.DEFAULT_COLOUR;
226  0 break;
227  0 case "defaultcolournuc":
228  0 prefName = Preferences.DEFAULT_COLOUR_NUC;
229  0 break;
230  0 case "defaultcolourprot":
231  0 prefName = Preferences.DEFAULT_COLOUR_PROT;
232  0 break;
233  0 case "annotationcolour_max":
234  0 prefName = Preferences.ANNOTATIONCOLOUR_MAX;
235  0 break;
236  0 case "annotationcolour_min":
237  0 prefName = Preferences.ANNOTATIONCOLOUR_MIN;
238  0 break;
239  0 case "enablesplitframe":
240  0 prefName = Preferences.ENABLE_SPLIT_FRAME;
241  0 break;
242  0 case "centrecolumnlabels":
243  0 prefName = Preferences.CENTRE_COLUMN_LABELS;
244  0 break;
245  0 case "sortby":
246  0 prefName = Preferences.SORT_ALIGNMENT; // id, etc.
247  0 break;
248  0 case "normalisesequencelogo":
249  0 prefName = Preferences.NORMALISE_CONSENSUS_LOGO;
250  0 break;
251  0 case "relaxedidmatch":
252  0 prefName = Preferences.RELAXEDSEQIDMATCHING;
253  0 break;
254  0 case "scaleproteinascdna":
255  0 prefName = Preferences.SCALE_PROTEIN_TO_CDNA;
256  0 break;
257  0 case "userdefinedcolour":
258  0 argName = "colour";
259  0 prefName = Preferences.USER_DEFINED_COLOURS;
260  0 break;
261  0 case "wrap":
262  0 prefName = Preferences.WRAP_ALIGNMENT;
263  0 break;
264  0 case "sortbytree":
265  0 argName = prefName;
266  0 prefName = Preferences.SORT_BY_TREE;
267  0 value = checkTF(value);
268  0 break;
269   
270    // implemented; not tested:
271   
272  0 case "pdbseq":
273  0 case "alignpdbfiles":
274  0 prefName = null;
275  0 break;
276  0 case "format":
277  0 argName = prefName;
278  0 break;
279  0 case "separator":
280  0 argName = prefName;
281  0 break;
282   
283    // TODO: probably not relevant?
284   
285  0 case "rgb":
286  0 prefName = null; // TODO no background for application?
287  0 break;
288  0 case "externalstructureviewer":
289  0 break;
290  0 case "application_url":
291  0 break;
292  0 case "automaticscrolling":
293  0 break;
294  0 case "heightscale":
295  0 break;
296  0 case "jalviewhelpurl":
297  0 break;
298  0 case "label":
299  0 break;
300  0 case "linklabel_":
301  0 prefName = "linkLabel_";
302  0 break;
303  0 case "linklabel_1":
304  0 prefName = "linkLabel_1";
305  0 break;
306  0 case "linkurl_":
307  0 prefName = "linkURL_";
308  0 break;
309   
310    // unknown:
311   
312  0 case "nojmol":
313  0 case "normaliselogo":
314  0 case "resolvetocodebase":
315  0 case "uppercase":
316  0 case "widthscale":
317  0 case "windowheight":
318  0 case "windowwidth":
319  0 prefName = null;
320  0 break;
321   
322    // TRUE/FALSE
323   
324  0 case "debug":
325  0 case "embedded":
326  0 case "showbutton":
327  0 value = checkTF(value);
328  0 break;
329  0 case "showannotation":
330  0 prefName = Preferences.SHOW_ANNOTATIONS;
331  0 value = checkTF(value);
332  0 break;
333  0 case "showconsensus":
334  0 prefName = Preferences.SHOW_CONSENSUS_LOGO;
335  0 value = checkTF(value);
336  0 break;
337  0 case "showconsensushistogram":
338  0 prefName = Preferences.SHOW_CONSENSUS_HISTOGRAM;
339  0 value = checkTF(value);
340  0 break;
341  0 case "showconservation":
342  0 prefName = Preferences.SHOW_CONSERVATION;
343  0 value = checkTF(value);
344  0 break;
345  0 case "showgroupconsensus":
346  0 prefName = Preferences.SHOW_GROUP_CONSENSUS;
347  0 value = checkTF(value);
348  0 break;
349  0 case "showgroupconservation":
350  0 prefName = Preferences.SHOW_GROUP_CONSERVATION;
351  0 value = checkTF(value);
352  0 break;
353  0 case "showoccupancy":
354  0 prefName = Preferences.SHOW_OCCUPANCY;
355  0 value = checkTF(value);
356  0 break;
357  0 case "showquality":
358  0 prefName = Preferences.SHOW_QUALITY;
359  0 value = checkTF(value);
360  0 break;
361  0 case "showsequencelogo":
362  0 prefName = Preferences.SHOW_CONSENSUS_LOGO;
363  0 value = checkTF(value);
364  0 break;
365  0 case "showunconserved":
366  0 prefName = Preferences.SHOW_UNCONSERVED;
367  0 value = checkTF(value);
368  0 break;
369  0 case "showfeaturegroups":
370  0 case "showfeaturesettings":
371  0 case "showfullid":
372  0 case "showtreebootstraps":
373  0 case "showtreedistances":
374  0 case "showunlinkedtreenodes":
375  0 value = checkTF(value);
376  0 break;
377  0 default:
378  0 if (appletName.startsWith("pdbfile")
379    || appletName.startsWith("sequence") && Character
380    .isDigit(appletName.charAt(appletName.length() - 1)))
381    {
382    // could be pdbFile2, for example
383  0 prefName = argName = null;
384  0 value = resourcePath + value;
385  0 break;
386    }
387    // or one of the app preference names
388  0 break;
389    }
390   
391    // CASE I. args[] name and value for ArgsParser
392    //
393    // If given an argument name,
394    // put name and value into application args
395  0 if (value != null && argName != null)
396    {
397  0 vargs.add(argName);
398  0 if (value != "true")
399    {
400  0 vargs.add(value.toString());
401    }
402    }
403   
404    // CASE II. applet parameter for JalviewJSApp
405   
406  0 if (value == null)
407    {
408  0 value = "false";
409    }
410  0 System.out.println("AppletParams propName=" + prefName + " argName="
411    + argName + " appletName=" + appletName + " value=" + value);
412  0 if (appletName != null)
413    {
414  0 appletParams.put(appletName, value);
415    }
416   
417    // CASE III. mapped to a Preference
418   
419  0 if (prefName != null)
420    {
421  0 Cache.setPropertyNoSave(prefName, value.toString());
422    }
423    }
424   
425    /**
426    * Check for a single-argument option.
427    *
428    * @param value
429    * @return "true" or null
430    */
 
431  0 toggle private static String checkTF(Object value)
432    {
433  0 return (("" + value).toLowerCase() == "true" ? "true" : null);
434    }
435   
436    /**
437    * Crude applet innerHTML parser
438    *
439    * @param tag
440    * @param attr
441    * @return
442    */
 
443  0 toggle private static String getAttr(String tag, String attr)
444    {
445  0 int pt = tag.indexOf(attr + "=\"");
446  0 if (pt < 0)
447    {
448  0 System.out
449    .println("AppletParams did not read " + attr + " in " + tag);
450  0 return null;
451    }
452    // <param name="sortByTree" value="True"/>
453  0 int pt1 = pt + attr.length() + 2;
454  0 int pt2 = tag.indexOf("\"", pt1);
455  0 return (pt < 0 ? null : tag.substring(pt1, pt2));
456    }
457   
 
458  0 toggle public static void main(String[] args)
459    {
460  0 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"
476    + " </applet>");
477    }
478   
479    }