From: jprocter Date: Mon, 12 May 2008 07:56:53 +0000 (+0000) Subject: fixed Jalview project archive bug where alignment view is not written to Jar that... X-Git-Tag: Release_2_4~98 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=51008f2829b2bf03318501e9b69edcda9bebd323;p=jalview.git fixed Jalview project archive bug where alignment view is not written to Jar that was introduced through refactoring JarEntry output code. --- diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 5c08fb0..97dfefd 100755 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -228,16 +228,10 @@ public class Jalview2XML fileName = fileName + ".xml"; } - JarEntry entry = new JarEntry(fileName); - jout.putNextEntry(entry); - out = new PrintWriter(new OutputStreamWriter(jout, "UTF-8")); - SaveState(apanel, fileName, - jout, out); + SaveState(apanel, fileName, jout); } } } - try { out.flush(); } catch (Exception foo) {}; - jout.closeEntry(); try { jout.flush(); } catch (Exception foo) {}; jout.close(); } catch (Exception ex) @@ -265,13 +259,7 @@ public class Jalview2XML { jfileName = jfileName + ".xml"; } - JarEntry entry = new JarEntry(jfileName); - jout.putNextEntry(entry); - PrintWriter out = new PrintWriter(new OutputStreamWriter(jout, - "UTF-8")); - SaveState(apanel, jfileName, jout, out); - try { out.flush(); } catch (Exception foo) {}; - jout.closeEntry(); + SaveState(apanel, jfileName, jout); } try { jout.flush(); } catch (Exception foo) {}; @@ -285,16 +273,16 @@ public class Jalview2XML } /** - * DOCUMENT ME! + * create a JalviewModel from an algnment view and marshall it + * to a JarOutputStream * - * @param af DOCUMENT ME! - * @param timeStamp DOCUMENT ME! - * @param fileName DOCUMENT ME! - * @param jout DOCUMENT ME! - * @param out DOCUMENT ME! + * @param ap panel to create jalview model for + * @param fileName name of alignment panel written to output stream + * @param jout jar output stream + * @param out jar entry name */ public JalviewModel SaveState(AlignmentPanel ap, String fileName, - JarOutputStream jout, PrintWriter out) + JarOutputStream jout) { initSeqRefs(); @@ -986,18 +974,24 @@ public class Jalview2XML object.setJalviewModelSequence(jms); object.getVamsasModel().addSequenceSet(vamsasSet); - if (out != null) + if (jout!=null && fileName!=null) { //We may not want to write the object to disk, //eg we can copy the alignViewport to a new view object //using save and then load try { - org.exolab.castor.xml.Marshaller marshaller = new org.exolab.castor.xml.Marshaller(out); + JarEntry entry = new JarEntry(fileName); + jout.putNextEntry(entry); + PrintWriter pout = new PrintWriter(new OutputStreamWriter(jout, + "UTF-8")); + org.exolab.castor.xml.Marshaller marshaller = new org.exolab.castor.xml.Marshaller(pout); marshaller.marshal(object); - out.flush(); + pout.flush(); + jout.closeEntry(); } catch (Exception ex) { + // TODO: raise error in GUI if marshalling failed. ex.printStackTrace(); } } @@ -1287,6 +1281,9 @@ public class Jalview2XML + ex + "\n"); } catch (Exception ex) { + System.err.println("Parsing as Jalview Version 2 file failed."); + ex.printStackTrace(System.err); + //Is Version 1 Jar file? try { af = new Jalview2XML_V1(raiseGUI).LoadJalviewAlign(file); @@ -2471,8 +2468,8 @@ public class Jalview2XML public jalview.gui.AlignmentPanel copyAlignPanel(AlignmentPanel ap, boolean keepSeqRefs) { - jalview.schemabinding.version2.JalviewModel jm = SaveState(ap, null, - null, null); + jalview.schemabinding.version2.JalviewModel jm = + SaveState(ap, null, null); if (!keepSeqRefs) {