2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.util.MessageManager;
25 import java.io.BufferedReader;
26 import java.io.InputStreamReader;
29 import javax.swing.JOptionPane;
31 public class UserQuestionnaireCheck implements Runnable
34 * Implements the client side machinery for detecting a new questionnaire,
35 * checking if the user has responded to an existing one, and prompting the
36 * user for responding to a questionnaire. This is intended to work with the
37 * perl CGI scripts checkresponder.pl and questionnaire.pl
41 UserQuestionnaireCheck(String url)
43 if (url.indexOf("questionnaire.pl") == -1)
45 jalview.bin.Cache.log.error("'" + url
46 + "' is an Invalid URL for the checkForQuestionnaire() method.\n"
47 + "This argument is only for questionnaires derived from jalview's questionnaire.pl cgi interface.");
55 String qid = null, rid = null;
57 private boolean checkresponse(URL qurl) throws Exception
59 jalview.bin.Cache.log.debug("Checking Response for : " + qurl);
60 boolean prompt = false;
61 // see if we have already responsed to this questionnaire or get a new
63 BufferedReader br = new BufferedReader(
64 new InputStreamReader(qurl.openStream()));
66 while ((qresp = br.readLine()) != null)
68 if (qresp.indexOf("NOTYET:") == 0)
70 prompt = true; // not yet responded under that ID
74 if (qresp.indexOf("QUESTIONNAIRE:") == 0)
76 // QUESTIONNAIRE:qid:rid for the latest questionnaire.
77 int p = qresp.indexOf(':', 14);
81 qid = qresp.substring(14, p);
82 if (p < (qresp.length() - 1))
84 rid = qresp.substring(p + 1);
85 prompt = true; // this is a new qid/rid pair
100 boolean prompt = false;
103 // First - check to see if wee have an old questionnaire/response id pair.
104 String lastq = jalview.bin.Cache.getProperty("QUESTIONNAIRE");
107 prompt = checkresponse(new URL(url
108 + (url.indexOf('?') > -1 ? "&" : "?") + "checkresponse=1"));
112 String qurl = url + (url.indexOf('?') > -1 ? "&" : "?")
114 // query the server with the old qid/id pair
115 String qqid = lastq.indexOf(':') > -1
116 ? lastq.substring(0, lastq.indexOf(':'))
118 if (qqid != null && qqid != "null" && qqid.length() > 0)
120 qurl += "&qid=" + qqid;
122 String qrid = lastq.substring(lastq.indexOf(':') + 1); // retrieve
124 if (qrid != null && !qrid.equals("null"))
127 qurl += "&rid=" + qrid;
130 // see if we have already responsed to this questionnaire.
131 prompt = checkresponse(new URL(qurl));
133 if (qid != null && rid != null)
135 // Update our local property cache with latest qid and rid
136 jalview.bin.Cache.setProperty("QUESTIONNAIRE", qid + ":" + rid);
140 String qurl = url + (url.indexOf('?') > -1 ? "&" : "?") + "qid="
141 + qid + "&rid=" + rid;
142 jalview.bin.Cache.log
143 .info("Prompting user for questionnaire at " + qurl);
144 int reply = JvOptionPane.showInternalConfirmDialog(Desktop.desktop,
145 MessageManager.getString("label.jalview_new_questionnaire"),
146 MessageManager.getString("label.jalview_user_survey"),
147 JvOptionPane.YES_NO_OPTION, JvOptionPane.QUESTION_MESSAGE);
149 if (reply == JvOptionPane.YES_OPTION)
151 jalview.bin.Cache.log.debug("Opening " + qurl);
152 jalview.util.BrowserLauncher.openURL(qurl);
155 } catch (Exception e)
157 jalview.bin.Cache.log
158 .warn("When trying to access questionnaire URL " + url, e);