X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Furls%2FIdentifiersUrlProvider.java;h=0988e7d2aa7eb5670ccdf8c145d351390a83929f;hb=c17981672620e0b780a2338bd0c74e55cf9ddec2;hp=45d3863fd19ef61a4e65566d379b2a3b59eeef2c;hpb=e63a4d52c27252dfb83efeeee1bda6c89b6dddec;p=jalview.git diff --git a/src/jalview/urls/IdentifiersUrlProvider.java b/src/jalview/urls/IdentifiersUrlProvider.java index 45d3863..0988e7d 100644 --- a/src/jalview/urls/IdentifiersUrlProvider.java +++ b/src/jalview/urls/IdentifiersUrlProvider.java @@ -35,7 +35,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.StringTokenizer; -import java.util.Vector; import org.json.simple.JSONArray; import org.json.simple.JSONObject; @@ -53,6 +52,10 @@ import org.json.simple.parser.ParseException; public class IdentifiersUrlProvider extends UrlProviderImpl { + private static final String LOCAL_KEY = "Local"; + + private static final String ID_ORG_KEY = "identifiers.org"; + // map of string ids to urls private HashMap urls; @@ -73,8 +76,7 @@ public class IdentifiersUrlProvider extends UrlProviderImpl * name of identifiers.org download file * @return hashmap of identifiers.org data, keyed by MIRIAM id */ - private HashMap readIdentifiers( - String idFileName) + private HashMap readIdentifiers(String idFileName) { JSONParser parser = new JSONParser(); @@ -84,8 +86,24 @@ public class IdentifiersUrlProvider extends UrlProviderImpl try { FileReader reader = new FileReader(idFileName); + String key = ""; + JSONObject obj = (JSONObject) parser.parse(reader); + if (obj.containsKey(ID_ORG_KEY)) + { + key = ID_ORG_KEY; + } + else if (obj.containsKey(LOCAL_KEY)) + { + key = LOCAL_KEY; + } + else + { + System.out.println( + "Unexpected key returned from identifiers jalview service"); + return idData; + } - JSONArray jsonarray = (JSONArray) parser.parse(reader); + JSONArray jsonarray = (JSONArray) obj.get(key); // loop over each entry in JSON array and build HashMap entry for (int i = 0; i < jsonarray.size(); i++) @@ -94,18 +112,22 @@ public class IdentifiersUrlProvider extends UrlProviderImpl String url = (String) item.get("url") + "/" + DELIM + DB_ACCESSION + DELIM; - UrlLink link = new UrlLink((String) item.get("name") + SEP + url); + UrlLink link = new UrlLink((String) item.get("name"), url, + (String) item.get("prefix")); idData.put((String) item.get("id"), link); } } catch (FileNotFoundException e) { e.printStackTrace(); + idData.clear(); } catch (IOException e) { e.printStackTrace(); + idData.clear(); } catch (ParseException e) { e.printStackTrace(); + idData.clear(); } return idData; } @@ -128,21 +150,22 @@ public class IdentifiersUrlProvider extends UrlProviderImpl } // reset defaultUrl in case it is no longer selected - setDefaultUrl(defaultUrl); + setPrimaryUrl(primaryUrl); } @Override - public boolean setDefaultUrl(String id) + public boolean setPrimaryUrl(String id) { - if (selectedUrls.contains(id)) + if (urls.containsKey(id)) { - defaultUrl = id; + primaryUrl = id; } else { - defaultUrl = null; + primaryUrl = null; } - return selectedUrls.contains(id); + + return urls.containsKey(id); } @Override @@ -168,12 +191,12 @@ public class IdentifiersUrlProvider extends UrlProviderImpl } @Override - public Vector getLinksForMenu() + public List getLinksForMenu() { - Vector links = new Vector(); + List links = new ArrayList(); for (String key : selectedUrls) { - links.add(urls.get(key).toString()); + links.add(urls.get(key).toStringWithTarget()); } return links; } @@ -198,48 +221,48 @@ public class IdentifiersUrlProvider extends UrlProviderImpl if (isMiriamId(link.getId())) { // select/deselect links accordingly and set default url - - if (link.getIsSelected()) + if (urls.containsKey(link.getId())) { - if (urls.containsKey(link.getId())) + if (link.getIsSelected()) { selectedUrls.add(link.getId()); } - if (link.getIsDefault()) + if (link.getIsPrimary()) { - setDefaultUrl(link.getId()); + setPrimaryUrl(link.getId()); } - } } - } } @Override - public String getDefaultUrl(String seqid) + public String getPrimaryUrl(String seqid) { - return super.getDefaultUrl(seqid, urls); + return super.getPrimaryUrl(seqid, urls); } @Override - public String getDefaultUrlId() + public String getPrimaryUrlId() { - return defaultUrl; + return primaryUrl; } @Override - public String getDefaultTarget(String seqid) + public String getPrimaryTarget(String seqid) { - // TODO Auto-generated method stub return null; } @Override - public String chooseDefaultUrl() + public String choosePrimaryUrl() { - // TODO Auto-generated method stub return null; } + @Override + public boolean contains(String id) + { + return (urls.containsKey(id)); + } }