From a425a1cbcc390b065e6bb447a1e29f4099e53119 Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 12 Jun 2009 15:47:50 +0000 Subject: [PATCH] retrieve and init vamsas session from vdoc at URL --- src/jalview/bin/Jalview.java | 21 ++++++++++------- src/jalview/gui/Desktop.java | 53 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 9 deletions(-) diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index a2ef369..ed51cee 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -86,9 +86,9 @@ public class Jalview + "-nousagestats\tTurn off google analytics tracking for this session.\n" + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n" // + "-setprop PROPERTY=VALUE\tSet the given Jalview property, after all other properties files have been read\n\t (quote the 'PROPERTY=VALUE' pair to ensure spaces are passed in correctly)" - + "-dasserver nickname=URL\tAdd and enable a das server with given nickname (alphanumeric or underscores only) for retrieval of features for all alignments.\n" - +"\t\tSources that also support the sequence command may be specified by prepending the URL with sequence:\n" - +"\t\t e.g. sequence:http://localdas.somewhere.org/das/source)\n" + + "-dasserver nickname=URL\tAdd and enable a das server with given nickname\n\t\t\t(alphanumeric or underscores only) for retrieval of features for all alignments.\n" + +"\t\t\tSources that also support the sequence command may be specified by prepending the URL with sequence:\n" + +"\t\t\t e.g. sequence:http://localdas.somewhere.org/das/source)\n" + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n" // + "-vdoc vamsas-document\tImport vamsas document into new session or join existing session with same URN\n" // + "-vses vamsas-session\tJoin session with given URN\n" @@ -219,9 +219,14 @@ public class Jalview boolean inSession = false; if (vamsasImport!=null) { - try { - inSession = desktop.vamsasImport(new File(vamsasImport)); - + try { + String viprotocol = Jalview.checkProtocol(vamsasImport); + if (viprotocol == jalview.io.FormatAdapter.FILE) { + inSession = desktop.vamsasImport(new File(vamsasImport)); + } else if (viprotocol == jalview.io.FormatAdapter.URL) { + inSession = desktop.vamsasImport(new URL(vamsasImport)); + } + } catch (Exception e) { System.err.println("Exeption when importing "+vamsasImport+" as a vamsas document."); @@ -231,8 +236,8 @@ public class Jalview System.err.println("Failed to import "+vamsasImport+" as a vamsas document."); } else { System.out.println("Imported Successfully into new session "+desktop.getVamsasApplication().getCurrentSession()); - } - } + } + } if (vamsasSession!=null) { if (vamsasImport!=null) { // close the newly imported session and import the Jalview specific remnants into the new session later on. diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index f9689db..484bcde 100755 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -24,8 +24,15 @@ import java.awt.*; import java.awt.datatransfer.*; import java.awt.dnd.*; import java.awt.event.*; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; import java.lang.reflect.Constructor; +import java.net.URL; +import java.net.URLConnection; +import java.nio.channels.ReadableByteChannel; import java.util.*; import javax.swing.*; @@ -1125,8 +1132,52 @@ public class Desktop extends jalview.jbgui.GDesktop implements * @param file * @return true if import was a success and a session was started. */ + public boolean vamsasImport(URL url) + { + // TODO: create progress bar + if (v_client != null) + { + + jalview.bin.Cache.log + .error("Implementation error - load session from a running session is not supported."); + return false; + } + + try + { + // copy the URL content to a temporary local file + // TODO: be a bit cleverer here with nio (?!) + File file = File.createTempFile("vdocfromurl", ".vdj"); + FileOutputStream fos = new FileOutputStream(file); + BufferedInputStream bis = new BufferedInputStream(url.openStream()); + byte[] buffer = new byte[2048]; + int ln; + while ((ln = bis.read(buffer))>-1) + { + fos.write(buffer,0,ln); + } + bis.close(); + fos.close(); + v_client = new jalview.gui.VamsasApplication(this, file, url.toExternalForm()); + } catch (Exception ex) + { + jalview.bin.Cache.log.error( + "Failed to create new vamsas session from contents of URL "+url,ex); + return false; + } + setupVamsasConnectedGui(); + v_client.initial_update(); // TODO: thread ? + return v_client.inSession(); + } + + /** + * import file into a new vamsas session (uses jalview.gui.VamsasApplication) + * @param file + * @return true if import was a success and a session was started. + */ public boolean vamsasImport(File file) { + // TODO: create progress bar if (v_client != null) { @@ -1137,7 +1188,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements try { - v_client = new jalview.gui.VamsasApplication(this, file); + v_client = new jalview.gui.VamsasApplication(this, file,null); } catch (Exception ex) { jalview.bin.Cache.log.error( -- 1.7.10.2