import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.StringTokenizer;
* update the protocol state variable for accessing the datasource located
* by file.
*
- * @param file
+ * @param path
* @return possibly updated datasource string
*/
- public String setProtocolState(String file)
+ public String resolveFileProtocol(String path)
{
- if (file.startsWith("PASTE"))
+ /*
+ * paste data
+ */
+ if (path.startsWith("PASTE"))
{
- file = file.substring(5);
protocol = AppletFormatAdapter.PASTE;
+ return path.substring(5);
}
- else if (inArchive(file))
+
+ /*
+ * a URL
+ */
+ if (path.indexOf("://") != -1)
{
- protocol = AppletFormatAdapter.CLASSLOADER;
+ protocol = AppletFormatAdapter.URL;
+ return path;
}
- else
+
+ /*
+ * relative to document root
+ */
+ URL documentBase = getDocumentBase();
+ String url = resolveUrlForLocalOrAbsolute(path, documentBase);
+ if (urlExists(url))
{
- file = addProtocol(file);
+ if (debug)
+ {
+ System.err.println("Prepended document base '" + documentBase
+ + "' to make: '" + url + "'");
+ }
protocol = AppletFormatAdapter.URL;
+ return url;
}
- dbgMsg("Protocol identified as '" + protocol + "'");
- return file;
+
+ /*
+ * relative to codebase
+ */
+ URL codeBase = getCodeBase();
+ url = applet.resolveUrlForLocalOrAbsolute(path, codeBase);
+ if (urlExists(url))
+ {
+ protocol = AppletFormatAdapter.URL;
+ if (debug)
+ {
+ System.err.println("Prepended codebase '" + codeBase
+ + "' to make: '" + url + "'");
+ }
+ return url;
+ }
+
+ /*
+ * locatable by classloader; test for this last as files in the document
+ * root may also be found by the classloader
+ */
+ if (inArchive(path))
+ {
+ protocol = AppletFormatAdapter.CLASSLOADER;
+ }
+ return path;
}
public LoadingThread(String file, String file2, JalviewLite _applet)
{
return null;
}
- String resolvedFile = setProtocolState(fileParam);
+ String resolvedFile = resolveFileProtocol(fileParam);
String format = new IdentifyFile().Identify(resolvedFile, protocol);
dbgMsg("File identified as '" + format + "'");
AlignmentI al = null;
else
{
param = st.nextToken();
- Vector tmp = new Vector();
- Vector tmp2 = new Vector();
+ List<SequenceI> tmp = new ArrayList<SequenceI>();
+ List<String> tmp2 = new ArrayList<String>();
while (st.hasMoreTokens())
{
if (st2.countTokens() > 1)
{
// This is the chain
- tmp2.addElement(st2.nextToken());
+ tmp2.add(st2.nextToken());
seqstring = st2.nextToken();
}
- tmp.addElement(matcher == null ? (Sequence) alignFrame
+ tmp.add(matcher == null ? (Sequence) alignFrame
.getAlignViewport().getAlignment()
.findName(seqstring) : matcher.findIdMatch(seqstring));
}
- seqs = new SequenceI[tmp.size()];
- tmp.copyInto(seqs);
+ seqs = tmp.toArray(new SequenceI[tmp.size()]);
if (tmp2.size() == tmp.size())
{
- chains = new String[tmp2.size()];
- tmp2.copyInto(chains);
+ chains = tmp2.toArray(new String[tmp2.size()]);
}
}
- param = setProtocolState(param);
-
- if (// !jmolAvailable
- // &&
- protocol == AppletFormatAdapter.CLASSLOADER && !useXtrnalSviewer)
- {
- // Re: JAL-357 : the bug isn't a problem if we are using an
- // external viewer!
- // TODO: verify this Re:
- // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
- // This exception preserves the current behaviour where, even if
- // the local pdb file was identified in the class loader
- protocol = AppletFormatAdapter.URL; // this is probably NOT
- // CORRECT!
- param = addProtocol(param); //
- }
-
+ param = resolveFileProtocol(param);
+ // TODO check JAL-357 for files in a jar (CLASSLOADER)
pdb.setFile(param);
if (seqs != null)
{
try
{
- param = setProtocolState(param);
+ param = resolveFileProtocol(param);
JPredFile predictions = new JPredFile(param, protocol);
JnetAnnotationMaker.add_annotation(predictions,
alignFrame.viewport.getAlignment(), 0, false);
String param = applet.getParameter("annotations");
if (param != null)
{
- param = setProtocolState(param);
+ param = resolveFileProtocol(param);
if (new AnnotationFile().annotateAlignmentView(alignFrame.viewport,
param, protocol))
param = applet.getParameter("features");
if (param != null)
{
- param = setProtocolState(param);
+ param = resolveFileProtocol(param);
result = alignFrame.parseFeaturesFile(param, protocol);
}
{
try
{
- treeFile = setProtocolState(treeFile);
+ treeFile = resolveFileProtocol(treeFile);
NewickFile fin = new NewickFile(treeFile, protocol);
fin.parse();