X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FGroupUrlLink.java;h=af0b3083e0c039d77bcfccefa61988fb9ec30fb5;hb=HEAD;hp=4900fc8fca3a2c625d61506c8438d825d7c30390;hpb=ad15cff29620f960119f80176f1fd443da9f6763;p=jalview.git diff --git a/src/jalview/util/GroupUrlLink.java b/src/jalview/util/GroupUrlLink.java index 4900fc8..af0b308 100644 --- a/src/jalview/util/GroupUrlLink.java +++ b/src/jalview/util/GroupUrlLink.java @@ -24,7 +24,6 @@ import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; import java.util.Hashtable; -import java.util.Vector; public class GroupUrlLink { @@ -37,6 +36,7 @@ public class GroupUrlLink public int urlLength; + @Override public String toString() { return "Generated url is estimated to be too long (" + urlLength @@ -83,8 +83,7 @@ public class GroupUrlLink { if (tokens == null) { - tokens = new String[] - { "SEQUENCEIDS", "SEQUENCES", "DATASETID" }; + tokens = new String[] { "SEQUENCEIDS", "SEQUENCES", "DATASETID" }; } } @@ -200,9 +199,8 @@ public class GroupUrlLink for (int pass = 0; pass < mtch.length; pass++) { int mlength = 3 + mtch[pass].length(); - if (link.indexOf("$" + mtch[pass] + "=/") == ptok[pass] - && (p = link.indexOf("/=$", ptok[pass] + mlength)) > ptok[pass] - + mlength) + if (link.indexOf("$" + mtch[pass] + "=/") == ptok[pass] && (p = link + .indexOf("/=$", ptok[pass] + mlength)) > ptok[pass] + mlength) { // Extract Regex and suffix if (ptok[pass + 1] < p + 3) @@ -217,8 +215,8 @@ public class GroupUrlLink regexReplace[pass] = link.substring(ptok[pass] + mlength, p); try { - com.stevesoft.pat.Regex rg = com.stevesoft.pat.Regex.perlCode("/" - + regexReplace[pass] + "/"); + com.stevesoft.pat.Regex rg = com.stevesoft.pat.Regex + .perlCode("/" + regexReplace[pass] + "/"); if (rg == null) { invalidMessage = "Invalid Regular Expression : '" @@ -320,10 +318,12 @@ public class GroupUrlLink private String _replaceFor(String token) { for (int i = 0; i < mtch.length; i++) + { if (segs[i] > -1 && mtch[i].equals(token)) { return regexReplace[i]; } + } return null; } @@ -386,17 +386,17 @@ public class GroupUrlLink * @param dsstring * @return */ - private Hashtable replacementArgs(String[] idstrings, - String[] seqstrings, String dsstring) + private Hashtable replacementArgs(String[] idstrings, String[] seqstrings, + String dsstring) { Hashtable rstrings = new Hashtable(); rstrings.put(tokens[0], idstrings); rstrings.put(tokens[1], seqstrings); - rstrings.put(tokens[2], new String[] - { dsstring }); + rstrings.put(tokens[2], new String[] { dsstring }); if (idstrings.length != seqstrings.length) { - throw new Error(MessageManager.getString("error.idstring_seqstrings_only_one_per_sequence")); + throw new Error(MessageManager.getString( + "error.idstring_seqstrings_only_one_per_sequence")); } return rstrings; } @@ -416,16 +416,16 @@ public class GroupUrlLink * @return URL stub objects ready to pass to constructFrom * @throws UrlStringTooLongException */ - public Object[] makeUrlStubs(String[] ids, String[] seqstr, - String string, boolean b) throws UrlStringTooLongException + public Object[] makeUrlStubs(String[] ids, String[] seqstr, String string, + boolean b) throws UrlStringTooLongException { Hashtable rstrings = replacementArgs(ids, seqstr, string); Object[] stubs = makeUrlsIf(false, rstrings, b); if (stubs != null) { - return new Object[] - { stubs[0], stubs[1], rstrings, new boolean[] - { b } }; + return new Object[] { stubs[0], stubs[1], rstrings, + new boolean[] + { b } }; } // TODO Auto-generated method stub return null; @@ -460,9 +460,8 @@ public class GroupUrlLink * }, String[] { url })} * @throws UrlStringTooLongException */ - protected Object[] makeUrlsIf(boolean createFullUrl, - Hashtable repstrings, boolean onlyIfMatches) - throws UrlStringTooLongException + protected Object[] makeUrlsIf(boolean createFullUrl, Hashtable repstrings, + boolean onlyIfMatches) throws UrlStringTooLongException { int pass = 0; @@ -486,14 +485,19 @@ public class GroupUrlLink { if (maxs != idseq[i].length) { - throw new Error(MessageManager.formatMessage("error.cannot_have_mixed_length_replacement_vectors", - new String[]{(mtch[i]), Integer.valueOf(idseq[i].length).toString(),Integer.valueOf(maxs).toString()})); + throw new Error(MessageManager.formatMessage( + "error.cannot_have_mixed_length_replacement_vectors", + new String[] + { (mtch[i]), + Integer.valueOf(idseq[i].length).toString(), + Integer.valueOf(maxs).toString() })); } } } else { - throw new Error(MessageManager.getString("error.cannot_have_zero_length_vector_replacement_strings")); + throw new Error(MessageManager.getString( + "error.cannot_have_zero_length_vector_replacement_strings")); } } // iterate through input, collating segments to be inserted into url @@ -505,8 +509,8 @@ public class GroupUrlLink matched[pass] = new StringBuffer(); if (regexReplace[pass] != null) { - rgxs[pass] = com.stevesoft.pat.Regex.perlCode("/" - + regexReplace[pass] + "/"); + rgxs[pass] = com.stevesoft.pat.Regex + .perlCode("/" + regexReplace[pass] + "/"); } else { @@ -581,7 +585,7 @@ public class GroupUrlLink // debug /* * for (int s = 0; s <= rg.numSubs(); s++) { - * System.err.println("Sub " + s + " : " + rg.matchedFrom(s) + + * jalview.bin.Console.errPrintln("Sub " + s + " : " + rg.matchedFrom(s) + * " : " + rg.matchedTo(s) + " : '" + rg.stringMatched(s) + "'"); * } */ @@ -689,9 +693,7 @@ public class GroupUrlLink { // just return the essential info about what the URL would be generated // from - return new Object[] - { new int[] - { seqsmatched }, thismatched }; + return new Object[] { new int[] { seqsmatched }, thismatched }; } // otherwise, create the URL completely. @@ -706,10 +708,9 @@ public class GroupUrlLink } } - return new Object[] - { new int[] - { seqsmatched }, thismatched, matched, new String[] - { submiturl.toString() } }; + return new Object[] { new int[] { seqsmatched }, thismatched, matched, + new String[] + { submiturl.toString() } }; } /** @@ -746,6 +747,7 @@ public class GroupUrlLink return r; } + @Override public String toString() { StringBuffer result = new StringBuffer(); @@ -785,40 +787,45 @@ public class GroupUrlLink if (url == null) { - System.out.println("Created NO urls."); + jalview.bin.Console.outPrintln("Created NO urls."); } else { - System.out.println("Created a url from " + ((int[]) url[0])[0] - + "out of " + idstring[0].length + " sequences."); - System.out.println("Sequences that did not match:"); + jalview.bin.Console + .outPrintln("Created a url from " + ((int[]) url[0])[0] + + "out of " + idstring[0].length + " sequences."); + jalview.bin.Console.outPrintln("Sequences that did not match:"); for (int sq = 0; sq < idstring[0].length; sq++) { if (!((boolean[]) url[1])[sq]) { - System.out.println("Seq " + sq + ": " + idstring[0][sq] + "\t: " - + idstring[1][sq]); + jalview.bin.Console.outPrintln("Seq " + sq + ": " + + idstring[0][sq] + "\t: " + idstring[1][sq]); } } - System.out.println("Sequences that DID match:"); + jalview.bin.Console.outPrintln("Sequences that DID match:"); for (int sq = 0; sq < idstring[0].length; sq++) { if (((boolean[]) url[1])[sq]) { - System.out.println("Seq " + sq + ": " + idstring[0][sq] + "\t: " - + idstring[1][sq]); + jalview.bin.Console.outPrintln("Seq " + sq + ": " + + idstring[0][sq] + "\t: " + idstring[1][sq]); } } - System.out.println("The generated URL:"); - System.out.println(((String[]) url[3])[0]); + jalview.bin.Console.outPrintln("The generated URL:"); + jalview.bin.Console.outPrintln(((String[]) url[3])[0]); } } + /** + * + * @param argv + * @j2sIgnore + */ public static void main(String argv[]) { // note - JAL-1383 - these services are all dead - String[] links = new String[] - { + String[] links = new String[] { "EnVision2|IDS|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=Enfin%20Default%20Workflow&datasetName=linkInDatasetFromJalview&input=$SEQUENCEIDS$&inputType=0|,", "EnVision2|Seqs|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=Enfin%20Default%20Workflow&datasetName=linkInDatasetFromJalview&input=$SEQUENCES$&inputType=1|,", "EnVision2|IDS|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=Enfin%20Default%20Workflow&datasetName=$DATASETID$&input=$SEQUENCEIDS$&inputType=0|,", @@ -827,32 +834,34 @@ public class GroupUrlLink "EnVision2|Seqs|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=$SEQUENCEIDS$&datasetName=$DATASETID$&input=$SEQUENCES$&inputType=1|,", "EnVision2 Seqs|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=Default&datasetName=JalviewSeqs$DATASETID$&input=$SEQUENCES=/([a-zA-Z]+)/=$&inputType=1|,", "EnVision2 Seqs|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=Default&datasetName=JalviewSeqs$DATASETID$&input=$SEQUENCES=/[A-Za-z]+/=$&inputType=1|," - /* - * http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?input=P38389,P38398 - * &inputType=0&workflow=Enfin%20Default%20Workflow&datasetName= - * linkInDatasetFromPRIDE - */ + /* + * http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?input=P38389,P38398 + * &inputType=0&workflow=Enfin%20Default%20Workflow&datasetName= + * linkInDatasetFromPRIDE + */ }; - SequenceI[] seqs = new SequenceI[] - { new Sequence("StupidLabel:gi|9234|pdb|102L|A", - "asdiasdpasdpadpwpadasdpaspdw"), }; + SequenceI[] seqs = new SequenceI[] { + new Sequence("StupidLabel:gi|9234|pdb|102L|A", + "asdiasdpasdpadpwpadasdpaspdw"), }; String[][] seqsandids = formStrings(seqs); for (int i = 0; i < links.length; i++) { GroupUrlLink ul = new GroupUrlLink(links[i]); if (ul.isValid()) { - System.out.println("\n\n\n"); - System.out.println("Link " + i + " " + links[i] + " : " - + ul.toString()); - System.out.println(" pref : " + ul.getUrl_prefix()); - System.out.println(" IdReplace : " + ul.getIDRegexReplace()); - System.out.println(" SeqReplace : " + ul.getSeqRegexReplace()); - System.out.println(" Suffixes : " + ul.getUrl_suffix()); - - System.out - .println(" Without onlyIfMatches:"); + jalview.bin.Console.outPrintln("\n\n\n"); + jalview.bin.Console.outPrintln( + "Link " + i + " " + links[i] + " : " + ul.toString()); + jalview.bin.Console.outPrintln(" pref : " + ul.getUrl_prefix()); + jalview.bin.Console + .outPrintln(" IdReplace : " + ul.getIDRegexReplace()); + jalview.bin.Console + .outPrintln(" SeqReplace : " + ul.getSeqRegexReplace()); + jalview.bin.Console.outPrintln(" Suffixes : " + ul.getUrl_suffix()); + + jalview.bin.Console.outPrintln( + " Without onlyIfMatches:"); Object[] urls; try { @@ -861,10 +870,10 @@ public class GroupUrlLink testUrls(ul, seqsandids, urls); } catch (UrlStringTooLongException ex) { - System.out.println("too long exception " + ex); + jalview.bin.Console.outPrintln("too long exception " + ex); } - System.out - .println(" With onlyIfMatches set:"); + jalview.bin.Console.outPrintln( + " With onlyIfMatches set:"); try { urls = ul.makeUrls(seqsandids[0], seqsandids[1], "mydataset", @@ -872,13 +881,13 @@ public class GroupUrlLink testUrls(ul, seqsandids, urls); } catch (UrlStringTooLongException ex) { - System.out.println("too long exception " + ex); + jalview.bin.Console.outPrintln("too long exception " + ex); } } else { - System.err.println("Invalid URLLink : " + links[i] + " : " - + ul.getInvalidMessage()); + jalview.bin.Console.errPrintln("Invalid URLLink : " + links[i] + + " : " + ul.getInvalidMessage()); } } }