JAL-3253 AppletParams class for processing applet-specific params
authorhansonr <hansonr@STO24954W.ad.stolaf.edu>
Wed, 8 May 2019 02:42:57 +0000 (21:42 -0500)
committerhansonr <hansonr@STO24954W.ad.stolaf.edu>
Wed, 8 May 2019 02:42:57 +0000 (21:42 -0500)
src/jalview/bin/AppletParams.java [new file with mode: 0644]

diff --git a/src/jalview/bin/AppletParams.java b/src/jalview/bin/AppletParams.java
new file mode 100644 (file)
index 0000000..8beee03
--- /dev/null
@@ -0,0 +1,143 @@
+package jalview.bin;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Collection of all known applet tags from JalviewLite
+ * 
+ * @author hansonr
+ *
+ */
+@SuppressWarnings("serial")
+public class AppletParams extends HashMap<String, String>
+{
+
+  private final static String[] params = { "alignpdbfiles",
+      "ANNOTATIONCOLOUR_MAX", "ANNOTATIONCOLOUR_MIN", "annotations",
+      "APPLICATION_URL", "automaticScrolling", "centrecolumnlabels",
+      "debug", "defaultColour", "defaultColourNuc", "defaultColourProt",
+      "embedded", "enableSplitFrame", "externalstructureviewer", "features",
+      "file", "file2", "format", "heightScale", "hidefeaturegroups",
+      "jalviewhelpurl", "jnetfile", "jpredfile", "label", "linkLabel_",
+      "linkLabel_1", "linkURL_", "nojmol", "normaliseLogo",
+      "normaliseSequenceLogo", "oninit", "PDBFILE", "PDBSEQ",
+      "relaxedidmatch", "resolvetocodebase", "RGB", "scaleProteinAsCdna",
+      "scoreFile", "separator", "sequence", "showAnnotation", "showbutton",
+      "showConsensus", "showConsensusHistogram", "showConservation",
+      "showfeaturegroups", "showFeatureSettings", "showFullId",
+      "showGroupConsensus", "showGroupConservation", "showOccupancy",
+      "showQuality", "showSequenceLogo", "showTreeBootstraps",
+      "showTreeDistances", "showUnconserved", "showUnlinkedTreeNodes",
+      "sortBy", "sortByTree", "tree", "treeFile", "upperCase",
+      "userDefinedColour", "widthScale", "windowHeight", "windowWidth",
+      "wrap", };
+
+  public AppletParams(Map<String, String> info)
+  {
+    for (int i = params.length; --i >= 0;)
+    {
+      put(params[i], info.get(params[i]));
+    }
+  }
+
+  public String getParam(String param, String def)
+  {
+    String val = get(param);
+    return (val != null ? val : def);
+  }
+
+  // <applet
+  // code="jalview.bin.JalviewLite" width="140" height="35"
+  // archive="jalviewApplet.jar,JmolApplet-14.6.4_2016.10.26.jar,java-json.jar,json_simple-1.1.jar">
+  // <param name="permissions" value="sandbox"/>
+  // <param name="file" value="uniref50.fa"/>
+  // <param name="treeFile" value="ferredoxin.nw"/>
+  // <param name="userDefinedColour" value="C=yellow; R,K,H=FF5555;
+  // D,E=5555FF"/>
+  // <param name="sortByTree" value="True"/>
+  // <param name="showSequenceLogo" value="true"/>
+  // <param name="showGroupConsensus" value="true"/>
+  // <param name="showFullId" value="false"/>
+  // <param name="linkLabel_1" value="Uniprot"/>
+  // <param name="linkUrl_1"
+  // value="http://www.uniprot.org/uniprot/$SEQUENCE_ID$"/>
+  // <param name="linkLabel_2" value="EMBL-EBI Search"/>
+  // <param name="linkUrl_2"
+  // value="http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$"/>
+  // <param name="APPLICATION_URL"
+  // value="http://www.jalview.org/services/launchApp"/>
+  // </applet>
+  //
+  public AppletParams(String outerHTML)
+  {
+    String[] tokens = outerHTML.split("<param");
+    outerHTML = tokens[0];
+    String code = getAttr(outerHTML, "code");
+    if (!code.equals("jalview.bin.JalviewLite"))
+    {
+      return;
+    }
+    for (int i = tokens.length; --i > 0;)
+    {
+      String param = tokens[i];
+      String key = getAttr(param, "name");
+      if (key != null)
+      {
+        String value = getAttr(param, "value");
+        System.out.println("AppletParams " + key + " = \"" + value + "\"");
+        put(key, value);
+      }
+    }
+    put("_width", getAttr(outerHTML, "width"));
+    put("_height", getAttr(outerHTML, "height"));
+    put("_id", getAttr(outerHTML, "id"));
+    put("_name", getAttr(outerHTML, "name"));
+    put("_archive", getAttr(outerHTML, "archive"));
+    put("_code", code);
+  }
+
+  /**
+   * Crude applet innerHTML parser
+   * 
+   * @param tag
+   * @param attr
+   * @return
+   */
+  private String getAttr(String tag, String attr)
+  {
+    int pt = tag.indexOf(attr + "=\"");
+    if (pt < 0)
+    {
+      System.out
+              .println("AppletParams did not read " + attr + " in " + tag);
+      return null;
+    }
+    // <param name="sortByTree" value="True"/>
+    int pt1 = pt + attr.length() + 2;
+    int pt2 = tag.indexOf("\"", pt1);
+    return (pt < 0 ? null : tag.substring(pt1, pt2));
+  }
+
+  public static void main(String[] args)
+  {
+    new AppletParams("<applet\r\n"
+            + "    code=\"jalview.bin.JalviewLite\" width=\"140\" height=\"35\"\r\n"
+            + "    archive=\"jalviewApplet.jar,JmolApplet-14.6.4_2016.10.26.jar,java-json.jar,json_simple-1.1.jar\">  \r\n"
+            + "  <param name=\"permissions\" value=\"sandbox\"/>\r\n"
+            + "  <param name=\"file\" value=\"uniref50.fa\"/>\r\n"
+            + "  <param name=\"treeFile\" value=\"ferredoxin.nw\"/>\r\n"
+            + "  <param name=\"userDefinedColour\" value=\"C=yellow; R,K,H=FF5555; D,E=5555FF\"/>\r\n"
+            + "  <param name=\"sortByTree\" value=\"True\"/>\r\n"
+            + "  <param name=\"showSequenceLogo\" value=\"true\"/>\r\n"
+            + "  <param name=\"showGroupConsensus\" value=\"true\"/>\r\n"
+            + "  <param name=\"showFullId\" value=\"false\"/>\r\n"
+            + "    <param name=\"linkLabel_1\" value=\"Uniprot\"/>\r\n"
+            + "    <param name=\"linkUrl_1\" value=\"http://www.uniprot.org/uniprot/$SEQUENCE_ID$\"/>\r\n"
+            + "    <param name=\"linkLabel_2\" value=\"EMBL-EBI Search\"/>\r\n"
+            + "    <param name=\"linkUrl_2\" value=\"http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$\"/>\r\n"
+            + "    <param name=\"APPLICATION_URL\" value=\"http://www.jalview.org/services/launchApp\"/>\r\n"
+            + "     </applet>");
+  }
+
+}
\ No newline at end of file