Fix DSpace Import to accept zip, adding subfolder to sourceDir

This commit is contained in:
Peter Dietz
2014-07-21 15:06:39 -04:00
parent d288e5851e
commit 63e960b785

View File

@@ -517,6 +517,7 @@ public class ItemImport
// If this is a zip archive, unzip it first
if (zip)
{
String sourceDirForZip = sourcedir;
ZipFile zf = new ZipFile(zipfilename);
ZipEntry entry;
Enumeration<? extends ZipEntry> entries = zf.entries();
@@ -546,6 +547,17 @@ public class ItemImport
{
log.error("Unable to create directory");
}
//Entries could have too many directories, and we need to adjust the sourcedir
//regex supports either windows or *nix file paths
String[] entryChunks = entry.getName().split("/|\\\\");
if(entryChunks.length > 1) {
if(sourceDirForZip == sourcedir) {
sourceDirForZip += "/" + entryChunks[0];
}
}
}
byte[] buffer = new byte[1024];
int len;
@@ -560,6 +572,11 @@ public class ItemImport
out.close();
}
}
if(sourceDirForZip != sourcedir) {
sourcedir = sourceDirForZip;
System.out.println("Set sourceDir using path inside of Zip: " + sourcedir);
}
}
c.turnOffAuthorisationSystem();