/** * @return the artifact meta data */ public BaseArtifactType getMetaData() { if (metaData == null && metaDataFile != null && metaDataFile.exists()) { try { metaData = SrampArchiveJaxbUtils.readMetaData(metaDataFile); } catch (JAXBException e) { throw new RuntimeException(e); } } return metaData; }
/** * Writes the artifact meta-data to the given working path. * @param outputFile * @param artifact * @throws JAXBException */ public static void writeMetaData(File outputFile, BaseArtifactType artifact) throws JAXBException { writeMetaData(outputFile, artifact, true); }
/** * Reads the meta-data (*.atom) file and returns a JAXB object. * @param metaDataFile * @throws JAXBException */ public static BaseArtifactType readMetaData(File metaDataFile) throws JAXBException { try { Unmarshaller unmarshaller = getJaxbContext().createUnmarshaller(); Entry entry = (Entry) unmarshaller.unmarshal(metaDataFile); return SrampAtomUtils.unwrapSrampArtifact(entry); } catch (JAXBException e) { throw e; } catch (Throwable t) { throw new JAXBException(t); } }
/** * Writes the artifact meta-data to the given output stream. * @param outputStream * @param artifact * @throws JAXBException */ public static void writeMetaData(OutputStream outputStream, BaseArtifactType artifact) throws JAXBException { try { Entry atomEntry = SrampAtomUtils.wrapSrampArtifact(artifact); Marshaller marshaller = getJaxbContext().createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(atomEntry, outputStream); } catch (JAXBException e) { throw e; } catch (Exception e) { throw new JAXBException(e); } }
SrampArchiveJaxbUtils.writeMetaData(zipOutputStream, entry.getMetaData()); } finally {
/** * Writes the artifact meta-data to the given working path. * @param outputFile * @param artifact * @param wrap * @throws JAXBException */ public static void writeMetaData(File outputFile, BaseArtifactType artifact, boolean wrap) throws JAXBException { try { Marshaller marshaller = getJaxbContext().createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); Entry atomEntry = SrampAtomUtils.wrapSrampArtifact(artifact); if (wrap) { marshaller.marshal(atomEntry, outputFile); } else { marshaller.marshal(atomEntry.getAnyOtherJAXBObject(), outputFile); } } catch (JAXBException e) { throw e; } catch (Exception e) { throw new JAXBException(e); } }
/** * Adds an entry to the S-RAMP archive. This method will close the content * {@link InputStream}. * @param path the path in the archive (usually just the name of the artifact) * @param metaData the artifact meta-data * @param content the entry content (or null if a meta-data only entry) * @throws SrampArchiveException */ public void addEntry(String path, BaseArtifactType metaData, InputStream content) throws SrampArchiveException { if (path == null) throw new SrampArchiveException(Messages.i18n.format("INVALID_ENTRY_PATH")); //$NON-NLS-1$ if (metaData == null) throw new SrampArchiveException(Messages.i18n.format("MISSING_META_DATA")); //$NON-NLS-1$ File metaDataFile = new File(this.workDir, path + ".atom"); //$NON-NLS-1$ File contentFile = new File(this.workDir, path); if (metaDataFile.exists()) throw new SrampArchiveException(Messages.i18n.format("ARCHIVE_ALREADY_EXISTS")); //$NON-NLS-1$ // Create any required parent directories metaDataFile.getParentFile().mkdirs(); if (content != null) writeContent(contentFile, content); try { SrampArchiveJaxbUtils.writeMetaData(metaDataFile, metaData); } catch (JAXBException e) { throw new SrampArchiveException(e); } }
/** * Updates an existing entry in the S-RAMP archive. This method will close the content * {@link InputStream}. * @param entry the archive entry (or null if just udpating the content) * @param content the entry content (or null if just updating meta data) * @throws SrampArchiveException */ public void updateEntry(SrampArchiveEntry entry, InputStream content) throws SrampArchiveException { if (entry.getPath() == null) throw new SrampArchiveException(Messages.i18n.format("INVALID_ENTRY_PATH")); //$NON-NLS-1$ File contentFile = new File(this.workDir, entry.getPath()); File metaDataFile = new File(this.workDir, entry.getPath() + ".atom"); //$NON-NLS-1$ if (content != null) writeContent(contentFile, content); if (entry.getMetaData() != null) { try { SrampArchiveJaxbUtils.writeMetaData(metaDataFile, entry.getMetaData()); } catch (JAXBException e) { throw new SrampArchiveException(e); } } }