2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 public class UserQuestionnaireCheck
30 * Implements the client side machinery for detecting a new questionnaire,
31 * checking if the user has responded to an existing one,
32 * and prompting the user for responding to a questionnaire.
33 * This is intended to work with the perl CGI scripts checkresponder.pl and
37 UserQuestionnaireCheck(String url)
39 if (url.indexOf("questionnaire.pl") == -1)
41 jalview.bin.Cache.log.error("'" + url +
42 "' is an Invalid URL for the checkForQuestionnaire() method.\n"
43 + "This argument is only for questionnaires derived from jalview's questionnaire.pl cgi interface.");
51 String qid = null, rid = null;
52 private boolean checkresponse(URL qurl)
55 jalview.bin.Cache.log.debug("Checking Response for : " + qurl);
56 boolean prompt = false;
57 // see if we have already responsed to this questionnaire or get a new qid/rid pair
58 BufferedReader br = new BufferedReader(new InputStreamReader(qurl.
61 while ( (qresp = br.readLine()) != null)
63 if (qresp.indexOf("NOTYET:") == 0)
65 prompt = true; // not yet responded under that ID
69 if (qresp.indexOf("QUESTIONNAIRE:") == 0)
71 // QUESTIONNAIRE:qid:rid for the latest questionnaire.
72 int p = qresp.indexOf(':', 14);
76 qid = qresp.substring(14, p);
77 if (p < (qresp.length() - 1))
79 rid = qresp.substring(p + 1);
80 prompt = true; // this is a new qid/rid pair
95 boolean prompt = false;
98 // First - check to see if wee have an old questionnaire/response id pair.
99 String lastq = jalview.bin.Cache.getProperty("QUESTIONNAIRE");
102 prompt = checkresponse(new URL(url + (url.indexOf('?') > -1 ? "&" : "?") +
107 String qurl = url + (url.indexOf('?') > -1 ? "&" : "?") +
109 // query the server with the old qid/id pair
110 String qqid = lastq.indexOf(':') > -1 ?
111 lastq.substring(0, lastq.indexOf(':')) : null;
112 if (qqid != null && qqid != "null" && qqid.length() > 0)
114 qurl += "&qid=" + qqid;
116 String qrid = lastq.substring(lastq.indexOf(':') + 1); // retrieve old rid
117 if (qrid != null && !qrid.equals("null"))
120 qurl += "&rid=" + qrid;
123 // see if we have already responsed to this questionnaire.
124 prompt = checkresponse(new URL(qurl));
126 if (qid != null && rid != null)
128 // Update our local property cache with latest qid and rid
129 jalview.bin.Cache.setProperty("QUESTIONNAIRE", qid + ":" + rid);
133 String qurl = url + (url.indexOf('?') > -1 ? "&" : "?") + "qid=" + qid +
135 jalview.bin.Cache.log.info("Prompting user for questionnaire at " +
137 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
138 "There is a new Questionnaire available." +
139 "Would you like to complete it now ?\n",
140 "Jalview User Survey",
141 JOptionPane.YES_NO_OPTION,
142 JOptionPane.QUESTION_MESSAGE);
144 if (reply == JOptionPane.YES_OPTION)
146 jalview.bin.Cache.log.debug("Opening " + qurl);
147 jalview.util.BrowserLauncher.openURL(qurl);
153 jalview.bin.Cache.log.warn("When trying to access questionnaire URL " +