1 Clazz.declarePackage ("jalview.util");
2 Clazz.load (null, "jalview.util.UrlLink", ["jalview.jsdev.RegExp", "java.util.Vector"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.url_suffix = null;
5 this.url_prefix = null;
8 this.regexReplace = null;
10 this.invalidMessage = null;
11 Clazz.instantialize (this, arguments);
12 }, jalview.util, "UrlLink");
13 Clazz.makeConstructor (c$,
15 var sep = link.indexOf ("|");
16 var psqid = link.indexOf ("$SEQUENCE_ID");
22 p = link.indexOf ("|", sep + 1);
23 } while (p > sep && p < psqid);
24 this.label = link.substring (0, sep);
25 if (this.label.indexOf ("|") > -1) {
26 this.target = this.label.substring (0, this.label.indexOf ("|"));
27 } else if (this.label.indexOf (" ") > 2) {
28 this.target = this.label.substring (0, this.label.indexOf (" "));
30 this.target = this.label;
31 }this.url_prefix = link.substring (sep + 1, psqid);
32 if (link.indexOf ("$SEQUENCE_ID=/") == psqid && (p = link.indexOf ("/=$", psqid + 14)) > psqid + 14) {
33 this.url_suffix = link.substring (p + 3);
34 this.regexReplace = link.substring (psqid + 14, p);
36 var rg = jalview.jsdev.RegExp.perlCode ("/" + this.regexReplace + "/");
38 this.invalidMessage = "Invalid Regular Expression : '" + this.regexReplace + "'\n";
40 if (Clazz.exceptionOf (e, Exception)) {
41 this.invalidMessage = "Invalid Regular Expression : '" + this.regexReplace + "'\n";
47 this.regexReplace = null;
48 if (link.indexOf ("$SEQUENCE_ID$") == psqid) {
49 this.url_suffix = link.substring (psqid + 13);
50 this.regexReplace = null;
52 this.invalidMessage = "Warning: invalid regex structure for URL link : " + link;
54 this.target = link.substring (0, sep);
55 this.label = link.substring (0, sep = link.lastIndexOf ("|"));
56 this.url_prefix = link.substring (sep + 1);
57 this.regexReplace = null;
58 this.url_suffix = null;
60 Clazz.defineMethod (c$, "getUrl_suffix",
62 return this.url_suffix;
64 Clazz.defineMethod (c$, "getUrl_prefix",
66 return this.url_prefix;
68 Clazz.defineMethod (c$, "getTarget",
72 Clazz.defineMethod (c$, "getLabel",
76 Clazz.defineMethod (c$, "getRegexReplace",
78 return this.regexReplace;
80 Clazz.defineMethod (c$, "getInvalidMessage",
82 return this.invalidMessage;
84 Clazz.defineMethod (c$, "isValid",
86 return this.invalidMessage == null;
88 Clazz.defineMethod (c$, "makeUrls",
89 function (idstring, onlyIfMatches) {
91 if (this.regexReplace != null) {
92 var rg = jalview.jsdev.RegExp.perlCode ("/" + this.regexReplace + "/");
93 if (rg.search (idstring)) {
94 var ns = rg.numSubs ();
96 return Clazz.newArray (-1, [rg.stringMatchedI (ns), this.url_prefix + rg.stringMatched () + this.url_suffix]);
98 for (var s = 0; s <= rg.numSubs (); s++) {
99 System.err.println ("Sub " + s + " : " + rg.matchedFromI (s) + " : " + rg.matchedToI (s) + " : '" + rg.stringMatchedI (s) + "'");
101 var subs = new java.util.Vector ();
104 if (s + 1 <= ns && rg.matchedToI (s) > -1 && rg.matchedToI (s + 1) > -1 && rg.matchedToI (s + 1) < rg.matchedToI (s)) {
107 while (r <= ns && rg.matchedToI (r) <= rg.matchedToI (s)) {
108 if (rg.matchedFromI (r) > -1) {
109 mtch += rg.stringMatchedI (r);
112 if (mtch.length > 0) {
113 subs.addElement (mtch);
114 subs.addElement (this.url_prefix + mtch + this.url_suffix);
117 if (rg.matchedFromI (s) > -1) {
118 subs.addElement (rg.stringMatchedI (s));
119 subs.addElement (this.url_prefix + rg.stringMatchedI (s) + this.url_suffix);
122 var res = new Array (subs.size ());
123 for (var r = 0, rs = subs.size (); r < rs; r++) {
124 res[r] = subs.elementAt (r);
126 subs.removeAllElements ();
128 }}if (onlyIfMatches) {
130 }}if (idstring.indexOf ("|") > -1) {
131 idstring = idstring.substring (idstring.lastIndexOf ("|") + 1);
132 }return Clazz.newArray (-1, [idstring, this.url_prefix + idstring + this.url_suffix]);
134 return Clazz.newArray (-1, ["", this.url_prefix]);
136 Clazz.overrideMethod (c$, "toString",
138 return this.label + "|" + this.url_prefix + (this.dynamic ? ("$SEQUENCE_ID" + ((this.regexReplace != null) ? "=" + this.regexReplace + "=$" : "$")) : "") + ((this.url_suffix == null) ? "" : this.url_suffix);
140 Clazz.defineMethod (c$, "isDynamic",
144 Clazz.defineMethod (c$, "setLabel",
145 function (newlabel) {
146 this.label = newlabel;