- thematches[pass] = new StringBuffer(); // initialise - in case there are
- // no more
- // matches.
- // if a regex is provided, then it must match for all sequences in all
- // tokens for it to be considered.
- if (idseq[pass].length <= sq)
- {
- // no more replacement strings to try for this token
- continue;
- }
- if (rgxs[pass] != null)
- {
- com.stevesoft.pat.Regex rg = rgxs[pass];
- int rematchat = 0;
- // concatenate all matches of re in the given string!
- while (rg.searchFrom(idseq[pass][sq], rematchat))
- {
- rematchat = rg.matchedTo();
- thismatched[sq] |= true;
- urllength += rg.charsMatched(); // count length
- if ((urllength + 32) > Platform.getMaxCommandLineLength())
- {
- throw new Exception("urllength");
- }
-
- if (!createFullUrl)
- {
- continue; // don't bother making the URL replacement text.
- }
- // do we take the cartesian products of the substituents ?
- int ns = rg.numSubs();
- if (ns == 0)
- {
- thematches[pass].append(rg.stringMatched());// take whole regex
- }
- /*
- * else if (ns==1) { // take only subgroup match return new String[]
- * { rg.stringMatched(1), url_prefix+rg.stringMatched(1)+url_suffix
- * }; }
- */
- // deal with multiple submatch case - for moment we do the simplest
- // - concatenate the matched regions, instead of creating a complete
- // list for each alternate match over all sequences.
- // TODO: specify a 'replace pattern' - next refinement
- else
- {
- // debug
- /*
- * for (int s = 0; s <= rg.numSubs(); s++) {
- * System.err.println("Sub " + s + " : " + rg.matchedFrom(s) +
- * " : " + rg.matchedTo(s) + " : '" + rg.stringMatched(s) + "'");
- * }
- */
- // try to collate subgroup matches
- StringBuffer subs = new StringBuffer();
- // have to loop through submatches, collating them at top level
- // match
- int s = 0; // 1;
- while (s <= ns)
- {
- if (s + 1 <= ns && rg.matchedTo(s) > -1
- && rg.matchedTo(s + 1) > -1
- && rg.matchedTo(s + 1) < rg.matchedTo(s))
- {
- // s is top level submatch. search for submatches enclosed by
- // this one
- int r = s + 1;
- StringBuffer rmtch = new StringBuffer();
- while (r <= ns && rg.matchedTo(r) <= rg.matchedTo(s))
- {
- if (rg.matchedFrom(r) > -1)
- {
- rmtch.append(rg.stringMatched(r));
- }
- r++;
- }
- if (rmtch.length() > 0)
- {
- subs.append(rmtch); // simply concatenate
- }
- s = r;
- }
- else
- {
- if (rg.matchedFrom(s) > -1)
- {
- subs.append(rg.stringMatched(s)); // concatenate
- }
- s++;
- }
- }
- thematches[pass].append(subs);
- }
- }
- }
- else
- {
- // are we only supposed to take regex matches ?
- if (!onlyIfMatches)
- {
- thismatched[sq] |= true;
- urllength += idseq[pass][sq].length(); // tot up length
- if (createFullUrl)
- {
- thematches[pass] = new StringBuffer(idseq[pass][sq]); // take
- // whole
- // string -
- // regardless - probably not a
- // good idea!
- /*
- * TODO: do some boilerplate trimming of the fields to make them
- * sensible e.g. trim off any 'prefix' in the id string (see
- * UrlLink for the below) - pre 2.4 Jalview behaviour if
- * (idstring.indexOf("|") > -1) { idstring =
- * idstring.substring(idstring.lastIndexOf("|") + 1); }
- */
- }
-
- }
- }
- }
-
- // check if we are going to add this sequence's results ? all token
- // replacements must be valid for this to happen!
- // (including single value replacements - eg. dataset name)
- if (thismatched[sq])