private String getVersions() throws Exception { String rawURL = "http://localhost:8080" + Service.PREFIX + "/list"; String urn = Utils.escape(docID); rawURL = calliope.URLEncoder.append(rawURL, urn); 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)); } return sb.toString(); }
/** * 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, " whole words", Params.WHOLE_WORDS, null); addCheckBox(p1, compact, " 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(" start offset:", p2); // all versions addCheckBox( p2, someVersions, " 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()); } }