X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=site%2Fj2s%2Fjalview%2Futil%2FUrlLink.js;h=a28894bccd830620bc39046202c7492bf5c62c5e;hp=c50c6ae7c71c77eb75505df503faf4854d8607a2;hb=b9b7a352eee79b7764c3b09c9d19663075061d8c;hpb=8ffd05b3abe52c0b6b79b011c0966361f82d5fe6 diff --git a/site/j2s/jalview/util/UrlLink.js b/site/j2s/jalview/util/UrlLink.js index c50c6ae..a28894b 100644 --- a/site/j2s/jalview/util/UrlLink.js +++ b/site/j2s/jalview/util/UrlLink.js @@ -1,148 +1,148 @@ -Clazz.declarePackage ("jalview.util"); -Clazz.load (null, "jalview.util.UrlLink", ["jalview.jsdev.RegExp", "java.util.Vector"], function () { -c$ = Clazz.decorateAsClass (function () { -this.url_suffix = null; -this.url_prefix = null; -this.target = null; -this.label = null; -this.regexReplace = null; -this.dynamic = false; -this.invalidMessage = null; -Clazz.instantialize (this, arguments); -}, jalview.util, "UrlLink"); -Clazz.makeConstructor (c$, -function (link) { -var sep = link.indexOf ("|"); -var psqid = link.indexOf ("$SEQUENCE_ID"); -if (psqid > -1) { -this.dynamic = true; -var p = sep; -do { -sep = p; -p = link.indexOf ("|", sep + 1); -} while (p > sep && p < psqid); -this.label = link.substring (0, sep); -if (this.label.indexOf ("|") > -1) { -this.target = this.label.substring (0, this.label.indexOf ("|")); -} else if (this.label.indexOf (" ") > 2) { -this.target = this.label.substring (0, this.label.indexOf (" ")); -} else { -this.target = this.label; -}this.url_prefix = link.substring (sep + 1, psqid); -if (link.indexOf ("$SEQUENCE_ID=/") == psqid && (p = link.indexOf ("/=$", psqid + 14)) > psqid + 14) { -this.url_suffix = link.substring (p + 3); -this.regexReplace = link.substring (psqid + 14, p); -try { -var rg = jalview.jsdev.RegExp.perlCode ("/" + this.regexReplace + "/"); -if (rg == null) { -this.invalidMessage = "Invalid Regular Expression : '" + this.regexReplace + "'\n"; -}} catch (e) { -if (Clazz.exceptionOf (e, Exception)) { -this.invalidMessage = "Invalid Regular Expression : '" + this.regexReplace + "'\n"; -} else { -throw e; -} -} -} else { -this.regexReplace = null; -if (link.indexOf ("$SEQUENCE_ID$") == psqid) { -this.url_suffix = link.substring (psqid + 13); -this.regexReplace = null; -} else { -this.invalidMessage = "Warning: invalid regex structure for URL link : " + link; -}}} else { -this.target = link.substring (0, sep); -this.label = link.substring (0, sep = link.lastIndexOf ("|")); -this.url_prefix = link.substring (sep + 1); -this.regexReplace = null; -this.url_suffix = null; -}}, "~S"); -Clazz.defineMethod (c$, "getUrl_suffix", -function () { -return this.url_suffix; -}); -Clazz.defineMethod (c$, "getUrl_prefix", -function () { -return this.url_prefix; -}); -Clazz.defineMethod (c$, "getTarget", -function () { -return this.target; -}); -Clazz.defineMethod (c$, "getLabel", -function () { -return this.label; -}); -Clazz.defineMethod (c$, "getRegexReplace", -function () { -return this.regexReplace; -}); -Clazz.defineMethod (c$, "getInvalidMessage", -function () { -return this.invalidMessage; -}); -Clazz.defineMethod (c$, "isValid", -function () { -return this.invalidMessage == null; -}); -Clazz.defineMethod (c$, "makeUrls", -function (idstring, onlyIfMatches) { -if (this.dynamic) { -if (this.regexReplace != null) { -var rg = jalview.jsdev.RegExp.perlCode ("/" + this.regexReplace + "/"); -if (rg.search (idstring)) { -var ns = rg.numSubs (); -if (ns == 0) { -return Clazz.newArray (-1, [rg.stringMatchedI (ns), this.url_prefix + rg.stringMatched () + this.url_suffix]); -} else { -for (var s = 0; s <= rg.numSubs (); s++) { -System.err.println ("Sub " + s + " : " + rg.matchedFromI (s) + " : " + rg.matchedToI (s) + " : '" + rg.stringMatchedI (s) + "'"); -} -var subs = new java.util.Vector (); -var s = 0; -while (s <= ns) { -if (s + 1 <= ns && rg.matchedToI (s) > -1 && rg.matchedToI (s + 1) > -1 && rg.matchedToI (s + 1) < rg.matchedToI (s)) { -var r = s + 1; -var mtch = ""; -while (r <= ns && rg.matchedToI (r) <= rg.matchedToI (s)) { -if (rg.matchedFromI (r) > -1) { -mtch += rg.stringMatchedI (r); -}r++; -} -if (mtch.length > 0) { -subs.addElement (mtch); -subs.addElement (this.url_prefix + mtch + this.url_suffix); -}s = r; -} else { -if (rg.matchedFromI (s) > -1) { -subs.addElement (rg.stringMatchedI (s)); -subs.addElement (this.url_prefix + rg.stringMatchedI (s) + this.url_suffix); -}s++; -}} -var res = new Array (subs.size ()); -for (var r = 0, rs = subs.size (); r < rs; r++) { -res[r] = subs.elementAt (r); -} -subs.removeAllElements (); -return res; -}}if (onlyIfMatches) { -return null; -}}if (idstring.indexOf ("|") > -1) { -idstring = idstring.substring (idstring.lastIndexOf ("|") + 1); -}return Clazz.newArray (-1, [idstring, this.url_prefix + idstring + this.url_suffix]); -} else { -return Clazz.newArray (-1, ["", this.url_prefix]); -}}, "~S,~B"); -Clazz.overrideMethod (c$, "toString", -function () { -return this.label + "|" + this.url_prefix + (this.dynamic ? ("$SEQUENCE_ID" + ((this.regexReplace != null) ? "=" + this.regexReplace + "=$" : "$")) : "") + ((this.url_suffix == null) ? "" : this.url_suffix); -}); -Clazz.defineMethod (c$, "isDynamic", -function () { -return this.dynamic; -}); -Clazz.defineMethod (c$, "setLabel", -function (newlabel) { -this.label = newlabel; -}, "~S"); -}); +Clazz.declarePackage ("jalview.util"); +Clazz.load (null, "jalview.util.UrlLink", ["jalview.jsdev.RegExp", "java.util.Vector"], function () { +c$ = Clazz.decorateAsClass (function () { +this.url_suffix = null; +this.url_prefix = null; +this.target = null; +this.label = null; +this.regexReplace = null; +this.dynamic = false; +this.invalidMessage = null; +Clazz.instantialize (this, arguments); +}, jalview.util, "UrlLink"); +Clazz.makeConstructor (c$, +function (link) { +var sep = link.indexOf ("|"); +var psqid = link.indexOf ("$SEQUENCE_ID"); +if (psqid > -1) { +this.dynamic = true; +var p = sep; +do { +sep = p; +p = link.indexOf ("|", sep + 1); +} while (p > sep && p < psqid); +this.label = link.substring (0, sep); +if (this.label.indexOf ("|") > -1) { +this.target = this.label.substring (0, this.label.indexOf ("|")); +} else if (this.label.indexOf (" ") > 2) { +this.target = this.label.substring (0, this.label.indexOf (" ")); +} else { +this.target = this.label; +}this.url_prefix = link.substring (sep + 1, psqid); +if (link.indexOf ("$SEQUENCE_ID=/") == psqid && (p = link.indexOf ("/=$", psqid + 14)) > psqid + 14) { +this.url_suffix = link.substring (p + 3); +this.regexReplace = link.substring (psqid + 14, p); +try { +var rg = jalview.jsdev.RegExp.perlCode ("/" + this.regexReplace + "/"); +if (rg == null) { +this.invalidMessage = "Invalid Regular Expression : '" + this.regexReplace + "'\n"; +}} catch (e) { +if (Clazz.exceptionOf (e, Exception)) { +this.invalidMessage = "Invalid Regular Expression : '" + this.regexReplace + "'\n"; +} else { +throw e; +} +} +} else { +this.regexReplace = null; +if (link.indexOf ("$SEQUENCE_ID$") == psqid) { +this.url_suffix = link.substring (psqid + 13); +this.regexReplace = null; +} else { +this.invalidMessage = "Warning: invalid regex structure for URL link : " + link; +}}} else { +this.target = link.substring (0, sep); +this.label = link.substring (0, sep = link.lastIndexOf ("|")); +this.url_prefix = link.substring (sep + 1); +this.regexReplace = null; +this.url_suffix = null; +}}, "~S"); +Clazz.defineMethod (c$, "getUrl_suffix", +function () { +return this.url_suffix; +}); +Clazz.defineMethod (c$, "getUrl_prefix", +function () { +return this.url_prefix; +}); +Clazz.defineMethod (c$, "getTarget", +function () { +return this.target; +}); +Clazz.defineMethod (c$, "getLabel", +function () { +return this.label; +}); +Clazz.defineMethod (c$, "getRegexReplace", +function () { +return this.regexReplace; +}); +Clazz.defineMethod (c$, "getInvalidMessage", +function () { +return this.invalidMessage; +}); +Clazz.defineMethod (c$, "isValid", +function () { +return this.invalidMessage == null; +}); +Clazz.defineMethod (c$, "makeUrls", +function (idstring, onlyIfMatches) { +if (this.dynamic) { +if (this.regexReplace != null) { +var rg = jalview.jsdev.RegExp.perlCode ("/" + this.regexReplace + "/"); +if (rg.search (idstring)) { +var ns = rg.numSubs (); +if (ns == 0) { +return Clazz.newArray (-1, [rg.stringMatchedI (ns), this.url_prefix + rg.stringMatched () + this.url_suffix]); +} else { +for (var s = 0; s <= rg.numSubs (); s++) { +System.err.println ("Sub " + s + " : " + rg.matchedFromI (s) + " : " + rg.matchedToI (s) + " : '" + rg.stringMatchedI (s) + "'"); +} +var subs = new java.util.Vector (); +var s = 0; +while (s <= ns) { +if (s + 1 <= ns && rg.matchedToI (s) > -1 && rg.matchedToI (s + 1) > -1 && rg.matchedToI (s + 1) < rg.matchedToI (s)) { +var r = s + 1; +var mtch = ""; +while (r <= ns && rg.matchedToI (r) <= rg.matchedToI (s)) { +if (rg.matchedFromI (r) > -1) { +mtch += rg.stringMatchedI (r); +}r++; +} +if (mtch.length > 0) { +subs.addElement (mtch); +subs.addElement (this.url_prefix + mtch + this.url_suffix); +}s = r; +} else { +if (rg.matchedFromI (s) > -1) { +subs.addElement (rg.stringMatchedI (s)); +subs.addElement (this.url_prefix + rg.stringMatchedI (s) + this.url_suffix); +}s++; +}} +var res = new Array (subs.size ()); +for (var r = 0, rs = subs.size (); r < rs; r++) { +res[r] = subs.elementAt (r); +} +subs.removeAllElements (); +return res; +}}if (onlyIfMatches) { +return null; +}}if (idstring.indexOf ("|") > -1) { +idstring = idstring.substring (idstring.lastIndexOf ("|") + 1); +}return Clazz.newArray (-1, [idstring, this.url_prefix + idstring + this.url_suffix]); +} else { +return Clazz.newArray (-1, ["", this.url_prefix]); +}}, "~S,~B"); +Clazz.overrideMethod (c$, "toString", +function () { +return this.label + "|" + this.url_prefix + (this.dynamic ? ("$SEQUENCE_ID" + ((this.regexReplace != null) ? "=" + this.regexReplace + "=$" : "$")) : "") + ((this.url_suffix == null) ? "" : this.url_suffix); +}); +Clazz.defineMethod (c$, "isDynamic", +function () { +return this.dynamic; +}); +Clazz.defineMethod (c$, "setLabel", +function (newlabel) { +this.label = newlabel; +}, "~S"); +});