[DS-636] Replace all lookups of handle.prefix with calls to new

HandleManager.getPrefix() to get a guaranteed non-null value possibly 
defaulted to "123456789".  Handle.net currently recognizes the default 
as "unconfigured DSpace instance".


git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@5448 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Mark Wood
2010-10-18 18:10:31 +00:00
parent 7c0a0cb07e
commit c5d022f96b
8 changed files with 63 additions and 48 deletions

View File

@@ -513,7 +513,7 @@ public class ItemExport
(dcv.element.equals("date") && qualifier.equals("available")) ||
(dcv.element.equals("identifier") && qualifier.equals("uri") &&
(dcv.value.startsWith("http://hdl.handle.net/" +
ConfigurationManager.getProperty("handle.prefix") + "/"))) ||
HandleManager.getPrefix() + "/"))) ||
(dcv.element.equals("description") && qualifier.equals("provenance")) ||
(dcv.element.equals("format") && qualifier.equals("extent")) ||
(dcv.element.equals("format") && qualifier.equals("mimetype")))))
@@ -521,7 +521,7 @@ public class ItemExport
out.write(utf8, 0, utf8.length);
}
// Store the date issued and assection to see if they are different
// Store the date issued and accession to see if they are different
// because we need to keep date.issued if they are, when migrating
if ((dcv.element.equals("date") && qualifier.equals("issued")))
{

View File

@@ -37,19 +37,14 @@
*/
package org.dspace.content;
import java.sql.SQLException;
import java.net.URI;
import java.io.IOException;
import java.sql.SQLException;
import org.dspace.authorize.AuthorizeException;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.core.LogManager;
import org.dspace.eperson.EPerson;
import org.dspace.eperson.Group;
import org.dspace.event.Event;
import org.dspace.authorize.AuthorizeException;
import org.dspace.handle.HandleManager;
/**
* Represents the root of the DSpace Archive.
@@ -103,13 +98,13 @@ public class Site extends DSpaceObject
public static String getSiteHandle()
{
if (handle == null)
handle = ConfigurationManager.getProperty("handle.prefix")+"/"+
handle = HandleManager.getPrefix()+"/"+
String.valueOf(SITE_ID);
return handle;
}
/**
* Get Site object corresponding to db id (which is ignroed).
* Get Site object corresponding to db id (which is ignored).
* @param context the context.
* @param id integer database id, ignored.
* @return Site object.

View File

@@ -72,6 +72,9 @@ public class HandleManager
/** log4j category */
private static Logger log = Logger.getLogger(HandleManager.class);
/** Prefix registered to no one */
static final String EXAMPLE_PREFIX = "123456789";
/** Private Constructor */
private HandleManager()
{
@@ -150,6 +153,7 @@ public class HandleManager
// {
// return "http://hdl.handle.net/" + handle;
// }
/**
* Creates a new handle in the database.
*
@@ -400,12 +404,12 @@ public class HandleManager
* @exception SQLException
* If a database error occurs
*/
static List getHandlesForPrefix(Context context, String prefix)
static List<String> getHandlesForPrefix(Context context, String prefix)
throws SQLException
{
String sql = "SELECT handle FROM handle WHERE handle LIKE ? ";
TableRowIterator iterator = DatabaseManager.queryTable(context, null, sql, prefix+"%");
List results = new ArrayList();
List<String> results = new ArrayList<String>();
try
{
@@ -425,6 +429,21 @@ public class HandleManager
return results;
}
/**
* Get the configured Handle prefix string, or a default
* @return configured prefix or "123456789"
*/
public static String getPrefix()
{
String prefix = ConfigurationManager.getProperty("handle.prefix");
if (null == prefix)
{
prefix = EXAMPLE_PREFIX; // XXX no good way to exit cleanly
log.error("handle.prefix is not configured; using " + prefix);
}
return prefix;
}
////////////////////////////////////////
// Internal methods
////////////////////////////////////////
@@ -484,7 +503,7 @@ public class HandleManager
*/
private static String createId(int id) throws SQLException
{
String handlePrefix = ConfigurationManager.getProperty("handle.prefix");
String handlePrefix = getPrefix();
return new StringBuffer().append(handlePrefix).append(
handlePrefix.endsWith("/") ? "" : "/").append(id).toString();

View File

@@ -356,10 +356,9 @@ public class HandlePlugin implements HandleStorage
// resolvable.
if (ConfigurationManager.getBooleanProperty("handle.plugin.checknameauthority",true))
{
// First, construct a string representating the naming authority Handle
// First, construct a string representing the naming authority Handle
// we'd expect.
String expected = "0.NA/"
+ ConfigurationManager.getProperty("handle.prefix");
String expected = "0.NA/" + HandleManager.getPrefix();
// Which authority does the request pertain to?
String received = Util.decodeString(theHandle);