newItem = addItem(c, mycollections, sourceDir, newItemName, null);
newItem = addItem(c, mycollections, sourceDir, newItemName, null, template);
    private void replaceItems(Context c, Collection[] mycollections,            String sourceDir, String mapFile) throws Exception    {        // verify the source directory        File d = new java.io.File(sourceDir);        if (d == null)        {            System.out.println("Error, cannot open source directory "                    + sourceDir);            System.exit(1);        }        // read in HashMap first, to get list of handles & source dirs        Map myhash = readMapFile(mapFile);        // for each handle, re-import the item, discard the new handle        // and re-assign the old handle        Iterator i = myhash.keySet().iterator();        ArrayList itemsToDelete = new ArrayList();        while (i.hasNext())        {            // get the old handle            String newItemName = (String) i.next();            String oldHandle = (String) myhash.get(newItemName);            Item oldItem = null;            Item newItem = null;            if (oldHandle.indexOf('/') != -1)            {                System.out.println("\tReplacing:  " + oldHandle);                // add new item, locate old one                oldItem = (Item) HandleManager.resolveToObject(c, oldHandle);            }            else            {                oldItem = Item.find(c, Integer.parseInt(oldHandle));            }                        /* Rather than exposing public item methods to change handles --              * two handles can't exist at the same time due to key constraints             * so would require temp handle being stored, old being copied to new and             * new being copied to old, all a bit messy -- a handle file is written to             * the import directory containing the old handle, the existing item is              * deleted and then the import runs as though it were loading an item which              * had already been assigned a handle (so a new handle is not even assigned).             * As a commit does not occur until after a successful add, it is safe to              * do a delete as any error results in an aborted transaction without harming             * the original item */            File handleFile = new File(sourceDir + File.separatorChar + newItemName + File.separatorChar + "handle");            PrintWriter handleOut = new PrintWriter(new FileWriter(handleFile, true));            if (handleOut == null)            {                throw new Exception("can't open handle file: " + handleFile.getCanonicalPath());            }                        handleOut.println(oldHandle);            handleOut.close();                        deleteItem(c, oldItem);                        newItem = addItem(c, mycollections, sourceDir, newItemName, null);        }    }