exception.url_cannot_have_duplicate_id = {0} cannot be used as a label for more than one line
label.filter = Filter text:
action.customfilter = Custom only
+action.showall = Show All
label.insert = Insert:
action.seq_id = $SEQUENCE_ID$
action.db_acc = $DB_ACCESSION$
exception.url_cannot_have_duplicate_id = {0} cannot be used as a label for more than one link
label.filter = Filter text:
action.customfilter = Custom only
+action.showall = Show All
label.insert = Insert:
action.seq_id = $SEQUENCE_ID$
action.db_acc = $DB_ACCESSION$
import jalview.datamodel.PDBEntry;
import jalview.structure.StructureImportSettings;
+import jalview.urls.IdOrgSettings;
import jalview.ws.dbsources.das.api.DasSourceRegistryI;
import jalview.ws.dbsources.das.datamodel.DasSourceRegistry;
import jalview.ws.sifts.SiftsSettings;
public static final String DAS_ACTIVE_SOURCE = "DAS_ACTIVE_SOURCE";
+ /**
+ * Sifts settings
+ */
public static final String DEFAULT_SIFTS_DOWNLOAD_DIR = System
.getProperty("user.home")
+ File.separatorChar
private final static String DEFAULT_FAIL_SAFE_PID_THRESHOLD = "30";
/**
+ * Identifiers.org download settings
+ */
+ private static final String ID_ORG_FILE = System.getProperty("user.home")
+ + File.separatorChar + ".jalview_identifiers";
+
+ private static final String ID_ORG_URL = "http://identifiers.org/rest/collections/";
+
+ /**
* Allowed values are PDB or mmCIF
*/
private final static String PDB_DOWNLOAD_FORMAT = PDBEntry.Type.MMCIF
"sifts_cache_threshold_in_days",
DEFAULT_CACHE_THRESHOLD_IN_DAYS));
+ IdOrgSettings.setUrl(ID_ORG_URL);
+ IdOrgSettings.setDownloadLocation(ID_ORG_FILE);
+
System.out
.println("Jalview Version: " + codeVersion + codeInstallation);
import jalview.jbgui.GSplitFrame;
import jalview.jbgui.GStructureViewer;
import jalview.structure.StructureSelectionManager;
+import jalview.urls.IdOrgSettings;
import jalview.util.ImageMaker;
import jalview.util.MessageManager;
import jalview.util.Platform;
import jalview.util.UrlConstants;
import jalview.viewmodel.AlignmentViewport;
+import jalview.ws.UrlDownloadClient;
import jalview.ws.params.ParamManager;
import java.awt.BorderLayout;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Hashtable;
showNews.setVisible(false);
+ getIdentifiersOrgData();
+
checkURLLinks();
this.addWindowListener(new WindowAdapter()
});
}
+ public void getIdentifiersOrgData()
+ {
+ // Thread off the identifiers fetcher
+ addDialogThread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ Cache.log.debug("Downloading data from identifiers.org");
+ UrlDownloadClient client = new UrlDownloadClient();
+ try
+ {
+ client.download(IdOrgSettings.getUrl(),
+ IdOrgSettings.getDownloadLocation());
+ } catch (IOException e)
+ {
+ Cache.log.debug("Exception downloading identifiers.org data"
+ + e.getMessage());
+ }
+ }
+ });
+ }
+
@Override
protected void showNews_actionPerformed(ActionEvent e)
{
public static List<String> groupURLLinks;
static
{
- String string = Cache.getDefault("SEQUENCE_LINKS",
+ String inMenuString = Cache.getDefault("SEQUENCE_LINKS",
UrlConstants.DEFAULT_STRING);
- UrlProviderFactoryI factory = new DesktopUrlProviderFactory(
- UrlConstants.DEFAULT_LABEL, string);
+ String notInMenuString = Cache.getDefault("STORED_LINKS", "");
+ String defaultUrl = Cache.getDefault("DEFAULT_URL",
+ UrlConstants.DEFAULT_LABEL);
+ UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
+ inMenuString, notInMenuString);
sequenceUrlLinks = factory.createUrlProvider();
dataModel = new UrlLinkTableModel(sequenceUrlLinks);
// set up radio buttons
linkUrlTable.getColumn("Default").setCellRenderer(
- new RadioButtonRenderer());
+ new RadioButtonRenderer());
linkUrlTable.getColumn("Default")
.setCellEditor(new RadioButtonEditor());
jalview.util.BrowserLauncher.resetBrowser();
// save user-defined and selected links
- String links = linkUrlTable.getModel().toString();
- if (links.isEmpty())
+ String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
+ if (menuLinks.isEmpty())
{
Cache.applicationProperties.remove("SEQUENCE_LINKS");
}
else
{
Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
- links.toString());
+ menuLinks.toString());
}
+ String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
+ if (nonMenuLinks.isEmpty())
+ {
+ Cache.applicationProperties.remove("STORED_LINKS");
+ }
+ else
+ {
+ Cache.applicationProperties.setProperty("STORED_LINKS",
+ nonMenuLinks.toString());
+ }
+
+ Cache.applicationProperties.setProperty("DEFAULT_URL",
+ sequenceUrlLinks.getDefaultUrlId());
+
Cache.applicationProperties.setProperty("USE_PROXY",
Boolean.toString(useProxy.isSelected()));
linkUrlTable.setAutoCreateRowSorter(true);
linkUrlTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ // adjust row height so radio buttons actually fit
+ // don't do this in the renderer, it causes the awt thread to activate
+ // constantly
+ JRadioButton temp = new JRadioButton();
+ linkUrlTable.setRowHeight(temp.getMinimumSize().height);
+
// Table in scrollpane so that the table is given a scrollbar
JScrollPane linkScrollPane = new JScrollPane(linkUrlTable);
linkScrollPane.setBorder(null);
filterTB.setFont(LABEL_FONT);
filterTB.setText("");
- doReset.setText(MessageManager.getString("action.reset"));
+ doReset.setText(MessageManager.getString("action.showall"));
userOnly.setText(MessageManager.getString("action.customfilter"));
// Panel for filter functionality
// set colours to match rest of table
if (isSelected)
- {
- setBackground(table.getSelectionBackground());
- setForeground(table.getSelectionForeground());
- }
- else
- {
- setBackground(table.getBackground());
- setForeground(table.getForeground());
+ {
+ setBackground(table.getSelectionBackground());
+ setForeground(table.getSelectionForeground());
+ }
+ else
+ {
+ setBackground(table.getBackground());
+ setForeground(table.getForeground());
}
- // adjust row height so radio buttons actually fit
- table.setRowHeight(row, getMinimumSize().height);
-
return this;
}
}
public class RadioButtonEditor extends AbstractCellEditor implements
- TableCellEditor
- {
- private JRadioButton button = new JRadioButton();
-
- public RadioButtonEditor()
+ TableCellEditor
{
- this.button.setHorizontalAlignment(SwingConstants.CENTER);
- this.button.addActionListener(new ActionListener()
+ private JRadioButton button = new JRadioButton();
+
+ public RadioButtonEditor()
{
- @Override
- public void actionPerformed(ActionEvent e)
+ // this.button.setHorizontalAlignment(SwingConstants.CENTER);
+ this.button.addActionListener(new ActionListener()
{
- fireEditingStopped();
- }
- });
- }
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ fireEditingStopped();
+ }
+ });
+ }
- @Override
- public Component getTableCellEditorComponent(JTable table,
- Object value, boolean isSelected, int row, int column)
- {
+ @Override
+ public Component getTableCellEditorComponent(JTable table,
+ Object value, boolean isSelected, int row, int column)
+ {
button.setSelected((boolean) value);
- return button;
- }
+ return button;
+ }
- @Override
- public Object getCellEditorValue()
- {
+ @Override
+ public Object getCellEditorValue()
+ {
return button.isSelected();
- }
+ }
}
}
{
// create all the UrlProviders we need
List<UrlProviderI> providers = new ArrayList<UrlProviderI>();
- UrlProviderI customProvider = new CustomUrlProvider(provUrlList);
+ UrlProviderI customProvider = new CustomUrlProvider(provUrlList, null);
providers.add(customProvider);
UrlProviderI prov = new UrlProvider(provDefaultUrl, providers);
- return null;
+ return prov;
}
}
// Default sequence URL link label for SRS
private static final String SRS_LABEL = "SRS";
- // map of string ids to urlLinks
- private HashMap<String, UrlLink> urls;
+ // map of string ids to urlLinks (selected)
+ private HashMap<String, UrlLink> selectedUrls;
+
+ // map of string ids to urlLinks (not selected)
+ private HashMap<String, UrlLink> nonselectedUrls;
/**
* Construct UrlProvider for custom (user-entered) URLs
*
- * @param cachedUrlList
- * list of URLs in form stored in Cache. i.e. SEP delimited string
+ * @param inMenuUrlList
+ * list of URLs set to be displayed in menu, in form stored in Cache.
+ * i.e. SEP delimited string
+ * @param storedUrlList
+ * list of custom URLs entered by user but not currently displayed in
+ * menu, in form stored in Cache
*/
- public CustomUrlProvider(String cachedUrlList)
+ public CustomUrlProvider(String inMenuUrlList, String storedUrlList)
{
try
{
- urls = new HashMap<String, UrlLink>();
-
- // cachedUrlList is in form <label>|<url>|<label>|<url>...
- // parse cachedUrlList into labels (used as id) and url links
- StringTokenizer st = new StringTokenizer(cachedUrlList, SEP);
- while (st.hasMoreElements())
- {
- String name = st.nextToken();
-
- if (!isMiriamId(name))
- {
- // this one of our custom urls
- String url = st.nextToken();
- // check for '|' within a regex
- int rxstart = url.indexOf(DELIM + DB_ACCESSION + DELIM);
- if (rxstart == -1)
- {
- rxstart = url.indexOf(DELIM + SEQUENCE_ID + DELIM);
- }
- while (rxstart == -1 && url.indexOf("/=" + DELIM) == -1
- && st.hasMoreTokens())
- {
- url = url + SEP + st.nextToken();
- }
- urls.put(name, new UrlLink(name + SEP + url));
- }
- }
+ selectedUrls = parseUrlStrings(inMenuUrlList);
+ nonselectedUrls = parseUrlStrings(storedUrlList);
} catch (Exception ex)
{
System.out.println(ex + "\nError parsing sequence links");
}
- upgradeOldLinks();
-
}
/**
* Construct UrlProvider for custom (user-entered) URLs
*
* @param urlList
- * list of URLs as (label,url) pairs
+ * list of URLs to be displayed in menu, as (label,url) pairs
+ * @param storedUrlList
+ * list of custom URLs entered by user but not currently displayed in
+ * menu, as (label,url) pairs
*/
- public CustomUrlProvider(Map<String, String> urlList)
+ public CustomUrlProvider(Map<String, String> inMenuUrlList,
+ Map<String, String> storedUrlList)
{
try
{
- urls = new HashMap<String, UrlLink>();
- Iterator<Map.Entry<String, String>> it = urlList.entrySet()
- .iterator();
- while (it.hasNext())
- {
- Map.Entry<String, String> pair = it.next();
- urls.put(pair.getKey(),
- new UrlLink(pair.getKey() + SEP + pair.getValue()));
- }
+ selectedUrls = parseUrlList(inMenuUrlList);
+ nonselectedUrls = parseUrlList(storedUrlList);
} catch (Exception ex)
{
System.out.println(ex + "\nError parsing sequence links");
}
- upgradeOldLinks();
+ }
+
+ private HashMap<String, UrlLink> parseUrlStrings(String urlStrings)
+ {
+ // cachedUrlList is in form <label>|<url>|<label>|<url>...
+ // parse cachedUrlList into labels (used as id) and url links
+ HashMap<String, UrlLink> urls = new HashMap<String, UrlLink>();
+
+ StringTokenizer st = new StringTokenizer(urlStrings, SEP);
+ while (st.hasMoreElements())
+ {
+ String name = st.nextToken();
+
+ if (!isMiriamId(name))
+ {
+ // this one of our custom urls
+ String url = st.nextToken();
+ // check for '|' within a regex
+ int rxstart = url.indexOf(DELIM + DB_ACCESSION + DELIM);
+ if (rxstart == -1)
+ {
+ rxstart = url.indexOf(DELIM + SEQUENCE_ID + DELIM);
+ }
+ while (rxstart == -1 && url.indexOf("/=" + DELIM) == -1
+ && st.hasMoreTokens())
+ {
+ url = url + SEP + st.nextToken();
+ }
+ urls.put(name, new UrlLink(name + SEP + url));
+ }
+ }
+ upgradeOldLinks(urls);
+ return urls;
+ }
+
+ private HashMap<String, UrlLink> parseUrlList(Map<String, String> urlList)
+ {
+ HashMap<String, UrlLink> urls = new HashMap<String, UrlLink>();
+ Iterator<Map.Entry<String, String>> it = urlList.entrySet().iterator();
+ while (it.hasNext())
+ {
+ Map.Entry<String, String> pair = it.next();
+ urls.put(pair.getKey(),
+ new UrlLink(pair.getKey() + SEP + pair.getValue()));
+ }
+ upgradeOldLinks(urls);
+ return urls;
}
/*
* Upgrade any legacy links which may have been left lying around
*/
- private void upgradeOldLinks()
+ private void upgradeOldLinks(HashMap<String, UrlLink> urls)
{
// upgrade old SRS link
if (urls.containsKey(SRS_LABEL))
public Vector<String> getLinksForMenu()
{
Vector<String> links = new Vector<String>();
- Iterator<Map.Entry<String, UrlLink>> it = urls.entrySet().iterator();
+ Iterator<Map.Entry<String, UrlLink>> it = selectedUrls.entrySet()
+ .iterator();
while (it.hasNext())
{
Map.Entry<String, UrlLink> pair = it.next();
public List<UrlLinkDisplay> getLinksForTable()
{
ArrayList<UrlLinkDisplay> displayLinks = new ArrayList<UrlLinkDisplay>();
- for (Entry<String, UrlLink> entry : urls.entrySet())
- {
- String key = entry.getKey();
- boolean isDefault = (key.equals(defaultUrl));
- boolean isSelected = true; // custom urls always selected
- String displayLink = entry.getValue().toString().split("\\|")[1]; // TODO
- // sort
- // this
- // out
- // properly!
- displayLinks.add(new UrlLinkDisplay(key, key, displayLink,
- isSelected, isDefault));
- }
+ displayLinks = getLinksForTable(selectedUrls, true);
+ displayLinks.addAll(getLinksForTable(nonselectedUrls, false));
return displayLinks;
}
+ private ArrayList<UrlLinkDisplay> getLinksForTable(
+ HashMap<String, UrlLink> urlList, boolean selected)
+ {
+ return super.getLinksForTable(urlList, null, selected);
+ }
+
@Override
public boolean setDefaultUrl(String id)
{
- if (urls.containsKey(id))
+ if (selectedUrls.containsKey(id))
+ {
+ defaultUrl = id;
+ }
+ else if (nonselectedUrls.containsKey(id))
{
+ selectedUrls.put(id, nonselectedUrls.get(id));
+ nonselectedUrls.remove(id);
defaultUrl = id;
}
else
{
defaultUrl = null;
}
- return urls.containsKey(id);
+ return (defaultUrl != null);
}
@Override
- public String writeUrlsAsString()
+ public String writeUrlsAsString(boolean selected)
{
StringBuffer links = new StringBuffer();
+ HashMap<String, UrlLink> urls;
+ if (selected)
+ {
+ urls = selectedUrls;
+ }
+ else
+ {
+ urls = nonselectedUrls;
+ }
if (urls.size() > 0)
{
- for (UrlLink link : urls.values())
+ for (Entry<String, UrlLink> entry : urls.entrySet())
{
- links.append(link.toString());
+ links.append(entry.getValue().toString());
links.append(SEP);
}
@Override
public String getDefaultUrl(String seqid)
{
- if (defaultUrl == null)
- {
- return null;
- }
+ return super.getDefaultUrl(seqid, selectedUrls);
+ }
- String url = null;
- UrlLink urlLink = urls.get(defaultUrl);
- String[] defaultUrls = urlLink.makeUrls(seqid, true);
- if (defaultUrls == null || defaultUrls[0] == null
- || defaultUrls[0].length() < MIN_SUBST_LENGTH)
- {
- url = null;
- }
- else
- {
- // just take first URL made from regex
- url = defaultUrls[1];
- }
- return url;
+ @Override
+ public String getDefaultUrlId()
+ {
+ return defaultUrl;
}
@Override
public String getDefaultTarget(String seqid)
{
- return urls.get(defaultUrl).getTarget();
+ return selectedUrls.get(defaultUrl).getTarget();
}
@Override
public void setUrlData(List<UrlLinkDisplay> links)
{
- HashMap<String, UrlLink> newurls = new HashMap<String, UrlLink>();
+ HashMap<String, UrlLink> unselurls = new HashMap<String, UrlLink>();
+ HashMap<String, UrlLink> selurls = new HashMap<String, UrlLink>();
Iterator<UrlLinkDisplay> it = links.iterator();
while (it.hasNext())
// MIRIAM ids will be handled by a different UrlProvider class
if (!isMiriamId(link.getId()))
{
-
// don't allow duplicate key names as entries will be overwritten
- if (newurls.containsKey(link.getId()))
+ if (unselurls.containsKey(link.getId())
+ || selurls.containsKey(link.getId()))
{
throw new IllegalArgumentException(MessageManager.formatMessage(
"exception.url_cannot_have_duplicate_id", link.getId()));
}
if (link.getIsSelected())
{
- newurls.put(link.getId(),
+ selurls.put(link.getId(),
new UrlLink(link.getId() + SEP + link.getUrl()));
// sort out default and selected ids
setDefaultUrl(link.getId());
}
}
- // TODO KM make it possible to set and save selected custom urls
-
+ else
+ {
+ unselurls.put(link.getId(),
+ new UrlLink(link.getId() + SEP + link.getUrl()));
+ }
}
}
- urls = newurls;
+ nonselectedUrls = unselurls;
+ selectedUrls = selurls;
}
@Override
{
// unilaterally set the default id to the EMBL_EBI link
- if (!urls.containsKey(UrlConstants.DEFAULT_LABEL))
+ if (nonselectedUrls.containsKey(UrlConstants.DEFAULT_LABEL))
{
- urls.put(UrlConstants.DEFAULT_LABEL, new UrlLink(UrlConstants.DEFAULT_STRING));
+ // default key must be selected so remove from nonselected list
+ nonselectedUrls.remove(UrlConstants.DEFAULT_LABEL);
+ }
+
+ if (!selectedUrls.containsKey(UrlConstants.DEFAULT_LABEL))
+ {
+ selectedUrls.put(UrlConstants.DEFAULT_LABEL, new UrlLink(
+ UrlConstants.DEFAULT_STRING));
}
defaultUrl = UrlConstants.DEFAULT_LABEL;
return UrlConstants.DEFAULT_LABEL;
private String provDefaultUrl;
- private String provUrlList;
+ private String menuUrlList;
+
+ private String nonMenuUrlList;
public DesktopUrlProviderFactory(String defaultUrlString,
- String cachedUrlList)
+ String cachedUrlList, String userUrlList)
{
provDefaultUrl = defaultUrlString;
- provUrlList = cachedUrlList;
+ menuUrlList = cachedUrlList;
+ nonMenuUrlList = userUrlList;
}
@Override
// create all the UrlProviders we need
List<UrlProviderI> providers = new ArrayList<UrlProviderI>();
- UrlProviderI idProvider = new IdentifiersUrlProvider(provUrlList,
- IdentifiersUrlProvider.ID_ORG_FILE);
- UrlProviderI customProvider = new CustomUrlProvider(provUrlList);
+ UrlProviderI idProvider = new IdentifiersUrlProvider(menuUrlList);
+ UrlProviderI customProvider = new CustomUrlProvider(menuUrlList,
+ nonMenuUrlList);
providers.add(idProvider);
providers.add(customProvider);
--- /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.urls;
+
+/**
+ * Holds settings for identifiers.org e.g. url, download location
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class IdOrgSettings
+{
+ private static String url;
+
+ private static String location;
+
+ public static void setUrl(String seturl)
+ {
+ url = seturl;
+ }
+
+ public static void setDownloadLocation(String setloc)
+ {
+ location = setloc;
+ }
+
+ public static String getUrl()
+ {
+ return url;
+ }
+
+ public static String getDownloadLocation()
+ {
+ return location;
+ }
+}
import static jalview.util.UrlConstants.DELIM;
import static jalview.util.UrlConstants.SEP;
-import java.io.BufferedInputStream;
-import java.io.File;
+import jalview.util.UrlLink;
+
import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-import java.util.Map.Entry;
+import java.util.StringTokenizer;
import java.util.Vector;
import org.json.simple.JSONArray;
{
// map of string ids to urls
- private HashMap<String, HashMap<String, String>> urls;
+ private HashMap<String, UrlLink> urls;
// list of selected urls
private ArrayList<String> selectedUrls;
- /*
- * Location of file for identifiers.org download
- */
- public static final String ID_ORG_FILE = System.getProperty("user.home")
- + File.separatorChar + ".jalview_identifiers";
-
- public IdentifiersUrlProvider(String cachedUrlList, String idFileName)
- {
- try
- {
- // File idFile = getIdentifiers();
- urls = readIdentifiers(new FileReader(idFileName));
- selectedUrls = new ArrayList<String>();
- checkSelectionMatchesUrls(cachedUrlList);
-
- } catch (IOException e)
- {
- System.out.println("Exception reading URLs from identifiers.org");
- System.out.println(e.getMessage());
- }
- }
-
- private File getIdentifiers() throws IOException
+ public IdentifiersUrlProvider(String cachedUrlList)
{
- String identifiersorgUrl = "http://identifiers.org/rest/collections/";
- String outfile = "identifiers.json";
- int BUFFER_SIZE = 4096;
-
- URL url = new URL(identifiersorgUrl);
- InputStream is = new BufferedInputStream(url.openStream());
- FileOutputStream os = new FileOutputStream(outfile);
- byte[] buffer = new byte[BUFFER_SIZE];
- int bytesRead = -1;
- while ((bytesRead = is.read(buffer)) != -1)
- {
- os.write(buffer, 0, bytesRead);
- }
- os.close();
- is.close();
-
- return new File(outfile);
+ urls = readIdentifiers(IdOrgSettings.getDownloadLocation());
+ selectedUrls = new ArrayList<String>();
+ checkSelectionMatchesUrls(cachedUrlList);
}
- private HashMap<String, HashMap<String, String>> readIdentifiers(
- FileReader reader)
+ /**
+ * Read data from an identifiers.org download file
+ *
+ * @param idFileName
+ * name of identifiers.org download file
+ * @return hashmap of identifiers.org data, keyed by MIRIAM id
+ */
+ private HashMap<String, UrlLink> readIdentifiers(
+ String idFileName)
{
JSONParser parser = new JSONParser();
- HashMap<String, HashMap<String, String>> idData = new HashMap<String, HashMap<String, String>>();
+
+ // identifiers.org data
+ HashMap<String, UrlLink> idData = new HashMap<String, UrlLink>();
try
{
+ FileReader reader = new FileReader(idFileName);
+
JSONArray jsonarray = (JSONArray) parser.parse(reader);
// loop over each entry in JSON array and build HashMap entry
{
JSONObject item = (JSONObject) jsonarray.get(i);
- HashMap<String, String> idEntry = new HashMap<String, String>();
- idEntry.put("name", (String) item.get("name"));
- idEntry.put("url", (String) item.get("url"));
- idData.put((String) item.get("id"), idEntry);
+ String url = (String) item.get("url") + "/" + DELIM + DB_ACCESSION
+ + DELIM;
+ UrlLink link = new UrlLink((String) item.get("name") + SEP + url);
+ idData.put((String) item.get("id"), link);
}
} catch (FileNotFoundException e)
{
private void checkSelectionMatchesUrls(String cachedUrlList)
{
-
- String[] prevSelected = cachedUrlList.split("\\" + SEP);
- for (String id : prevSelected)
+ StringTokenizer st = new StringTokenizer(cachedUrlList, SEP);
+ while (st.hasMoreElements())
{
- if (urls.containsKey(id))
- {
- selectedUrls.add(id);
- }
- }
-
- // reset defaultUrl in case it is no longer selected
- setDefaultUrl(defaultUrl);
- }
+ String id = st.nextToken();
- private void checkSelectionMatchesUrls(Vector<String> idList)
- {
- String[] prevSelected = new String[idList.size()];
- idList.toArray(prevSelected);
- for (String id : prevSelected)
- {
- if (urls.containsKey(id))
+ if (isMiriamId(id))
{
- selectedUrls.add(id);
+ // this is an identifiers.org MIRIAM id
+ if (urls.containsKey(id))
+ {
+ selectedUrls.add(id);
+ }
}
}
}
@Override
- public String writeUrlsAsString()
+ public String writeUrlsAsString(boolean selected)
{
+ if (!selected)
+ {
+ return ""; // we don't cache unselected identifiers.org urls
+ }
+
+ StringBuffer links = new StringBuffer();
if (!selectedUrls.isEmpty())
{
- StringBuffer links = new StringBuffer();
for (String k : selectedUrls)
{
links.append(k);
}
// remove last SEP
links.setLength(links.length() - 1);
- return links.toString();
}
- return "";
+ return links.toString();
}
@Override
Vector<String> links = new Vector<String>();
for (String key : selectedUrls)
{
- links.add(urls.get(key).get("name") + SEP + urls.get(key).get("url")
- + "/" + DELIM
- + DB_ACCESSION + DELIM);
+ links.add(urls.get(key).toString());
}
return links;
}
@Override
public List<UrlLinkDisplay> getLinksForTable()
{
- ArrayList<UrlLinkDisplay> displayLinks = new ArrayList<UrlLinkDisplay>();
- for (Entry<String, HashMap<String, String>> entry : urls.entrySet())
- {
- String key = entry.getKey();
- boolean isDefault = (key == defaultUrl);
- boolean isSelected = (selectedUrls.contains(key));
- displayLinks.add(new UrlLinkDisplay(key,
- entry.getValue().get("name"),
- entry.getValue().get("url")
- + "/" + DELIM + DB_ACCESSION + DELIM, isSelected, isDefault));
- }
- return displayLinks;
+ return super.getLinksForTable(urls, selectedUrls, false);
}
@Override
UrlLinkDisplay link = it.next();
// Handle links with MIRIAM ids only
- if (isMiriamId(link.getId())) // TODO separate use of name and id
+ if (isMiriamId(link.getId()))
{
// select/deselect links accordingly and set default url
@Override
public String getDefaultUrl(String seqid)
{
- if (seqid.length() < MIN_SUBST_LENGTH)
- {
- return null;
- }
- else if (defaultUrl == null)
- {
- return null;
- }
- else
- {
- return urls.get(defaultUrl).get("url") + "/" + seqid;
- }
+ return super.getDefaultUrl(seqid, urls);
+ }
+
+ @Override
+ public String getDefaultUrlId()
+ {
+ return defaultUrl;
}
@Override
import java.util.Iterator;
import java.util.List;
+import javax.swing.event.TableModelEvent;
+import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;
/**
defaultRow++;
}
}
+
+ this.addTableModelListener(new TableModelListener()
+ {
+ @Override
+ public void tableChanged(TableModelEvent e)
+ {
+ // update the UrlProvider from data list
+ dataProvider.setUrlData(data);
+ }
+ });
+
}
@Override
return displayColumns.get(columnIndex);
}
- @Override
- public String toString()
- {
- // update the UrlProvider from data list
- dataProvider.setUrlData(data);
-
- return dataProvider.writeUrlsAsString();
- }
-
public void removeRow(int rowIndex)
{
// remove the row from data
fireTableRowsInserted(index, index);
return index;
}
+
}
@Override
public boolean setDefaultUrl(String id)
{
+ boolean outcome = false;
for (UrlProviderI p : providers)
{
if (p.setDefaultUrl(id))
{
- return true;
+ outcome = true;
}
}
- return false;
+ return outcome;
}
@Override
- public String writeUrlsAsString()
+ public String writeUrlsAsString(boolean selected)
{
String result = "";
for (UrlProviderI p : providers)
{
- result += p.writeUrlsAsString();
- result += SEP;
+ String next = p.writeUrlsAsString(selected);
+ if (!next.isEmpty())
+ {
+ result += next;
+ result += SEP;
+ }
}
// remove last sep
- result = result.substring(0, result.length() - 1);
+ if (!result.isEmpty())
+ {
+ result = result.substring(0, result.length() - 1);
+ }
return result;
}
{
for (UrlProviderI p : providers)
{
+ p.setDefaultUrl(null);
p.setUrlData(links);
}
}
}
@Override
+ public String getDefaultUrlId()
+ {
+ String id = null;
+ for (UrlProviderI p : providers)
+ {
+ if (p.getDefaultUrlId() == null)
+ {
+ continue;
+ }
+ else
+ {
+ id = p.getDefaultUrlId();
+ break;
+ }
+ }
+ return id;
+ }
+
+ @Override
public String getDefaultTarget(String seqid)
{
String target = null;
String getDefaultUrl(String seqid);
/**
+ * Get the default URL id
+ *
+ * @return id for default URL
+ */
+ String getDefaultUrlId();
+
+ /**
* Get the target of thelink for the default URL
*
* @seqid sequence id for which to build link
*
* @return string representation of available URLs
*/
- String writeUrlsAsString();
+ String writeUrlsAsString(boolean selected);
/**
* Choose the default URL in the event of the selected default being
*/
package jalview.urls;
+import jalview.util.UrlLink;
+
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map.Entry;
import java.util.Vector;
import java.util.regex.Pattern;
return null;
}
+ protected String getDefaultUrl(String seqid, HashMap<String, UrlLink> urls)
+ {
+ if (seqid.length() < MIN_SUBST_LENGTH)
+ {
+ return null;
+ }
+ else if (defaultUrl == null)
+ {
+ return null;
+ }
+ else
+ {
+ String url = null;
+ UrlLink urlLink = urls.get(defaultUrl);
+ String[] defaultUrls = urlLink.makeUrls(seqid, true);
+ if (defaultUrls == null || defaultUrls[0] == null
+ || defaultUrls[0].length() < MIN_SUBST_LENGTH)
+ {
+ url = null;
+ }
+ else
+ {
+ // just take first URL made from regex
+ url = defaultUrls[1];
+ }
+ return url;
+ }
+ }
+
@Override
public boolean setDefaultUrl(String id)
{
}
@Override
- public String writeUrlsAsString()
+ public String writeUrlsAsString(boolean selected)
{
// TODO Auto-generated method stub
return null;
return null;
}
+ protected ArrayList<UrlLinkDisplay> getLinksForTable(
+ HashMap<String, UrlLink> urls, ArrayList<String> selectedUrls,
+ boolean selected)
+ {
+ ArrayList<UrlLinkDisplay> displayLinks = new ArrayList<UrlLinkDisplay>();
+ for (Entry<String, UrlLink> entry : urls.entrySet())
+ {
+ String key = entry.getKey();
+ boolean isDefault = (key.equals(defaultUrl));
+ boolean isSelected;
+ if (selectedUrls != null)
+ {
+ isSelected = selectedUrls.contains(key);
+ }
+ else
+ {
+ isSelected = selected;
+ }
+ String displayLink = entry.getValue().getUrlWithToken();
+ displayLinks.add(new UrlLinkDisplay(key, entry.getValue().getLabel(),
+ displayLink, isSelected, isDefault));
+ }
+ return displayLinks;
+ }
+
@Override
public void setUrlData(List<UrlLinkDisplay> links)
{
return !isMiriamId(id);
}
+ @Override
+ public String getDefaultUrlId()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
return label;
}
+ public String getUrlWithToken()
+ {
+ String var = (usesDBaccession ? DB_ACCESSION : SEQUENCE_ID);
+
+ return urlPrefix
+ + (dynamic ? (DELIM + var + ((regexReplace != null) ? "="
+ + regexReplace + "=" + DELIM : DELIM)) : "")
+ + ((urlSuffix == null) ? "" : urlSuffix);
+ }
+
/**
* @return the regexReplace
*/
@Override
public String toString()
{
- String var = (usesDBaccession ? DB_ACCESSION : SEQUENCE_ID);
-
- return label
- + SEP
- + urlPrefix
- + (dynamic ? (DELIM + var + ((regexReplace != null) ? "="
- + regexReplace + "=" + DELIM : DELIM)) : "")
- + ((urlSuffix == null) ? "" : urlSuffix);
+ return label + SEP + getUrlWithToken();
}
/**
--- /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.ws;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+
+public class UrlDownloadClient
+{
+ public UrlDownloadClient()
+ {
+
+ }
+
+ /**
+ * Download persistent database URLs from identifiers.org
+ *
+ * @param urlstring
+ * url to download from, as string
+ * @param outfile
+ * the name of file to save the URLs to
+ * @throws IOException
+ */
+ public void download(String urlstring, String outfile) throws IOException
+ {
+ FileOutputStream fos = null;
+ ReadableByteChannel rbc = null;
+ Path temp = null;
+ try
+ {
+ temp = Files.createTempFile(".jalview_", ".tmp");
+
+ URL url = new URL(urlstring);
+ rbc = Channels.newChannel(url.openStream());
+ fos = new FileOutputStream(temp.toString());
+ fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
+
+ // copy tempfile to outfile once our download completes
+ // incase something goes wrong
+ Files.copy(temp, Paths.get(outfile),
+ StandardCopyOption.REPLACE_EXISTING);
+ } catch (IOException e)
+ {
+ throw e;
+ } finally
+ {
+ try
+ {
+ if (fos != null)
+ {
+ fos.close();
+ }
+ } catch (IOException e)
+ {
+ System.out
+ .println("Exception while closing download file output stream: "
+ + e.getMessage());
+ }
+ try
+ {
+ if (rbc != null)
+ {
+ rbc.close();
+ }
+ } catch (IOException e)
+ {
+ System.out.println("Exception while closing download channel: "
+ + e.getMessage());
+ }
+ try
+ {
+ if (temp != null)
+ {
+ Files.deleteIfExists(temp);
+ }
+ } catch (IOException e)
+ {
+ System.out.println("Exception while deleting download temp file: "
+ + e.getMessage());
+ }
+ }
+ }
+}
+ "TEST2|http://address/$SEQUENCE_ID$|SRS|"
+ "http://theSRSlink/$SEQUENCE_ID$";
+ private static final String unselectedList = "NON1|http://x/y/$DB_ACCESSION$|"
+ + "NON2|http://a/b/c/$DB_ACCESSION";
+
private static final HashMap<String, String> urlMap = new HashMap<String, String>()
{
{
}
};
+ private static final HashMap<String, String> unselUrlMap = new HashMap<String, String>()
+ {
+ {
+ put("NON1", "http://x/y/$DB_ACCESSION$");
+ put("NON2", "http://a/b/c/$DB_ACCESSION");
+ }
+ };
+
private static final String[] dlinks = {
"TEST|http://someurl.blah/$DB_ACCESSION$",
"ANOTHER|http://test/t$SEQUENCE_ID$",
"TEST2|http://address/$SEQUENCE_ID$",
UrlConstants.DEFAULT_STRING };
+ private static final String[] unselDlinks = {
+ "NON1|http://x/y/$DB_ACCESSION$", "NON2|http://a/b/c/$DB_ACCESSION" };
+
private static final Vector<String> displayLinks = new Vector<String>(
Arrays.asList(dlinks));
+ private static final Vector<String> unselDisplayLinks = new Vector<String>(
+ Arrays.asList(unselDlinks));
+
private static final String[] dlinks2 = { "a|http://x.y.z/$SEQUENCE_ID$" };
private static final Vector<String> displayLinks2 = new Vector<String>(
@Test(groups = { "Functional" })
public void testDefaultUrl()
{
- UrlProviderI customProv = new CustomUrlProvider(cachedList);
+ UrlProviderI customProv = new CustomUrlProvider(cachedList,
+ unselectedList);
// default url can be set
assertTrue(customProv.setDefaultUrl("ANOTHER"));
public void testUrlLinks()
{
// creation from cached url list works + old links upgraded
- UrlProviderI customProv = new CustomUrlProvider(cachedList);
+ UrlProviderI customProv = new CustomUrlProvider(cachedList,
+ unselectedList);
assertTrue(displayLinks.containsAll(customProv.getLinksForMenu()));
// creation from map works + old links upgraded
- UrlProviderI customProv2 = new CustomUrlProvider(urlMap);
+ UrlProviderI customProv2 = new CustomUrlProvider(urlMap, unselUrlMap);
assertTrue(displayLinks.containsAll(customProv2.getLinksForMenu()));
// writing url links as a string works
// because UrlProvider does not guarantee order of links, we can't just
// compare the output of writeUrlsAsString to a string, hence the hoops here
- String result = customProv.writeUrlsAsString();
- UrlProviderI up = new CustomUrlProvider(result);
+ String result = customProv.writeUrlsAsString(true);
+ UrlProviderI up = new CustomUrlProvider(result, "");
assertTrue(displayLinks.containsAll(up.getLinksForMenu()));
- result = customProv2.writeUrlsAsString();
- UrlProviderI up2 = new CustomUrlProvider(result);
+ result = customProv.writeUrlsAsString(false);
+ up = new CustomUrlProvider("", result);
+ assertTrue(unselDisplayLinks.containsAll(up.getLinksForMenu()));
+
+ result = customProv2.writeUrlsAsString(true);
+ UrlProviderI up2 = new CustomUrlProvider(result, "");
+ assertTrue(displayLinks.containsAll(up2.getLinksForMenu()));
+
+ result = customProv2.writeUrlsAsString(false);
+ up2 = new CustomUrlProvider("", result);
assertTrue(displayLinks.containsAll(up2.getLinksForMenu()));
}
}
+ "MIR:00000011|http://identifiers.org/interpro/$DB_ACCESSION$"
+ "MIR:00000372|http://identifiers.org/ena.embl/$DB_ACCESSION$";
+ private static final String[] unselDlinks = { "ChEBI|http://identifiers.org/chebi/$DB_ACCESSION$" };
+
private static final Vector<String> displayLinks = new Vector<String>(
Arrays.asList(dlinks));
+ private static final Vector<String> unselDisplayLinks = new Vector<String>(
+ Arrays.asList(unselDlinks));
+
private static final Vector<String> displayLinks1 = new Vector<String>(
Arrays.asList(dlinks1));
{
System.err.println(ex);
}
+
+ IdOrgSettings.setDownloadLocation(testfile);
}
/*
{
// creation from cached id list
String idList = "MIR:00000005|MIR:00000011|MIR:00000372";
- UrlProviderI idProv = new IdentifiersUrlProvider(idList, testfile);
+ UrlProviderI idProv = new IdentifiersUrlProvider(idList);
assertTrue(displayLinks.containsAll(idProv.getLinksForMenu()));
// because UrlProvider does not guarantee order of links, we can't just
// compare the output of writeUrlsAsString to a string, hence the hoops here
- String result = idProv.writeUrlsAsString();
- UrlProviderI up = new IdentifiersUrlProvider(result, testfile);
+ String result = idProv.writeUrlsAsString(true);
+ UrlProviderI up = new IdentifiersUrlProvider(result);
assertTrue(displayLinks.containsAll(up.getLinksForMenu()));
+ result = idProv.writeUrlsAsString(false);
+ up = new IdentifiersUrlProvider(result);
+ assertTrue(unselDisplayLinks.containsAll(up.getLinksForMenu()));
+
}
/*
{
// creation from cached id list
String idList = "MIR:00000005|MIR:00000011|MIR:00000372";
- UrlProviderI idProv = new IdentifiersUrlProvider(idList, testfile);
+ UrlProviderI idProv = new IdentifiersUrlProvider(idList);
// initially no default
assertEquals(null, idProv.getDefaultUrl("seqid"));