X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FGroupUrlLink.java;h=4900fc8fca3a2c625d61506c8438d825d7c30390;hb=2fc1013d3c126983a8d7d932671168e11cfab63d;hp=ef32e998c9a665e4bec13f0f5e92c7a0b7e58f55;hpb=a124e525dece0edc422cd2f8888d03ea14f65f15;p=jalview.git diff --git a/src/jalview/util/GroupUrlLink.java b/src/jalview/util/GroupUrlLink.java index ef32e99..4900fc8 100644 --- a/src/jalview/util/GroupUrlLink.java +++ b/src/jalview/util/GroupUrlLink.java @@ -1,19 +1,22 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5) - * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * * Jalview is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * * Jalview is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along with Jalview. If not, see . + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.util; @@ -25,6 +28,21 @@ import java.util.Vector; public class GroupUrlLink { + public class UrlStringTooLongException extends Exception + { + public UrlStringTooLongException(int lng) + { + urlLength = lng; + } + + public int urlLength; + + public String toString() + { + return "Generated url is estimated to be too long (" + urlLength + + ")"; + } + } /** * Helper class based on the UrlLink class which enables URLs to be @@ -69,14 +87,17 @@ public class GroupUrlLink { "SEQUENCEIDS", "SEQUENCES", "DATASETID" }; } } + /** * test for GroupURLType bitfield (with default tokens) */ public static final int SEQUENCEIDS = 1; + /** * test for GroupURLType bitfield (with default tokens) */ public static final int SEQUENCES = 2; + /** * test for GroupURLType bitfield (with default tokens) */ @@ -347,9 +368,11 @@ public class GroupUrlLink * @return null or Object[] { int[] { number of seqs substituted},boolean[] { * which seqs were substituted }, StringBuffer[] { substituted lists * for each token }, String[] { url } } + * @throws UrlStringTooLongException */ public Object[] makeUrls(String[] idstrings, String[] seqstrings, String dsstring, boolean onlyIfMatches) + throws UrlStringTooLongException { Hashtable rstrings = replacementArgs(idstrings, seqstrings, dsstring); return makeUrls(rstrings, onlyIfMatches); @@ -373,13 +396,13 @@ public class GroupUrlLink { dsstring }); if (idstrings.length != seqstrings.length) { - throw new Error( - "idstrings and seqstrings contain one string each per sequence."); + throw new Error(MessageManager.getString("error.idstring_seqstrings_only_one_per_sequence")); } return rstrings; } public Object[] makeUrls(Hashtable repstrings, boolean onlyIfMatches) + throws UrlStringTooLongException { return makeUrlsIf(true, repstrings, onlyIfMatches); } @@ -391,9 +414,10 @@ public class GroupUrlLink * @param string * @param b * @return URL stub objects ready to pass to constructFrom + * @throws UrlStringTooLongException */ public Object[] makeUrlStubs(String[] ids, String[] seqstr, - String string, boolean b) + String string, boolean b) throws UrlStringTooLongException { Hashtable rstrings = replacementArgs(ids, seqstr, string); Object[] stubs = makeUrlsIf(false, rstrings, b); @@ -413,8 +437,10 @@ public class GroupUrlLink * * @param stubs * @return URL string. + * @throws UrlStringTooLongException */ public String constructFrom(Object[] stubs) + throws UrlStringTooLongException { Object[] results = makeUrlsIf(true, (Hashtable) stubs[2], ((boolean[]) stubs[3])[0]); @@ -432,9 +458,11 @@ public class GroupUrlLink * seqs }, boolean[] { which matched }, (if createFullUrl also has * StringBuffer[] { segment generated from inputs that is used in URL * }, String[] { url })} + * @throws UrlStringTooLongException */ protected Object[] makeUrlsIf(boolean createFullUrl, Hashtable repstrings, boolean onlyIfMatches) + throws UrlStringTooLongException { int pass = 0; @@ -458,18 +486,14 @@ public class GroupUrlLink { if (maxs != idseq[i].length) { - throw new Error( - "Cannot have mixed length replacement vectors. Replacement vector for " - + (mtch[i]) + " is " + idseq[i].length - + " strings long, and have already seen a " - + maxs + " length vector."); + 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( - "Cannot have zero length vector of replacement strings - either 1 value or n values."); + throw new Error(MessageManager.getString("error.cannot_have_zero_length_vector_replacement_strings")); } } // iterate through input, collating segments to be inserted into url @@ -528,6 +552,11 @@ public class GroupUrlLink rematchat = rg.matchedTo(); thismatched[sq] |= true; urllength += rg.charsMatched(); // count length + if ((urllength + 32) > Platform.getMaxCommandLineLength()) + { + throw new UrlStringTooLongException(urllength); + } + if (!createFullUrl) { continue; // don't bother making the URL replacement text. @@ -654,8 +683,7 @@ public class GroupUrlLink // platform if ((urllength + 32) > Platform.getMaxCommandLineLength()) { - System.err.println("URL estimated to be too long " + urllength); - return null; + throw new UrlStringTooLongException(urllength); } if (!createFullUrl) { @@ -788,6 +816,7 @@ public class GroupUrlLink public static void main(String argv[]) { + // note - JAL-1383 - these services are all dead 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|,", @@ -824,13 +853,27 @@ public class GroupUrlLink System.out .println(" Without onlyIfMatches:"); - Object[] urls = ul.makeUrls(seqsandids[0], seqsandids[1], - "mydataset", false); - testUrls(ul, seqsandids, urls); + Object[] urls; + try + { + urls = ul.makeUrls(seqsandids[0], seqsandids[1], "mydataset", + false); + testUrls(ul, seqsandids, urls); + } catch (UrlStringTooLongException ex) + { + System.out.println("too long exception " + ex); + } System.out .println(" With onlyIfMatches set:"); - urls = ul.makeUrls(seqsandids[0], seqsandids[1], "mydataset", true); - testUrls(ul, seqsandids, urls); + try + { + urls = ul.makeUrls(seqsandids[0], seqsandids[1], "mydataset", + true); + testUrls(ul, seqsandids, urls); + } catch (UrlStringTooLongException ex) + { + System.out.println("too long exception " + ex); + } } else {