* Jalview 2.4 extension allows regular expressions to be used to parse ID
* strings and replace the result in the URL. Regex's operate on the whole ID
* string given to the matchURL method, if no regex is supplied, then only
- * text following the first pipe symbol will be susbstituted. Usage
+ * text following the first pipe symbol will be substituted. Usage
* documentation todo.
*/
- private String url_suffix, url_prefix, target, label, regexReplace;
+
+ // Internal constants
+ private static final String SEP = "|";
+
+ private static final String DELIM = "$";
+
+ private String urlSuffix;
+
+ private String urlPrefix;
+
+ private String target;
+
+ private String label;
+
+ private String regexReplace;
private boolean dynamic = false;
- private boolean uses_db_accession = false;
+ private boolean usesDBaccession = false;
private String invalidMessage = null;
/**
- * parse the given linkString of the form '<label>|<url>' into parts url may
+ * parse the given linkString of the form '<label>SEP<url>' into parts url may
* contain a string $SEQUENCE_ID<=optional regex=>$ where <=optional regex=>
* must be of the form =/<perl style regex>/=$
*
*/
public UrlLink(String link)
{
- int sep = link.indexOf("|");
- int psqid = link.indexOf("$" + DB_ACCESSION);
- int nsqid = link.indexOf("$" + SEQUENCE_ID);
+ int sep = link.indexOf(SEP);
+ int psqid = link.indexOf(DELIM + DB_ACCESSION);
+ int nsqid = link.indexOf(DELIM + SEQUENCE_ID);
if (psqid > -1)
{
dynamic = true;
- uses_db_accession = true;
+ usesDBaccession = true;
sep = parseTargetAndLabel(sep, psqid, link);
else
{
target = link.substring(0, sep);
- sep = link.lastIndexOf("|");
+ sep = link.lastIndexOf(SEP);
label = link.substring(0, sep);
- url_prefix = link.substring(sep + 1).trim();
+ urlPrefix = link.substring(sep + 1).trim();
regexReplace = null; // implies we trim any prefix if necessary //
- // regexReplace=".*\\|?(.*)";
- url_suffix = null;
+ urlSuffix = null;
}
label = label.trim();
*/
public String getUrl_suffix()
{
- return url_suffix;
+ return urlSuffix;
}
/**
*/
public String getUrl_prefix()
{
- return url_prefix;
+ return urlPrefix;
}
/**
}
/**
+ *
+ * @return whether link is dynamic
+ */
+ public boolean isDynamic()
+ {
+ return dynamic;
+ }
+
+ /**
+ *
+ * @return whether link uses DB Accession id
+ */
+ public boolean usesDBAccession()
+ {
+ return usesDBaccession;
+ }
+
+ /**
+ * Set the label
+ *
+ * @param newlabel
+ */
+ public void setLabel(String newlabel)
+ {
+ this.label = newlabel;
+ }
+
+ /**
* return one or more URL strings by applying regex to the given idstring
*
* @param idstring
{
// take whole regex
return new String[] { rg.stringMatched(),
- url_prefix + rg.stringMatched() + url_suffix };
+ urlPrefix + rg.stringMatched() + urlSuffix };
} /*
* else if (ns==1) { // take only subgroup match return new String[]
* { rg.stringMatched(1), url_prefix+rg.stringMatched(1)+url_suffix
if (mtch.length() > 0)
{
subs.addElement(mtch);
- subs.addElement(url_prefix + mtch + url_suffix);
+ subs.addElement(urlPrefix + mtch + urlSuffix);
}
s = r;
}
if (rg.matchedFrom(s) > -1)
{
subs.addElement(rg.stringMatched(s));
- subs.addElement(url_prefix + rg.stringMatched(s)
- + url_suffix);
+ subs.addElement(urlPrefix + rg.stringMatched(s)
+ + urlSuffix);
}
s++;
}
}
}
/* Otherwise - trim off any 'prefix' - pre 2.4 Jalview behaviour */
- if (idstring.indexOf("|") > -1)
+ if (idstring.indexOf(SEP) > -1)
{
- idstring = idstring.substring(idstring.lastIndexOf("|") + 1);
+ idstring = idstring.substring(idstring.lastIndexOf(SEP) + 1);
}
// just return simple url substitution.
- return new String[] { idstring, url_prefix + idstring + url_suffix };
+ return new String[] { idstring, urlPrefix + idstring + urlSuffix };
}
else
{
- return new String[] { "", url_prefix };
+ return new String[] { "", urlPrefix };
}
}
@Override
public String toString()
{
- String var = (uses_db_accession ? DB_ACCESSION : SEQUENCE_ID);
+ String var = (usesDBaccession ? DB_ACCESSION : SEQUENCE_ID);
return label
- + "|"
- + url_prefix
- + (dynamic ? ("$" + var + ((regexReplace != null) ? "="
- + regexReplace + "=$" : "$")) : "")
- + ((url_suffix == null) ? "" : url_suffix);
+ + SEP
+ + urlPrefix
+ + (dynamic ? (DELIM + var + ((regexReplace != null) ? "="
+ + regexReplace + "=" + DELIM : DELIM)) : "")
+ + ((urlSuffix == null) ? "" : urlSuffix);
}
/**
do
{
sep = p;
- p = link.indexOf("|", sep + 1);
+ p = link.indexOf(SEP, sep + 1);
} while (p > sep && p < psqid);
- // Assuming that the URL itself does not contain any '|' symbols
+ // Assuming that the URL itself does not contain any SEP symbols
// sep now contains last pipe symbol position prior to any regex symbols
label = link.substring(0, sep);
- if (label.indexOf("|") > -1)
+ if (label.indexOf(SEP) > -1)
{
- // | terminated database name / www target at start of Label
- target = label.substring(0, label.indexOf("|"));
+ // SEP terminated database name / www target at start of Label
+ target = label.substring(0, label.indexOf(SEP));
}
else if (label.indexOf(" ") > 2)
{
*/
protected void parseUrl(String link, String varName, int sqidPos, int sep)
{
- url_prefix = link.substring(sep + 1, sqidPos).trim();
+ urlPrefix = link.substring(sep + 1, sqidPos).trim();
// delimiter at start of regex: e.g. $SEQUENCE_ID=/
- String startDelimiter = "$" + varName + "=/";
+ String startDelimiter = DELIM + varName + "=/";
// delimiter at end of regex: /=$
- String endDelimiter = "/=$";
+ String endDelimiter = "/=" + DELIM;
int startLength = startDelimiter.length();
&& (p > sqidPos + startLength))
{
// Extract Regex and suffix
- url_suffix = link.substring(p + endDelimiter.length());
+ urlSuffix = link.substring(p + endDelimiter.length());
regexReplace = link.substring(sqidPos + startLength, p);
try
{
// no regex
regexReplace = null;
// verify format is really correct.
- if (link.indexOf("$" + varName + "$") == sqidPos)
+ if (link.indexOf(DELIM + varName + DELIM) == sqidPos)
{
- url_suffix = link.substring(sqidPos + startLength - 1);
+ urlSuffix = link.substring(sqidPos + startLength - 1);
regexReplace = null;
}
else
* @param seq
* The sequence to create links for
* @param linkset
- * Map of links: key = id | link, value = [target, label, id, link]
+ * Map of links: key = id + SEP + link, value = [target, label, id,
+ * link]
*/
public void createLinksFromSeq(final SequenceI seq,
Map<String, List<String>> linkset)
* Create a static URL link
*
* @param linkset
- * Map of links: key = id | link, value = [target, label, id, link]
+ * Map of links: key = id + SEP + link, value = [target, label, id,
+ * link]
*/
protected void createStaticLink(Map<String, List<String>> linkset)
{
- if (!linkset.containsKey(label + "|" + getUrl_prefix()))
+ if (!linkset.containsKey(label + SEP + getUrl_prefix()))
{
// Add a non-dynamic link
- linkset.put(label + "|" + getUrl_prefix(),
+ linkset.put(label + SEP + getUrl_prefix(),
Arrays.asList(target, label, null, getUrl_prefix()));
}
}
* @param seq
* The sequence to create links for
* @param linkset
- * Map of links: key = id | link, value = [target, label, id, link]
+ * Map of links: key = id + SEP + link, value = [target, label, id,
+ * link]
*/
protected void createDynamicLinks(final SequenceI seq,
Map<String, List<String>> linkset)
/*
* Create a bare URL Link
- * Returns map where key = id | link, and value = [target, label, id, link]
+ * Returns map where key = id + SEP + link, and value = [target, label, id, link]
*/
protected void createBareURLLink(String id, Boolean combineLabel,
Map<String, List<String>> linkset)
{
for (int u = 0; u < urls.length; u += 2)
{
- if (!linkset.containsKey(urls[u] + "|" + urls[u + 1]))
+ if (!linkset.containsKey(urls[u] + SEP + urls[u + 1]))
{
String thisLabel = label;
if (combineLabel)
{
// incorporate label with idstring
- thisLabel = label + "|" + urls[u];
+ thisLabel = label + SEP + urls[u];
}
- linkset.put(urls[u] + "|" + urls[u + 1],
+ linkset.put(urls[u] + SEP + urls[u + 1],
Arrays.asList(target, thisLabel, urls[u], urls[u + 1]));
}
}
}
}
}
-
- public boolean isDynamic()
- {
- return dynamic;
- }
-
- public boolean usesDBAccession()
- {
- return uses_db_accession;
- }
-
- public void setLabel(String newlabel)
- {
- this.label = newlabel;
- }
}