mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-14 21:43:11 +00:00
Extend supported handles for supports() method
Updates the supports() method across the three relevant handle provider classes to check if the identifier a) matches a valid handle starting pattern or b) does not match a DOI starting pattern and does contain a slash but is not an arbitrary URL.
This commit is contained in:
@@ -15,6 +15,7 @@ import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.core.LogManager;
|
||||
import org.dspace.handle.service.HandleService;
|
||||
import org.dspace.services.factory.DSpaceServicesFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -50,22 +51,30 @@ public class HandleIdentifierProvider extends IdentifierProvider {
|
||||
@Override
|
||||
public boolean supports(String identifier)
|
||||
{
|
||||
String prefix = handleService.getPrefix();
|
||||
String handleResolver = ConfigurationManager.getProperty("handle.canonical.prefix");
|
||||
String prefix = handleService.getPrefix();
|
||||
String canonicalPrefix = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("handle.canonical.prefix");
|
||||
if (identifier == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// return true if handle has valid starting pattern
|
||||
if (identifier.startsWith(prefix)
|
||||
|| identifier.startsWith(handleResolver)
|
||||
|| identifier.startsWith("http://hdl.handle.net/")
|
||||
|| identifier.startsWith(canonicalPrefix)
|
||||
|| identifier.startsWith("hdl:")
|
||||
|| identifier.startsWith("info:hdl"))
|
||||
|| identifier.startsWith("info:hdl")
|
||||
|| identifier.matches("^https?://hdl.handle.net/")
|
||||
|| identifier.matches("^https?://.+/handle/"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
// return false if identifier starts with DOI prefix
|
||||
if(identifier.startsWith("10.") || identifier.matches("^https?://dx.doi.org") || identifier.startsWith("doi:"))
|
||||
return false;
|
||||
// return false if identifier does not contain a '/' or is a URL that does not match above patterns
|
||||
if(! identifier.contains("/") || identifier.matches("^https?://.+"))
|
||||
return false;
|
||||
// otherwise, assumed a valid handle
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user