X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FGroupUrlLink.java;h=fccf3a4b80f348cc37a88afd880959709fa2d54f;hb=34e81d4c2a02e30ccbea5295e550137b57810f25;hp=ef32e998c9a665e4bec13f0f5e92c7a0b7e58f55;hpb=a124e525dece0edc422cd2f8888d03ea14f65f15;p=jalview.git diff --git a/src/jalview/util/GroupUrlLink.java b/src/jalview/util/GroupUrlLink.java index ef32e99..fccf3a4 100644 --- a/src/jalview/util/GroupUrlLink.java +++ b/src/jalview/util/GroupUrlLink.java @@ -1,5 +1,5 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5) + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6) * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle * * This file is part of Jalview. @@ -25,6 +25,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 +84,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 +365,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); @@ -380,6 +400,7 @@ public class GroupUrlLink } public Object[] makeUrls(Hashtable repstrings, boolean onlyIfMatches) + throws UrlStringTooLongException { return makeUrlsIf(true, repstrings, onlyIfMatches); } @@ -391,9 +412,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 +435,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 +456,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; @@ -528,6 +554,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 +685,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) { @@ -824,13 +854,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 {