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;
/**
public IdentifiersUrlProvider(String cachedUrlList)
{
urls = readIdentifiers(IdOrgSettings.getDownloadLocation());
- selectedUrls = new ArrayList<String>();
+ selectedUrls = new ArrayList<>();
checkSelectionMatchesUrls(cachedUrlList);
}
* name of identifiers.org download file
* @return hashmap of identifiers.org data, keyed by MIRIAM id
*/
+ @SuppressWarnings("unchecked")
private HashMap<String, UrlLink> readIdentifiers(String idFileName)
{
- JSONParser parser = new JSONParser();
-
// identifiers.org data
- HashMap<String, UrlLink> idData = new HashMap<String, UrlLink>();
+ HashMap<String, UrlLink> 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<String, Object> obj = (Map<String, Object>) JSONUtils
+ .parse(reader);
if (obj.containsKey(ID_ORG_KEY))
{
key = ID_ORG_KEY;
}
else
{
- System.out.println(
+ jalview.bin.Console.outPrintln(
"Unexpected key returned from identifiers jalview service");
return idData;
}
- JSONArray jsonarray = (JSONArray) obj.get(key);
+ List<Object> jsonarray = (List<Object>) 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<String, Object> item = (Map<String, Object>) jsonarray.get(i);
String url = (String) item.get("url") + "/" + DELIM + DB_ACCESSION
+ DELIM;
} catch (IOException | ParseException e)
{
// unnecessary e.printStackTrace();
- // Note how in JavaScript we can grab the first bytes from any file reader.
+ // Note how in JavaScript we can grab the first bytes from any file
+ // reader.
// Typical report here is "NetworkError" because the file does not exist.
- // "https://." is coming from System.getProperty("user.home"), but this could
+ // "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);
+ {
+ jalview.bin.Console.errPrintln("IdentifiersUrlProvider: cannot read "
+ + idFileName + ": " + errorMessage);
+ }
return idData;
}
@Override
public List<String> getLinksForMenu()
{
- List<String> links = new ArrayList<String>();
+ List<String> links = new ArrayList<>();
for (String key : selectedUrls)
{
links.add(urls.get(key).toStringWithTarget());
@Override
public void setUrlData(List<UrlLinkDisplay> links)
{
- selectedUrls = new ArrayList<String>();
+ selectedUrls = new ArrayList<>();
Iterator<UrlLinkDisplay> it = links.iterator();
while (it.hasNext())