X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Furls%2FIdentifiersUrlProvider.java;h=07eb23efc9211dd3054b79a1818dc317a6fcaa9a;hb=2eaab3084d84daa55785c0c288592d2a7f603742;hp=f32e5908ea9599b16b4967a7d627e611aea8e9da;hpb=97e2831b327bd80268a39cdd5a6d948d9fe4d185;p=jalview.git diff --git a/src/jalview/urls/IdentifiersUrlProvider.java b/src/jalview/urls/IdentifiersUrlProvider.java index f32e590..07eb23e 100644 --- a/src/jalview/urls/IdentifiersUrlProvider.java +++ b/src/jalview/urls/IdentifiersUrlProvider.java @@ -25,20 +25,18 @@ import static jalview.util.UrlConstants.DB_ACCESSION; import static jalview.util.UrlConstants.DELIM; import static jalview.util.UrlConstants.SEP; +import jalview.util.JSONUtils; import jalview.util.UrlLink; -import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.StringTokenizer; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; /** @@ -65,7 +63,7 @@ public class IdentifiersUrlProvider extends UrlProviderImpl public IdentifiersUrlProvider(String cachedUrlList) { urls = readIdentifiers(IdOrgSettings.getDownloadLocation()); - selectedUrls = new ArrayList(); + selectedUrls = new ArrayList<>(); checkSelectionMatchesUrls(cachedUrlList); } @@ -76,19 +74,20 @@ 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) + @SuppressWarnings("unchecked") +private HashMap readIdentifiers(String idFileName) { - JSONParser parser = new JSONParser(); - // identifiers.org data - HashMap idData = new HashMap(); + HashMap idData = new HashMap<>(); String errorMessage = null; try { + // NOTE: THIS WILL FAIL IN SWINGJS BECAUSE IT INVOLVES A FILE READER + FileReader reader = new FileReader(idFileName); String key = ""; - JSONObject obj = (JSONObject) parser.parse(reader); + Map obj = (Map) JSONUtils.parse(reader); if (obj.containsKey(ID_ORG_KEY)) { key = ID_ORG_KEY; @@ -104,12 +103,12 @@ public class IdentifiersUrlProvider extends UrlProviderImpl return idData; } - JSONArray jsonarray = (JSONArray) obj.get(key); + List jsonarray = (List) obj.get(key); // loop over each entry in JSON array and build HashMap entry for (int i = 0; i < jsonarray.size(); i++) { - JSONObject item = (JSONObject) jsonarray.get(i); + Map item = (Map) jsonarray.get(i); String url = (String) item.get("url") + "/" + DELIM + DB_ACCESSION + DELIM; @@ -124,12 +123,14 @@ public class IdentifiersUrlProvider extends UrlProviderImpl // Typical report here is "NetworkError" because the file does not exist. // "https://." is coming from System.getProperty("user.home"), but this could // be set by the page developer to anything, of course. - errorMessage = (/** @j2sNative String.fromCharCode.apply(null, reader.$in.is.buf.slice(0,12)) || */e.toString()); + errorMessage = e.toString(); idData.clear(); } // BH 2018 -- added more valuable report if (errorMessage != null) + { System.err.println("IdentifiersUrlProvider: cannot read " + idFileName + ": " + errorMessage); + } return idData; } @@ -194,7 +195,7 @@ public class IdentifiersUrlProvider extends UrlProviderImpl @Override public List getLinksForMenu() { - List links = new ArrayList(); + List links = new ArrayList<>(); for (String key : selectedUrls) { links.add(urls.get(key).toStringWithTarget()); @@ -211,7 +212,7 @@ public class IdentifiersUrlProvider extends UrlProviderImpl @Override public void setUrlData(List links) { - selectedUrls = new ArrayList(); + selectedUrls = new ArrayList<>(); Iterator it = links.iterator(); while (it.hasNext())