Guard against Community/Collection metadata having only whitespace characters and eliminate cases where null pointer exceptions would be thrown.

git-svn-id: http://scm.dspace.org/svn/repo/branches/dspace-1_5_x@3024 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Mark Diggory
2008-07-31 23:23:06 +00:00
parent 8d93f1d810
commit 77cb5d313d
2 changed files with 41 additions and 20 deletions

View File

@@ -409,7 +409,8 @@ public class Collection extends DSpaceObject
*/
public void setMetadata(String field, String value) throws MissingResourceException
{
if ((field.trim()).equals("name") && (value.trim()).equals(""))
if ((field.trim()).equals("name")
&& (value == null || value.trim().equals("")))
{
try
{
@@ -420,7 +421,21 @@ public class Collection extends DSpaceObject
value = "Untitled";
}
}
collectionRow.setColumn(field, value);
/*
* Set metadata field to null if null
* and trim strings to eliminate excess
* whitespace.
*/
if(value == null)
{
collectionRow.setColumnNull(field);
}
else
{
collectionRow.setColumn(field, value.trim());
}
modifiedMetadata = true;
addDetails(field);
}
@@ -732,9 +747,9 @@ public class Collection extends DSpaceObject
*/
public String getLicense()
{
String license = collectionRow.getStringColumn("license");
String license = getMetadata("license");
if ((license == null) || license.equals(""))
if (license == null || license.trim().equals(""))
{
// Fallback to site-wide default
license = ConfigurationManager.getDefaultSubmissionLicense();
@@ -751,8 +766,7 @@ public class Collection extends DSpaceObject
*/
public String getLicenseCollection()
{
String license = collectionRow.getStringColumn("license");
return license;
return getMetadata("license");
}
/**
@@ -762,9 +776,9 @@ public class Collection extends DSpaceObject
*/
public boolean hasCustomLicense()
{
String license = collectionRow.getStringColumn("license");
String license = getMetadata("license");
return ((license != null) && !license.equals(""));
return !( license == null || license.trim().equals("") );
}
/**
@@ -776,15 +790,7 @@ public class Collection extends DSpaceObject
*/
public void setLicense(String license)
{
if (license == null)
{
collectionRow.setColumnNull("license");
}
else
{
collectionRow.setColumn("license", license);
}
modified = true;
setMetadata("license",license);
}
/**