- ptok[ntoks] = link.length();
- tmtch[ntoks] = "$$$$$$$$$";
- jalview.util.QuickSort.sort(ptok, tmtch);
- for (int i = 0; i < ntoks; i++)
- {
- mtch[i] = tmtch[i]; // TODO: check order is ascending
- }
- /*
- * replaces the specific code below {}; if (psqids > -1 && pseqs > -1) { if
- * (psqids > pseqs) { idseg = 1; seqseg = 0;
- *
- * ptok = new int[] { pseqs, psqids, link.length() }; mtch = new String[] {
- * "$SEQUENCES", "$SEQUENCEIDS" }; } else { idseg = 0; seqseg = 1; ptok =
- * new int[] { psqids, pseqs, link.length() }; mtch = new String[] {
- * "$SEQUENCEIDS", "$SEQUENCES" }; } } else { if (psqids != -1) { idseg = 0;
- * ptok = new int[] { psqids, link.length() }; mtch = new String[] {
- * "$SEQUENCEIDS" }; } else { seqseg = 0; ptok = new int[] { pseqs,
- * link.length() }; mtch = new String[] { "$SEQUENCES" }; } }
- */
-
- int p = sep;
- // first get the label and target part before the first |
- do
- {
- sep = p;
- p = link.indexOf("|", sep + 1);
- } while (p > sep && p < ptok[0]);
- // Assuming that the URL itself does not contain any '|' symbols
- // sep now contains last pipe symbol position prior to any regex symbols
- label = link.substring(0, sep);
- if (label.indexOf("|") > -1)
- {
- // | terminated database name / www target at start of Label
- target = label.substring(0, label.indexOf("|"));
- }
- else if (label.indexOf(" ") > 2)
- {
- // space separated Label - matches database name
- target = label.substring(0, label.indexOf(" "));
- }
- else
- {
- target = label;
- }
- // Now Parse URL : Whole URL string first
- url_prefix = link.substring(sep + 1, ptok[0]);
- url_suffix = new String[mtch.length];
- regexReplace = new String[mtch.length];
- // and loop through tokens
- 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)
- {
- // Extract Regex and suffix
- if (ptok[pass + 1] < p + 3)
- {
- // tokens are not allowed inside other tokens - e.g. inserting a
- // $sequences$ into the regex match for the sequenceid
- invalidMessage = "Token regexes cannot contain other regexes (did you terminate the $"
- + mtch[pass] + " regex with a '/=$' ?";
- return;
- }
- url_suffix[pass] = link.substring(p + 3, ptok[pass + 1]);
- regexReplace[pass] = link.substring(ptok[pass] + mlength, p);
- try
- {
- com.stevesoft.pat.Regex rg = com.stevesoft.pat.Regex.perlCode("/"
- + regexReplace[pass] + "/");
- if (rg == null)
- {
- invalidMessage = "Invalid Regular Expression : '"
- + regexReplace[pass] + "'\n";
- }
- } catch (Exception e)
- {
- invalidMessage = "Invalid Regular Expression : '"
- + regexReplace[pass] + "'\n";
- }
- }
- else
- {
- regexReplace[pass] = null;
- // verify format is really correct.
- if ((p = link.indexOf("$" + mtch[pass] + "$")) == ptok[pass])
- {
- url_suffix[pass] = link.substring(p + mtch[pass].length() + 2,
- ptok[pass + 1]);
- }
- else
- {
- invalidMessage = "Warning: invalid regex structure (after '"
- + mtch[0] + "') for URL link : " + link;
- }
- }
- }
- int pass = 0;
- separators = new String[url_suffix.length];
- String suffices = url_suffix[url_suffix.length - 1], lastsep = ",";
- // have a look in the last suffix for any more separators.
- while ((p = suffices.indexOf('|')) > -1)
- {
- separators[pass] = suffices.substring(p + 1);
- if (pass == 0)
- {
- // trim the original suffix string
- url_suffix[url_suffix.length - 1] = suffices.substring(0, p);
- }
- else
- {
- lastsep = (separators[pass - 1] = separators[pass - 1].substring(0,
- p));
- }
- suffices = separators[pass];
- pass++;
- }
- if (pass > 0)
- {
- lastsep = separators[pass - 1];
- }
- // last separator is always used for all the remaining separators
- while (pass < separators.length)
- {
- separators[pass++] = lastsep;
- }
- }
-
- /**
- * @return the url_suffix
- */
- public String getUrl_suffix()
- {
- return url_suffix[url_suffix.length - 1];