⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 itemexport.java

📁 dspace 用j2ee架构的一个数字图书馆.开源程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * ItemExport.java * * Version: $Revision: 1.14 $ * * Date: $Date: 2005/11/16 21:40:52 $ * * Copyright (c) 2002-2005, 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 org.dspace.app.itemexport;import java.io.BufferedOutputStream;import java.io.File;import java.io.FileOutputStream;import java.io.FileWriter;import java.io.InputStream;import java.io.PrintWriter;import java.util.HashMap;import java.util.Iterator;import org.apache.commons.cli.CommandLine;import org.apache.commons.cli.CommandLineParser;import org.apache.commons.cli.HelpFormatter;import org.apache.commons.cli.Options;import org.apache.commons.cli.PosixParser;import org.dspace.content.Bitstream;import org.dspace.content.Bundle;import org.dspace.content.Collection;import org.dspace.content.DCValue;import org.dspace.content.Item;import org.dspace.content.ItemIterator;import org.dspace.content.MetadataSchema;import org.dspace.core.Constants;import org.dspace.core.Context;import org.dspace.core.Utils;import org.dspace.handle.HandleManager;/** * Item exporter to create simple AIPs for DSpace content. Currently exports * individual items, or entire collections. For instructions on use, see * printUsage() method. * <P> * ItemExport creates the simple AIP package that the importer also uses. It * consists of: * <P> * /exportdir/42/ (one directory per item) / dublin_core.xml - qualified dublin * core in RDF schema / contents - text file, listing one file per line / file1 - * files contained in the item / file2 / ... * <P> * issues -doesn't handle special characters in metadata (needs to turn &'s into * &amp;, etc.) * <P> * Modified by David Little, UCSD Libraries 12/21/04 to * allow the registration of files (bitstreams) into DSpace. */public class ItemExport{    /*     *       */    public static void main(String[] argv) throws Exception    {        // create an options object and populate it        CommandLineParser parser = new PosixParser();        Options options = new Options();        options.addOption("t", "type", true, "type: COLLECTION or ITEM");        options.addOption("i", "id", true, "ID or handle of thing to export");        options.addOption("d", "dest", true,                "destination where you want items to go");        options.addOption("n", "number", true,                "sequence number to begin exporting items with");        options.addOption("h", "help", false, "help");        CommandLine line = parser.parse(options, argv);        String typeString = null;        String destDirName = null;        String myIDString = null;        int seqStart = -1;        int myType = -1;        Item myItem = null;        Collection mycollection = null;        if (line.hasOption('h'))        {            HelpFormatter myhelp = new HelpFormatter();            myhelp.printHelp("ItemExport\n", options);            System.out                    .println("\nfull collection: ItemExport -t COLLECTION -i ID -d dest -n number");            System.out                    .println("singleitem:       ItemExport -t ITEM -i ID -d dest -n number");            System.exit(0);        }        if (line.hasOption('t')) // type        {            typeString = line.getOptionValue('t');            if (typeString.equals("ITEM"))            {                myType = Constants.ITEM;            }            else if (typeString.equals("COLLECTION"))            {                myType = Constants.COLLECTION;            }        }        if (line.hasOption('i')) // id        {            myIDString = line.getOptionValue('i');        }        if (line.hasOption('d')) // dest        {            destDirName = line.getOptionValue('d');        }        if (line.hasOption('n')) // number        {            seqStart = Integer.parseInt(line.getOptionValue('n'));        }        // now validate the args        if (myType == -1)        {            System.out                    .println("type must be either COLLECTION or ITEM (-h for help)");            System.exit(1);        }        if (destDirName == null)        {            System.out                    .println("destination directory must be set (-h for help)");            System.exit(1);        }        if (seqStart == -1)        {            System.out                    .println("sequence start number must be set (-h for help)");            System.exit(1);        }        if (myIDString == null)        {            System.out                    .println("ID must be set to either a database ID or a handle (-h for help)");            System.exit(1);        }        Context c = new Context();        c.setIgnoreAuthorization(true);        if (myType == Constants.ITEM)        {            // first, is myIDString a handle?            if (myIDString.indexOf('/') != -1)            {                myItem = (Item) HandleManager.resolveToObject(c, myIDString);                if ((myItem == null) || (myItem.getType() != Constants.ITEM))                {                    myItem = null;                }            }            else            {                myItem = Item.find(c, Integer.parseInt(myIDString));            }            if (myItem == null)            {                System.out                        .println("Error, item cannot be found: " + myIDString);            }        }        else        {            if (myIDString.indexOf('/') != -1)            {                // has a / must be a handle                mycollection = (Collection) HandleManager.resolveToObject(c,                        myIDString);                // ensure it's a collection                if ((mycollection == null)                        || (mycollection.getType() != Constants.COLLECTION))                {                    mycollection = null;                }            }            else if (myIDString != null)            {                mycollection = Collection.find(c, Integer.parseInt(myIDString));            }            if (mycollection == null)            {                System.out.println("Error, collection cannot be found: "                        + myIDString);                System.exit(1);            }        }        if (myItem != null)        {            // it's only a single item            exportItem(c, myItem, destDirName, seqStart);        }        else        {            System.out.println("Exporting from collection: " + myIDString);            // it's a collection, so do a bunch of items            ItemIterator i = mycollection.getItems();            exportItem(c, i, destDirName, seqStart);        }        c.complete();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -