Avoid mysterious NPE if ItemImporter is given a path that is not a directory.

Plus comment, visibility, type safety cleanups and replace deprecated 
Context.setIgnoreAuthorization().


git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@6072 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Mark Wood
2011-02-09 19:25:31 +00:00
parent 381688cb24
commit 711a59adfa

View File

@@ -73,22 +73,22 @@ public class ItemImport
{ {
private static final Logger log = Logger.getLogger(ItemImport.class); private static final Logger log = Logger.getLogger(ItemImport.class);
static boolean useWorkflow = false; private static boolean useWorkflow = false;
static boolean useWorkflowSendEmail = false; private static boolean useWorkflowSendEmail = false;
static boolean isTest = false; private static boolean isTest = false;
static boolean isResume = false; private static boolean isResume = false;
static boolean isQuiet = false; private static boolean isQuiet = false;
static boolean template = false;
static PrintWriter mapOut = null; private static boolean template = false;
private static PrintWriter mapOut = null;
// File listing filter to look for metadata files // File listing filter to look for metadata files
static FilenameFilter metadataFileFilter = new FilenameFilter() private static FilenameFilter metadataFileFilter = new FilenameFilter()
{ {
public boolean accept(File dir, String n) public boolean accept(File dir, String n)
{ {
@@ -97,7 +97,7 @@ public class ItemImport
}; };
// File listing filter to check for folders // File listing filter to check for folders
static FilenameFilter directoryFilter = new FilenameFilter() private static FilenameFilter directoryFilter = new FilenameFilter()
{ {
public boolean accept(File dir, String n) public boolean accept(File dir, String n)
{ {
@@ -447,10 +447,10 @@ public class ItemImport
{ {
ZipFile zf = new ZipFile(zipfilename); ZipFile zf = new ZipFile(zipfilename);
ZipEntry entry; ZipEntry entry;
Enumeration entries = zf.entries(); Enumeration<? extends ZipEntry> entries = zf.entries();
while (entries.hasMoreElements()) while (entries.hasMoreElements())
{ {
entry = (ZipEntry)entries.nextElement(); entry = entries.nextElement();
if (entry.isDirectory()) if (entry.isDirectory())
{ {
if (!new File(ziptempdir + entry.getName()).mkdir()) if (!new File(ziptempdir + entry.getName()).mkdir())
@@ -490,7 +490,7 @@ public class ItemImport
} }
} }
c.setIgnoreAuthorization(true); c.turnOffAuthorisationSystem();
if ("add".equals(command)) if ("add".equals(command))
{ {
@@ -595,7 +595,7 @@ public class ItemImport
// open and process the source directory // open and process the source directory
File d = new java.io.File(sourceDir); File d = new java.io.File(sourceDir);
if (d == null) if (d == null || !d.isDirectory())
{ {
System.out.println("Error, cannot open source directory " + sourceDir); System.out.println("Error, cannot open source directory " + sourceDir);
System.exit(1); System.exit(1);
@@ -626,7 +626,7 @@ public class ItemImport
// verify the source directory // verify the source directory
File d = new java.io.File(sourceDir); File d = new java.io.File(sourceDir);
if (d == null) if (d == null || !d.isDirectory())
{ {
System.out.println("Error, cannot open source directory " System.out.println("Error, cannot open source directory "
+ sourceDir); + sourceDir);
@@ -693,7 +693,7 @@ public class ItemImport
Map<String, String> myhash = readMapFile(mapFile); Map<String, String> myhash = readMapFile(mapFile);
// now delete everything that appeared in the mapFile // now delete everything that appeared in the mapFile
Iterator i = myhash.keySet().iterator(); Iterator<String> i = myhash.keySet().iterator();
while (i.hasNext()) while (i.hasNext())
{ {
@@ -717,9 +717,11 @@ public class ItemImport
} }
/** /**
* item? try and add it to the archive c mycollection path itemname handle - * item? try and add it to the archive.
* non-null means we have a pre-defined handle already mapOut - mapfile * @param mycollections - add item to these Collections.
* we're writing * @param path - directory containing the item directories.
* @param itemname handle - non-null means we have a pre-defined handle already
* @param mapOut - mapfile we're writing
*/ */
private Item addItem(Context c, Collection[] mycollections, String path, private Item addItem(Context c, Collection[] mycollections, String path,
String itemname, PrintWriter mapOut, boolean template) throws Exception String itemname, PrintWriter mapOut, boolean template) throws Exception