/*
- * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
- * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b1)
+ * Copyright (C) 2015 The Jalview Authors
*
* This file is part of Jalview.
*
import jalview.structure.StructureMapping;
import jalview.structure.StructureMappingcommandSet;
import jalview.structure.StructureSelectionManager;
+import jalview.util.HttpUtils;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
import java.util.ArrayList;
import java.util.List;
{
for (int i = 0; i < modelSet.length; i++)
{
- // ? leave file names 'as is' to match StructureMapping.pdbfile
- // modelSet[i] = resolveModelFile(modelSet[i]);
+ modelSet[i] = resolveModelFile(modelSet[i]);
}
}
}
/**
- * Returns the first out of file, file prefixed by document base, or file
+ * Returns the first out of: file, file prefixed by document base, or file
* prefixed by codebase which can be resolved to a valid URL. If none can,
* returns the input parameter value.
*
*/
public String resolveModelFile(String file)
{
- if (isValidUrl(file))
+ // TODO reuse JalviewLite.LoadingThread.addProtocol instead
+ if (HttpUtils.isValidUrl(file))
{
return file;
}
String db = jvlite.getDocumentBase().toString();
db = db.substring(0, db.lastIndexOf("/"));
String docBaseFile = db + "/" + file;
- if (isValidUrl(docBaseFile))
+ if (HttpUtils.isValidUrl(docBaseFile))
{
return docBaseFile;
}
String cb = jvlite.getCodeBase() + file;
- if (isValidUrl(cb))
+ if (HttpUtils.isValidUrl(cb))
{
return cb;
}
return file;
}
- /**
- * Returns true if it is possible to open an input stream at the given URL,
- * else false. The input stream is closed.
- *
- * @param file
- * @return
- */
- private boolean isValidUrl(String file)
- {
- InputStream is = null;
- try
- {
- is = new URL(file).openStream();
- if (is != null)
- {
- return true;
- }
- } catch (IOException x)
- {
- // MalformedURLException, FileNotFoundException
- return false;
- } finally
- {
- if (is != null)
- {
- try
- {
- is.close();
- } catch (IOException e)
- {
- // ignore
- }
- }
- }
- return false;
- }
-
@Override
public String[] getPdbFile()
{