8 public class UserQuestionnaireCheck
12 * Implements the client side machinery for detecting a new questionnaire,
13 * checking if the user has responded to an existing one,
14 * and prompting the user for responding to a questionnaire.
15 * This is intended to work with the perl CGI scripts checkresponder.pl and
19 UserQuestionnaireCheck(String url)
21 if (url.indexOf("questionnaire.pl") == -1)
23 jalview.bin.Cache.log.error("'" + url +
24 "' is an Invalid URL for the checkForQuestionnaire() method.\n"
25 + "This argument is only for questionnaires derived from jalview's questionnaire.pl cgi interface.");
33 String qid = null, rid = null;
34 private boolean checkresponse(URL qurl)
37 jalview.bin.Cache.log.debug("Checking Response for : " + qurl);
38 boolean prompt = false;
39 // see if we have already responsed to this questionnaire or get a new qid/rid pair
40 BufferedReader br = new BufferedReader(new InputStreamReader(qurl.
43 while ( (qresp = br.readLine()) != null)
45 if (qresp.indexOf("NOTYET:") == 0)
47 prompt = true; // not yet responded under that ID
51 if (qresp.indexOf("QUESTIONNAIRE:") == 0)
53 // QUESTIONNAIRE:qid:rid for the latest questionnaire.
54 int p = qresp.indexOf(':', 14);
58 qid = qresp.substring(14, p);
59 if (p < (qresp.length() - 1))
61 rid = qresp.substring(p + 1);
62 prompt = true; // this is a new qid/rid pair
77 boolean prompt = false;
80 // First - check to see if wee have an old questionnaire/response id pair.
81 String lastq = jalview.bin.Cache.getProperty("QUESTIONNAIRE");
84 prompt = checkresponse(new URL(url + (url.indexOf('?') > -1 ? "&" : "?") +
89 String qurl = url + (url.indexOf('?') > -1 ? "&" : "?") +
91 // query the server with the old qid/id pair
92 String qqid = lastq.indexOf(':') > -1 ?
93 lastq.substring(0, lastq.indexOf(':')) : null;
94 if (qqid != null && qqid != "null" && qqid.length() > 0)
96 qurl += "&qid=" + qqid;
98 String qrid = lastq.substring(lastq.indexOf(':') + 1); // retrieve old rid
99 if (qrid != null && !qrid.equals("null"))
102 qurl += "&rid=" + qrid;
105 // see if we have already responsed to this questionnaire.
106 prompt = checkresponse(new URL(qurl));
108 if (qid != null && rid != null)
110 // Update our local property cache with latest qid and rid
111 jalview.bin.Cache.setProperty("QUESTIONNAIRE", qid + ":" + rid);
115 String qurl = url + (url.indexOf('?') > -1 ? "&" : "?") + "qid=" + qid +
117 jalview.bin.Cache.log.info("Prompting user for questionnaire at " +
119 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
120 "There is a new Questionnaire available." +
121 "Would you like to complete it now ?\n",
122 "Jalview User Survey",
123 JOptionPane.YES_NO_OPTION,
124 JOptionPane.QUESTION_MESSAGE);
126 if (reply == JOptionPane.YES_OPTION)
128 jalview.bin.Cache.log.debug("Opening " + qurl);
129 jalview.util.BrowserLauncher.openURL(qurl);
135 jalview.bin.Cache.log.warn("When trying to access questionnaire URL " +