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.bin.Cache;
24 import jalview.bin.Console;
25 import jalview.util.MessageManager;
27 import java.io.BufferedReader;
28 import java.io.InputStreamReader;
31 import javax.swing.JOptionPane;
33 public class UserQuestionnaireCheck implements Runnable
36 * Implements the client side machinery for detecting a new questionnaire,
37 * checking if the user has responded to an existing one, and prompting the
38 * user for responding to a questionnaire. This is intended to work with the
39 * perl CGI scripts checkresponder.pl and questionnaire.pl
43 UserQuestionnaireCheck(String url)
45 if (url.indexOf("questionnaire.pl") == -1)
47 Console.error("'" + url
48 + "' is an Invalid URL for the checkForQuestionnaire() method.\n"
49 + "This argument is only for questionnaires derived from jalview's questionnaire.pl cgi interface.");
57 String qid = null, rid = null;
59 private boolean checkresponse(URL qurl) throws Exception
61 Console.debug("Checking Response for : " + qurl);
62 boolean prompt = false;
63 // see if we have already responsed to this questionnaire or get a new
65 BufferedReader br = new BufferedReader(
66 new InputStreamReader(qurl.openStream()));
68 while ((qresp = br.readLine()) != null)
70 if (qresp.indexOf("NOTYET:") == 0)
72 prompt = true; // not yet responded under that ID
76 if (qresp.indexOf("QUESTIONNAIRE:") == 0)
78 // QUESTIONNAIRE:qid:rid for the latest questionnaire.
79 int p = qresp.indexOf(':', 14);
83 qid = qresp.substring(14, p);
84 if (p < (qresp.length() - 1))
86 rid = qresp.substring(p + 1);
87 prompt = true; // this is a new qid/rid pair
102 boolean prompt = false;
105 // First - check to see if wee have an old questionnaire/response id pair.
106 String lastq = Cache.getProperty("QUESTIONNAIRE");
109 prompt = checkresponse(new URL(url
110 + (url.indexOf('?') > -1 ? "&" : "?") + "checkresponse=1"));
114 String qurl = url + (url.indexOf('?') > -1 ? "&" : "?")
116 // query the server with the old qid/id pair
117 String qqid = lastq.indexOf(':') > -1
118 ? lastq.substring(0, lastq.indexOf(':'))
120 if (qqid != null && qqid != "null" && qqid.length() > 0)
122 qurl += "&qid=" + qqid;
124 String qrid = lastq.substring(lastq.indexOf(':') + 1); // retrieve
126 if (qrid != null && !qrid.equals("null"))
129 qurl += "&rid=" + qrid;
132 // see if we have already responsed to this questionnaire.
133 prompt = checkresponse(new URL(qurl));
135 if (qid != null && rid != null)
137 // Update our local property cache with latest qid and rid
138 Cache.setProperty("QUESTIONNAIRE", qid + ":" + rid);
142 String qurl = url + (url.indexOf('?') > -1 ? "&" : "?") + "qid="
143 + qid + "&rid=" + rid;
144 Console.info("Prompting user for questionnaire at " + qurl);
145 int reply = JvOptionPane.showInternalConfirmDialog(Desktop.desktop,
146 MessageManager.getString("label.jalview_new_questionnaire"),
147 MessageManager.getString("label.jalview_user_survey"),
148 JvOptionPane.YES_NO_OPTION, JvOptionPane.QUESTION_MESSAGE);
150 if (reply == JvOptionPane.YES_OPTION)
152 Console.debug("Opening " + qurl);
153 jalview.util.BrowserLauncher.openURL(qurl);
156 } catch (Exception e)
158 Console.warn("When trying to access questionnaire URL " + url, e);