3 import java.io.BufferedReader;
4 import java.io.InputStreamReader;
7 import javax.swing.JOptionPane;
9 public class UserQuestionnaireCheck implements Runnable {
11 * Implements the client side machinery for detecting a new questionnaire,
12 * checking if the user has responded to an existing one,
13 * and prompting the user for responding to a questionnaire.
14 * This is intended to work with the perl CGI scripts checkresponder.pl and
18 UserQuestionnaireCheck(String url) {
19 if (url.indexOf("questionnaire.pl")==-1) {
20 jalview.bin.Cache.log.error("'"+url+"' is an Invalid URL for the checkForQuestionnaire() method.\n"
21 +"This argument is only for questionnaires derived from jalview's questionnaire.pl cgi interface.");
26 String qid=null,rid=null;
27 private boolean checkresponse(URL qurl) throws Exception {
28 jalview.bin.Cache.log.debug("Checking Response for : "+qurl);
30 // see if we have already responsed to this questionnaire or get a new qid/rid pair
31 BufferedReader br = new BufferedReader(new InputStreamReader(qurl.openStream()));
33 while ((qresp=br.readLine())!=null) {
34 if (qresp.indexOf("NOTYET:")==0) {
35 prompt=true; // not yet responded under that ID
37 if (qresp.indexOf("RESPONDED:")==-1) {
38 // may be a qid:rid for the latest questionnaire.
39 // check if response is of form we expect.
40 if (qresp.indexOf(':')>-1) {
42 qid=qresp.substring(0,qresp.indexOf(':'));
43 if (qresp.indexOf(':')<(qresp.length()-1)) {
44 rid = qresp.substring(qresp.indexOf(':')+1);
45 prompt=true; // this is a new qid/rid pair
60 // First - check to see if wee have an old questionnaire/response id pair.
61 String lastq=jalview.bin.Cache.getProperty("QUESTIONNAIRE");
63 prompt = checkresponse(new URL(url+(url.indexOf('?')>-1 ? "&" : "?") +"checkresponse=1"));
65 String qurl=url+(url.indexOf('?')>-1 ? "&" : "?") +"checkresponse=1";
66 // query the server with the old qid/id pair
67 String qqid = lastq.indexOf(':')>-1 ? lastq.substring(0,lastq.indexOf(':')) : null;
68 if (qqid!=null && qqid.length()>0) {
72 String qrid = lastq.substring(lastq.indexOf(':')+1); // retrieve old rid
73 if (qrid!=null && !qrid.equals("null")) {
77 // see if we have already responsed to this questionnaire.
78 prompt = checkresponse(new URL(qurl));
80 // Update our local property cache with latest qid and rid
81 jalview.bin.Cache.setProperty("QUESTIONNAIRE",qid+":"+rid);
83 String qurl = url+(url.indexOf('?')>-1 ? "&" : "?") + "qid="+qid+"&rid="+rid;
84 jalview.bin.Cache.log.info("Prompting user for questionnaire at "+qurl);
85 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
86 "There is a new Questionnaire available." +
87 "Would you like to complete it now ?\n",
88 "Jalview User Survey",
89 JOptionPane.YES_NO_OPTION,
90 JOptionPane.QUESTION_MESSAGE);
92 if (reply == JOptionPane.YES_OPTION)
94 jalview.bin.Cache.log.debug("Opening "+qurl);
95 jalview.util.BrowserLauncher.openURL(qurl);
98 } catch (Exception e) {
99 jalview.bin.Cache.log.warn("When trying to access questionnaire URL "+url,e);