*/
package jalview.gui;
-import static jalview.util.UrlConstants.DB_ACCESSION;
import static jalview.util.UrlConstants.EMBLEBI_STRING;
-import static jalview.util.UrlConstants.SEQUENCE_ID;
-import static jalview.util.UrlConstants.SRS_STRING;
import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
import jalview.bin.Cache;
import jalview.schemes.ColourSchemeProperty;
import jalview.util.MessageManager;
import jalview.util.Platform;
+import jalview.util.UrlProvider;
+import jalview.util.UrlProviderI;
import jalview.ws.sifts.SiftsSettings;
import java.awt.BorderLayout;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
-import java.util.StringTokenizer;
import java.util.Vector;
import javax.help.HelpSetException;
* Holds name and link separated with | character. Sequence ID must be
* $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
*/
- public static Vector<String> sequenceURLLinks;
+ // public static Vector<String> sequenceURLLinks;
+ public static UrlProviderI sequenceUrlLinks;
/**
* Holds name and link separated with | character. Sequence IDS and Sequences
static
{
String string = Cache.getDefault("SEQUENCE_LINKS", EMBLEBI_STRING);
- sequenceURLLinks = new Vector<String>();
+ sequenceUrlLinks = new UrlProvider(EMBLEBI_STRING.split("\\|")[0],
+ string); // TODO sort out the default string
+ // sequenceURLLinks = new Vector<String>();
- try
- {
- StringTokenizer st = new StringTokenizer(string, "|");
- while (st.hasMoreElements())
- {
- String name = st.nextToken();
- String url = st.nextToken();
- // check for '|' within a regex
- int rxstart = url.indexOf("$" + DB_ACCESSION + "$");
- if (rxstart == -1)
+ /* try
+ {
+ StringTokenizer st = new StringTokenizer(string, "|");
+ while (st.hasMoreElements())
+ {
+ String name = st.nextToken();
+ String url = st.nextToken();
+ // check for '|' within a regex
+ int rxstart = url.indexOf("$" + DB_ACCESSION + "$");
+ if (rxstart == -1)
+ {
+ rxstart = url.indexOf("$" + SEQUENCE_ID + "$");
+ }
+ while (rxstart == -1 && url.indexOf("/=$") == -1)
+ {
+ url = url + "|" + st.nextToken();
+ }
+ sequenceURLLinks.addElement(name + "|" + url);
+ }
+ } catch (Exception ex)
{
- rxstart = url.indexOf("$" + SEQUENCE_ID + "$");
+ System.out.println(ex + "\nError parsing sequence links");
}
- while (rxstart == -1 && url.indexOf("/=$") == -1)
{
- url = url + "|" + st.nextToken();
+ // upgrade old SRS link
+ int srsPos = sequenceURLLinks.indexOf(SRS_STRING);
+ if (srsPos > -1)
+ {
+ sequenceURLLinks.setElementAt(EMBLEBI_STRING, srsPos);
+ }
}
- sequenceURLLinks.addElement(name + "|" + url);
- }
- } catch (Exception ex)
- {
- System.out.println(ex + "\nError parsing sequence links");
- }
- {
- // upgrade old SRS link
- int srsPos = sequenceURLLinks.indexOf(SRS_STRING);
- if (srsPos > -1)
- {
- sequenceURLLinks.setElementAt(EMBLEBI_STRING, srsPos);
- }
- }
-
+ */
/**
* TODO: reformulate groupURL encoding so two or more can be stored in the
* .properties file as '|' separated strings
*/
nameLinks = new Vector<String>();
urlLinks = new Vector<String>();
- for (int i = 0; i < sequenceURLLinks.size(); i++)
- {
- String link = sequenceURLLinks.elementAt(i).toString();
- nameLinks.addElement(link.substring(0, link.indexOf("|")));
- urlLinks.addElement(link.substring(link.indexOf("|") + 1));
- }
-
+ sequenceUrlLinks.getLinksForDisplay(nameLinks, urlLinks);
+ /* for (HashMap.Entry<String, UrlLink> entry: sequenceUrlLinks.getUrlLinks())
+ {
+ String link = sequenceURLLinks.elementAt(i).toString();
+ nameLinks.addElement(link.substring(0, link.indexOf("|")));
+ urlLinks.addElement(link.substring(link.indexOf("|") + 1));
+ }
+ */
updateLinkData();
useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
jalview.util.BrowserLauncher.resetBrowser();
- if (nameLinks.size() > 0)
+ String links = sequenceUrlLinks.writeUrlsAsString();
+ if (links.isEmpty())
{
- StringBuffer links = new StringBuffer();
- sequenceURLLinks = new Vector<String>();
- for (int i = 0; i < nameLinks.size(); i++)
- {
- sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|"
- + urlLinks.elementAt(i));
- links.append(sequenceURLLinks.elementAt(i).toString());
- links.append("|");
- }
- // remove last "|"
- links.setLength(links.length() - 1);
- Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
- links.toString());
+ Cache.applicationProperties.remove("SEQUENCE_LINKS");
}
else
{
- Cache.applicationProperties.remove("SEQUENCE_LINKS");
- sequenceURLLinks.clear();
+ Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
+ links.toString());
}
+ /* if (nameLinks.size() > 0)
+ {
+ StringBuffer links = new StringBuffer();
+ sequenceURLLinks = new Vector<String>();
+ for (int i = 0; i < nameLinks.size(); i++)
+ {
+ sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|"
+ + urlLinks.elementAt(i));
+ links.append(sequenceURLLinks.elementAt(i).toString());
+ links.append("|");
+ }
+ // remove last "|"
+ links.setLength(links.length() - 1);
+ Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
+ links.toString());
+ }
+ else
+ {
+ Cache.applicationProperties.remove("SEQUENCE_LINKS");
+ sequenceURLLinks.clear();
+ }*/
+
Cache.applicationProperties.setProperty("USE_PROXY",
Boolean.toString(useProxy.isSelected()));
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+
+package jalview.util;
+
+import static jalview.util.UrlConstants.DB_ACCESSION;
+import static jalview.util.UrlConstants.EMBLEBI_STRING;
+import static jalview.util.UrlConstants.SEQUENCE_ID;
+import static jalview.util.UrlConstants.SRS_STRING;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+/**
+ *
+ * Implements the UrlProviderI interface for a UrlProvider object which serves
+ * custom URLs defined by the user
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class CustomUrlProvider implements UrlProviderI
+{
+
+ private HashMap<String, UrlLink> urls;
+
+ public CustomUrlProvider(String cachedUrlList)
+ {
+ try
+ {
+ StringTokenizer st = new StringTokenizer(cachedUrlList, "|");
+ while (st.hasMoreElements())
+ {
+ String name = st.nextToken();
+ String url = st.nextToken();
+ // check for '|' within a regex
+ int rxstart = url.indexOf("$" + DB_ACCESSION + "$");
+ if (rxstart == -1)
+ {
+ rxstart = url.indexOf("$" + SEQUENCE_ID + "$");
+ }
+ while (rxstart == -1 && url.indexOf("/=$") == -1)
+ {
+ url = url + "|" + st.nextToken();
+ }
+ urls.put(name, new UrlLink(url));
+ // sequenceURLLinks.addElement(name + "|" + url);
+ }
+ } catch (Exception ex)
+ {
+ System.out.println(ex + "\nError parsing sequence links");
+ }
+
+ // upgrade old SRS link
+ String srs_key = SRS_STRING.split("\\|")[0];
+ if (urls.containsKey(srs_key))
+ {
+ urls.remove(srs_key);
+ urls.put(EMBLEBI_STRING.split("//|")[0],
+ new UrlLink(EMBLEBI_STRING.split("//|")[1]));
+ }
+ }
+
+ @Override
+ public HashMap<String, UrlLink> getUrlLinks()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void getLinksForDisplay(Vector<String> nameLinks,
+ Vector<String> urlLinks)
+ {
+ Iterator<Map.Entry<String, UrlLink>> it = urls.entrySet().iterator();
+ while (it.hasNext())
+ {
+ Map.Entry<String, UrlLink> pair = it.next();
+ nameLinks.addElement(pair.getKey());
+ urlLinks.addElement(pair.getValue().toString()); // TODO check this is
+ // right
+ }
+ }
+
+ @Override
+ public String getDefaultUrl()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setDefaultUrl(String id)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public String writeUrlsAsString()
+ {
+ StringBuffer links = new StringBuffer();
+ if (urls.size() > 0)
+ {
+ for (UrlLink link : urls.values())
+ {
+ links.append(link.toString());
+ links.append("|");
+ }
+
+ // remove last "|"
+ links.setLength(links.length() - 1);
+ }
+ else
+ {
+ urls.clear();
+ }
+ return links.toString();
+ }
+
+ @Override
+ public void setUrlLinks(String cachedUrl)
+ {
+ // TODO Auto-generated method stub, maybe don't need this? watch out for
+ // superclass interactions
+
+ }
+
+ @Override
+ public void setUrlLinks(HashMap<String, UrlLink> links)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+
+package jalview.util;
+
+import java.util.HashMap;
+import java.util.Vector;
+
+/**
+ *
+ * Implements the UrlProviderI interface for a UrlProvider object which serves
+ * URLs from identifiers.org
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class IdentifiersUrlProvider implements UrlProviderI
+{
+
+ public IdentifiersUrlProvider(String cachedUrlList)
+ {
+
+ }
+
+ @Override
+ public HashMap<String, UrlLink> getUrlLinks()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getDefaultUrl()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setDefaultUrl(String id)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public String writeUrlsAsString()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setUrlLinks(String cachedUrl)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setUrlLinks(HashMap<String, UrlLink> links)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void getLinksForDisplay(Vector<String> nameLinks,
+ Vector<String> urlLinks)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.util;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Vector;
+
+/**
+ *
+ * Implements the UrlProviderI interface for a composite UrlProvider object
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class UrlProvider implements UrlProviderI
+{
+ // List of actual URL link providers
+ private List<UrlProviderI> providers;
+
+ // Record of default URL
+ private String defaultUrl;
+
+ /**
+ * Construct URL provider from string of cached URLs, and set default URL
+ *
+ * @param defaultUrl
+ * id of the current default URL
+ * @param cachedUrlList
+ * string listing current active URLs, expected to be custom URLs
+ * separated by |, or ids of URLs
+ */
+ public UrlProvider(String defaultUrl, String cachedUrlList)
+ {
+ // create all the UrlProviders we need
+ providers = new ArrayList<UrlProviderI>();
+
+ UrlProviderI idProvider = new IdentifiersUrlProvider(cachedUrlList);
+ UrlProviderI customProvider = new CustomUrlProvider(cachedUrlList);
+ providers.add(idProvider);
+ providers.add(customProvider);
+
+ // check that the defaultUrl still exists
+ }
+
+ /**
+ * Get all the URL links
+ * @return all URL links
+ */
+ @Override
+ public HashMap<String, UrlLink> getUrlLinks()
+ {
+ HashMap<String, UrlLink> urls = new HashMap<String, UrlLink>();
+ for (UrlProviderI p : providers)
+ {
+ urls.putAll(p.getUrlLinks());
+ }
+ return urls;
+ }
+
+ /**
+ * Get the default URL
+ * @return id of the default URL
+ */
+ @Override
+ public String getDefaultUrl()
+ {
+ return defaultUrl;
+ }
+
+ /**
+ * Set the default URL
+ * @param id the id of the URL to set as default
+ */
+ @Override
+ public void setDefaultUrl(String id)
+ {
+ defaultUrl = id;
+ }
+
+ /**
+ * Write out all URLs as a string suitable for serialising
+ * @return string representation of available URLs
+ */
+ @Override
+ public String writeUrlsAsString()
+ {
+ String result = "";
+ for (UrlProviderI p : providers)
+ {
+ result += p.writeUrlsAsString();
+ }
+ return result;
+ }
+
+ /**
+ * Set URL links from string
+ *
+ * @param cachedUrl
+ * string representation of URL links, i.e. | separated
+ */
+ @Override
+ public void setUrlLinks(String cachedUrl)
+ {
+ for (UrlProviderI p : providers)
+ {
+ p.setUrlLinks(cachedUrl);
+ }
+ }
+
+ /**
+ * Set URL links from collection
+ *
+ * @param links
+ * hashmap containing string indexed UrlLinks
+ */
+ @Override
+ public void setUrlLinks(HashMap<String, UrlLink> links)
+ {
+ for (UrlProviderI p : providers)
+ {
+ p.setUrlLinks(links);
+ }
+ }
+
+ @Override
+ public void getLinksForDisplay(Vector<String> nameLinks,
+ Vector<String> urlLinks)
+ {
+ Vector<String> names = new Vector<String>();
+ Vector<String> links = new Vector<String>();
+ for (UrlProviderI p : providers)
+ {
+ p.getLinksForDisplay(names, links);
+ nameLinks.addAll(names);
+ urlLinks.addAll(links);
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.util;
+
+import java.util.HashMap;
+import java.util.Vector;
+
+/**
+ * Methods for providing consistent access to up-to-date URLs
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public interface UrlProviderI
+{
+ /**
+ * Get all the URL links
+ *
+ * @return all URL links
+ */
+ public HashMap<String, UrlLink> getUrlLinks();
+
+ /**
+ * Get names and urls in as strings for display
+ *
+ * @param nameLinks
+ * @param urlLinks
+ */
+ public void getLinksForDisplay(Vector<String> nameLinks,
+ Vector<String> urlLinks);
+
+ /**
+ * Get the default URL
+ *
+ * @return id of the default URL
+ */
+ public String getDefaultUrl();
+
+ /**
+ * Set the default URL
+ *
+ * @param id
+ * the id of the URL to set as default
+ */
+ public void setDefaultUrl(String id);
+
+ /**
+ * Write out all URLs as a string suitable for serialising
+ *
+ * @return string representation of available URLs
+ */
+ public String writeUrlsAsString();
+
+ /**
+ * Set URL links from string
+ *
+ * @param cachedUrl
+ * string representation of URL links, i.e. | separated
+ */
+ public void setUrlLinks(String cachedUrl);
+
+ /**
+ * Set URL links from collection
+ *
+ * @param links
+ * hashmap containing string indexed UrlLinks
+ */
+ public void setUrlLinks(HashMap<String, UrlLink> links);
+}