diff --git a/dspace-api/src/main/java/org/dspace/app/itemexport/ItemExport.java b/dspace-api/src/main/java/org/dspace/app/itemexport/ItemExport.java index 5399479712..1639ab0a7e 100644 --- a/dspace-api/src/main/java/org/dspace/app/itemexport/ItemExport.java +++ b/dspace-api/src/main/java/org/dspace/app/itemexport/ItemExport.java @@ -74,7 +74,7 @@ import org.dspace.handle.HandleManager; *
* Modified by David Little, UCSD Libraries 12/21/04 to allow the registration
* of files (bitstreams) into DSpace.
- *
+ *
* @author David Little
* @author Jay Paz
*/
@@ -86,12 +86,12 @@ public class ItemExport
* used for export download
*/
public static final String COMPRESSED_EXPORT_MIME_TYPE = "application/zip";
-
+
/** log4j logger */
private static Logger log = Logger.getLogger(ItemExport.class);
/*
- *
+ *
*/
public static void main(String[] argv) throws Exception
{
@@ -390,7 +390,7 @@ public class ItemExport
/**
* Discover the different schemas in use and output a separate metadata XML
* file for each schema.
- *
+ *
* @param c
* @param i
* @param destDir
@@ -561,7 +561,7 @@ public class ItemExport
* were originally registered will be marked in the contents file as such.
* However, the export directory will contain actual copies of the content
* files being exported.
- *
+ *
* @param c
* the DSpace context
* @param i
@@ -720,7 +720,7 @@ public class ItemExport
/**
* Convenience methot to create export a single Community, Collection, or
* Item
- *
+ *
* @param dso
* - the dspace object to export
* @param context
@@ -740,7 +740,7 @@ public class ItemExport
/**
* Convenience method to export a List of dspace objects (Community,
* Collection or Item)
- *
+ *
* @param dsObjects
* - List containing dspace objects
* @param context
@@ -758,7 +758,7 @@ public class ItemExport
/**
* Convenience methot to create export a single Community, Collection, or
* Item
- *
+ *
* @param dso
* - the dspace object to export
* @param context
@@ -778,7 +778,7 @@ public class ItemExport
/**
* Convenience method to export a List of dspace objects (Community,
* Collection or Item)
- *
+ *
* @param dsObjects
* - List containing dspace objects
* @param context
@@ -797,7 +797,7 @@ public class ItemExport
* Does the work creating a List with all the Items in the Community or
* Collection It then kicks off a new Thread to export the items, zip the
* export directory and send confirmation email
- *
+ *
* @param dsObjects
* - List of dspace objects to process
* @param context
@@ -1008,7 +1008,7 @@ public class ItemExport
{
iitems.close();
}
-
+
// Make sure the database connection gets closed in all conditions.
try {
context.complete();
@@ -1027,7 +1027,7 @@ public class ItemExport
/**
* Create a file name based on the date and eperson
- *
+ *
* @param eperson
* - eperson who requested export and will be able to download it
* @param date
@@ -1061,7 +1061,7 @@ public class ItemExport
/**
* Use config file entry for org.dspace.app.itemexport.download.dir and id
* of the eperson to create a download directory name
- *
+ *
* @param ePersonID
* - id of the eperson who requested export archive
* @return String representing a directory in the form of
@@ -1085,7 +1085,7 @@ public class ItemExport
/**
* Returns config file entry for org.dspace.app.itemexport.work.dir
- *
+ *
* @return String representing config file entry for
* org.dspace.app.itemexport.work.dir
* @throws Exception
@@ -1104,7 +1104,7 @@ public class ItemExport
/**
* Used to read the export archived. Inteded for download.
- *
+ *
* @param fileName
* the name of the file to download
* @param eperson
@@ -1129,7 +1129,7 @@ public class ItemExport
/**
* Get the file size of the export archive represented by the file name.
- *
+ *
* @param fileName
* name of the file to get the size.
* @throws Exception
@@ -1175,7 +1175,7 @@ public class ItemExport
* The file name of the export archive contains the eperson id of the person
* who created it When requested for download this method can check if the
* person requesting it is the same one that created it
- *
+ *
* @param context
* dspace context
* @param fileName
@@ -1208,7 +1208,7 @@ public class ItemExport
/**
* Reads the download directory for the eperson to see if any export
* archives are available
- *
+ *
* @param eperson
* @return a list of file names representing export archives that have been
* processed
@@ -1245,7 +1245,7 @@ public class ItemExport
* A clean up method that is ran before a new export archive is created. It
* uses the config file entry 'org.dspace.app.itemexport.life.span.hours' to
* determine if the current exports are too old and need pruging
- *
+ *
* @param epersonID
* - the id of the eperson to clean up
* @throws Exception
@@ -1328,7 +1328,7 @@ public class ItemExport
* with calling method about success or failure. We accomplis this
* communication with email instead. Send a success email once the export
* archive is complete and ready for download
- *
+ *
* @param context
* - the current Context
* @param eperson
@@ -1344,7 +1344,7 @@ public class ItemExport
try
{
Locale supportedLocale = I18nUtil.getEPersonLocale(eperson);
- Email email = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(supportedLocale, "export_success"));
+ Email email = Email.getEmail(I18nUtil.getEmailFilename(supportedLocale, "export_success"));
email.addRecipient(eperson.getEmail());
email.addArgument(ConfigurationManager.getProperty("dspace.url") + "/exportdownload/" + fileName);
email.addArgument(ConfigurationManager.getProperty("org.dspace.app.itemexport.life.span.hours"));
@@ -1362,7 +1362,7 @@ public class ItemExport
* with calling method about success or failure. We accomplis this
* communication with email instead. Send an error email if the export
* archive fails
- *
+ *
* @param eperson
* - EPerson to send the error message to
* @param error
@@ -1376,7 +1376,7 @@ public class ItemExport
try
{
Locale supportedLocale = I18nUtil.getEPersonLocale(eperson);
- Email email = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(supportedLocale, "export_error"));
+ Email email = Email.getEmail(I18nUtil.getEmailFilename(supportedLocale, "export_error"));
email.addRecipient(eperson.getEmail());
email.addArgument(error);
email.addArgument(ConfigurationManager.getProperty("dspace.url") + "/feedback");
@@ -1461,7 +1461,7 @@ public class ItemExport
// byte[] b = new byte[ (int)(cpFile.length()) ];
- cpFileInputStream = new FileInputStream(cpFile);
+ cpFileInputStream = new FileInputStream(cpFile);
ZipEntry cpZipEntry = new ZipEntry(strZipEntryName);
cpZipOutputStream.putNextEntry(cpZipEntry);
diff --git a/dspace-api/src/main/java/org/dspace/content/Collection.java b/dspace-api/src/main/java/org/dspace/content/Collection.java
index f9c350ccf4..20bba5eb53 100644
--- a/dspace-api/src/main/java/org/dspace/content/Collection.java
+++ b/dspace-api/src/main/java/org/dspace/content/Collection.java
@@ -31,6 +31,7 @@ import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.core.I18nUtil;
+import org.dspace.core.LicenseManager;
import org.dspace.core.LogManager;
import org.dspace.eperson.Group;
import org.dspace.event.Event;
@@ -52,7 +53,7 @@ import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
* database after calling update
. The default group of
* submitters is slightly different - creating or removing this has instant
* effect.
- *
+ *
* @author Robert Tansley
* @version $Revision$
*/
@@ -96,7 +97,7 @@ public class Collection extends DSpaceObject
/**
* Construct a collection with the given table row
- *
+ *
* @param context
* the context this object exists in
* @param row
@@ -139,7 +140,7 @@ public class Collection extends DSpaceObject
submitters = groupFromColumn("submitter");
admins = groupFromColumn("admin");
-
+
// Get our Handle if any
handle = HandleManager.findHandle(context, this);
@@ -153,12 +154,12 @@ public class Collection extends DSpaceObject
/**
* Get a collection from the database. Loads in the metadata
- *
+ *
* @param context
* DSpace context object
* @param id
* ID of the collection
- *
+ *
* @return the collection, or null if the ID is invalid.
* @throws SQLException
*/
@@ -199,10 +200,10 @@ public class Collection extends DSpaceObject
/**
* Create a new collection, with a new ID. This method is not public, and
* does not check authorisation.
- *
+ *
* @param context
* DSpace context object
- *
+ *
* @return the newly created collection
* @throws SQLException
* @throws AuthorizeException
@@ -288,10 +289,10 @@ public class Collection extends DSpaceObject
/**
* Get all collections in the system. These are alphabetically sorted by
* collection name.
- *
+ *
* @param context
* DSpace context object
- *
+ *
* @return the collections in the system
* @throws SQLException
*/
@@ -339,7 +340,7 @@ public class Collection extends DSpaceObject
/**
* Get the in_archive items in this collection. The order is indeterminate.
- *
+ *
* @return an iterator over the items in the collection.
* @throws SQLException
*/
@@ -358,7 +359,7 @@ public class Collection extends DSpaceObject
/**
* Get all the items in this collection. The order is indeterminate.
- *
+ *
* @return an iterator over the items in the collection.
* @throws SQLException
*/
@@ -376,7 +377,7 @@ public class Collection extends DSpaceObject
/**
* Get the internal ID of this collection
- *
+ *
* @return the internal identifier
*/
public int getID()
@@ -402,36 +403,36 @@ public class Collection extends DSpaceObject
/**
* Get the value of a metadata field
- *
+ *
* @param field
* the name of the metadata field to get
- *
+ *
* @return the value of the metadata field
- *
+ *
* @exception IllegalArgumentException
* if the requested metadata field doesn't exist
*/
public String getMetadata(String field)
{
String metadata = collectionRow.getStringColumn(field);
- return (metadata == null) ? "" : metadata;
+ return (metadata == null) ? "" : metadata;
}
/**
* Set a metadata value
- *
+ *
* @param field
* the name of the metadata field to get
* @param value
* value to set the field to
- *
+ *
* @exception IllegalArgumentException
* if the requested metadata field doesn't exist
* @exception MissingResourceException
*/
public void setMetadata(String field, String value) throws MissingResourceException
{
- if ((field.trim()).equals("name")
+ if ((field.trim()).equals("name")
&& (value == null || value.trim().equals("")))
{
try
@@ -443,9 +444,9 @@ public class Collection extends DSpaceObject
value = "Untitled";
}
}
-
- /*
- * Set metadata field to null if null
+
+ /*
+ * Set metadata field to null if null
* and trim strings to eliminate excess
* whitespace.
*/
@@ -457,7 +458,7 @@ public class Collection extends DSpaceObject
{
collectionRow.setColumn(field, value.trim());
}
-
+
modifiedMetadata = true;
addDetails(field);
}
@@ -470,7 +471,7 @@ public class Collection extends DSpaceObject
/**
* Get the logo for the collection. null
is returned if the
* collection does not have a logo.
- *
+ *
* @return the logo of the collection, or null
*/
public Bitstream getLogo()
@@ -546,10 +547,10 @@ public class Collection extends DSpaceObject
* Note that while the new group is created in the database, the association
* between the group and the collection is not written until
* update
is called.
- *
+ *
* @param step
* the step (1-3) of the workflow to create or get the group for
- *
+ *
* @return the workflow group associated with this collection
* @throws SQLException
* @throws AuthorizeException
@@ -581,7 +582,7 @@ public class Collection extends DSpaceObject
* Set the workflow group corresponding to a particular workflow step.
* null
can be passed in if there should be no associated
* group for that workflow step; any existing group is NOT deleted.
- *
+ *
* @param step
* the workflow step (1-3)
* @param g
@@ -606,10 +607,10 @@ public class Collection extends DSpaceObject
* Get the the workflow group corresponding to a particular workflow step.
* This returns null
if there is no group associated with
* this collection for the given step.
- *
+ *
* @param step
* the workflow step (1-3)
- *
+ *
* @return the group of reviewers or null
*/
public Group getWorkflowGroup(int step)
@@ -622,7 +623,7 @@ public class Collection extends DSpaceObject
* either the newly created group or the previously existing one. Note that
* other groups may also be allowed to submit to this collection by the
* authorization system.
- *
+ *
* @return the default group of submitters associated with this collection
* @throws SQLException
* @throws AuthorizeException
@@ -645,7 +646,7 @@ public class Collection extends DSpaceObject
// register this as the submitter group
collectionRow.setColumn("submitter", submitters.getID());
-
+
AuthorizeManager.addPolicy(ourContext, this, Constants.ADD, submitters);
modified = true;
@@ -653,9 +654,9 @@ public class Collection extends DSpaceObject
}
/**
- * Remove the submitters group, if no group has already been created
- * then return without error. This will merely dereference the current
- * submitters group from the collection so that it may be deleted
+ * Remove the submitters group, if no group has already been created
+ * then return without error. This will merely dereference the current
+ * submitters group from the collection so that it may be deleted
* without violating database constraints.
*/
public void removeSubmitters() throws SQLException, AuthorizeException
@@ -672,11 +673,11 @@ public class Collection extends DSpaceObject
// Remove the link to the collection table.
collectionRow.setColumnNull("submitter");
submitters = null;
-
+
modified = true;
}
-
+
/**
* Get the default group of submitters, if there is one. Note that the
* authorization system may allow others to submit to the collection, so
@@ -684,7 +685,7 @@ public class Collection extends DSpaceObject
*
* The default group of submitters for collection 100 is the one called
* collection_100_submit
.
- *
+ *
* @return the default group of submitters, or null
if there
* is no default group.
*/
@@ -697,7 +698,7 @@ public class Collection extends DSpaceObject
* Create a default administrators group if one does not already exist.
* Returns either the newly created group or the previously existing one.
* Note that other groups may also be administrators.
- *
+ *
* @return the default group of editors associated with this collection
* @throws SQLException
* @throws AuthorizeException
@@ -713,7 +714,7 @@ public class Collection extends DSpaceObject
ourContext.turnOffAuthorisationSystem();
admins = Group.create(ourContext);
ourContext.restoreAuthSystemState();
-
+
admins.setName("COLLECTION_" + getID() + "_ADMIN");
admins.update();
}
@@ -723,15 +724,15 @@ public class Collection extends DSpaceObject
// register this as the admin group
collectionRow.setColumn("admin", admins.getID());
-
+
modified = true;
return admins;
}
-
+
/**
- * Remove the administrators group, if no group has already been created
- * then return without error. This will merely dereference the current
- * administrators group from the collection so that it may be deleted
+ * Remove the administrators group, if no group has already been created
+ * then return without error. This will merely dereference the current
+ * administrators group from the collection so that it may be deleted
* without violating database constraints.
*/
public void removeAdministrators() throws SQLException, AuthorizeException
@@ -748,7 +749,7 @@ public class Collection extends DSpaceObject
// Remove the link to the collection table.
collectionRow.setColumnNull("admin");
admins = null;
-
+
modified = true;
}
@@ -759,7 +760,7 @@ public class Collection extends DSpaceObject
*
* The default group of administrators for collection 100 is the one called
*
- *
+ *
*
* If the example code above was used to send this mail, the resulting mail
* would have the subject
- *
+ *
*
* Note that parameters like
* If the token is not found return null.
*
* For example, if today's date is 2002-10-10 (in UTC) items made available
* during 2002-10-09 (UTC) will be included.
- *
+ *
* @param context
* DSpace context object
- * @param test
+ * @param test
*/
public static void processDaily(Context context, boolean test) throws SQLException,
IOException
@@ -306,7 +306,7 @@ public class Subscribe
tri.close();
}
}
-
+
// Process the last person
if (currentEPerson != null)
{
@@ -327,36 +327,36 @@ public class Subscribe
* Sends an email to the given e-person with details of new items in the
* given collections, items that appeared yesterday. No e-mail is sent if
* there aren't any new items in any of the collections.
- *
+ *
* @param context
* DSpace context object
* @param eperson
* eperson to send to
* @param collections
* List of collection IDs (Integers)
- * @param test
+ * @param test
*/
public static void sendEmail(Context context, EPerson eperson,
Listcollection_100_admin
.
- *
+ *
* @return group of administrators, or null
if there is no
* default group.
*/
@@ -772,7 +773,7 @@ public class Collection extends DSpaceObject
* Get the license that users must grant before submitting to this
* collection. If the collection does not have a specific license, the
* site-wide default is returned.
- *
+ *
* @return the license for this collection
*/
public String getLicense()
@@ -782,7 +783,7 @@ public class Collection extends DSpaceObject
if (license == null || license.trim().equals(""))
{
// Fallback to site-wide default
- license = ConfigurationManager.getDefaultSubmissionLicense();
+ license = LicenseManager.getDefaultSubmissionLicense();
}
return license;
@@ -790,8 +791,8 @@ public class Collection extends DSpaceObject
/**
* Get the license that users must grant before submitting to this
- * collection.
- *
+ * collection.
+ *
* @return the license for this collection
*/
public String getLicenseCollection()
@@ -801,7 +802,7 @@ public class Collection extends DSpaceObject
/**
* Find out if the collection has a custom license
- *
+ *
* @return true
if the collection has a custom license
*/
public boolean hasCustomLicense()
@@ -814,7 +815,7 @@ public class Collection extends DSpaceObject
/**
* Set the license for this collection. Passing in null
means
* that the site-wide default will be used.
- *
+ *
* @param license
* the license, or null
*/
@@ -828,7 +829,7 @@ public class Collection extends DSpaceObject
* returned if the collection does not have a template. Submission
* mechanisms may copy this template to provide a convenient starting point
* for a submission.
- *
+ *
* @return the item template, or null
*/
public Item getTemplateItem() throws SQLException
@@ -841,7 +842,7 @@ public class Collection extends DSpaceObject
* no action is taken. Caution: Make sure you call update
on
* the collection after doing this, or the item will have been created but
* the collection record will not refer to it.
- *
+ *
* @throws SQLException
* @throws AuthorizeException
*/
@@ -868,7 +869,7 @@ public class Collection extends DSpaceObject
* record in the database, the collection record will be changed, including
* any other changes made; in other words, this method does an
* update
.
- *
+ *
* @throws SQLException
* @throws AuthorizeException
* @throws IOException
@@ -881,7 +882,7 @@ public class Collection extends DSpaceObject
collectionRow.setColumnNull("template_item_id");
DatabaseManager.update(ourContext, collectionRow);
-
+
if (template != null)
{
log.info(LogManager.getHeader(ourContext, "remove_template_item",
@@ -894,7 +895,7 @@ public class Collection extends DSpaceObject
ourContext.restoreAuthSystemState();
template = null;
}
-
+
ourContext.addEvent(new Event(Event.MODIFY, Constants.COLLECTION, getID(), "remove_template_item"));
}
@@ -903,7 +904,7 @@ public class Collection extends DSpaceObject
* the item and the collection - it does nothing like set an issue date,
* remove a personal workspace item etc. This has instant effect;
* update
need not be called.
- *
+ *
* @param item
* item to add
* @throws SQLException
@@ -930,7 +931,7 @@ public class Collection extends DSpaceObject
/**
* Remove an item. If the item is then orphaned, it is deleted.
- *
+ *
* @param item
* item to remove
* @throws SQLException
@@ -956,20 +957,20 @@ public class Collection extends DSpaceObject
}
log.info(LogManager.getHeader(ourContext, "remove_item",
"collection_id=" + getID() + ",item_id=" + item.getID()));
-
+
DatabaseManager.updateQuery(ourContext,
"DELETE FROM collection2item WHERE collection_id= ? "+
"AND item_id= ? ",
getID(), item.getID());
DatabaseManager.setConstraintImmediate(ourContext, "coll2item_item_fk");
-
+
ourContext.addEvent(new Event(Event.REMOVE, Constants.COLLECTION, getID(), Constants.ITEM, item.getID(), item.getHandle()));
}
/**
* Update the collection metadata (including logo and workflow groups) to
* the database. Inserts if this is a new collection.
- *
+ *
* @throws SQLException
* @throws IOException
* @throws AuthorizeException
@@ -996,7 +997,7 @@ public class Collection extends DSpaceObject
clearDetails();
}
}
-
+
public boolean canEditBoolean() throws java.sql.SQLException
{
return canEditBoolean(true);
@@ -1020,7 +1021,7 @@ public class Collection extends DSpaceObject
{
canEdit(true);
}
-
+
public void canEdit(boolean useInheritance) throws AuthorizeException, SQLException
{
Community[] parents = getCommunities();
@@ -1047,7 +1048,7 @@ public class Collection extends DSpaceObject
* Delete the collection, including the metadata and logo. Items that are
* then orphans are deleted. Groups associated with this collection
* (workflow participants and submitters) are NOT deleted.
- *
+ *
* @throws SQLException
* @throws AuthorizeException
* @throws IOException
@@ -1064,12 +1065,12 @@ public class Collection extends DSpaceObject
// remove subscriptions - hmm, should this be in Subscription.java?
DatabaseManager.updateQuery(ourContext,
- "DELETE FROM subscription WHERE collection_id= ? ",
+ "DELETE FROM subscription WHERE collection_id= ? ",
getID());
// Remove Template Item
removeTemplateItem();
-
+
// Remove items
ItemIterator items = getAllItems();
@@ -1079,7 +1080,7 @@ public class Collection extends DSpaceObject
{
Item item = items.next();
IndexBrowse ib = new IndexBrowse(ourContext);
-
+
if (item.isOwningCollection(this))
{
// the collection to be deleted is the owning collection, thus remove
@@ -1092,12 +1093,12 @@ public class Collection extends DSpaceObject
// Browse.itemRemoved(ourContext, itemId);
collections[i].removeItem(item);
}
-
- }
+
+ }
// the item was only mapped to this collection, so just remove it
else
{
- //notify Browse of removing item mapping.
+ //notify Browse of removing item mapping.
ib.indexItem(item);
// Browse.itemChanged(ourContext, item);
removeItem(item);
@@ -1226,7 +1227,7 @@ public class Collection extends DSpaceObject
/**
* Get the communities this collection appears in
- *
+ *
* @return array of Community
objects
* @throws SQLException
*/
@@ -1282,10 +1283,10 @@ public class Collection extends DSpaceObject
/**
* Return true
if other
is the same Collection
* as this object, false
otherwise
- *
+ *
* @param other
* object to compare to
- *
+ *
* @return true
if object passed in represents the same
* collection as this object
*/
@@ -1321,7 +1322,7 @@ public class Collection extends DSpaceObject
/**
* Utility method for reading in a group from a group ID in a column. If the
* column is null, null is returned.
- *
+ *
* @param col
* the column name to read
* @return the group referred to by that column, or null
@@ -1339,7 +1340,7 @@ public class Collection extends DSpaceObject
/**
* return type found in Constants
- *
+ *
* @return int Constants.COLLECTION
*/
public int getType()
@@ -1351,13 +1352,13 @@ public class Collection extends DSpaceObject
* return an array of collections that user has a given permission on
* (useful for trimming 'select to collection' list) or figuring out which
* collections a person is an editor for.
- *
+ *
* @param context
* @param comm
* (optional) restrict search to a community, else null
* @param actionID
* of the action
- *
+ *
* @return Collection [] of collections with matching permissions
* @throws SQLException
*/
@@ -1437,7 +1438,7 @@ public class Collection extends DSpaceObject
return itemcount;
}
-
+
public DSpaceObject getAdminObject(int action) throws SQLException
{
DSpaceObject adminObject = null;
@@ -1473,7 +1474,7 @@ public class Collection extends DSpaceObject
}
return adminObject;
}
-
+
@Override
public DSpaceObject getParentObject() throws SQLException
{
diff --git a/dspace-api/src/main/java/org/dspace/core/ConfigurationManager.java b/dspace-api/src/main/java/org/dspace/core/ConfigurationManager.java
index 31ca94e61f..5ebd29d5d2 100644
--- a/dspace-api/src/main/java/org/dspace/core/ConfigurationManager.java
+++ b/dspace-api/src/main/java/org/dspace/core/ConfigurationManager.java
@@ -43,7 +43,7 @@ import org.apache.log4j.helpers.OptionConverter;
* of the DSpace installation directory (specified as the property
* dspace.dir
in the main configuration file.)
*
- *
+ *
* @author Robert Tansley
* @author Larry Stone - Interpolated values.
* @author Mark Diggory - General Improvements to detection, logging and loading.
@@ -56,20 +56,17 @@ public class ConfigurationManager
/** The configuration properties */
private static Properties properties = null;
-
+
/** module configuration properties */
private static Mapnull
if the property
* does not exist.
*/
@@ -176,11 +173,11 @@ public class ConfigurationManager
String value = props == null ? null : props.getProperty(property);
return (value != null) ? value.trim() : null;
}
-
+
/**
* Get a module configuration property value.
- *
- * @param module
+ *
+ * @param module
* the name of the module, or null
for regular configuration
* property
* @param property
@@ -195,7 +192,7 @@ public class ConfigurationManager
{
return getProperty(property);
}
-
+
String value = null;
Properties modProps = getMutableProperties(module);
@@ -215,10 +212,10 @@ public class ConfigurationManager
/**
* Get a configuration property as an integer
- *
+ *
* @param property
* the name of the property
- *
+ *
* @return the value of the property. 0
is returned if the
* property does not exist. To differentiate between this case and
* when the property actually is zero, use getProperty
.
@@ -227,16 +224,16 @@ public class ConfigurationManager
{
return getIntProperty(property, 0);
}
-
+
/**
* Get a module configuration property as an integer
*
* @param module
* the name of the module
- *
+ *
* @param property
* the name of the property
- *
+ *
* @return the value of the property. 0
is returned if the
* property does not exist. To differentiate between this case and
* when the property actually is zero, use getProperty
.
@@ -248,10 +245,10 @@ public class ConfigurationManager
/**
* Get a configuration property as an integer, with default
- *
+ *
* @param property
* the name of the property
- *
+ *
* @param defaultValue
* value to return if property is not found or is not an Integer.
*
@@ -264,16 +261,16 @@ public class ConfigurationManager
{
return getIntProperty(null, property, defaultValue);
}
-
+
/**
* Get a module configuration property as an integer, with default
- *
+ *
* @param module
* the name of the module
- *
+ *
* @param property
* the name of the property
- *
+ *
* @param defaultValue
* value to return if property is not found or is not an Integer.
*
@@ -316,12 +313,12 @@ public class ConfigurationManager
{
return getLongProperty(property, 0);
}
-
+
/**
* Get a module configuration property as a long
*
* @param module
- * the name of the module
+ * the name of the module
* @param property
* the name of the property
*
@@ -333,10 +330,10 @@ public class ConfigurationManager
{
return getLongProperty(module, property, 0);
}
-
+
/**
* Get a configuration property as an long, with default
- *
+ *
*
* @param property
* the name of the property
@@ -356,7 +353,7 @@ public class ConfigurationManager
/**
* Get a configuration property as an long, with default
- *
+ *
* @param module the module, or null
for regular property
*
* @param property
@@ -390,91 +387,14 @@ public class ConfigurationManager
return longValue;
}
- /**
- * Get the License
- *
- * @param
- * licenseFile file name
- *
- * @return
- * license text
- *
- */
- public static String getLicenseText(String licenseFile)
- {
- // Load in default license
-
- InputStream is = null;
- InputStreamReader ir = null;
- BufferedReader br = null;
- try
- {
- is = new FileInputStream(licenseFile);
- ir = new InputStreamReader(is, "UTF-8");
- br = new BufferedReader(ir);
- String lineIn;
- license = "";
- while ((lineIn = br.readLine()) != null)
- {
- license = license + lineIn + '\n';
- }
- }
- catch (IOException e)
- {
- fatal("Can't load configuration", e);
-
- // FIXME: Maybe something more graceful here, but with the
- // configuration we can't do anything
- throw new IllegalStateException("Failed to read default license.", e);
- }
- finally
- {
- if (br != null)
- {
- try
- {
- br.close();
- }
- catch (IOException ioe)
- {
- }
- }
-
- if (ir != null)
- {
- try
- {
- ir.close();
- }
- catch (IOException ioe)
- {
-
- }
- }
- if (is != null)
- {
- try
- {
- is.close();
- }
- catch (IOException ioe)
- {
-
- }
- }
- }
-
- return license;
- }
-
/**
* Get a configuration property as a boolean. True is indicated if the value
* of the property is TRUE
or YES
(case
* insensitive.)
- *
+ *
* @param property
* the name of the property
- *
+ *
* @return the value of the property. false
is returned if
* the property does not exist. To differentiate between this case
* and when the property actually is false, use
@@ -484,17 +404,17 @@ public class ConfigurationManager
{
return getBooleanProperty(property, false);
}
-
+
/**
- * Get a module configuration property as a boolean. True is indicated if
+ * Get a module configuration property as a boolean. True is indicated if
* the value of the property is TRUE
or YES
(case
* insensitive.)
- *
- * @param module the module, or null
for regular property
- *
+ *
+ * @param module the module, or null
for regular property
+ *
* @param property
* the name of the property
- *
+ *
* @return the value of the property. false
is returned if
* the property does not exist. To differentiate between this case
* and when the property actually is false, use
@@ -504,7 +424,7 @@ public class ConfigurationManager
{
return getBooleanProperty(module, property, false);
}
-
+
/**
* Get a configuration property as a boolean, with default.
* True is indicated if the value
@@ -532,8 +452,8 @@ public class ConfigurationManager
* True is indicated if the value
* of the property is TRUE
or YES
(case
* insensitive.)
- *
- * @param module module, or null
for regular property
+ *
+ * @param module module, or null
for regular property
*
* @param property
* the name of the property
@@ -564,19 +484,19 @@ public class ConfigurationManager
/**
* Returns an enumeration of all the keys in the DSpace configuration
- *
+ *
* @return an enumeration of all the keys in the DSpace configuration
*/
public static Enumeration> propertyNames()
{
return propertyNames(null);
}
-
+
/**
* Returns an enumeration of all the keys in a module configuration
- *
- * @param module module, or null
for regular property
- *
+ *
+ * @param module module, or null
for regular property
+ *
* @return an enumeration of all the keys in the module configuration,
* or null
if the module does not exist.
*/
@@ -586,235 +506,13 @@ public class ConfigurationManager
return props == null ? null : props.propertyNames();
}
- /**
- * Get the template for an email message. The message is suitable for
- * inserting values using java.text.MessageFormat
.
- *
- * @param emailFile
- * full name for the email template, for example "/dspace/config/emails/register".
- *
- * @return the email object, with the content and subject filled out from
- * the template
- *
- * @throws IOException
- * if the template couldn't be found, or there was some other
- * error reading the template
- */
- public static Email getEmail(String emailFile) throws IOException
- {
- String charset = null;
- String subject = "";
- StringBuffer contentBuffer = new StringBuffer();
-
- // Read in template
- InputStream is = null;
- InputStreamReader ir = null;
- BufferedReader br = null;
- try
- {
- is = new FileInputStream(emailFile);
- ir = new InputStreamReader(is, "UTF-8");
- br = new BufferedReader(ir);
-
- boolean more = true;
-
- while (more)
- {
- String line = br.readLine();
-
- if (line == null)
- {
- more = false;
- }
- else if (line.toLowerCase().startsWith("subject:"))
- {
- // Extract the first subject line - everything to the right
- // of the colon, trimmed of whitespace
- subject = line.substring(8).trim();
- }
- else if (line.toLowerCase().startsWith("charset:"))
- {
- // Extract the character set from the email
- charset = line.substring(8).trim();
- }
- else if (!line.startsWith("#"))
- {
- // Add non-comment lines to the content
- contentBuffer.append(line);
- contentBuffer.append("\n");
- }
- }
- }
- finally
- {
- if (br != null)
- {
- try {
- br.close();
- } catch (IOException ioe)
- {
- }
- }
- if (ir != null)
- {
- try {
- ir.close();
- } catch (IOException ioe)
- {
- }
- }
- if (is != null)
- {
- try {
- is.close();
- } catch (IOException ioe)
- {
- }
- }
- }
- // Create an email
- Email email = new Email();
- email.setSubject(subject);
- email.setContent(contentBuffer.toString());
-
- if (charset != null)
- {
- email.setCharset(charset);
- }
-
- return email;
- }
-
- /**
- * Get the site-wide default license that submitters need to grant
- *
- * @return the default license
- */
- public static String getDefaultSubmissionLicense()
- {
- if (properties == null)
- {
- loadConfig(null);
- }
-
- return license;
- }
-
- /**
- * Get the path for the news files.
- *
- */
- public static String getNewsFilePath()
- {
- String filePath = ConfigurationManager.getProperty("dspace.dir")
- + File.separator + "config" + File.separator;
-
- return filePath;
- }
-
- /**
- * Reads news from a text file.
- *
- * @param newsFile
- * name of the news file to read in, relative to the news file path.
- */
- public static String readNewsFile(String newsFile)
- {
- String fileName = getNewsFilePath();
-
- fileName += newsFile;
-
- StringBuilder text = new StringBuilder();
-
- try
- {
- // retrieve existing news from file
- FileInputStream fir = new FileInputStream(fileName);
- InputStreamReader ir = new InputStreamReader(fir, "UTF-8");
- BufferedReader br = new BufferedReader(ir);
-
- String lineIn;
-
- while ((lineIn = br.readLine()) != null)
- {
- text.append(lineIn);
- }
-
- br.close();
- ir.close();
- fir.close();
- }
- catch (IOException e)
- {
- warn("news_read: " + e.getLocalizedMessage());
- }
-
- return text.toString();
- }
-
- /**
- * Writes news to a text file.
- *
- * @param newsFile
- * name of the news file to read in, relative to the news file path.
- * @param news
- * the text to be written to the file.
- */
- public static String writeNewsFile(String newsFile, String news)
- {
- String fileName = getNewsFilePath();
-
- fileName += newsFile;
-
- try
- {
- // write the news out to the appropriate file
- FileOutputStream fos = new FileOutputStream(fileName);
- OutputStreamWriter osr = new OutputStreamWriter(fos, "UTF-8");
- PrintWriter out = new PrintWriter(osr);
- out.print(news);
- out.close();
- }
- catch (IOException e)
- {
- warn("news_write: " + e.getLocalizedMessage());
- }
-
- return news;
- }
-
- /**
- * Writes license to a text file.
- *
- * @param licenseFile
- * name for the file int which license will be written,
- * relative to the current directory.
- */
- public static void writeLicenseFile(String licenseFile, String newLicense)
- {
- try
- {
- // write the news out to the appropriate file
- FileOutputStream fos = new FileOutputStream(licenseFile);
- OutputStreamWriter osr = new OutputStreamWriter(fos, "UTF-8");
- PrintWriter out = new PrintWriter(osr);
- out.print(newLicense);
- out.close();
- }
- catch (IOException e)
- {
- warn("license_write: " + e.getLocalizedMessage());
- }
-
- license = newLicense;
- }
-
+ /** The configuration that was loaded. */
private static File loadedFile = null;
/**
* Return the file that configuration was actually loaded from. Only returns
* a valid File after configuration has been loaded.
- *
+ *
* @deprecated Please remove all direct usage of the configuration file.
* @return File naming configuration data file, or null if not loaded yet.
*/
@@ -883,17 +581,16 @@ public class ConfigurationManager
}
catch (IOException ioE)
{
- fatal("Can't load configuration: " + (modFile == null ? "dspace.cfg
configuration file to use, or
* null
to try default locations
@@ -906,7 +603,7 @@ public class ConfigurationManager
}
URL url = null;
-
+
InputStream is = null;
InputStreamReader reader = null;
try
@@ -922,27 +619,27 @@ public class ConfigurationManager
// This isn't really a fatal error though, so catch and ignore
log.warn("Unable to access system properties, ignoring.", se);
}
-
+
// should only occur after a flush()
if (loadedFile != null)
{
info("Reloading current config file: " + loadedFile.getAbsolutePath());
-
+
url = loadedFile.toURI().toURL();
}
else if (configFile != null)
{
info("Loading provided config file: " + configFile);
-
+
loadedFile = new File(configFile);
url = loadedFile.toURI().toURL();
-
+
}
// Has the default configuration location been overridden?
else if (configProperty != null)
{
info("Loading system provided config property (-Ddspace.configuration): " + configProperty);
-
+
// Load the overriding configuration
loadedFile = new File(configProperty);
url = loadedFile.toURI().toURL();
@@ -954,11 +651,11 @@ public class ConfigurationManager
if (url != null)
{
info("Loading from classloader: " + url);
-
+
loadedFile = new File(url.getPath());
}
}
-
+
if (url == null)
{
fatal("Cannot find dspace.cfg");
@@ -988,8 +685,8 @@ public class ConfigurationManager
{
fatal("Can't load configuration: " + url, e);
- // FIXME: Maybe something more graceful here, but with the
- // configuration we can't do anything
+ // FIXME: Maybe something more graceful here, but without a
+ // configuration we can't do anything.
throw new IllegalStateException("Cannot load configuration: " + url, e);
}
finally
@@ -1006,131 +703,61 @@ public class ConfigurationManager
if (is != null)
{
try
- {
+ {
is.close();
}
catch (IOException ioe)
- {
- }
- }
- }
-
- // Load in default license
- File licenseFile = new File(getProperty("dspace.dir") + File.separator
- + "config" + File.separator + "default.license");
-
- FileInputStream fir = null;
- InputStreamReader ir = null;
- BufferedReader br = null;
- try
- {
-
- fir = new FileInputStream(licenseFile);
- ir = new InputStreamReader(fir, "UTF-8");
- br = new BufferedReader(ir);
- String lineIn;
- license = "";
-
- while ((lineIn = br.readLine()) != null)
- {
- license = license + lineIn + '\n';
- }
-
- br.close();
-
- }
- catch (IOException e)
- {
- fatal("Can't load license: " + licenseFile.toString() , e);
-
- // FIXME: Maybe something more graceful here, but with the
- // configuration we can't do anything
- throw new IllegalStateException("Cannot load license: " + licenseFile.toString(),e);
- }
- finally
- {
- if (br != null)
- {
- try
{
- br.close();
- }
- catch (IOException ioe)
- {
- }
- }
-
- if (ir != null)
- {
- try
- {
- ir.close();
- }
- catch (IOException ioe)
- {
- }
- }
-
- if (fir != null)
- {
- try
- {
- fir.close();
- }
- catch (IOException ioe)
- {
}
}
}
-
-
try
{
/*
* Initialize Logging once ConfigurationManager is initialized.
- *
- * This is selection from a property in dspace.cfg, if the property
+ *
+ * This is controlled by a property in dspace.cfg. If the property
* is absent then nothing will be configured and the application
- * will use the defaults provided by log4j.
- *
+ * will use the defaults provided by log4j.
+ *
* Property format is:
- *
+ *
* log.init.config = ${dspace.dir}/config/log4j.properties
* or
* log.init.config = ${dspace.dir}/config/log4j.xml
- *
+ *
* See default log4j initialization documentation here:
* http://logging.apache.org/log4j/docs/manual.html
- *
+ *
* If there is a problem with the file referred to in
- * "log.configuration" it needs to be sent to System.err
+ * "log.configuration", it needs to be sent to System.err
* so do not instantiate another Logging configuration.
*
*/
String dsLogConfiguration = ConfigurationManager.getProperty("log.init.config");
- if (dsLogConfiguration == null || System.getProperty("dspace.log.init.disable") != null)
+ if (dsLogConfiguration == null || System.getProperty("dspace.log.init.disable") != null)
{
- /*
- * Do nothing if log config not set in dspace.cfg or "dspace.log.init.disable"
- * system property set. Leave it upto log4j to properly init its logging
+ /*
+ * Do nothing if log config not set in dspace.cfg or "dspace.log.init.disable"
+ * system property set. Leave it upto log4j to properly init its logging
* via classpath or system properties.
*/
- info("Using default log4j provided log configuration," +
- "if unintended, check your dspace.cfg for (log.init.config)");
+ info("Using default log4j provided log configuration." +
+ " If unintended, check your dspace.cfg for (log.init.config)");
}
else
{
info("Using dspace provided log configuration (log.init.config)");
-
-
+
+
File logConfigFile = new File(dsLogConfiguration);
-
+
if(logConfigFile.exists())
{
info("Loading: " + dsLogConfiguration);
-
+
OptionConverter.selectAndConfigure(logConfigFile.toURI()
.toURL(), null, org.apache.log4j.LogManager
.getLoggerRepository());
@@ -1147,7 +774,7 @@ public class ConfigurationManager
fatal("Can't load dspace provided log4j configuration", e);
throw new IllegalStateException("Cannot load dspace provided log4j configuration",e);
}
-
+
}
/**
@@ -1224,7 +851,7 @@ public class ConfigurationManager
* name
from dspace.cfg
to the standard
* output. If the property does not exist, nothing is written.
*
- *
+ *
* @param argv
* command-line arguments
*/
@@ -1246,7 +873,7 @@ public class ConfigurationManager
System.exit(0);
}
else if ((argv.length == 4) && argv[0].equals("-module") &&
- argv[2].equals("-property"))
+ argv[2].equals("-property"))
{
String val = getProperty(argv[1], argv[3]);
@@ -1269,7 +896,7 @@ public class ConfigurationManager
System.exit(1);
}
-
+
private static void info(String string)
{
if (!isLog4jConfigured())
@@ -1320,8 +947,8 @@ public class ConfigurationManager
}
/*
- * Only current solution available to detect
- * if log4j is truly configured.
+ * Only current solution available to detect
+ * if log4j is truly configured.
*/
private static boolean isLog4jConfigured()
{
diff --git a/dspace-api/src/main/java/org/dspace/core/Email.java b/dspace-api/src/main/java/org/dspace/core/Email.java
index 540b978912..892be854a0 100644
--- a/dspace-api/src/main/java/org/dspace/core/Email.java
+++ b/dspace-api/src/main/java/org/dspace/core/Email.java
@@ -7,9 +7,12 @@
*/
package org.dspace.core;
+import java.io.BufferedReader;
import org.apache.log4j.Logger;
import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Date;
@@ -54,57 +57,47 @@ import javax.mail.internet.MimeMultipart;
* starts with "Subject:" the text on the right of the colon is used for the
* subject line. For example:
*
- *
+ *
* # This is a comment line which is stripped
* #
* # Parameters: {0} is a person's name
* # {1} is the name of a submission
* #
* Subject: Example e-mail
- *
+ *
* Dear {0},
- *
+ *
* Thank you for sending us your submission "{1}".
- *
+ *
*
- *
+ *
* Example e-mail
and the body would be:
*
- *
- *
+ *
+ *
* Dear John,
- *
+ *
* Thank you for sending us your submission "On the Testing of DSpace".
- *
+ *
*
- *
+ *
* {0}
cannot be placed in the subject
* of the e-mail; they won't get filled out.
- *
- *
+ *
+ *
* @author Robert Tansley
* @author Jim Downing - added attachment handling code
* @version $Revision$
*/
public class Email
{
- /*
- * Implementation note: It might be necessary to add a quick utility method
- * like "send(to, subject, message)". We'll see how far we get without it -
- * having all emails as templates in the config allows customisation and
- * internationalisation.
- *
- * Note that everything is stored and the run in send() so that only send()
- * throws a MessagingException.
- */
-
/** The content of the message */
private String content;
@@ -143,7 +136,7 @@ public class Email
/**
* Add a recipient
- *
+ *
* @param email
* the recipient's email address
*/
@@ -156,7 +149,7 @@ public class Email
* Set the content of the message. Setting this "resets" the message
* formatting -addArgument
will start. Comments and any
* "Subject:" line must be stripped.
- *
+ *
* @param cnt
* the content of the message
*/
@@ -168,7 +161,7 @@ public class Email
/**
* Set the subject of the message
- *
+ *
* @param s
* the subject of the message
*/
@@ -179,7 +172,7 @@ public class Email
/**
* Set the reply-to email address
- *
+ *
* @param email
* the reply-to email address
*/
@@ -190,7 +183,7 @@ public class Email
/**
* Fill out the next argument in the template
- *
+ *
* @param arg
* the value for the next argument
*/
@@ -224,7 +217,7 @@ public class Email
/**
* Sends the email.
- *
+ *
* @throws MessagingException
* if there was a problem sending the mail.
*/
@@ -255,16 +248,16 @@ public class Email
// If no character set specified, attempt to retrieve a default
if (charset == null)
{
- charset = ConfigurationManager.getProperty("mail.charset");
+ charset = ConfigurationManager.getProperty("mail.charset");
}
// Get session
Session session;
-
+
// Get the SMTP server authentication information
String username = ConfigurationManager.getProperty("mail.server.username");
String password = ConfigurationManager.getProperty("mail.server.password");
-
+
if (username != null)
{
props.put("mail.smtp.auth", "true");
@@ -321,7 +314,7 @@ public class Email
{
message.setSubject(fullSubject);
}
-
+
// Add attachments
if (attachments.isEmpty())
{
@@ -366,6 +359,78 @@ public class Email
Transport.send(message);
}
+ /**
+ * Get the template for an email message. The message is suitable for
+ * inserting values using java.text.MessageFormat
.
+ *
+ * @param emailFile
+ * full name for the email template, for example "/dspace/config/emails/register".
+ *
+ * @return the email object, with the content and subject filled out from
+ * the template
+ *
+ * @throws IOException
+ * if the template couldn't be found, or there was some other
+ * error reading the template
+ */
+ public static Email getEmail(String emailFile)
+ throws IOException
+ {
+ String charset = null;
+ String subject = "";
+ StringBuilder contentBuffer = new StringBuilder();
+ BufferedReader reader = null;
+ try
+ {
+ reader = new BufferedReader(new FileReader(emailFile));
+ boolean more = true;
+ while (more)
+ {
+ String line = reader.readLine();
+ if (line == null)
+ {
+ more = false;
+ }
+ else if (line.toLowerCase().startsWith("subject:"))
+ {
+ subject = line.substring(8).trim();
+ }
+ else if (line.toLowerCase().startsWith("charset:"))
+ {
+ charset = line.substring(8).trim();
+ }
+ else if (!line.startsWith("#"))
+ {
+ contentBuffer.append(line);
+ contentBuffer.append("\n");
+ }
+ }
+ } finally
+ {
+ if (reader != null)
+ {
+ reader.close();
+ }
+ }
+ Email email = new Email();
+ email.setSubject(subject);
+ email.setContent(contentBuffer.toString());
+ if (charset != null)
+ {
+ email.setCharset(charset);
+ }
+ return email;
+ }
+ /*
+ * Implementation note: It might be necessary to add a quick utility method
+ * like "send(to, subject, message)". We'll see how far we get without it -
+ * having all emails as templates in the config allows customisation and
+ * internationalisation.
+ *
+ * Note that everything is stored and the run in send() so that only send()
+ * throws a MessagingException.
+ */
+
/**
* Test method to send an email to check email server settings
*
@@ -402,9 +467,9 @@ public class Email
/**
* Utility struct class for handling file attachments.
- *
+ *
* @author ojd20
- *
+ *
*/
private static class FileAttachment
{
@@ -418,7 +483,7 @@ public class Email
String name;
}
-
+
/**
* Inner Class for SMTP authentication information
*/
@@ -426,16 +491,16 @@ public class Email
{
// User name
private String name;
-
+
// Password
private String password;
-
+
public SMTPAuthenticator(String n, String p)
{
name = n;
password = p;
}
-
+
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(name, password);
diff --git a/dspace-api/src/main/java/org/dspace/core/LicenseManager.java b/dspace-api/src/main/java/org/dspace/core/LicenseManager.java
new file mode 100644
index 0000000000..a82ea98a84
--- /dev/null
+++ b/dspace-api/src/main/java/org/dspace/core/LicenseManager.java
@@ -0,0 +1,191 @@
+
+package org.dspace.core;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Encapsulate the deposit license.
+ *
+ * @author mhwood
+ */
+public class LicenseManager
+{
+ private static final Logger log = LoggerFactory.getLogger(LicenseManager.class);
+
+ /** The default license */
+ private static String license;
+
+ /**
+ * Writes license to a text file.
+ *
+ * @param licenseFile
+ * name for the file into which license will be written,
+ * relative to the current directory.
+ */
+ public static void writeLicenseFile(String licenseFile,
+ String newLicense)
+ {
+ try
+ {
+ FileOutputStream fos = new FileOutputStream(licenseFile);
+ OutputStreamWriter osr = new OutputStreamWriter(fos, "UTF-8");
+ PrintWriter out = new PrintWriter(osr);
+ out.print(newLicense);
+ out.close();
+ } catch (IOException e)
+ {
+ log.warn("license_write: " + e.getLocalizedMessage());
+ }
+ license = newLicense;
+ }
+
+ /**
+ * Get the License
+ *
+ * @param
+ * licenseFile file name
+ *
+ * @return
+ * license text
+ *
+ */
+ public static String getLicenseText(String licenseFile)
+ {
+ FileReader fr = null;
+ BufferedReader br = null;
+ try
+ {
+ fr = new FileReader(licenseFile);
+ br = new BufferedReader(fr);
+ String lineIn;
+ license = "";
+ while ((lineIn = br.readLine()) != null)
+ {
+ license = license + lineIn + '\n';
+ }
+ } catch (IOException e)
+ {
+ log.error("Can't load configuration", e);
+ throw new IllegalStateException("Failed to read default license.", e);
+ } finally
+ {
+ if (br != null)
+ {
+ try
+ {
+ br.close();
+ } catch (IOException ioe)
+ {
+ }
+ }
+ if (fr != null)
+ {
+ try
+ {
+ fr.close();
+ } catch (IOException ioe)
+ {
+ }
+ }
+ }
+ return license;
+ }
+
+ /**
+ * Get the site-wide default license that submitters need to grant
+ *
+ * @return the default license
+ */
+ public static String getDefaultSubmissionLicense()
+ {
+ if (null == license)
+ {
+ init();
+ }
+ return license;
+ }
+
+ /**
+ * Load in the default license.
+ */
+ private static void init()
+ {
+ File licenseFile = new File(ConfigurationManager.getProperty("dspace.dir")
+ + File.separator + "config" + File.separator + "default.license");
+
+ FileInputStream fir = null;
+ InputStreamReader ir = null;
+ BufferedReader br = null;
+ try
+ {
+
+ fir = new FileInputStream(licenseFile);
+ ir = new InputStreamReader(fir, "UTF-8");
+ br = new BufferedReader(ir);
+ String lineIn;
+ LicenseManager.license = "";
+
+ while ((lineIn = br.readLine()) != null)
+ {
+ LicenseManager.license = LicenseManager.license + lineIn + '\n';
+ }
+
+ br.close();
+
+ }
+ catch (IOException e)
+ {
+ log.error("Can't load license: " + licenseFile.toString() , e);
+
+ // FIXME: Maybe something more graceful here, but with the
+ // configuration we can't do anything
+ throw new IllegalStateException("Cannot load license: "
+ + licenseFile.toString(),e);
+ }
+ finally
+ {
+ if (br != null)
+ {
+ try
+ {
+ br.close();
+ }
+ catch (IOException ioe)
+ {
+ }
+ }
+
+ if (ir != null)
+ {
+ try
+ {
+ ir.close();
+ }
+ catch (IOException ioe)
+ {
+ }
+ }
+
+ if (fir != null)
+ {
+ try
+ {
+ fir.close();
+ }
+ catch (IOException ioe)
+ {
+ }
+ }
+ }
+ }
+}
diff --git a/dspace-api/src/main/java/org/dspace/core/NewsManager.java b/dspace-api/src/main/java/org/dspace/core/NewsManager.java
new file mode 100644
index 0000000000..aafc473a7b
--- /dev/null
+++ b/dspace-api/src/main/java/org/dspace/core/NewsManager.java
@@ -0,0 +1,107 @@
+
+package org.dspace.core;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Encapsulate access to the news texts.
+ *
+ * @author mhwood
+ */
+public class NewsManager
+{
+ private static final Logger log = LoggerFactory.getLogger(NewsManager.class);
+
+ /** Not instantiable. */
+ private NewsManager() {}
+
+ /**
+ * Reads news from a text file.
+ *
+ * @param newsFile
+ * name of the news file to read in, relative to the news file path.
+ */
+ public static String readNewsFile(String newsFile)
+ {
+ String fileName = getNewsFilePath();
+
+ fileName += newsFile;
+
+ StringBuilder text = new StringBuilder();
+
+ try
+ {
+ // retrieve existing news from file
+ FileInputStream fir = new FileInputStream(fileName);
+ InputStreamReader ir = new InputStreamReader(fir, "UTF-8");
+ BufferedReader br = new BufferedReader(ir);
+
+ String lineIn;
+
+ while ((lineIn = br.readLine()) != null)
+ {
+ text.append(lineIn);
+ }
+
+ br.close();
+ }
+ catch (IOException e)
+ {
+ log.warn("news_read: " + e.getLocalizedMessage());
+ }
+
+ return text.toString();
+ }
+
+ /**
+ * Writes news to a text file.
+ *
+ * @param newsFile
+ * name of the news file to read in, relative to the news file path.
+ * @param news
+ * the text to be written to the file.
+ */
+ public static String writeNewsFile(String newsFile, String news)
+ {
+ String fileName = getNewsFilePath();
+
+ fileName += newsFile;
+
+ try
+ {
+ // write the news out to the appropriate file
+ FileOutputStream fos = new FileOutputStream(fileName);
+ OutputStreamWriter osr = new OutputStreamWriter(fos, "UTF-8");
+ PrintWriter out = new PrintWriter(osr);
+ out.print(news);
+ out.close();
+ }
+ catch (IOException e)
+ {
+ log.warn("news_write: " + e.getLocalizedMessage());
+ }
+
+ return news;
+ }
+
+ /**
+ * Get the path for the news files.
+ *
+ */
+ public static String getNewsFilePath()
+ {
+ String filePath = ConfigurationManager.getProperty("dspace.dir")
+ + File.separator + "config" + File.separator;
+
+ return filePath;
+ }
+}
diff --git a/dspace-api/src/main/java/org/dspace/discovery/SolrServiceImpl.java b/dspace-api/src/main/java/org/dspace/discovery/SolrServiceImpl.java
index 43819abbc6..216fb81d66 100644
--- a/dspace-api/src/main/java/org/dspace/discovery/SolrServiceImpl.java
+++ b/dspace-api/src/main/java/org/dspace/discovery/SolrServiceImpl.java
@@ -78,9 +78,9 @@ public class SolrServiceImpl implements SearchService, IndexingService {
public static final String FILTER_SEPARATOR = "\n|||\n";
public static final String AUTHORITY_SEPARATOR = "###";
-
+
public static final String STORE_SEPARATOR = "\n|||\n";
-
+
public static final String VARIANTS_STORE_SEPARATOR = "###";
/**
@@ -326,7 +326,7 @@ public class SolrServiceImpl implements SearchService, IndexingService {
try {
ItemIterator items = null;
try {
- for (items = Item.findAllUnfiltered(context); items.hasNext();)
+ for (items = Item.findAllUnfiltered(context); items.hasNext();)
{
Item item = items.next();
indexContent(context, item, force);
@@ -461,7 +461,7 @@ public class SolrServiceImpl implements SearchService, IndexingService {
if (recipient != null)
{
- Email email = ConfigurationManager
+ Email email = Email
.getEmail(I18nUtil.getEmailFilename(
Locale.getDefault(), "internal_error"));
email.addRecipient(recipient);
@@ -754,7 +754,7 @@ public class SolrServiceImpl implements SearchService, IndexingService {
SolrInputDocument doc = buildDocument(Constants.ITEM, item.getID(), handle,
locations);
-
+
log.debug("Building Item: " + handle);
doc.addField("withdrawn", item.isWithdrawn());
@@ -839,7 +839,7 @@ public class SolrServiceImpl implements SearchService, IndexingService {
toProjectionFields.add(projectionFieldsString);
}
}
-
+
DCValue[] mydc = item.getMetadata(Item.ANY, Item.ANY, Item.ANY, Item.ANY);
for (DCValue meta : mydc)
{
@@ -848,7 +848,7 @@ public class SolrServiceImpl implements SearchService, IndexingService {
String value = meta.value;
- if (value == null)
+ if (value == null)
{
continue;
}
@@ -864,7 +864,7 @@ public class SolrServiceImpl implements SearchService, IndexingService {
{
continue;
}
-
+
String authority = null;
String preferedLabel = null;
Listtrue
, this is registration email;
* otherwise, it is a forgot-password email.
- *
+ *
* @param email
* The email address to mail to
* @param isRegister
@@ -255,7 +255,7 @@ public class AccountManager
.append("token=").append(rd.getStringColumn("token"))
.toString();
Locale locale = context.getCurrentLocale();
- Email bean = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(locale, isRegister ? "register"
+ Email bean = Email.getEmail(I18nUtil.getEmailFilename(locale, isRegister ? "register"
: "change_password"));
bean.addRecipient(email);
bean.addArgument(specialLink);
diff --git a/dspace-api/src/main/java/org/dspace/eperson/EPersonConsumer.java b/dspace-api/src/main/java/org/dspace/eperson/EPersonConsumer.java
index 44ec870f07..fd6738f8e2 100644
--- a/dspace-api/src/main/java/org/dspace/eperson/EPersonConsumer.java
+++ b/dspace-api/src/main/java/org/dspace/eperson/EPersonConsumer.java
@@ -72,7 +72,7 @@ public class EPersonConsumer implements Consumer
try
{
EPerson eperson = EPerson.find(context, id);
- Email adminEmail = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(context.getCurrentLocale(), "registration_notify"));
+ Email adminEmail = Email.getEmail(I18nUtil.getEmailFilename(context.getCurrentLocale(), "registration_notify"));
adminEmail.addRecipient(notifyRecipient);
adminEmail.addArgument(ConfigurationManager.getProperty("dspace.name"));
@@ -80,7 +80,7 @@ public class EPersonConsumer implements Consumer
adminEmail.addArgument(eperson.getFirstName() + " " + eperson.getLastName()); // Name
adminEmail.addArgument(eperson.getEmail());
adminEmail.addArgument(new Date());
-
+
adminEmail.setReplyTo(eperson.getEmail());
adminEmail.send();
diff --git a/dspace-api/src/main/java/org/dspace/eperson/Subscribe.java b/dspace-api/src/main/java/org/dspace/eperson/Subscribe.java
index 3e01a44a64..4fe492d1c5 100644
--- a/dspace-api/src/main/java/org/dspace/eperson/Subscribe.java
+++ b/dspace-api/src/main/java/org/dspace/eperson/Subscribe.java
@@ -48,7 +48,7 @@ import org.dspace.storage.rdbms.TableRowIterator;
/**
* Class defining methods for sending new item e-mail alerts to users
- *
+ *
* @author Robert Tansley
* @version $Revision$
*/
@@ -60,7 +60,7 @@ public class Subscribe
/**
* Subscribe an e-person to a collection. An e-mail will be sent every day a
* new item appears in the collection.
- *
+ *
* @param context
* DSpace context
* @param eperson
@@ -76,10 +76,10 @@ public class Subscribe
|| ((context.getCurrentUser() != null) && (context
.getCurrentUser().getID() == eperson.getID())))
{
- // already subscribed?
+ // already subscribed?
TableRowIterator r = DatabaseManager.query(context,
"SELECT * FROM subscription WHERE eperson_id= ? " +
- " AND collection_id= ? ",
+ " AND collection_id= ? ",
eperson.getID(),collection.getID());
try
@@ -117,7 +117,7 @@ public class Subscribe
* Unsubscribe an e-person to a collection. Passing in null
* for the collection unsubscribes the e-person from all collections they
* are subscribed to.
- *
+ *
* @param context
* DSpace context
* @param eperson
@@ -141,10 +141,10 @@ public class Subscribe
eperson.getID());
}
else
- {
+ {
DatabaseManager.updateQuery(context,
"DELETE FROM subscription WHERE eperson_id= ? " +
- "AND collection_id= ? ",
+ "AND collection_id= ? ",
eperson.getID(),collection.getID());
log.info(LogManager.getHeader(context, "unsubscribe",
@@ -161,7 +161,7 @@ public class Subscribe
/**
* Find out which collections an e-person is subscribed to
- *
+ *
* @param context
* DSpace context
* @param eperson
@@ -195,7 +195,7 @@ public class Subscribe
tri.close();
}
}
-
+
Collection[] collArray = new Collection[collections.size()];
return (Collection[]) collections.toArray(collArray);
@@ -203,7 +203,7 @@ public class Subscribe
/**
* Is that e-person subscribed to that collection?
- *
+ *
* @param context
* DSpace context
* @param eperson
@@ -217,7 +217,7 @@ public class Subscribe
{
TableRowIterator tri = DatabaseManager.query(context,
"SELECT * FROM subscription WHERE eperson_id= ? " +
- "AND collection_id= ? ",
+ "AND collection_id= ? ",
eperson.getID(),collection.getID());
try
@@ -246,10 +246,10 @@ public class Subscribe
* null
if there is no location, i.e. "all of DSpace"
* is the location.
- *
+ *
* @param request
* current HTTP request
- *
+ *
* @return the current community location, or null
*/
public static Community getCommunityLocation(HttpServletRequest request)
@@ -177,10 +177,10 @@ public class UIUtil extends Util
* Get the current collection location, that is, where the user "is". This
* returns null if there is no collection location, i.e. the location is
* "all of DSpace" or a community.
- *
+ *
* @param request
* current HTTP request
- *
+ *
* @return the current collection location, or null
*/
public static Collection getCollectionLocation(HttpServletRequest request)
@@ -193,7 +193,7 @@ public class UIUtil extends Util
* later use. This is necessary because forwarding a request removes this
* information. The attribute is only written if it hasn't been before; thus
* it can be called after a forward safely.
- *
+ *
* @param request
* the HTTP request
*/
@@ -216,10 +216,10 @@ public class UIUtil extends Util
/**
* Get the original request URL.
- *
+ *
* @param request
* the HTTP request
- *
+ *
* @return the original request URL
*/
public static String getOriginalURL(HttpServletRequest request)
@@ -232,7 +232,7 @@ public class UIUtil extends Util
/**
* Write a human-readable version of a DCDate.
- *
+ *
* @param d
* the date
* @param time
@@ -240,8 +240,8 @@ public class UIUtil extends Util
* @param localTime
* if true, adjust for local timezone, otherwise GMT
* @param request
- * the servlet request
- *
+ * the servlet request
+ *
* @return the date in a human-readable form.
*/
public static String displayDate(DCDate d, boolean time, boolean localTime, HttpServletRequest request)
@@ -252,7 +252,7 @@ public class UIUtil extends Util
/**
* Return a string for logging, containing useful information about the
* current request - the URL, the method and parameters.
- *
+ *
* @param request
* the request object.
* @return a multi-line string containing information about the request.
@@ -288,15 +288,15 @@ public class UIUtil extends Util
return report.toString();
}
-
-
+
+
/**
* Get the Locale for a session according to the user's language selection or language preferences.
* Order of selection
* - language selected via UI
* - language as set by application
* - language browser default
- *
+ *
* @param request
* the request Object
* @return supportedLocale
@@ -314,8 +314,8 @@ public class UIUtil extends Util
/* get session locale according to user selection */
sessionLocale = new Locale(paramLocale);
}
-
-
+
+
if (sessionLocale == null)
{
/* get session locale set by application */
@@ -331,17 +331,17 @@ public class UIUtil extends Util
{
sessionLocale = request.getLocale();
}
-
+
if (sessionLocale == null)
{
sessionLocale = I18nUtil.DEFAULTLOCALE;
}
supportedLocale = I18nUtil.getSupportedLocale(sessionLocale);
-
- return supportedLocale;
- }
-
+ return supportedLocale;
+ }
+
+
/**
* Send an alert to the designated "alert recipient" - that is, when a
* database error or internal error occurs, this person is sent an e-mail
@@ -354,7 +354,7 @@ public class UIUtil extends Util
* This method "swallows" any exception that might occur - it will just be
* logged. This is because this method will usually be invoked as part of an
* error handling routine anyway.
- *
+ *
* @param request
* the HTTP request leading to the error
* @param exception
@@ -374,7 +374,7 @@ public class UIUtil extends Util
if (recipient != null)
{
- Email email = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(locale, "internal_error"));
+ Email email = Email.getEmail(I18nUtil.getEmailFilename(locale, "internal_error"));
email.addRecipient(recipient);
email.addArgument(ConfigurationManager
.getProperty("dspace.url"));
@@ -406,7 +406,7 @@ public class UIUtil extends Util
{
log.warn("No context, the database might be down or the connection pool exhausted.");
}
-
+
if (user != null)
{
email.addArgument(user.getFullName() + " (" + user.getEmail() + ")");
@@ -425,10 +425,10 @@ public class UIUtil extends Util
log.warn("Unable to send email alert", e);
}
}
-
+
/**
* Evaluate filename and client and encode appropriate disposition
- *
+ *
* @param filename
* @param request
* @param response
@@ -437,31 +437,31 @@ public class UIUtil extends Util
public static void setBitstreamDisposition(String filename, HttpServletRequest request,
HttpServletResponse response)
{
-
+
String name = filename;
-
+
Matcher m = p.matcher(name);
-
+
if (m.find() && !m.group().equals(""))
{
name = m.group();
}
- try
+ try
{
String agent = request.getHeader("USER-AGENT");
- if (null != agent && -1 != agent.indexOf("MSIE"))
+ if (null != agent && -1 != agent.indexOf("MSIE"))
{
name = URLEncoder.encode(name, "UTF8");
- }
- else if (null != agent && -1 != agent.indexOf("Mozilla"))
+ }
+ else if (null != agent && -1 != agent.indexOf("Mozilla"))
{
name = MimeUtility.encodeText(name, "UTF8", "B");
- }
+ }
- }
- catch (UnsupportedEncodingException e)
+ }
+ catch (UnsupportedEncodingException e)
{
log.error(e.getMessage(),e);
}
diff --git a/dspace-lni/src/main/java/org/dspace/app/dav/DAVSite.java b/dspace-lni/src/main/java/org/dspace/app/dav/DAVSite.java
index 7b051e237f..ecb9ceb826 100644
--- a/dspace-lni/src/main/java/org/dspace/app/dav/DAVSite.java
+++ b/dspace-lni/src/main/java/org/dspace/app/dav/DAVSite.java
@@ -20,6 +20,8 @@ import org.dspace.authorize.AuthorizeManager;
import org.dspace.content.Community;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Context;
+import org.dspace.core.LicenseManager;
+import org.dspace.core.NewsManager;
import org.jdom.Element;
@@ -61,7 +63,7 @@ class DAVSite extends DAVResource
/**
* Instantiates a new DAV site.
- *
+ *
* @param context the context
* @param request the request
* @param response the response
@@ -76,14 +78,14 @@ class DAVSite extends DAVResource
/**
* Match resource URI.
- *
+ *
* @param context the context
* @param request the request
* @param response the response
* @param pathElt the path elt
- *
+ *
* @return the DAV resource
- *
+ *
* @throws DAVStatusException the DAV status exception
* @throws SQLException the SQL exception
*/
@@ -143,15 +145,15 @@ class DAVSite extends DAVResource
}
else if (elementsEqualIsh(property, news_topProperty))
{
- value = ConfigurationManager.readNewsFile("news-top.html");
+ value = NewsManager.readNewsFile("news-top.html");
}
else if (elementsEqualIsh(property, news_sideProperty))
{
- value = ConfigurationManager.readNewsFile("news-side.html");
+ value = NewsManager.readNewsFile("news-side.html");
}
else if (elementsEqualIsh(property, default_licenseProperty))
{
- value = ConfigurationManager.getDefaultSubmissionLicense();
+ value = LicenseManager.getDefaultSubmissionLicense();
}
else
{
@@ -186,7 +188,7 @@ class DAVSite extends DAVResource
throw new DAVStatusException(HttpServletResponse.SC_FORBIDDEN,
"Not authorized to modify this property.");
}
- ConfigurationManager.writeNewsFile("news-top.html", newValue);
+ NewsManager.writeNewsFile("news-top.html", newValue);
}
else if (elementsEqualIsh(prop, news_sideProperty))
{
@@ -195,7 +197,7 @@ class DAVSite extends DAVResource
throw new DAVStatusException(HttpServletResponse.SC_FORBIDDEN,
"Not authorized to modify this property.");
}
- ConfigurationManager.writeNewsFile("news-side.html", newValue);
+ NewsManager.writeNewsFile("news-side.html", newValue);
}
else if (elementsEqualIsh(prop, displaynameProperty))
{
diff --git a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/SendFeedbackAction.java b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/SendFeedbackAction.java
index 02ca38d3eb..dbf37e7be3 100644
--- a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/SendFeedbackAction.java
+++ b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/SendFeedbackAction.java
@@ -128,7 +128,7 @@ public class SendFeedbackAction extends AbstractAction
}
// All data is there, send the email
- Email email = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(context.getCurrentLocale(), "feedback"));
+ Email email = Email.getEmail(I18nUtil.getEmailFilename(context.getCurrentLocale(), "feedback"));
email.addRecipient(ConfigurationManager
.getProperty("feedback.recipient"));