1 Clazz.declarePackage ("jalview.util");
\r
2 Clazz.load (["java.lang.Exception"], "jalview.util.GroupUrlLink", ["jalview.jsdev.RegExp", "jalview.util.MessageManager", "$.Platform", "$.QuickSort", "java.lang.Error", "$.StringBuffer", "java.util.Hashtable"], function () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
4 if (!Clazz.isClassDefined ("jalview.util.GroupUrlLink.UrlStringTooLongException")) {
\r
5 jalview.util.GroupUrlLink.$GroupUrlLink$UrlStringTooLongException$ ();
\r
7 this.url_prefix = null;
\r
10 this.url_suffix = null;
\r
11 this.separators = null;
\r
12 this.regexReplace = null;
\r
13 this.invalidMessage = null;
\r
16 Clazz.instantialize (this, arguments);
\r
17 }, jalview.util, "GroupUrlLink");
\r
18 Clazz.makeConstructor (c$,
\r
20 var sep = link.indexOf ("|");
\r
21 this.segs = Clazz.newIntArray (jalview.util.GroupUrlLink.tokens.length, 0);
\r
23 for (var i = 0; i < this.segs.length; i++) {
\r
24 if ((this.segs[i] = link.indexOf ("$" + jalview.util.GroupUrlLink.tokens[i])) > -1) {
\r
28 this.invalidMessage = "Group URL string must contain at least one of ";
\r
29 for (var i = 0; i < this.segs.length; i++) {
\r
30 this.invalidMessage += " '$" + jalview.util.GroupUrlLink.tokens[i] + "[=/regex=/]$'";
\r
33 }var ptok = Clazz.newIntArray (ntoks + 1, 0);
\r
34 var tmtch = new Array (ntoks + 1);
\r
35 this.mtch = new Array (ntoks);
\r
36 for (var i = 0, t = 0; i < this.segs.length; i++) {
\r
37 if (this.segs[i] > -1) {
\r
38 ptok[t] = this.segs[i];
\r
39 tmtch[t++] = jalview.util.GroupUrlLink.tokens[i];
\r
41 ptok[ntoks] = link.length;
\r
42 tmtch[ntoks] = "$$$$$$$$$";
\r
43 jalview.util.QuickSort.sortInt (ptok, tmtch);
\r
44 for (var i = 0; i < ntoks; i++) {
\r
45 this.mtch[i] = tmtch[i];
\r
50 p = link.indexOf ("|", sep + 1);
\r
51 } while (p > sep && p < ptok[0]);
\r
52 this.label = link.substring (0, sep);
\r
53 if (this.label.indexOf ("|") > -1) {
\r
54 this.target = this.label.substring (0, this.label.indexOf ("|"));
\r
55 } else if (this.label.indexOf (" ") > 2) {
\r
56 this.target = this.label.substring (0, this.label.indexOf (" "));
\r
58 this.target = this.label;
\r
59 }this.url_prefix = link.substring (sep + 1, ptok[0]);
\r
60 this.url_suffix = new Array (this.mtch.length);
\r
61 this.regexReplace = new Array (this.mtch.length);
\r
62 for (var pass = 0; pass < this.mtch.length; pass++) {
\r
63 var mlength = 3 + this.mtch[pass].length;
\r
64 if (link.indexOf ("$" + this.mtch[pass] + "=/") == ptok[pass] && (p = link.indexOf ("/=$", ptok[pass] + mlength)) > ptok[pass] + mlength) {
\r
65 if (ptok[pass + 1] < p + 3) {
\r
66 this.invalidMessage = "Token regexes cannot contain other regexes (did you terminate the $" + this.mtch[pass] + " regex with a '/=$' ?";
\r
68 }this.url_suffix[pass] = link.substring (p + 3, ptok[pass + 1]);
\r
69 this.regexReplace[pass] = link.substring (ptok[pass] + mlength, p);
\r
71 var rg = jalview.jsdev.RegExp.perlCode ("/" + this.regexReplace[pass] + "/");
\r
73 this.invalidMessage = "Invalid Regular Expression : '" + this.regexReplace[pass] + "'\n";
\r
75 if (Clazz.exceptionOf (e, Exception)) {
\r
76 this.invalidMessage = "Invalid Regular Expression : '" + this.regexReplace[pass] + "'\n";
\r
82 this.regexReplace[pass] = null;
\r
83 if ((p = link.indexOf ("$" + this.mtch[pass] + "$")) == ptok[pass]) {
\r
84 this.url_suffix[pass] = link.substring (p + this.mtch[pass].length + 2, ptok[pass + 1]);
\r
86 this.invalidMessage = "Warning: invalid regex structure (after '" + this.mtch[0] + "') for URL link : " + link;
\r
89 this.separators = new Array (this.url_suffix.length);
\r
90 var suffices = this.url_suffix[this.url_suffix.length - 1];
\r
92 while ((p = suffices.indexOf ('|')) > -1) {
\r
93 this.separators[pass] = suffices.substring (p + 1);
\r
95 this.url_suffix[this.url_suffix.length - 1] = suffices.substring (0, p);
\r
97 lastsep = (this.separators[pass - 1] = this.separators[pass - 1].substring (0, p));
\r
98 }suffices = this.separators[pass];
\r
102 lastsep = this.separators[pass - 1];
\r
103 }while (pass < this.separators.length) {
\r
104 this.separators[pass++] = lastsep;
\r
107 Clazz.defineMethod (c$, "getUrl_suffix",
\r
109 return this.url_suffix[this.url_suffix.length - 1];
\r
111 Clazz.defineMethod (c$, "getUrl_prefix",
\r
113 return this.url_prefix;
\r
115 Clazz.defineMethod (c$, "getTarget",
\r
117 return this.target;
\r
119 Clazz.defineMethod (c$, "getLabel",
\r
123 Clazz.defineMethod (c$, "getIDRegexReplace",
\r
125 return this._replaceFor (jalview.util.GroupUrlLink.tokens[0]);
\r
127 Clazz.defineMethod (c$, "_replaceFor",
\r
128 ($fz = function (token) {
\r
129 for (var i = 0; i < this.mtch.length; i++) {
\r
130 if (this.segs[i] > -1 && this.mtch[i].equals (token)) {
\r
131 return this.regexReplace[i];
\r
134 }, $fz.isPrivate = true, $fz), "~S");
\r
135 Clazz.defineMethod (c$, "getSeqRegexReplace",
\r
137 return this._replaceFor (jalview.util.GroupUrlLink.tokens[1]);
\r
139 Clazz.defineMethod (c$, "getInvalidMessage",
\r
141 return this.invalidMessage;
\r
143 Clazz.defineMethod (c$, "isValid",
\r
145 return this.invalidMessage == null;
\r
147 Clazz.defineMethod (c$, "makeUrls",
\r
148 function (idstrings, seqstrings, dsstring, onlyIfMatches) {
\r
149 var rstrings = this.replacementArgs (idstrings, seqstrings, dsstring);
\r
150 return this.makeUrls (rstrings, onlyIfMatches);
\r
152 Clazz.defineMethod (c$, "replacementArgs",
\r
153 ($fz = function (idstrings, seqstrings, dsstring) {
\r
154 var rstrings = new java.util.Hashtable ();
\r
155 rstrings.put (jalview.util.GroupUrlLink.tokens[0], idstrings);
\r
156 rstrings.put (jalview.util.GroupUrlLink.tokens[1], seqstrings);
\r
157 rstrings.put (jalview.util.GroupUrlLink.tokens[2], Clazz.newArray (-1, [dsstring]));
\r
158 if (idstrings.length != seqstrings.length) {
\r
159 throw new Error (jalview.util.MessageManager.getString ("error.idstring_seqstrings_only_one_per_sequence"));
\r
161 }, $fz.isPrivate = true, $fz), "~A,~A,~S");
\r
162 Clazz.defineMethod (c$, "makeUrls",
\r
163 function (repstrings, onlyIfMatches) {
\r
164 return this.makeUrlsIf (true, repstrings, onlyIfMatches);
\r
165 }, "java.util.Hashtable,~B");
\r
166 Clazz.defineMethod (c$, "makeUrlStubs",
\r
167 function (ids, seqstr, string, b) {
\r
168 var rstrings = this.replacementArgs (ids, seqstr, string);
\r
169 var stubs = this.makeUrlsIf (false, rstrings, b);
\r
170 if (stubs != null) {
\r
171 return Clazz.newArray (-1, [stubs[0], stubs[1], rstrings, Clazz.newBooleanArray (-1, [b])]);
\r
174 Clazz.defineMethod (c$, "constructFrom",
\r
176 var results = this.makeUrlsIf (true, stubs[2], (stubs[3])[0]);
\r
177 return (results[3])[0];
\r
179 Clazz.defineMethod (c$, "makeUrlsIf",
\r
180 function (createFullUrl, repstrings, onlyIfMatches) {
\r
182 var idseq = new Array (this.mtch.length);
\r
185 for (var i = 0; i < this.mtch.length; i++) {
\r
186 idseq[i] = repstrings.get (this.mtch[i]);
\r
187 if (idseq[i].length >= 1) {
\r
188 if (mins == 0 && idseq[i].length == 1) {
\r
191 maxs = idseq[i].length;
\r
193 if (maxs != idseq[i].length) {
\r
194 throw new Error (jalview.util.MessageManager.formatMessage ("error.cannot_have_mixed_length_replacement_vectors", Clazz.newArray (-1, [(this.mtch[i]), Integer.$valueOf (idseq[i].length).toString (), Integer.$valueOf (maxs).toString ()])));
\r
196 throw new Error (jalview.util.MessageManager.getString ("error.cannot_have_zero_length_vector_replacement_strings"));
\r
198 var matched = new Array (idseq.length);
\r
199 var rgxs = new Array (matched.length);
\r
200 for (pass = 0; pass < matched.length; pass++) {
\r
201 matched[pass] = new StringBuffer ();
\r
202 if (this.regexReplace[pass] != null) {
\r
203 rgxs[pass] = jalview.jsdev.RegExp.perlCode ("/" + this.regexReplace[pass] + "/");
\r
207 var urllength = this.url_prefix.length;
\r
208 for (pass = 0; pass < matched.length; pass++) {
\r
209 urllength += this.url_suffix[pass].length;
\r
211 var thismatched = Clazz.newBooleanArray (maxs, false);
\r
212 var seqsmatched = 0;
\r
213 for (var sq = 0; sq < maxs; sq++) {
\r
214 thismatched[sq] = false;
\r
215 var thematches = new Array (rgxs.length);
\r
216 for (pass = 0; pass < rgxs.length; pass++) {
\r
217 thematches[pass] = new StringBuffer ();
\r
218 if (idseq[pass].length <= sq) {
\r
220 }if (rgxs[pass] != null) {
\r
221 var rg = rgxs[pass];
\r
223 while (rg.searchFrom (idseq[pass][sq], rematchat)) {
\r
224 rematchat = rg.matchedTo ();
\r
225 thismatched[sq] = new Boolean (thismatched[sq] | true).valueOf ();
\r
226 urllength += rg.charsMatched ();
\r
227 if ((urllength + 32) > jalview.util.Platform.getMaxCommandLineLength ()) {
\r
228 throw Clazz.innerTypeInstance (jalview.util.GroupUrlLink.UrlStringTooLongException, this, null, urllength);
\r
229 }if (!createFullUrl) {
\r
231 }var ns = rg.numSubs ();
\r
233 thematches[pass].append (rg.stringMatched ());
\r
235 var subs = new StringBuffer ();
\r
238 if (s + 1 <= ns && rg.matchedToI (s) > -1 && rg.matchedToI (s + 1) > -1 && rg.matchedToI (s + 1) < rg.matchedToI (s)) {
\r
240 var rmtch = new StringBuffer ();
\r
241 while (r <= ns && rg.matchedToI (r) <= rg.matchedToI (s)) {
\r
242 if (rg.matchedFromI (r) > -1) {
\r
243 rmtch.append (rg.stringMatchedI (r));
\r
246 if (rmtch.length () > 0) {
\r
247 subs.append (rmtch);
\r
250 if (rg.matchedFromI (s) > -1) {
\r
251 subs.append (rg.stringMatchedI (s));
\r
254 thematches[pass].append (subs);
\r
257 if (!onlyIfMatches) {
\r
258 thismatched[sq] = new Boolean (thismatched[sq] | true).valueOf ();
\r
259 urllength += idseq[pass][sq].length;
\r
260 if (createFullUrl) {
\r
261 thematches[pass] = new StringBuffer (idseq[pass][sq]);
\r
263 if (thismatched[sq]) {
\r
264 if (createFullUrl) {
\r
265 for (pass = 0; pass < matched.length; pass++) {
\r
266 if (idseq[pass].length > 1 && matched[pass].length () > 0) {
\r
267 matched[pass].append (this.separators[pass]);
\r
268 }matched[pass].append (thematches[pass]);
\r
272 if (seqsmatched == 0 || (createFullUrl && matched[0].length () == 0)) {
\r
274 }if ((urllength + 32) > jalview.util.Platform.getMaxCommandLineLength ()) {
\r
275 throw Clazz.innerTypeInstance (jalview.util.GroupUrlLink.UrlStringTooLongException, this, null, urllength);
\r
276 }if (!createFullUrl) {
\r
277 return Clazz.newArray (-1, [ Clazz.newIntArray (-1, [seqsmatched]), thismatched]);
\r
278 }var submiturl = new StringBuffer ();
\r
279 submiturl.append (this.url_prefix);
\r
280 for (pass = 0; pass < matched.length; pass++) {
\r
281 submiturl.append (matched[pass]);
\r
282 if (this.url_suffix[pass] != null) {
\r
283 submiturl.append (this.url_suffix[pass]);
\r
285 return Clazz.newArray (-1, [ Clazz.newIntArray (-1, [seqsmatched]), thismatched, matched, Clazz.newArray (-1, [submiturl.toString ()])]);
\r
286 }, "~B,java.util.Hashtable,~B");
\r
287 Clazz.defineMethod (c$, "getNumberInvolved",
\r
288 function (urlstub) {
\r
289 return (urlstub[0])[0];
\r
291 Clazz.defineMethod (c$, "getGroupURLType",
\r
294 for (var pass = 0; pass < jalview.util.GroupUrlLink.tokens.length; pass++) {
\r
295 for (var i = 0; i < this.mtch.length; i++) {
\r
296 if (this.mtch[i].equals (jalview.util.GroupUrlLink.tokens[pass])) {
\r
302 Clazz.overrideMethod (c$, "toString",
\r
304 var result = new StringBuffer ();
\r
305 result.append (this.label + "|" + this.url_prefix);
\r
307 for (r = 0; r < this.url_suffix.length; r++) {
\r
308 result.append ("$");
\r
309 result.append (this.mtch[r]);
\r
310 if (this.regexReplace[r] != null) {
\r
311 result.append ("=/");
\r
312 result.append (this.regexReplace[r]);
\r
313 result.append ("/=");
\r
314 }result.append ("$");
\r
315 result.append (this.url_suffix[r]);
\r
317 for (r = 0; r < this.separators.length; r++) {
\r
318 result.append ("|");
\r
319 result.append (this.separators[r]);
\r
321 return result.toString ();
\r
323 c$.formStrings = Clazz.defineMethod (c$, "formStrings",
\r
325 var idset = Clazz.newArray (2, seqs.length, null);
\r
326 for (var i = 0; i < seqs.length; i++) {
\r
327 idset[0][i] = seqs[i].getName ();
\r
328 idset[1][i] = seqs[i].getSequenceAsString ();
\r
332 Clazz.defineMethod (c$, "setLabel",
\r
333 function (newlabel) {
\r
334 this.label = newlabel;
\r
336 c$.$GroupUrlLink$UrlStringTooLongException$ = function () {
\r
338 c$ = Clazz.decorateAsClass (function () {
\r
339 Clazz.prepareCallback (this, arguments);
\r
340 this.urlLength = 0;
\r
341 Clazz.instantialize (this, arguments);
\r
342 }, jalview.util.GroupUrlLink, "UrlStringTooLongException", Exception);
\r
343 Clazz.makeConstructor (c$,
\r
345 Clazz.superConstructor (this, jalview.util.GroupUrlLink.UrlStringTooLongException, []);
\r
346 this.urlLength = a;
\r
348 Clazz.overrideMethod (c$, "toString",
\r
350 return "Generated url is estimated to be too long (" + this.urlLength + ")";
\r
354 Clazz.defineStatics (c$,
\r
357 if (jalview.util.GroupUrlLink.tokens == null) {
\r
358 jalview.util.GroupUrlLink.tokens = Clazz.newArray (-1, ["SEQUENCEIDS", "SEQUENCES", "DATASETID"]);
\r
359 }}Clazz.defineStatics (c$,
\r