options.addOption( "e", "eperson",     true,  "remove items in mapfile");
options.addOption( "e", "eperson",     true,  "email of eperson doing importing");
    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( "a", "add",         false, "add items to DSpace");        options.addOption( "r", "replace",     false, "replace items in mapfile");        options.addOption( "R", "remove",      false, "remove items in mapfile");        options.addOption( "s", "source",      true,  "source of items (directory)");        options.addOption( "c", "collection",  true,  "destination collection databse ID");        options.addOption( "m", "mapfile",     true,  "mapfile items in mapfile");        options.addOption( "e", "eperson",     true,  "remove items in mapfile");        options.addOption( "w", "workflow",    false, "send submission through collection's workflow");        options.addOption( "h", "help",        false, "help");        CommandLine line = parser.parse( options, argv );        String command    = null;  // add replace remove, etc        String sourcedir  = null;        String mapfile    = null;        String eperson    = null;  // db ID or email        String [] collections = null; // db ID or handles        if( line.hasOption('h') )        {            HelpFormatter myhelp = new HelpFormatter();            myhelp.printHelp( "ItemImport\n", options );            System.out.println("\nadding items:    ItemImport -a -e eperson -c collection -s sourcedir -m mapfile");            System.out.println("replacing items: ItemImport -r -e eperson -c collection -s sourcedir -m mapfile");            System.out.println("removing items:  ItemImport -R -e eperson -m mapfile");            System.exit(0);        }        if( line.hasOption( 'a' ) ) { command = "add";    }         if( line.hasOption( 'r' ) ) { command = "replace";}        if( line.hasOption( 'R' ) ) { command = "remove"; }        if( line.hasOption( 'w' ) ) { useWorkflow = true; }               if( line.hasOption( 's' ) ) // source        {            sourcedir = line.getOptionValue( 's' );            }        if( line.hasOption( 'm' ) ) // mapfile        {            mapfile = line.getOptionValue( 'm' );            }        if( line.hasOption( 'e' ) ) // eperson        {            eperson = line.getOptionValue( 'e' );            }        if( line.hasOption( 'c' ) ) // collections        {            collections = line.getOptionValues( 'c' );            }        // now validate        // must have a command set        if( command == null )        {            System.out.println("Error - must run with either add, replace, or remove (run with -h flag for details)");                System.exit(1);        }        else if( command.equals("add") || command.equals("replace") )        {            if( sourcedir == null )            {                System.out.println("Error - a source directory containing items must be set (run with -h flag for details)");                 System.exit(1);            }            if( mapfile == null )            {                System.out.println("Error - a map file to hold importing results must be specified (run with -h flag for details)");                System.exit(1);            }            if( eperson == null )            {                System.out.println("Error - an eperson to do the importing must be specified (run with -h flag for details)");                System.exit(1);            }            if( collections == null )            {                System.out.println("Error - at least one destination collection must be specified (run with -h flag for details)");                System.exit(1);            }        }        else if( command.equals("remove") )        {            if( eperson == null )            {                System.out.println("Error - an eperson to do the importing must be specified");                System.exit(1);            }            if( mapfile == null )            {                System.out.println("Error - a map file must be specified");                System.exit(1);            }        }         ItemImport myloader = new ItemImport();        // create a context        Context c = new Context();        // find the EPerson, assign to context        EPerson myEPerson = null;	if( eperson.indexOf('@') != -1)        {            // @ sign, must be an email            myEPerson = EPerson.findByEmail( c, eperson );        }        else        {            myEPerson = EPerson.find( c, Integer.parseInt( eperson ) );         }        if( myEPerson == null )        {            System.out.println( "Error, eperson cannot be found: " + eperson );            System.exit(1);        }        c.setCurrentUser( myEPerson );        // find collections        Collection mycollection = null;        // dont' need to validate collections set if command is "remove"        if( !command.equals("remove") )        {            if( collections[0].indexOf('/') != -1 )            {                // has a / must be a handle                mycollection = (Collection)HandleManager.resolveToObject( c, collections[0] );                // ensure it's a collection                if( (mycollection == null) || (mycollection.getType() != Constants.COLLECTION) )                {                    mycollection = null;                }             }             else if( collections != null )            {                mycollection = Collection.find( c, Integer.parseInt( collections[0] ) );            }            if( mycollection == null )            {                System.out.println( "Error, collection cannot be found: " + collections[0] );                System.exit(1);            }        } // end of validating collections                try        {            c.setIgnoreAuthorization( true );            if( command.equals( "add" ) )            {                myloader.addItems( c, mycollection, sourcedir, mapfile );            }            else if( command.equals( "replace" ) )            {                myloader.replaceItems( c, mycollection, sourcedir, mapfile );            }            else if( command.equals( "remove" ) )            {                myloader.removeItems( c, mapfile );            }            // complete all transactions            c.complete();        }        catch( Exception e )        {            // abort all operations            c.abort();            e.printStackTrace();            System.out.println( e );        }    }