From 4e7a3bfd7279669b9040c5265a9c4c4fc4ff1baa Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 2 Apr 2010 10:33:54 +0000 Subject: [PATCH] urllength limit and more efficient url construction --- src/jalview/util/GroupUrlLink.java | 39 ++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/jalview/util/GroupUrlLink.java b/src/jalview/util/GroupUrlLink.java index 55e3bd9..0401bb2 100644 --- a/src/jalview/util/GroupUrlLink.java +++ b/src/jalview/util/GroupUrlLink.java @@ -410,6 +410,8 @@ public class GroupUrlLink */ protected Object[] makeUrlsIf(boolean createFullUrl, Hashtable repstrings, boolean onlyIfMatches) { + int pass = 0; + // prepare string arrays in correct order to be assembled into URL input String[][] idseq = new String[mtch.length][]; // indexed by pass int mins = 0, maxs = 0; // allowed two values, 1 or n-sequences. @@ -444,7 +446,6 @@ public class GroupUrlLink "Cannot have zero length vector of replacement strings - either 1 value or n values."); } } - int pass = 0; // iterate through input, collating segments to be inserted into url StringBuffer matched[] = new StringBuffer[idseq.length]; // and precompile regexes @@ -462,7 +463,14 @@ public class GroupUrlLink rgxs[pass] = null; } } - // record which of the input sequences were actually used to generate the + // tot up the invariant lengths for this url + int urllength = url_prefix.length(); + for (pass=0;pass -1) { - rmtch += rg.stringMatched(r); + rmtch.append(rg.stringMatched(r)); } r++; } @@ -557,7 +566,7 @@ public class GroupUrlLink s++; } } - thematches[pass] += subs.toString(); + thematches[pass].append(subs); } } } @@ -567,9 +576,10 @@ public class GroupUrlLink if (!onlyIfMatches) { thismatched[sq] |= true; + urllength+=idseq[pass][sq].length(); // tot up length if (createFullUrl) { - thematches[pass] = idseq[pass][sq]; // take whole string - + thematches[pass] = new StringBuffer(idseq[pass][sq]); // take whole string - // regardless - probably not a // good idea! /* @@ -609,6 +619,12 @@ public class GroupUrlLink // no matches - no url generated return null; } + // check if we are beyond the feasible command line string limit for this platform + if ((urllength+32)>Platform.getMaxCommandLineLength()) + { + System.err.println("URL estimated to be too long "+urllength); + return null; + } if (!createFullUrl) { // just return the essential info about what the URL would be generated from @@ -617,6 +633,7 @@ public class GroupUrlLink { seqsmatched }, thismatched}; } // otherwise, create the URL completely. + StringBuffer submiturl = new StringBuffer(); submiturl.append(url_prefix); for (pass = 0; pass < matched.length; pass++) -- 1.7.10.2