import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
import jalview.io.gff.GffConstants;
-import jalview.util.DBRefUtils;
import jalview.util.UrlLink;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
{
try
{
- for (String[] urllink : createLinksFrom(null, urlstring))
+ for (List<String> urllink : createLinksFrom(null, urlstring))
{
sb.append("<br/> <a href=\""
- + urllink[3]
+ + urllink.get(3)
+ "\" target=\""
- + urllink[0]
+ + urllink.get(0)
+ "\">"
- + (urllink[0].toLowerCase().equals(
- urllink[1].toLowerCase()) ? urllink[0]
- : (urllink[0] + ":" + urllink[1]))
+ + (urllink.get(0).toLowerCase()
+ .equals(urllink.get(1).toLowerCase()) ? urllink
+ .get(0) : (urllink.get(0) + ":" + urllink
+ .get(1)))
+ "</a></br>");
}
} catch (Exception x)
*
* @param seq
* @param link
- * @return String[][] { String[] { link target, link label, dynamic component
- * inserted (if any), url }}
+ * @return Collection< List<String> > { List<String> { link target, link
+ * label, dynamic component inserted (if any), url }}
*/
- String[][] createLinksFrom(SequenceI seq, String link)
+ Collection<List<String>> createLinksFrom(SequenceI seq, String link)
{
- List<String[]> urlSets = new ArrayList<String[]>();
- List<String> uniques = new ArrayList<String>();
+ Map<String, List<String>> urlSets = new LinkedHashMap<String, List<String>>();
UrlLink urlLink = new UrlLink(link);
if (!urlLink.isValid())
{
System.err.println(urlLink.getInvalidMessage());
return null;
}
- if (seq != null && urlLink.isDynamic())
- {
- urlSets.addAll(createDynamicLinks(seq, urlLink, uniques));
- }
- else
- {
- String target = urlLink.getTarget();
- String label = urlLink.getLabel();
- String unq = label + "|" + urlLink.getUrl_prefix();
- if (!uniques.contains(unq))
- {
- uniques.add(unq);
- urlSets.add(new String[] { target, label, null,
- urlLink.getUrl_prefix() });
- }
- }
-
- return urlSets.toArray(new String[][] {});
- }
- /**
- * Formats and returns a list of dynamic href links
- *
- * @param seq
- * @param urlLink
- * @param uniques
- */
- List<String[]> createDynamicLinks(SequenceI seq, UrlLink urlLink,
- List<String> uniques)
- {
- List<String[]> result = new ArrayList<String[]>();
- final String target = urlLink.getTarget();
- final String label = urlLink.getLabel();
+ urlLink.createLinksFromSeq(seq, urlSets);
- // collect matching db-refs
- DBRefEntry[] dbr = DBRefUtils.selectRefs(seq.getDBRefs(),
- new String[] { target });
- // collect id string too
- String id = seq.getName();
- String descr = seq.getDescription();
- if (descr != null && descr.length() < 1)
- {
- descr = null;
- }
- if (dbr != null)
- {
- for (int r = 0; r < dbr.length; r++)
- {
- if (id != null && dbr[r].getAccessionId().equals(id))
- {
- // suppress duplicate link creation for the bare sequence ID
- // string with this link
- id = null;
- }
- // create Bare ID link for this URL
- String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(), true);
- if (urls != null)
- {
- for (int u = 0; u < urls.length; u += 2)
- {
- String unq = urls[u] + "|" + urls[u + 1];
- if (!uniques.contains(unq))
- {
- result.add(new String[] { target, label, urls[u], urls[u + 1] });
- uniques.add(unq);
- }
- }
- }
- }
- }
- if (id != null)
- {
- // create Bare ID link for this URL
- String[] urls = urlLink.makeUrls(id, true);
- if (urls != null)
- {
- for (int u = 0; u < urls.length; u += 2)
- {
- String unq = urls[u] + "|" + urls[u + 1];
- if (!uniques.contains(unq))
- {
- result.add(new String[] { target, label, urls[u], urls[u + 1] });
- uniques.add(unq);
- }
- }
- }
- }
- if (descr != null && urlLink.getRegexReplace() != null)
- {
- // create link for this URL from description only if regex matches
- String[] urls = urlLink.makeUrls(descr, true);
- if (urls != null)
- {
- for (int u = 0; u < urls.length; u += 2)
- {
- String unq = urls[u] + "|" + urls[u + 1];
- if (!uniques.contains(unq))
- {
- result.add(new String[] { target, label, urls[u], urls[u + 1] });
- uniques.add(unq);
- }
- }
- }
- }
- return result;
+ return urlSets.values();
}
public void createSequenceAnnotationReport(final StringBuffer tip,
import jalview.datamodel.DBRefEntry;
import jalview.datamodel.SequenceI;
+import java.util.Arrays;
+import java.util.List;
import java.util.Map;
import java.util.Vector;
* @param linkset
*/
public void createLinksFromSeq(final SequenceI seq,
- Map<String, String[]> linkset)
+ Map<String, List<String>> linkset)
{
if (seq != null && dynamic)
{
*
* @param linkset
*/
- public void createStaticLink(Map<String, String[]> linkset)
+ public void createStaticLink(Map<String, List<String>> linkset)
{
if (!linkset.containsKey(label + "|" + getUrl_prefix()))
{
// Add a non-dynamic link
- linkset.put(label + "|" + getUrl_prefix(), new String[] { "", label,
- "", getUrl_prefix() });
+ linkset.put(label + "|" + getUrl_prefix(),
+ Arrays.asList(target, label, null, getUrl_prefix()));
}
}
* @param linkset
*/
public void createDynamicLinks(final SequenceI seq,
- Map<String, String[]> linkset)
+ Map<String, List<String>> linkset)
{
// collect id string too
String id = seq.getName();
* Create a bare URL Link
*/
protected void createBareURLLink(String id,
- Map<String, String[]> linkset, Boolean combineLabel)
+ Map<String, List<String>> linkset, Boolean combineLabel)
{
String[] urls = makeUrls(id, true);
if (urls != null)
thisLabel = label + "|" + urls[u];
}
- linkset.put(urls[u] + "|" + urls[u + 1], new String[] { target,
- thisLabel, urls[u], urls[u + 1] });
+ linkset.put(urls[u] + "|" + urls[u + 1],
+ Arrays.asList(target, thisLabel, urls[u], urls[u + 1]));
}
}
}