import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
+import jalview.datamodel.DBRefEntry;
import jalview.datamodel.GraphLine;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.Point;
import java.awt.Font;
import java.awt.Rectangle;
import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
*/
public class Jalview2XML
{
+
+ // BH 2018 we add the .jvp binary extension to J2S so that
+ // it will declare that binary when we do the file save from the browser
+
+ private static void addJ2SBinaryType(String ext)
+ {
+ ext = "." + ext + "?";
+
+ /**
+ * @j2sNative
+ *
+ * J2S._binaryTypes.push(ext);
+ *
+ */
+ }
+
+ static
+ {
+ addJ2SBinaryType(".jvp?");
+ }
+
private static final String VIEWER_PREFIX = "viewer_";
private static final String RNA_PREFIX = "rna_";
try
{
// create backupfiles object and get new temp filename destination
- BackupFiles backupfiles = new BackupFiles(jarFile);
- FileOutputStream fos = new FileOutputStream(
- backupfiles.getTempFilePath());
+ boolean doBackup = BackupFiles.getEnabled();
+ BackupFiles backupfiles = doBackup ? new BackupFiles(jarFile) : null;
+ FileOutputStream fos = new FileOutputStream(doBackup ?
+ backupfiles.getTempFilePath() : jarFile);
JarOutputStream jout = new JarOutputStream(fos);
List<AlignFrame> frames = new ArrayList<>();
jout.close();
boolean success = true;
- backupfiles.setWriteSuccess(success);
- success = backupfiles.rollBackupsAndRenameTempFile();
+ if (doBackup)
+ {
+ backupfiles.setWriteSuccess(success);
+ success = backupfiles.rollBackupsAndRenameTempFile();
+ }
return success;
} catch (Exception ex)
// using save and then load
try
{
+ fileName = fileName.replace('\\', '/');
System.out.println("Writing jar entry " + fileName);
JarEntry entry = new JarEntry(fileName);
jout.putNextEntry(entry);
{
if (jout != null)
{
+ jarEntryName = jarEntryName.replace('\\','/');
System.out.println("Writing jar entry " + jarEntryName);
jout.putNextEntry(new JarEntry(jarEntryName));
DataOutputStream dout = new DataOutputStream(jout);
vamsasSeq.setName(jds.getName());
vamsasSeq.setSequence(jds.getSequenceAsString());
vamsasSeq.setDescription(jds.getDescription());
- jalview.datamodel.DBRefEntry[] dbrefs = null;
+ List<DBRefEntry> dbrefs = null;
if (jds.getDatasetSequence() != null)
{
vamsasSeq.setDsseqid(seqHash(jds.getDatasetSequence()));
}
if (dbrefs != null)
{
- for (int d = 0; d < dbrefs.length; d++)
+ for (int d = 0, nd = dbrefs.size(); d < nd; d++)
{
DBRef dbref = new DBRef();
- dbref.setSource(dbrefs[d].getSource());
- dbref.setVersion(dbrefs[d].getVersion());
- dbref.setAccessionId(dbrefs[d].getAccessionId());
- if (dbrefs[d].hasMap())
+ DBRefEntry ref = dbrefs.get(d);
+ dbref.setSource(ref.getSource());
+ dbref.setVersion(ref.getVersion());
+ dbref.setAccessionId(ref.getAccessionId());
+ if (ref.hasMap())
{
- Mapping mp = createVamsasMapping(dbrefs[d].getMap(), parentseq,
+ Mapping mp = createVamsasMapping(ref.getMap(), parentseq,
jds, recurse);
dbref.setMapping(mp);
}
* @param file
* - HTTP URL or filename
*/
- public AlignFrame loadJalviewAlign(final String file)
+ public AlignFrame loadJalviewAlign(final Object file)
{
jalview.gui.AlignFrame af = null;
return af;
}
- private jarInputStreamProvider createjarInputStreamProvider(
- final String file) throws MalformedURLException
- {
- 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 (_url != null)
- {
- return new JarInputStream(_url.openStream());
- }
- else
- {
- return new JarInputStream(new FileInputStream(file));
- }
- }
-
- @Override
- public String getFilename()
- {
- return file;
- }
- };
- }
+ @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());
+ byte[] bytes = /** @j2sNative ofile._bytes || */
+ 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;
+ }
+ }
/**
* Recover jalview session from a jalview project archive. Caller may
if (jarentry != null && jarentry.getName().endsWith(".xml"))
{
- InputStreamReader in = new InputStreamReader(jin, UTF_8);
- // JalviewModel object = new JalviewModel();
-
JAXBContext jc = JAXBContext
.newInstance("jalview.xml.binding.jalview");
XMLStreamReader streamReader = XMLInputFactory.newInstance()
.unmarshal(streamReader, JalviewModel.class);
JalviewModel object = jbe.getValue();
- /*
- Unmarshaller unmar = new Unmarshaller(object);
- unmar.setValidation(false);
- object = (JalviewModel) unmar.unmarshal(in);
- */
if (true) // !skipViewport(object))
{
_af = loadFromObject(object, file, true, jprovider);
// TODO: verify 'associate with all views' works still
tp.getTreeCanvas().setViewport(av); // af.viewport;
tp.getTreeCanvas().setAssociatedPanel(ap); // af.alignPanel;
- // FIXME: should we use safeBoolean here ?
- tp.getTreeCanvas().setApplyToAllViews(tree.isLinkToAllViews());
-
}
+ tp.getTreeCanvas().setApplyToAllViews(tree.isLinkToAllViews());
if (tp == null)
{
warn("There was a problem recovering stored Newick tree: \n"
{
AlignFrame af = null;
af = new AlignFrame(al, safeInt(view.getWidth()),
- safeInt(view.getHeight()), uniqueSeqSetId, viewId);
+ safeInt(view.getHeight()), uniqueSeqSetId, viewId)
+// {
+//
+// @Override
+// protected void processKeyEvent(java.awt.event.KeyEvent e) {
+// System.out.println("Jalview2XML AF " + e);
+// super.processKeyEvent(e);
+//
+// }
+//
+// }
+ ;
af.setFileName(file, FileFormat.Jalview);