- public void run() {
- boolean prompt=false;
- try {
- if (url.indexOf("checkresponder.pl")==-1) {
- throw new Error("Invalid URL for the checkForQuestionnaire() method. The -questionnaire method is for Jalview user questionnaires only.");
- }
- // extract qid if there is one - else just get the latest
- String rid=null,qid=null;
- String args=null;
- String baseurl=null,surl=null;
- int t;
- if ((t=url.indexOf("?"))>-1) {
- args=url.substring(t+1);
- surl=url.substring(0,t);
- }
- if ((t=url.lastIndexOf('/'))>-1) {
- baseurl=url.substring(0,t+1);
- }
- if (args!=null && (t=args.indexOf("qid="))>-1) {
- int e = args.indexOf("&",t+4);
- if (e<0)
- qid=args.substring(t+4);
- else
- qid=args.substring(t+4,e);
- if (qid!=null && qid.length()==0)
- qid=null;
- }
-
- if (qid==null) {
- // get a new questionnaire
- URL qurl = new URL(url);
- BufferedReader br = new BufferedReader(new InputStreamReader(qurl.openStream()));
- String qresp=null;
- while ((qresp=br.readLine())!=null) {
- // check if response is of form we expect.
- if (qresp.indexOf(':')>-1) {
- rid=null;
- qid=qresp.substring(0,qresp.indexOf(':'));
- if (qresp.indexOf(':')<(qresp.length()-1)) {
- rid = qresp.substring(qresp.indexOf(':')+1);
- }
- }
- }
- } else {
- // retrieve an id for an existing questionnaire
- // get a new questionnaire
- URL qurl = new URL(url);
- BufferedReader br = new BufferedReader(new InputStreamReader(qurl.openStream()));
- String qresp=null;
- while ((qresp=br.readLine())!=null) {
- // check if response is of form we expect.
- if (qresp.indexOf(':')>-1) {
- rid=null;
- qid=qresp.substring(0,qresp.indexOf(':'));
- if (qresp.indexOf(':')<(qresp.length()-1)) {
- rid = qresp.substring(qresp.indexOf(':')+1);
- }
- }
- }