X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fproject%2FJalview2XML.java;h=c28002f1840e54f1b9f5284372cbdd2851436499;hb=25e36b8f366dab01f838d8175e59e9148628eb68;hp=186f7866b2e7fdbe3652af5660ab2f7815789a67;hpb=cb51e62fe2166b236ef488e0a8f35081fcd71388;p=jalview.git diff --git a/src/jalview/project/Jalview2XML.java b/src/jalview/project/Jalview2XML.java index 186f786..c28002f 100644 --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@ -161,6 +161,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; @@ -266,6 +267,25 @@ public class Jalview2XML private Map rnaSessions = new HashMap<>(); /** + * contains last error message (if any) encountered by XML loader. + */ + String errorMessage = null; + + /** + * flag to control whether the Jalview2XML_V1 parser should be deferred to if + * exceptions are raised during project XML parsing + */ + public boolean attemptversion1parse = false; + + /* + * JalviewJS only -- to allow read file bytes to be saved in the + * created AlignFrame, allowing File | Reload of a project file to work + * + * BH 2019 JAL-3436 + */ + private File jarFile; + + /** * A helper method for safely using the value of an optional attribute that * may be null if not present in the XML. Answers the boolean value, or false * if null. @@ -425,7 +445,7 @@ public class Jalview2XML * @param _jmap * @return */ - public SeqFref newMappingRef(final String sref, + protected SeqFref newMappingRef(final String sref, final jalview.datamodel.Mapping _jmap) { SeqFref fref = new SeqFref(sref, "Mapping") @@ -447,7 +467,7 @@ public class Jalview2XML return fref; } - public SeqFref newAlcodMapRef(final String sref, + protected SeqFref newAlcodMapRef(final String sref, final AlignedCodonFrame _cf, final jalview.datamodel.Mapping _jmap) { @@ -479,7 +499,7 @@ public class Jalview2XML return fref; } - public void resolveFrefedSequences() + protected void resolveFrefedSequences() { Iterator nextFref = frefedSequence.iterator(); int toresolve = frefedSequence.size(); @@ -847,7 +867,7 @@ public class Jalview2XML * @param out * jar entry name */ - public JalviewModel saveState(AlignmentPanel ap, String fileName, + protected JalviewModel saveState(AlignmentPanel ap, String fileName, JarOutputStream jout, List viewIds) { return saveState(ap, fileName, false, jout, viewIds); @@ -869,7 +889,7 @@ public class Jalview2XML * @param out * jar entry name */ - public JalviewModel saveState(AlignmentPanel ap, String fileName, + protected JalviewModel saveState(AlignmentPanel ap, String fileName, boolean storeDS, JarOutputStream jout, List viewIds) { if (viewIds == null) @@ -2731,17 +2751,6 @@ public class Jalview2XML } /** - * contains last error message (if any) encountered by XML loader. - */ - String errorMessage = null; - - /** - * flag to control whether the Jalview2XML_V1 parser should be deferred to if - * exceptions are raised during project XML parsing - */ - public boolean attemptversion1parse = false; - - /** * Load a jalview project archive from a jar file * * @param file @@ -2789,55 +2798,55 @@ public class Jalview2XML System.err.println("Error loading alignment: " + x.getMessage()); } } + this.jarFile = null; return af; } @SuppressWarnings("unused") - private jarInputStreamProvider createjarInputStreamProvider(final Object ofile) throws MalformedURLException { - - // BH 2018 allow for bytes already attached to File object - try { - String file = (ofile instanceof File ? ((File) ofile).getCanonicalPath() : ofile.toString()); + private jarInputStreamProvider createjarInputStreamProvider( + final Object ofile) throws MalformedURLException + { + try + { + String file = (ofile instanceof File + ? ((File) ofile).getCanonicalPath() + : ofile.toString()); byte[] bytes = Platform.isJS() ? Platform.getFileBytes((File) ofile) : null; - URL url = null; - errorMessage = null; - uniqueSetSuffix = null; - seqRefIds = null; - viewportsAdded.clear(); - frefedSequence = null; - - if (file.startsWith("http://")) { - url = new URL(file); - } - final URL _url = url; - return new jarInputStreamProvider() { - - @Override - public JarInputStream getJarInputStream() throws IOException { - if (bytes != null) { -// System.out.println("Jalview2XML: opening byte jarInputStream for bytes.length=" + bytes.length); - return new JarInputStream(new ByteArrayInputStream(bytes)); - } - if (_url != null) { -// System.out.println("Jalview2XML: opening url jarInputStream for " + _url); - return new JarInputStream(_url.openStream()); - } else { -// System.out.println("Jalview2XML: opening file jarInputStream for " + file); - return new JarInputStream(new FileInputStream(file)); - } - } - - @Override - public String getFilename() { - return file; - } - }; - } catch (IOException e) { - e.printStackTrace(); - return null; - } - } + if (bytes != null) + { + this.jarFile = (File) ofile; + } + errorMessage = null; + uniqueSetSuffix = null; + seqRefIds = null; + viewportsAdded.clear(); + frefedSequence = null; + + URL url = file.startsWith("http://") ? new URL(file) : null; + return new jarInputStreamProvider() + { + @Override + public JarInputStream getJarInputStream() throws IOException + { + InputStream is = bytes != null ? new ByteArrayInputStream(bytes) + : (url != null ? url.openStream() + : new FileInputStream(file)); + return new JarInputStream(is); + } + + @Override + public String getFilename() + { + return file; + } + }; + } catch (IOException e) + { + e.printStackTrace(); + return null; + } + } /** * Recover jalview session from a jalview project archive. Caller may @@ -4685,7 +4694,8 @@ public class Jalview2XML String reformatedOldFilename = oldfilenam.replaceAll("/", "\\\\"); filedat = oldFiles.get(new File(reformatedOldFilename)); } - newFileLoc.append(Platform.escapeString(filedat.getFilePath())); + newFileLoc + .append(Platform.escapeBackslashes(filedat.getFilePath())); pdbfilenames.add(filedat.getFilePath()); pdbids.add(filedat.getPdbId()); seqmaps.add(filedat.getSeqList().toArray(new SequenceI[0])); @@ -4997,7 +5007,7 @@ public class Jalview2XML } } - AlignFrame loadViewport(String file, List JSEQ, + AlignFrame loadViewport(String fileName, List JSEQ, List hiddenSeqs, AlignmentI al, JalviewModel jm, Viewport view, String uniqueSeqSetId, String viewId, List autoAlan) @@ -5017,7 +5027,8 @@ public class Jalview2XML // } ; af.alignPanel.setHoldRepaint(true); - af.setFileName(file, FileFormat.Jalview); + af.setFileName(fileName, FileFormat.Jalview); + af.setFileObject(jarFile); // BH 2019 JAL-3436 final AlignViewport viewport = af.getViewport(); for (int i = 0; i < JSEQ.size(); i++) @@ -5623,7 +5634,7 @@ public class Jalview2XML return false; } - public void addToSkipList(AlignFrame af) + protected void addToSkipList(AlignFrame af) { if (skipList == null) { @@ -5632,7 +5643,7 @@ public class Jalview2XML skipList.put(af.getViewport().getSequenceSetId(), af); } - public void clearSkipList() + protected void clearSkipList() { if (skipList != null) { @@ -6117,6 +6128,7 @@ public class Jalview2XML af.getAlignPanels().clear(); af.closeMenuItem_actionPerformed(true); af.alignPanel.setHoldRepaint(false); + this.jarFile = null; return af.alignPanel; }