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:
mjmarttila
2016-06-02 09:27:59 -04:00
parent ab2f876155
commit 12649fe1fe
3 changed files with 48 additions and 31 deletions

View File

@@ -15,6 +15,7 @@ import org.dspace.core.ConfigurationManager;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.LogManager; import org.dspace.core.LogManager;
import org.dspace.handle.service.HandleService; import org.dspace.handle.service.HandleService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -50,22 +51,30 @@ public class HandleIdentifierProvider extends IdentifierProvider {
@Override @Override
public boolean supports(String identifier) public boolean supports(String identifier)
{ {
String prefix = handleService.getPrefix(); String prefix = handleService.getPrefix();
String handleResolver = ConfigurationManager.getProperty("handle.canonical.prefix"); String canonicalPrefix = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("handle.canonical.prefix");
if (identifier == null) if (identifier == null)
{ {
return false; return false;
} }
// return true if handle has valid starting pattern
if (identifier.startsWith(prefix) if (identifier.startsWith(prefix)
|| identifier.startsWith(handleResolver) || identifier.startsWith(canonicalPrefix)
|| identifier.startsWith("http://hdl.handle.net/")
|| identifier.startsWith("hdl:") || identifier.startsWith("hdl:")
|| identifier.startsWith("info:hdl")) || identifier.startsWith("info:hdl")
|| identifier.matches("^https?://hdl.handle.net/")
|| identifier.matches("^https?://.+/handle/"))
{ {
return true; return true;
} }
// return false if identifier starts with DOI prefix
return false; 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 @Override

View File

@@ -16,6 +16,7 @@ import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.LogManager; import org.dspace.core.LogManager;
import org.dspace.handle.service.HandleService; import org.dspace.handle.service.HandleService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.versioning.*; import org.dspace.versioning.*;
import org.dspace.versioning.service.VersionHistoryService; import org.dspace.versioning.service.VersionHistoryService;
import org.dspace.versioning.service.VersioningService; import org.dspace.versioning.service.VersioningService;
@@ -70,32 +71,30 @@ public class VersionedHandleIdentifierProvider extends IdentifierProvider {
@Override @Override
public boolean supports(String identifier) public boolean supports(String identifier)
{ {
String prefix = handleService.getPrefix(); String prefix = handleService.getPrefix();
String handleResolver = ConfigurationManager.getProperty("handle.canonical.prefix"); String canonicalPrefix = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("handle.canonical.prefix");
if (identifier == null) if (identifier == null)
{ {
return false; return false;
} }
// return true if handle has valid starting pattern
if (identifier.startsWith(prefix) if (identifier.startsWith(prefix)
|| identifier.startsWith(handleResolver) || identifier.startsWith(canonicalPrefix)
|| identifier.startsWith("http://hdl.handle.net/")
|| identifier.startsWith("hdl:") || identifier.startsWith("hdl:")
|| identifier.startsWith("info:hdl")) || identifier.startsWith("info:hdl")
|| identifier.matches("^https?://hdl.handle.net/")
|| identifier.matches("^https?://.+/handle/"))
{ {
return true; return true;
} }
// return false if identifier starts with DOI prefix
try { if(identifier.startsWith("10.") || identifier.matches("^https?://dx.doi.org") || identifier.startsWith("doi:"))
String outOfUrl = retrieveHandleOutOfUrl(identifier); return false;
if(outOfUrl != null) // 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 true; return false;
} // otherwise, assumed a valid handle
} catch (SQLException e) { return true;
log.error(e.getMessage(), e);
}
return false;
} }
@Override @Override

View File

@@ -16,6 +16,7 @@ import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.LogManager; import org.dspace.core.LogManager;
import org.dspace.handle.service.HandleService; import org.dspace.handle.service.HandleService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.versioning.*; import org.dspace.versioning.*;
import org.dspace.versioning.service.VersionHistoryService; import org.dspace.versioning.service.VersionHistoryService;
import org.dspace.versioning.service.VersioningService; import org.dspace.versioning.service.VersioningService;
@@ -66,22 +67,30 @@ public class VersionedHandleIdentifierProviderWithCanonicalHandles extends Ident
@Override @Override
public boolean supports(String identifier) public boolean supports(String identifier)
{ {
String prefix = handleService.getPrefix(); String prefix = handleService.getPrefix();
String handleResolver = ConfigurationManager.getProperty("handle.canonical.prefix"); String canonicalPrefix = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("handle.canonical.prefix");
if (identifier == null) if (identifier == null)
{ {
return false; return false;
} }
// return true if handle has valid starting pattern
if (identifier.startsWith(prefix) if (identifier.startsWith(prefix)
|| identifier.startsWith(handleResolver) || identifier.startsWith(canonicalPrefix)
|| identifier.startsWith("http://hdl.handle.net/")
|| identifier.startsWith("hdl:") || identifier.startsWith("hdl:")
|| identifier.startsWith("info:hdl")) || identifier.startsWith("info:hdl")
|| identifier.matches("^https?://hdl.handle.net/")
|| identifier.matches("^https?://.+/handle/"))
{ {
return true; return true;
} }
// return false if identifier starts with DOI prefix
return false; 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 @Override