mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Merge pull request #1408 from terrywbrady/ds-3212
DS-3212: Consolidate logic for local schema file detection for ItemUpdate and ItemImport
This commit is contained in:
@@ -38,6 +38,7 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.xpath.XPathAPI;
|
||||
import org.dspace.app.itemimport.service.ItemImportService;
|
||||
import org.dspace.app.util.LocalSchemaFilenameFilter;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.authorize.ResourcePolicy;
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
@@ -141,14 +142,7 @@ public class ItemImportServiceImpl implements ItemImportService, InitializingBea
|
||||
}
|
||||
|
||||
// File listing filter to look for metadata files
|
||||
protected FilenameFilter metadataFileFilter = new FilenameFilter()
|
||||
{
|
||||
@Override
|
||||
public boolean accept(File dir, String n)
|
||||
{
|
||||
return n.startsWith("metadata_");
|
||||
}
|
||||
};
|
||||
protected FilenameFilter metadataFileFilter = new LocalSchemaFilenameFilter();
|
||||
|
||||
// File listing filter to check for folders
|
||||
protected FilenameFilter directoryFilter = new FilenameFilter()
|
||||
@@ -1131,10 +1125,11 @@ public class ItemImportServiceImpl implements ItemImportService, InitializingBea
|
||||
}
|
||||
else
|
||||
{
|
||||
String[] dirListing = new File(path).list();
|
||||
File dir = new File(path);
|
||||
String[] dirListing = dir.list();
|
||||
for (String fileName : dirListing)
|
||||
{
|
||||
if (!"dublin_core.xml".equals(fileName) && !fileName.equals("handle") && !fileName.startsWith("metadata_"))
|
||||
if (!"dublin_core.xml".equals(fileName) && !fileName.equals("handle") && !metadataFileFilter.accept(dir, fileName))
|
||||
{
|
||||
throw new FileNotFoundException("No contents file found");
|
||||
}
|
||||
|
@@ -33,6 +33,7 @@ import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.TransformerConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.util.LocalSchemaFilenameFilter;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.Item;
|
||||
@@ -103,16 +104,7 @@ public class ItemArchive {
|
||||
itarch.dtomList = MetadataUtilities.loadDublinCore(getDocumentBuilder(), is);
|
||||
|
||||
//The code to search for local schema files was copied from org.dspace.app.itemimport.ItemImportServiceImpl.java
|
||||
File file[] = dir.listFiles(
|
||||
new FilenameFilter()
|
||||
{
|
||||
@Override
|
||||
public boolean accept(File dir, String n)
|
||||
{
|
||||
return n.startsWith("metadata_");
|
||||
}
|
||||
}
|
||||
);
|
||||
File file[] = dir.listFiles(new LocalSchemaFilenameFilter());
|
||||
for (int i = 0; i < file.length; i++)
|
||||
{
|
||||
is = new FileInputStream(file[i]);
|
||||
|
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.app.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/*
|
||||
* This class is used to identify local schema files when running the itemupdate and itemimport tools.
|
||||
*/
|
||||
|
||||
public class LocalSchemaFilenameFilter implements FilenameFilter {
|
||||
|
||||
static Pattern patt = Pattern.compile("^metadata_.*.xml$");
|
||||
|
||||
@Override
|
||||
public boolean accept(File arg0, String arg1) {
|
||||
return patt.matcher(arg1).matches();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user