1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.util; |
22 |
|
|
23 |
|
import jalview.datamodel.Sequence; |
24 |
|
import jalview.datamodel.SequenceI; |
25 |
|
|
26 |
|
import java.util.Hashtable; |
27 |
|
|
|
|
| 0% |
Uncovered Elements: 418 (418) |
Complexity: 109 |
Complexity Density: 0.43 |
|
28 |
|
public class GroupUrlLink |
29 |
|
{ |
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
30 |
|
public class UrlStringTooLongException extends Exception |
31 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
32 |
0 |
public UrlStringTooLongException(int lng)... |
33 |
|
{ |
34 |
0 |
urlLength = lng; |
35 |
|
} |
36 |
|
|
37 |
|
public int urlLength; |
38 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
39 |
0 |
public String toString()... |
40 |
|
{ |
41 |
0 |
return "Generated url is estimated to be too long (" + urlLength |
42 |
|
+ ")"; |
43 |
|
} |
44 |
|
} |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
private String url_prefix, target, label; |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
private String url_suffix[], separators[], regexReplace[]; |
64 |
|
|
65 |
|
private String invalidMessage = null; |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
private static String[] tokens; |
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
private int[] segs; |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
private String[] mtch; |
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
81 |
0 |
static... |
82 |
|
{ |
83 |
0 |
if (tokens == null) |
84 |
|
{ |
85 |
0 |
tokens = new String[] { "SEQUENCEIDS", "SEQUENCES", "DATASETID" }; |
86 |
|
} |
87 |
|
} |
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
public static final int SEQUENCEIDS = 1; |
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
public static final int SEQUENCES = 2; |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
public static final int DATASETID = 4; |
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
@param |
114 |
|
|
|
|
| 0% |
Uncovered Elements: 105 (105) |
Complexity: 23 |
Complexity Density: 0.34 |
|
115 |
0 |
public GroupUrlLink(String link)... |
116 |
|
{ |
117 |
0 |
int sep = link.indexOf("|"); |
118 |
0 |
segs = new int[tokens.length]; |
119 |
0 |
int ntoks = 0; |
120 |
0 |
for (int i = 0; i < segs.length; i++) |
121 |
|
{ |
122 |
0 |
if ((segs[i] = link.indexOf("$" + tokens[i])) > -1) |
123 |
|
{ |
124 |
0 |
ntoks++; |
125 |
|
} |
126 |
|
} |
127 |
|
|
128 |
0 |
if (ntoks == 0) |
129 |
|
{ |
130 |
0 |
invalidMessage = "Group URL string must contain at least one of "; |
131 |
0 |
for (int i = 0; i < segs.length; i++) |
132 |
|
{ |
133 |
0 |
invalidMessage += " '$" + tokens[i] + "[=/regex=/]$'"; |
134 |
|
} |
135 |
0 |
return; |
136 |
|
} |
137 |
|
|
138 |
0 |
int[] ptok = new int[ntoks + 1]; |
139 |
0 |
String[] tmtch = new String[ntoks + 1]; |
140 |
0 |
mtch = new String[ntoks]; |
141 |
0 |
for (int i = 0, t = 0; i < segs.length; i++) |
142 |
|
{ |
143 |
0 |
if (segs[i] > -1) |
144 |
|
{ |
145 |
0 |
ptok[t] = segs[i]; |
146 |
0 |
tmtch[t++] = tokens[i]; |
147 |
|
} |
148 |
|
} |
149 |
0 |
ptok[ntoks] = link.length(); |
150 |
0 |
tmtch[ntoks] = "$$$$$$$$$"; |
151 |
0 |
jalview.util.QuickSort.sort(ptok, tmtch); |
152 |
0 |
for (int i = 0; i < ntoks; i++) |
153 |
|
{ |
154 |
0 |
mtch[i] = tmtch[i]; |
155 |
|
} |
156 |
|
|
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
0 |
int p = sep; |
170 |
|
|
171 |
0 |
do |
172 |
|
{ |
173 |
0 |
sep = p; |
174 |
0 |
p = link.indexOf("|", sep + 1); |
175 |
0 |
} while (p > sep && p < ptok[0]); |
176 |
|
|
177 |
|
|
178 |
0 |
label = link.substring(0, sep); |
179 |
0 |
if (label.indexOf("|") > -1) |
180 |
|
{ |
181 |
|
|
182 |
0 |
target = label.substring(0, label.indexOf("|")); |
183 |
|
} |
184 |
0 |
else if (label.indexOf(" ") > 2) |
185 |
|
{ |
186 |
|
|
187 |
0 |
target = label.substring(0, label.indexOf(" ")); |
188 |
|
} |
189 |
|
else |
190 |
|
{ |
191 |
0 |
target = label; |
192 |
|
} |
193 |
|
|
194 |
0 |
url_prefix = link.substring(sep + 1, ptok[0]); |
195 |
0 |
url_suffix = new String[mtch.length]; |
196 |
0 |
regexReplace = new String[mtch.length]; |
197 |
|
|
198 |
0 |
for (int pass = 0; pass < mtch.length; pass++) |
199 |
|
{ |
200 |
0 |
int mlength = 3 + mtch[pass].length(); |
201 |
0 |
if (link.indexOf("$" + mtch[pass] + "=/") == ptok[pass] && (p = link |
202 |
|
.indexOf("/=$", ptok[pass] + mlength)) > ptok[pass] + mlength) |
203 |
|
{ |
204 |
|
|
205 |
0 |
if (ptok[pass + 1] < p + 3) |
206 |
|
{ |
207 |
|
|
208 |
|
|
209 |
0 |
invalidMessage = "Token regexes cannot contain other regexes (did you terminate the $" |
210 |
|
+ mtch[pass] + " regex with a '/=$' ?"; |
211 |
0 |
return; |
212 |
|
} |
213 |
0 |
url_suffix[pass] = link.substring(p + 3, ptok[pass + 1]); |
214 |
0 |
regexReplace[pass] = link.substring(ptok[pass] + mlength, p); |
215 |
0 |
try |
216 |
|
{ |
217 |
0 |
com.stevesoft.pat.Regex rg = com.stevesoft.pat.Regex |
218 |
|
.perlCode("/" + regexReplace[pass] + "/"); |
219 |
0 |
if (rg == null) |
220 |
|
{ |
221 |
0 |
invalidMessage = "Invalid Regular Expression : '" |
222 |
|
+ regexReplace[pass] + "'\n"; |
223 |
|
} |
224 |
|
} catch (Exception e) |
225 |
|
{ |
226 |
0 |
invalidMessage = "Invalid Regular Expression : '" |
227 |
|
+ regexReplace[pass] + "'\n"; |
228 |
|
} |
229 |
|
} |
230 |
|
else |
231 |
|
{ |
232 |
0 |
regexReplace[pass] = null; |
233 |
|
|
234 |
0 |
if ((p = link.indexOf("$" + mtch[pass] + "$")) == ptok[pass]) |
235 |
|
{ |
236 |
0 |
url_suffix[pass] = link.substring(p + mtch[pass].length() + 2, |
237 |
|
ptok[pass + 1]); |
238 |
|
} |
239 |
|
else |
240 |
|
{ |
241 |
0 |
invalidMessage = "Warning: invalid regex structure (after '" |
242 |
|
+ mtch[0] + "') for URL link : " + link; |
243 |
|
} |
244 |
|
} |
245 |
|
} |
246 |
0 |
int pass = 0; |
247 |
0 |
separators = new String[url_suffix.length]; |
248 |
0 |
String suffices = url_suffix[url_suffix.length - 1], lastsep = ","; |
249 |
|
|
250 |
0 |
while ((p = suffices.indexOf('|')) > -1) |
251 |
|
{ |
252 |
0 |
separators[pass] = suffices.substring(p + 1); |
253 |
0 |
if (pass == 0) |
254 |
|
{ |
255 |
|
|
256 |
0 |
url_suffix[url_suffix.length - 1] = suffices.substring(0, p); |
257 |
|
} |
258 |
|
else |
259 |
|
{ |
260 |
0 |
lastsep = (separators[pass - 1] = separators[pass - 1].substring(0, |
261 |
|
p)); |
262 |
|
} |
263 |
0 |
suffices = separators[pass]; |
264 |
0 |
pass++; |
265 |
|
} |
266 |
0 |
if (pass > 0) |
267 |
|
{ |
268 |
0 |
lastsep = separators[pass - 1]; |
269 |
|
} |
270 |
|
|
271 |
0 |
while (pass < separators.length) |
272 |
|
{ |
273 |
0 |
separators[pass++] = lastsep; |
274 |
|
} |
275 |
|
} |
276 |
|
|
277 |
|
|
278 |
|
@return |
279 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
280 |
0 |
public String getUrl_suffix()... |
281 |
|
{ |
282 |
0 |
return url_suffix[url_suffix.length - 1]; |
283 |
|
} |
284 |
|
|
285 |
|
|
286 |
|
@return |
287 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
288 |
0 |
public String getUrl_prefix()... |
289 |
|
{ |
290 |
0 |
return url_prefix; |
291 |
|
} |
292 |
|
|
293 |
|
|
294 |
|
@return |
295 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
296 |
0 |
public String getTarget()... |
297 |
|
{ |
298 |
0 |
return target; |
299 |
|
} |
300 |
|
|
301 |
|
|
302 |
|
@return |
303 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
304 |
0 |
public String getLabel()... |
305 |
|
{ |
306 |
0 |
return label; |
307 |
|
} |
308 |
|
|
309 |
|
|
310 |
|
@return |
311 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
312 |
0 |
public String getIDRegexReplace()... |
313 |
|
{ |
314 |
0 |
return _replaceFor(tokens[0]); |
315 |
|
} |
316 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 4 |
Complexity Density: 1 |
|
317 |
0 |
private String _replaceFor(String token)... |
318 |
|
{ |
319 |
0 |
for (int i = 0; i < mtch.length; i++) |
320 |
0 |
if (segs[i] > -1 && mtch[i].equals(token)) |
321 |
|
{ |
322 |
0 |
return regexReplace[i]; |
323 |
|
} |
324 |
0 |
return null; |
325 |
|
} |
326 |
|
|
327 |
|
|
328 |
|
@return |
329 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
330 |
0 |
public String getSeqRegexReplace()... |
331 |
|
{ |
332 |
0 |
return _replaceFor(tokens[1]); |
333 |
|
} |
334 |
|
|
335 |
|
|
336 |
|
@return |
337 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
338 |
0 |
public String getInvalidMessage()... |
339 |
|
{ |
340 |
0 |
return invalidMessage; |
341 |
|
} |
342 |
|
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
@return |
347 |
|
|
348 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
349 |
0 |
public boolean isValid()... |
350 |
|
{ |
351 |
0 |
return invalidMessage == null; |
352 |
|
} |
353 |
|
|
354 |
|
|
355 |
|
|
356 |
|
|
357 |
|
@param |
358 |
|
|
359 |
|
@param |
360 |
|
|
361 |
|
@param |
362 |
|
|
363 |
|
|
364 |
|
|
365 |
|
@return |
366 |
|
|
367 |
|
|
368 |
|
@throws |
369 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
370 |
0 |
public Object[] makeUrls(String[] idstrings, String[] seqstrings,... |
371 |
|
String dsstring, boolean onlyIfMatches) |
372 |
|
throws UrlStringTooLongException |
373 |
|
{ |
374 |
0 |
Hashtable rstrings = replacementArgs(idstrings, seqstrings, dsstring); |
375 |
0 |
return makeUrls(rstrings, onlyIfMatches); |
376 |
|
} |
377 |
|
|
378 |
|
|
379 |
|
|
380 |
|
|
381 |
|
@param |
382 |
|
@param |
383 |
|
@param |
384 |
|
@return |
385 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
386 |
0 |
private Hashtable replacementArgs(String[] idstrings, String[] seqstrings,... |
387 |
|
String dsstring) |
388 |
|
{ |
389 |
0 |
Hashtable rstrings = new Hashtable(); |
390 |
0 |
rstrings.put(tokens[0], idstrings); |
391 |
0 |
rstrings.put(tokens[1], seqstrings); |
392 |
0 |
rstrings.put(tokens[2], new String[] { dsstring }); |
393 |
0 |
if (idstrings.length != seqstrings.length) |
394 |
|
{ |
395 |
0 |
throw new Error(MessageManager.getString( |
396 |
|
"error.idstring_seqstrings_only_one_per_sequence")); |
397 |
|
} |
398 |
0 |
return rstrings; |
399 |
|
} |
400 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
401 |
0 |
public Object[] makeUrls(Hashtable repstrings, boolean onlyIfMatches)... |
402 |
|
throws UrlStringTooLongException |
403 |
|
{ |
404 |
0 |
return makeUrlsIf(true, repstrings, onlyIfMatches); |
405 |
|
} |
406 |
|
|
407 |
|
|
408 |
|
|
409 |
|
@param |
410 |
|
@param |
411 |
|
@param |
412 |
|
@param |
413 |
|
@return |
414 |
|
@throws |
415 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
416 |
0 |
public Object[] makeUrlStubs(String[] ids, String[] seqstr, String string,... |
417 |
|
boolean b) throws UrlStringTooLongException |
418 |
|
{ |
419 |
0 |
Hashtable rstrings = replacementArgs(ids, seqstr, string); |
420 |
0 |
Object[] stubs = makeUrlsIf(false, rstrings, b); |
421 |
0 |
if (stubs != null) |
422 |
|
{ |
423 |
0 |
return new Object[] { stubs[0], stubs[1], rstrings, |
424 |
|
new boolean[] |
425 |
|
{ b } }; |
426 |
|
} |
427 |
|
|
428 |
0 |
return null; |
429 |
|
} |
430 |
|
|
431 |
|
|
432 |
|
|
433 |
|
|
434 |
|
|
435 |
|
@param |
436 |
|
@return |
437 |
|
@throws |
438 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
439 |
0 |
public String constructFrom(Object[] stubs)... |
440 |
|
throws UrlStringTooLongException |
441 |
|
{ |
442 |
0 |
Object[] results = makeUrlsIf(true, (Hashtable) stubs[2], |
443 |
|
((boolean[]) stubs[3])[0]); |
444 |
0 |
return ((String[]) results[3])[0]; |
445 |
|
} |
446 |
|
|
447 |
|
|
448 |
|
|
449 |
|
|
450 |
|
@param |
451 |
|
|
452 |
|
@param |
453 |
|
@param |
454 |
|
@return |
455 |
|
|
456 |
|
|
457 |
|
|
458 |
|
@throws |
459 |
|
|
|
|
| 0% |
Uncovered Elements: 154 (154) |
Complexity: 42 |
Complexity Density: 0.48 |
|
460 |
0 |
protected Object[] makeUrlsIf(boolean createFullUrl, Hashtable repstrings,... |
461 |
|
boolean onlyIfMatches) throws UrlStringTooLongException |
462 |
|
{ |
463 |
0 |
int pass = 0; |
464 |
|
|
465 |
|
|
466 |
0 |
String[][] idseq = new String[mtch.length][]; |
467 |
0 |
int mins = 0, maxs = 0; |
468 |
0 |
for (int i = 0; i < mtch.length; i++) |
469 |
|
{ |
470 |
0 |
idseq[i] = (String[]) repstrings.get(mtch[i]); |
471 |
0 |
if (idseq[i].length >= 1) |
472 |
|
{ |
473 |
0 |
if (mins == 0 && idseq[i].length == 1) |
474 |
|
{ |
475 |
0 |
mins = 1; |
476 |
|
} |
477 |
0 |
if (maxs < 2) |
478 |
|
{ |
479 |
0 |
maxs = idseq[i].length; |
480 |
|
} |
481 |
|
else |
482 |
|
{ |
483 |
0 |
if (maxs != idseq[i].length) |
484 |
|
{ |
485 |
0 |
throw new Error(MessageManager.formatMessage( |
486 |
|
"error.cannot_have_mixed_length_replacement_vectors", |
487 |
|
new String[] |
488 |
|
{ (mtch[i]), |
489 |
|
Integer.valueOf(idseq[i].length).toString(), |
490 |
|
Integer.valueOf(maxs).toString() })); |
491 |
|
} |
492 |
|
} |
493 |
|
} |
494 |
|
else |
495 |
|
{ |
496 |
0 |
throw new Error(MessageManager.getString( |
497 |
|
"error.cannot_have_zero_length_vector_replacement_strings")); |
498 |
|
} |
499 |
|
} |
500 |
|
|
501 |
0 |
StringBuffer matched[] = new StringBuffer[idseq.length]; |
502 |
|
|
503 |
0 |
com.stevesoft.pat.Regex[] rgxs = new com.stevesoft.pat.Regex[matched.length]; |
504 |
0 |
for (pass = 0; pass < matched.length; pass++) |
505 |
|
{ |
506 |
0 |
matched[pass] = new StringBuffer(); |
507 |
0 |
if (regexReplace[pass] != null) |
508 |
|
{ |
509 |
0 |
rgxs[pass] = com.stevesoft.pat.Regex |
510 |
|
.perlCode("/" + regexReplace[pass] + "/"); |
511 |
|
} |
512 |
|
else |
513 |
|
{ |
514 |
0 |
rgxs[pass] = null; |
515 |
|
} |
516 |
|
} |
517 |
|
|
518 |
0 |
int urllength = url_prefix.length(); |
519 |
0 |
for (pass = 0; pass < matched.length; pass++) |
520 |
|
{ |
521 |
0 |
urllength += url_suffix[pass].length(); |
522 |
|
} |
523 |
|
|
524 |
|
|
525 |
|
|
526 |
|
|
527 |
0 |
boolean[] thismatched = new boolean[maxs]; |
528 |
0 |
int seqsmatched = 0; |
529 |
0 |
for (int sq = 0; sq < maxs; sq++) |
530 |
|
{ |
531 |
|
|
532 |
0 |
thismatched[sq] = false; |
533 |
0 |
StringBuffer[] thematches = new StringBuffer[rgxs.length]; |
534 |
0 |
for (pass = 0; pass < rgxs.length; pass++) |
535 |
|
{ |
536 |
0 |
thematches[pass] = new StringBuffer(); |
537 |
|
|
538 |
|
|
539 |
|
|
540 |
|
|
541 |
0 |
if (idseq[pass].length <= sq) |
542 |
|
{ |
543 |
|
|
544 |
0 |
continue; |
545 |
|
} |
546 |
0 |
if (rgxs[pass] != null) |
547 |
|
{ |
548 |
0 |
com.stevesoft.pat.Regex rg = rgxs[pass]; |
549 |
0 |
int rematchat = 0; |
550 |
|
|
551 |
0 |
while (rg.searchFrom(idseq[pass][sq], rematchat)) |
552 |
|
{ |
553 |
0 |
rematchat = rg.matchedTo(); |
554 |
0 |
thismatched[sq] |= true; |
555 |
0 |
urllength += rg.charsMatched(); |
556 |
0 |
if ((urllength + 32) > Platform.getMaxCommandLineLength()) |
557 |
|
{ |
558 |
0 |
throw new UrlStringTooLongException(urllength); |
559 |
|
} |
560 |
|
|
561 |
0 |
if (!createFullUrl) |
562 |
|
{ |
563 |
0 |
continue; |
564 |
|
} |
565 |
|
|
566 |
0 |
int ns = rg.numSubs(); |
567 |
0 |
if (ns == 0) |
568 |
|
{ |
569 |
0 |
thematches[pass].append(rg.stringMatched()); |
570 |
|
} |
571 |
|
|
572 |
|
|
573 |
|
|
574 |
|
|
575 |
|
|
576 |
|
|
577 |
|
|
578 |
|
|
579 |
|
|
580 |
|
else |
581 |
|
{ |
582 |
|
|
583 |
|
|
584 |
|
|
585 |
|
|
586 |
|
|
587 |
|
|
588 |
|
|
589 |
|
|
590 |
0 |
StringBuffer subs = new StringBuffer(); |
591 |
|
|
592 |
|
|
593 |
0 |
int s = 0; |
594 |
0 |
while (s <= ns) |
595 |
|
{ |
596 |
0 |
if (s + 1 <= ns && rg.matchedTo(s) > -1 |
597 |
|
&& rg.matchedTo(s + 1) > -1 |
598 |
|
&& rg.matchedTo(s + 1) < rg.matchedTo(s)) |
599 |
|
{ |
600 |
|
|
601 |
|
|
602 |
0 |
int r = s + 1; |
603 |
0 |
StringBuffer rmtch = new StringBuffer(); |
604 |
0 |
while (r <= ns && rg.matchedTo(r) <= rg.matchedTo(s)) |
605 |
|
{ |
606 |
0 |
if (rg.matchedFrom(r) > -1) |
607 |
|
{ |
608 |
0 |
rmtch.append(rg.stringMatched(r)); |
609 |
|
} |
610 |
0 |
r++; |
611 |
|
} |
612 |
0 |
if (rmtch.length() > 0) |
613 |
|
{ |
614 |
0 |
subs.append(rmtch); |
615 |
|
} |
616 |
0 |
s = r; |
617 |
|
} |
618 |
|
else |
619 |
|
{ |
620 |
0 |
if (rg.matchedFrom(s) > -1) |
621 |
|
{ |
622 |
0 |
subs.append(rg.stringMatched(s)); |
623 |
|
} |
624 |
0 |
s++; |
625 |
|
} |
626 |
|
} |
627 |
0 |
thematches[pass].append(subs); |
628 |
|
} |
629 |
|
} |
630 |
|
} |
631 |
|
else |
632 |
|
{ |
633 |
|
|
634 |
0 |
if (!onlyIfMatches) |
635 |
|
{ |
636 |
0 |
thismatched[sq] |= true; |
637 |
0 |
urllength += idseq[pass][sq].length(); |
638 |
0 |
if (createFullUrl) |
639 |
|
{ |
640 |
0 |
thematches[pass] = new StringBuffer(idseq[pass][sq]); |
641 |
|
|
642 |
|
|
643 |
|
|
644 |
|
|
645 |
|
|
646 |
|
|
647 |
|
|
648 |
|
|
649 |
|
|
650 |
|
|
651 |
|
|
652 |
|
} |
653 |
|
|
654 |
|
} |
655 |
|
} |
656 |
|
} |
657 |
|
|
658 |
|
|
659 |
|
|
660 |
|
|
661 |
0 |
if (thismatched[sq]) |
662 |
|
{ |
663 |
0 |
if (createFullUrl) |
664 |
|
{ |
665 |
0 |
for (pass = 0; pass < matched.length; pass++) |
666 |
|
{ |
667 |
0 |
if (idseq[pass].length > 1 && matched[pass].length() > 0) |
668 |
|
{ |
669 |
0 |
matched[pass].append(separators[pass]); |
670 |
|
} |
671 |
0 |
matched[pass].append(thematches[pass]); |
672 |
|
} |
673 |
|
} |
674 |
0 |
seqsmatched++; |
675 |
|
} |
676 |
|
} |
677 |
|
|
678 |
0 |
if (seqsmatched == 0 || (createFullUrl && matched[0].length() == 0)) |
679 |
|
{ |
680 |
|
|
681 |
0 |
return null; |
682 |
|
} |
683 |
|
|
684 |
|
|
685 |
0 |
if ((urllength + 32) > Platform.getMaxCommandLineLength()) |
686 |
|
{ |
687 |
0 |
throw new UrlStringTooLongException(urllength); |
688 |
|
} |
689 |
0 |
if (!createFullUrl) |
690 |
|
{ |
691 |
|
|
692 |
|
|
693 |
0 |
return new Object[] { new int[] { seqsmatched }, thismatched }; |
694 |
|
} |
695 |
|
|
696 |
|
|
697 |
0 |
StringBuffer submiturl = new StringBuffer(); |
698 |
0 |
submiturl.append(url_prefix); |
699 |
0 |
for (pass = 0; pass < matched.length; pass++) |
700 |
|
{ |
701 |
0 |
submiturl.append(matched[pass]); |
702 |
0 |
if (url_suffix[pass] != null) |
703 |
|
{ |
704 |
0 |
submiturl.append(url_suffix[pass]); |
705 |
|
} |
706 |
|
} |
707 |
|
|
708 |
0 |
return new Object[] { new int[] { seqsmatched }, thismatched, matched, |
709 |
|
new String[] |
710 |
|
{ submiturl.toString() } }; |
711 |
|
} |
712 |
|
|
713 |
|
|
714 |
|
|
715 |
|
@param |
716 |
|
@return |
717 |
|
|
718 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
719 |
0 |
public int getNumberInvolved(Object[] urlstub)... |
720 |
|
{ |
721 |
0 |
return ((int[]) urlstub[0])[0]; |
722 |
|
|
723 |
|
} |
724 |
|
|
725 |
|
|
726 |
|
|
727 |
|
|
728 |
|
|
729 |
|
@return |
730 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.67 |
|
731 |
0 |
public int getGroupURLType()... |
732 |
|
{ |
733 |
0 |
int r = 0; |
734 |
0 |
for (int pass = 0; pass < tokens.length; pass++) |
735 |
|
{ |
736 |
0 |
for (int i = 0; i < mtch.length; i++) |
737 |
|
{ |
738 |
0 |
if (mtch[i].equals(tokens[pass])) |
739 |
|
{ |
740 |
0 |
r += 1 << pass; |
741 |
|
} |
742 |
|
} |
743 |
|
} |
744 |
0 |
return r; |
745 |
|
} |
746 |
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 4 |
Complexity Density: 0.25 |
|
747 |
0 |
public String toString()... |
748 |
|
{ |
749 |
0 |
StringBuffer result = new StringBuffer(); |
750 |
0 |
result.append(label + "|" + url_prefix); |
751 |
0 |
int r; |
752 |
0 |
for (r = 0; r < url_suffix.length; r++) |
753 |
|
{ |
754 |
0 |
result.append("$"); |
755 |
0 |
result.append(mtch[r]); |
756 |
0 |
if (regexReplace[r] != null) |
757 |
|
{ |
758 |
0 |
result.append("=/"); |
759 |
0 |
result.append(regexReplace[r]); |
760 |
0 |
result.append("/="); |
761 |
|
} |
762 |
0 |
result.append("$"); |
763 |
0 |
result.append(url_suffix[r]); |
764 |
|
} |
765 |
0 |
for (r = 0; r < separators.length; r++) |
766 |
|
{ |
767 |
0 |
result.append("|"); |
768 |
0 |
result.append(separators[r]); |
769 |
|
} |
770 |
0 |
return result.toString(); |
771 |
|
} |
772 |
|
|
773 |
|
|
774 |
|
|
775 |
|
|
776 |
|
@param |
777 |
|
@param |
778 |
|
@param |
779 |
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 6 |
Complexity Density: 0.46 |
|
780 |
0 |
private static void testUrls(GroupUrlLink ul, String[][] idstring,... |
781 |
|
Object[] url) |
782 |
|
{ |
783 |
|
|
784 |
0 |
if (url == null) |
785 |
|
{ |
786 |
0 |
System.out.println("Created NO urls."); |
787 |
|
} |
788 |
|
else |
789 |
|
{ |
790 |
0 |
System.out.println("Created a url from " + ((int[]) url[0])[0] |
791 |
|
+ "out of " + idstring[0].length + " sequences."); |
792 |
0 |
System.out.println("Sequences that did not match:"); |
793 |
0 |
for (int sq = 0; sq < idstring[0].length; sq++) |
794 |
|
{ |
795 |
0 |
if (!((boolean[]) url[1])[sq]) |
796 |
|
{ |
797 |
0 |
System.out.println("Seq " + sq + ": " + idstring[0][sq] + "\t: " |
798 |
|
+ idstring[1][sq]); |
799 |
|
} |
800 |
|
} |
801 |
0 |
System.out.println("Sequences that DID match:"); |
802 |
0 |
for (int sq = 0; sq < idstring[0].length; sq++) |
803 |
|
{ |
804 |
0 |
if (((boolean[]) url[1])[sq]) |
805 |
|
{ |
806 |
0 |
System.out.println("Seq " + sq + ": " + idstring[0][sq] + "\t: " |
807 |
|
+ idstring[1][sq]); |
808 |
|
} |
809 |
|
} |
810 |
0 |
System.out.println("The generated URL:"); |
811 |
0 |
System.out.println(((String[]) url[3])[0]); |
812 |
|
} |
813 |
|
} |
814 |
|
|
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 5 |
Complexity Density: 0.21 |
|
815 |
0 |
public static void main(String argv[])... |
816 |
|
{ |
817 |
|
|
818 |
0 |
String[] links = new String[] { |
819 |
|
"EnVision2|IDS|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=Enfin%20Default%20Workflow&datasetName=linkInDatasetFromJalview&input=$SEQUENCEIDS$&inputType=0|,", |
820 |
|
"EnVision2|Seqs|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=Enfin%20Default%20Workflow&datasetName=linkInDatasetFromJalview&input=$SEQUENCES$&inputType=1|,", |
821 |
|
"EnVision2|IDS|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=Enfin%20Default%20Workflow&datasetName=$DATASETID$&input=$SEQUENCEIDS$&inputType=0|,", |
822 |
|
"EnVision2|Seqs|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=Enfin%20Default%20Workflow&datasetName=$DATASETID$&input=$SEQUENCES$&inputType=1|,", |
823 |
|
"EnVision2|IDS|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=$SEQUENCEIDS$&datasetName=linkInDatasetFromJalview&input=$SEQUENCEIDS$&inputType=0|,", |
824 |
|
"EnVision2|Seqs|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=$SEQUENCEIDS$&datasetName=$DATASETID$&input=$SEQUENCES$&inputType=1|,", |
825 |
|
"EnVision2 Seqs|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=Default&datasetName=JalviewSeqs$DATASETID$&input=$SEQUENCES=/([a-zA-Z]+)/=$&inputType=1|,", |
826 |
|
"EnVision2 Seqs|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=Default&datasetName=JalviewSeqs$DATASETID$&input=$SEQUENCES=/[A-Za-z]+/=$&inputType=1|," |
827 |
|
|
828 |
|
|
829 |
|
|
830 |
|
|
831 |
|
|
832 |
|
}; |
833 |
|
|
834 |
0 |
SequenceI[] seqs = new SequenceI[] { |
835 |
|
new Sequence("StupidLabel:gi|9234|pdb|102L|A", |
836 |
|
"asdiasdpasdpadpwpadasdpaspdw"), }; |
837 |
0 |
String[][] seqsandids = formStrings(seqs); |
838 |
0 |
for (int i = 0; i < links.length; i++) |
839 |
|
{ |
840 |
0 |
GroupUrlLink ul = new GroupUrlLink(links[i]); |
841 |
0 |
if (ul.isValid()) |
842 |
|
{ |
843 |
0 |
System.out.println("\n\n\n"); |
844 |
0 |
System.out.println( |
845 |
|
"Link " + i + " " + links[i] + " : " + ul.toString()); |
846 |
0 |
System.out.println(" pref : " + ul.getUrl_prefix()); |
847 |
0 |
System.out.println(" IdReplace : " + ul.getIDRegexReplace()); |
848 |
0 |
System.out.println(" SeqReplace : " + ul.getSeqRegexReplace()); |
849 |
0 |
System.out.println(" Suffixes : " + ul.getUrl_suffix()); |
850 |
|
|
851 |
0 |
System.out.println( |
852 |
|
"<insert input id and sequence strings here> Without onlyIfMatches:"); |
853 |
0 |
Object[] urls; |
854 |
0 |
try |
855 |
|
{ |
856 |
0 |
urls = ul.makeUrls(seqsandids[0], seqsandids[1], "mydataset", |
857 |
|
false); |
858 |
0 |
testUrls(ul, seqsandids, urls); |
859 |
|
} catch (UrlStringTooLongException ex) |
860 |
|
{ |
861 |
0 |
System.out.println("too long exception " + ex); |
862 |
|
} |
863 |
0 |
System.out.println( |
864 |
|
"<insert input id and sequence strings here> With onlyIfMatches set:"); |
865 |
0 |
try |
866 |
|
{ |
867 |
0 |
urls = ul.makeUrls(seqsandids[0], seqsandids[1], "mydataset", |
868 |
|
true); |
869 |
0 |
testUrls(ul, seqsandids, urls); |
870 |
|
} catch (UrlStringTooLongException ex) |
871 |
|
{ |
872 |
0 |
System.out.println("too long exception " + ex); |
873 |
|
} |
874 |
|
} |
875 |
|
else |
876 |
|
{ |
877 |
0 |
System.err.println("Invalid URLLink : " + links[i] + " : " |
878 |
|
+ ul.getInvalidMessage()); |
879 |
|
} |
880 |
|
} |
881 |
|
} |
882 |
|
|
883 |
|
|
884 |
|
|
885 |
|
|
886 |
|
|
887 |
|
|
888 |
|
@param |
889 |
|
@return |
890 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
891 |
0 |
public static String[][] formStrings(SequenceI[] seqs)... |
892 |
|
{ |
893 |
0 |
String[][] idset = new String[2][seqs.length]; |
894 |
0 |
for (int i = 0; i < seqs.length; i++) |
895 |
|
{ |
896 |
0 |
idset[0][i] = seqs[i].getName(); |
897 |
0 |
idset[1][i] = seqs[i].getSequenceAsString(); |
898 |
|
} |
899 |
0 |
return idset; |
900 |
|
} |
901 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
902 |
0 |
public void setLabel(String newlabel)... |
903 |
|
{ |
904 |
0 |
this.label = newlabel; |
905 |
|
} |
906 |
|
|
907 |
|
} |