itemsToDelete.add(oldItem); }      i = itemsToDelete.iterator();  while (i.hasNext()) { deleteItem(c, (Item) i.next());
    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));            }            newItem = addItem(c, mycollections, sourceDir, newItemName, null);            // schedule item for demolition            itemsToDelete.add(oldItem);        }        // now run through again, deleting items (do this last to avoid        // disasters!)        // (this way deletes only happen if there have been no errors        // previously)        i = itemsToDelete.iterator();        while (i.hasNext())        {            deleteItem(c, (Item) i.next());        }    }