2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 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 implements Runnable
29 * Implements the client side machinery for detecting a new questionnaire,
30 * checking if the user has responded to an existing one, and prompting the
31 * user for responding to a questionnaire. This is intended to work with the
32 * perl CGI scripts checkresponder.pl and questionnaire.pl
36 UserQuestionnaireCheck(String url)
38 if (url.indexOf("questionnaire.pl") == -1)
43 + "' is an Invalid URL for the checkForQuestionnaire() method.\n"
44 + "This argument is only for questionnaires derived from jalview's questionnaire.pl cgi interface.");
52 String qid = null, rid = null;
54 private boolean checkresponse(URL qurl) throws Exception
56 jalview.bin.Cache.log.debug("Checking Response for : " + qurl);
57 boolean prompt = false;
58 // see if we have already responsed to this questionnaire or get a new
60 BufferedReader br = new BufferedReader(new InputStreamReader(qurl
63 while ((qresp = br.readLine()) != null)
65 if (qresp.indexOf("NOTYET:") == 0)
67 prompt = true; // not yet responded under that ID
71 if (qresp.indexOf("QUESTIONNAIRE:") == 0)
73 // QUESTIONNAIRE:qid:rid for the latest questionnaire.
74 int p = qresp.indexOf(':', 14);
78 qid = qresp.substring(14, p);
79 if (p < (qresp.length() - 1))
81 rid = qresp.substring(p + 1);
82 prompt = true; // this is a new qid/rid pair
97 boolean prompt = false;
100 // First - check to see if wee have an old questionnaire/response id pair.
101 String lastq = jalview.bin.Cache.getProperty("QUESTIONNAIRE");
104 prompt = checkresponse(new URL(url
105 + (url.indexOf('?') > -1 ? "&" : "?") + "checkresponse=1"));
109 String qurl = url + (url.indexOf('?') > -1 ? "&" : "?")
111 // query the server with the old qid/id pair
112 String qqid = lastq.indexOf(':') > -1 ? lastq.substring(0, lastq
113 .indexOf(':')) : null;
114 if (qqid != null && qqid != "null" && qqid.length() > 0)
116 qurl += "&qid=" + qqid;
118 String qrid = lastq.substring(lastq.indexOf(':') + 1); // retrieve
120 if (qrid != null && !qrid.equals("null"))
123 qurl += "&rid=" + qrid;
126 // see if we have already responsed to this questionnaire.
127 prompt = checkresponse(new URL(qurl));
129 if (qid != null && rid != null)
131 // Update our local property cache with latest qid and rid
132 jalview.bin.Cache.setProperty("QUESTIONNAIRE", qid + ":" + rid);
136 String qurl = url + (url.indexOf('?') > -1 ? "&" : "?") + "qid="
137 + qid + "&rid=" + rid;
138 jalview.bin.Cache.log.info("Prompting user for questionnaire at "
140 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
141 "There is a new Questionnaire available."
142 + "Would you like to complete it now ?\n",
143 "Jalview User Survey", JOptionPane.YES_NO_OPTION,
144 JOptionPane.QUESTION_MESSAGE);
146 if (reply == JOptionPane.YES_OPTION)
148 jalview.bin.Cache.log.debug("Opening " + qurl);
149 jalview.util.BrowserLauncher.openURL(qurl);
152 } catch (Exception e)
154 jalview.bin.Cache.log.warn("When trying to access questionnaire URL "