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