1 package org.vamsas.client.simpleclient;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.util.Iterator;
7 import java.util.jar.JarEntry;
8 import java.util.jar.JarFile;
9 import java.util.jar.JarInputStream;
10 import java.util.jar.JarOutputStream;
12 import org.apache.commons.logging.Log;
13 import org.apache.commons.logging.LogFactory;
15 * Basic methods for accessing an existing Vamsas Archive,
16 * and Jar entry names for creating new vamsas archives.
21 public class VamsasArchiveReader {
22 private static Log log = LogFactory.getLog(VamsasArchiveReader.class);
24 public VamsasArchiveReader(File vamsasfile) {
26 if (vamsasfile.exists()) {
28 jfile=new JarFile(vamsasfile);
37 * the vamsas document version(s) handled by this Reader
39 final public static String DOCUMENT_VERSION="0.1";
41 * name of the jarEntry containing a well formatted vamsas XML Document
44 final public static String VAMSASDOC="vamsasDocument.xml";
47 * name of the jarEntry containing a root VAMSAS element, and containing a
48 * random sequence of VAMSAS DataSet elements
51 final public static String VAMSASXML="vamsas.xml";
55 * @return JarEntry for VamsasArchiveReader.VAMSASDOC
57 protected JarEntry getVamsasDocumentEntry() {
59 return jfile.getJarEntry(VAMSASDOC);
64 * @return JarEntry for VamsasArchiveReader.VAMSASXML
66 protected JarEntry getVamsasXmlEntry() {
68 return jfile.getJarEntry(VAMSASXML);
72 * Test for valid vamsas document archive
73 * @return true if getVamsasDocumentStream will return a stream likely to contain valid XML
75 public boolean isValid() {
77 // TODO: check if VAMSASDOC is well formed (follows www.vamsas.ac.uk/schemas/vamsasDocument.xsd) and all appData references are resolvable - preferably as jar entries
78 return (getVamsasDocumentEntry()!=null);
83 protected JarEntry getAppdataEntry(String AppdataRef) {
85 if (jfile==null || !isValid() || (entry=jfile.getJarEntry(AppdataRef))==null)
90 public InputStream getAppdataStream(String AppdataRef) {
91 JarEntry entry=getAppdataEntry(AppdataRef);
94 return jfile.getInputStream(entry);
95 } catch (IOException e) {
96 System.err.println("Failed when opening AppdataStream for "+AppdataRef);
97 e.printStackTrace(System.err);
102 * get the VamsasDocument input stream, if it exists.
103 * @return null or valid input stream
105 public InputStream getVamsasDocumentStream() {
107 if (jfile==null || !isValid())
110 vdoc = jfile.getInputStream(getVamsasDocumentEntry());
111 } catch (IOException e) {
112 e.printStackTrace(System.err);
119 * get the VamsasXML input stream, if it exists.
120 * Note: Deprecated beyond our prealpha testing.
121 * @return null or valid input stream.
124 public InputStream getVamsasXmlStream() {
125 // log.warn("Deprecated call");
126 JarEntry xmle=getVamsasXmlEntry();
131 vdoc = jfile.getInputStream(xmle);
132 } catch (IOException e) {
133 e.printStackTrace(System.err);
140 * silently close the jar file.
143 public void close() {
147 } catch (IOException e) {
148 e.printStackTrace(System.err);