/* * Copyright (c) 2008, Hewlett-Packard Company and Massachusetts * Institute of Technology. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * - Neither the name of the Hewlett-Packard Company nor the name of the * Massachusetts Institute of Technology nor the names of their * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. */ package edu.mit.libraries.facade.app; import java.net.URLEncoder; import java.io.UnsupportedEncodingException; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.ByteArrayInputStream; import java.sql.SQLException; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import java.util.zip.Deflater; import org.jdom.Element; import org.jdom.Namespace; import org.jdom.output.Format; import org.jdom.output.XMLOutputter; import edu.harvard.hul.ois.mets.Agent; import edu.harvard.hul.ois.mets.AmdSec; import edu.harvard.hul.ois.mets.Checksumtype; import edu.harvard.hul.ois.mets.Div; import edu.harvard.hul.ois.mets.DmdSec; import edu.harvard.hul.ois.mets.FLocat; import edu.harvard.hul.ois.mets.FileGrp; import edu.harvard.hul.ois.mets.FileSec; import edu.harvard.hul.ois.mets.Fptr; import edu.harvard.hul.ois.mets.Loctype; import edu.harvard.hul.ois.mets.MdRef ; import edu.harvard.hul.ois.mets.MdWrap; import edu.harvard.hul.ois.mets.Mdtype; import edu.harvard.hul.ois.mets.Mets; import edu.harvard.hul.ois.mets.MetsHdr; import edu.harvard.hul.ois.mets.Name; import edu.harvard.hul.ois.mets.Role; import edu.harvard.hul.ois.mets.StructMap; import edu.harvard.hul.ois.mets.TechMD; import edu.harvard.hul.ois.mets.Type; import edu.harvard.hul.ois.mets.XmlData; import edu.harvard.hul.ois.mets.helper.MetsElement; import edu.harvard.hul.ois.mets.helper.MetsException; import edu.harvard.hul.ois.mets.helper.MetsValidator; import edu.harvard.hul.ois.mets.helper.MetsWriter; import edu.harvard.hul.ois.mets.helper.PCData; import edu.harvard.hul.ois.mets.helper.PreformedXML; import edu.harvard.hul.ois.mets.helper.MetsReader; import edu.harvard.hul.ois.mets.helper.Any; /** *
Prepare a METS SIP (Submission Information Package) to ingest * into DSpace, creating a new Item. * * This is a utility to help another application prepare a DSpace * SIP with as little effort as possible. All it has to do is: * - Create a SIP * - Add Bitstreams * - Add Descriptive Metadata * - Write the SIP, to either a file or OutputStream. * It works in conjunction with the simple LNI client to upload a SIP * directly to the LNI. * * It does not rely on *any* DSpace code. It only requires JDOM (for XML) * and the Harvard METS toolkit. * * Requires Sun Java JRE 5 and these libraries: * * - Harvard METS Java toolkit, version 1.5 * http://hul.harvard.edu/mets/ * * - JDOM 1.0 * http://jdom.org/ ** @author Larry Stone * @version $Revision: 2108 $ */ public class DSpaceSIP { // Describes the DSpace SIP version implemented here private static final String METS_PROFILE = "DSpace METS SIP Profile 1.0"; // default value for validate private static final boolean VALIDATE_DEFAULT = true; // Filename of manifest, relative to package toplevel private static final String MANIFEST_FILE = "mets.xml"; // PREMIS XML namespace; URI and JDOM namespace object private static final String PREMIS_NS_URI = "http://www.loc.gov/standards/premis"; private static final Namespace PREMIS_NS = Namespace.getNamespace("premis", PREMIS_NS_URI); // JDOM xml output writer - indented format for readability. private static XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); // counter for gensym() private int idCounter = 1; // Put all DMD sections for the Item into one group with this ID private String dmdGroupID = gensym("dmd_group"); // attempt to validate the METS manifest before writing SIP private boolean validate = VALIDATE_DEFAULT; // Zip file compression level private int compression = 0; /** * Table of files to add to package, such as mdRef'd metadata. * Key is relative pathname of file, value a record of associated paths. */ private Map