コード例 #1
0
ファイル: TestTable.java プロジェクト: Ecdosis/calliope
 private void addCheckBox(
     Element form, boolean flag, String prompt, String paramName, String onclick) {
   Element check = new Element(HTMLNames.INPUT);
   check.addAttribute(HTMLNames.TYPE, HTMLNames.CHECKBOX);
   check.addAttribute(HTMLNames.NAME, paramName);
   if (flag) check.addAttribute(HTMLNames.CHECKED, null);
   if (onclick != null) check.addAttribute(HTMLNames.ONCLICK, onclick);
   Element span = new Element(HTMLNames.SPAN);
   span.addText(prompt);
   form.addChild(span);
   form.addChild(check);
 }
コード例 #2
0
ファイル: TestTable.java プロジェクト: Ecdosis/calliope
 /**
  * Add a dropdown menu of lengths
  *
  * @param prompt the prompt explaining the menu
  * @param parent the parnet element to attach it to
  */
 private void addLengthSelector(String prompt, Element parent) {
   Element select = new Element(HTMLNames.SELECT);
   select.addAttribute(HTMLNames.NAME, Params.LENGTH);
   addOption(select, "100", length == 100);
   addOption(select, "150", length == 150);
   addOption(select, "200", length == 200);
   addOption(select, "250", length == 250);
   parent.addText(prompt);
   parent.addChild(select);
 }
コード例 #3
0
ファイル: TestTable.java プロジェクト: Ecdosis/calliope
 /**
  * Add a dropdown menu of lengths
  *
  * @param prompt the prompt explaining the menu
  * @param parent the parent element to attach it to
  */
 private void addOffsetSelector(String prompt, Element parent) {
   Element select = new Element(HTMLNames.SELECT);
   select.addAttribute(HTMLNames.NAME, Params.OFFSET);
   addOption(select, "0", offset == 0);
   addOption(select, "100", offset == 100);
   addOption(select, "200", offset == 200);
   addOption(select, "300", offset == 300);
   addOption(select, "400", offset == 400);
   addOption(select, "500", offset == 500);
   addOption(select, "600", offset == 600);
   addOption(select, "700", offset == 700);
   parent.addText(prompt);
   parent.addChild(select);
 }
コード例 #4
0
ファイル: TestTable.java プロジェクト: Ecdosis/calliope
  /**
   * Add a dropdown menu containing all the nested versions and groups
   *
   * @param parent the parent element to attach it to
   * @throws Exception
   */
  void addVersionDropdown(Element parent) throws Exception {
    Element select = new Element(HTMLNames.SELECT);
    String versions = getVersions();
    String[] opts = versions.split(",");
    // remove trailing LF-
    HashSet<String> selected = new HashSet<String>();
    if (selectedVersions != null) {
      String[] shortNames = selectedVersions.split(",");
      for (int i = 0; i < shortNames.length; i++) selected.add(shortNames[i]);
    }
    opts[opts.length - 1] = opts[opts.length - 1].trim();
    for (int i = 0; i < opts.length; i++) {
      String[] cols = opts[i].split("/");
      if (cols.length > 0 && cols[0].length() == 0) cols = popArray(cols);
      if (cols.length > 1) {
        HTMLOptGroup group = getGroup(select, cols[0]);
        if (selected.contains(opts[i])) cols[cols.length - 1] += " ×";
        if (group == null) {
          group = new HTMLOptGroup(cols[0]);
          select.addChild(group);
        }
        group.add(opts[i], popArray(cols));

      } else if (cols.length == 1) {
        Element option = new Element(HTMLNames.OPTION);
        select.addChild(option);
        String content = cols[cols.length - 1];
        if (selected.contains(opts[i])) content += " \327";
        option.addText(content);
        option.addAttribute(HTMLNames.VALUE, opts[i]);
      }
    }
    parent.addChild(select);
    if (!someVersions) select.addAttribute(HTMLNames.DISABLED, null);
    select.addAttribute(HTMLNames.ONCHANGE, "checkmark(this)");
    select.addAttribute(HTMLNames.ID, "selector");
    Element hidden = new Element(HTMLNames.INPUT);
    hidden.addAttribute(HTMLNames.TYPE, HTMLNames.HIDDEN);
    hidden.addAttribute(HTMLNames.ID, "versions");
    hidden.addAttribute(HTMLNames.NAME, Params.SELECTED_VERSIONS);
    parent.addChild(hidden);
  }
コード例 #5
0
ファイル: TestTable.java プロジェクト: Ecdosis/calliope
 /**
  * Get the content of this test: a table of versions
  *
  * @return a select element object with appropriate attributes and children
  */
 @Override
 public Element getContent() {
   try {
     Element div = new Element("div");
     String rawURL = "http://localhost:8080" + Service.PREFIX + "/html/table";
     String urn = Utils.escape(docID);
     rawURL = calliope.URLEncoder.append(rawURL, urn);
     // add required params
     rawURL = addGetParam(rawURL, Params.HIDE_MERGED, (hideMerged) ? "1" : "0");
     rawURL = addGetParam(rawURL, Params.COMPACT, (compact) ? "1" : "0");
     rawURL = addGetParam(rawURL, Params.WHOLE_WORDS, (wholeWords) ? "1" : "0");
     rawURL = addGetParam(rawURL, Params.LENGTH, Integer.toString(length));
     rawURL = addGetParam(rawURL, Params.OFFSET, Integer.toString(offset));
     rawURL = addGetParam(rawURL, Params.SOME_VERSIONS, (someVersions) ? "1" : "0");
     if (someVersions && selectedVersions != null)
       rawURL = addGetParam(rawURL, Params.SELECTED_VERSIONS, selectedVersions);
     URL url = new URL(rawURL);
     URLConnection conn = url.openConnection();
     InputStream is = conn.getInputStream();
     StringBuilder sb = new StringBuilder();
     while (is.available() != 0) {
       byte[] data = new byte[is.available()];
       is.read(data);
       sb.append(new String(data, "UTF-8"));
     }
     div.addChild(new HTMLLiteral(sb.toString()));
     Element panel = new Element(HTMLNames.DIV);
     Element form = formElement(Service.PREFIX + "/tests/table/");
     Element p1 = new Element(HTMLNames.P);
     form.addChild(p1);
     addCheckBox(p1, hideMerged, "hide merged", Params.HIDE_MERGED, null);
     addCheckBox(p1, wholeWords, "&nbsp;&nbsp;whole words", Params.WHOLE_WORDS, null);
     addCheckBox(p1, compact, "&nbsp;&nbsp;compact", Params.COMPACT, null);
     // submit button
     Element submit = new Element(HTMLNames.INPUT);
     submit.addAttribute(HTMLNames.TYPE, HTMLNames.SUBMIT);
     submit.addAttribute(HTMLNames.ONCLICK, "presubmit()");
     p1.addChild(submit);
     // next row of buttons
     Element p2 = new Element(HTMLNames.P);
     form.addChild(p2);
     // length and offset
     addLengthSelector("length:", p2);
     addOffsetSelector("&nbsp;&nbsp;start offset:", p2);
     // all versions
     addCheckBox(
         p2,
         someVersions,
         "&nbsp;&nbsp;some versions",
         Params.SOME_VERSIONS,
         "toggleVersionSelector(this)");
     addVersionDropdown(p2);
     panel.addChild(form);
     div.addChild(panel);
     Element explanation = new Element(HTMLNames.DIV);
     Element p3 = new HTMLLiteral(EXPLANATION);
     explanation.addChild(p3);
     div.addChild(explanation);
     return div;
   } catch (Exception e) {
     return new Text("Failed Table (HTML) test: " + e.getMessage());
   }
 }
コード例 #6
0
ファイル: TestTable.java プロジェクト: Ecdosis/calliope
 /**
  * Add the specified option to the selector
  *
  * @param select the selector element
  * @param value the new value
  */
 private void addOption(Element select, String value, boolean selectit) {
   Element option = new Element(HTMLNames.OPTION);
   option.addText(value);
   if (selectit) option.addAttribute(HTMLNames.SELECTED, HTMLNames.SELECTED);
   select.addChild(option);
 }