[DS-1390] stage 1: move license, email texts, news out of Configuration Manager.

This commit is contained in:
Mark H. Wood
2013-04-20 19:18:49 -04:00
parent 96cc0d5bd4
commit ed9149608d
24 changed files with 1182 additions and 1187 deletions

View File

@@ -1344,7 +1344,7 @@ public class ItemExport
try try
{ {
Locale supportedLocale = I18nUtil.getEPersonLocale(eperson); 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.addRecipient(eperson.getEmail());
email.addArgument(ConfigurationManager.getProperty("dspace.url") + "/exportdownload/" + fileName); email.addArgument(ConfigurationManager.getProperty("dspace.url") + "/exportdownload/" + fileName);
email.addArgument(ConfigurationManager.getProperty("org.dspace.app.itemexport.life.span.hours")); email.addArgument(ConfigurationManager.getProperty("org.dspace.app.itemexport.life.span.hours"));
@@ -1376,7 +1376,7 @@ public class ItemExport
try try
{ {
Locale supportedLocale = I18nUtil.getEPersonLocale(eperson); 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.addRecipient(eperson.getEmail());
email.addArgument(error); email.addArgument(error);
email.addArgument(ConfigurationManager.getProperty("dspace.url") + "/feedback"); email.addArgument(ConfigurationManager.getProperty("dspace.url") + "/feedback");

View File

@@ -31,6 +31,7 @@ import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.I18nUtil; import org.dspace.core.I18nUtil;
import org.dspace.core.LicenseManager;
import org.dspace.core.LogManager; import org.dspace.core.LogManager;
import org.dspace.eperson.Group; import org.dspace.eperson.Group;
import org.dspace.event.Event; import org.dspace.event.Event;
@@ -782,7 +783,7 @@ public class Collection extends DSpaceObject
if (license == null || license.trim().equals("")) if (license == null || license.trim().equals(""))
{ {
// Fallback to site-wide default // Fallback to site-wide default
license = ConfigurationManager.getDefaultSubmissionLicense(); license = LicenseManager.getDefaultSubmissionLicense();
} }
return license; return license;

View File

@@ -60,9 +60,6 @@ public class ConfigurationManager
/** module configuration properties */ /** module configuration properties */
private static Map<String, Properties> moduleProps = new HashMap<String, Properties>(); private static Map<String, Properties> moduleProps = new HashMap<String, Properties>();
/** The default license */
private static String license;
// limit of recursive depth of property variable interpolation in // limit of recursive depth of property variable interpolation in
// configuration; anything greater than this is very likely to be a loop. // configuration; anything greater than this is very likely to be a loop.
private static final int RECURSION_LIMIT = 9; private static final int RECURSION_LIMIT = 9;
@@ -390,83 +387,6 @@ public class ConfigurationManager
return longValue; 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 * Get a configuration property as a boolean. True is indicated if the value
* of the property is <code>TRUE</code> or <code>YES</code> (case * of the property is <code>TRUE</code> or <code>YES</code> (case
@@ -586,229 +506,7 @@ public class ConfigurationManager
return props == null ? null : props.propertyNames(); return props == null ? null : props.propertyNames();
} }
/** /** The configuration that was loaded. */
* Get the template for an email message. The message is suitable for
* inserting values using <code>java.text.MessageFormat</code>.
*
* @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;
}
private static File loadedFile = null; private static File loadedFile = null;
/** /**
@@ -883,10 +581,9 @@ public class ConfigurationManager
} }
catch (IOException ioE) catch (IOException ioE)
{ {
fatal("Can't load configuration: " + (modFile == null ? "<unknown>" : modFile.getAbsolutePath()), ioE); fatal("Can't load configuration: " +
(modFile == null ? "<unknown>" : modFile.getAbsolutePath()), ioE);
} }
return;
} }
/** /**
@@ -988,8 +685,8 @@ public class ConfigurationManager
{ {
fatal("Can't load configuration: " + url, e); fatal("Can't load configuration: " + url, e);
// FIXME: Maybe something more graceful here, but with the // FIXME: Maybe something more graceful here, but without a
// configuration we can't do anything // configuration we can't do anything.
throw new IllegalStateException("Cannot load configuration: " + url, e); throw new IllegalStateException("Cannot load configuration: " + url, e);
} }
finally finally
@@ -1015,82 +712,12 @@ public class ConfigurationManager
} }
} }
// 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 try
{ {
/* /*
* Initialize Logging once ConfigurationManager is initialized. * 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 * is absent then nothing will be configured and the application
* will use the defaults provided by log4j. * will use the defaults provided by log4j.
* *
@@ -1104,7 +731,7 @@ public class ConfigurationManager
* http://logging.apache.org/log4j/docs/manual.html * http://logging.apache.org/log4j/docs/manual.html
* *
* If there is a problem with the file referred to in * 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. * so do not instantiate another Logging configuration.
* *
*/ */
@@ -1117,8 +744,8 @@ public class ConfigurationManager
* system property set. Leave it upto log4j to properly init its logging * system property set. Leave it upto log4j to properly init its logging
* via classpath or system properties. * via classpath or system properties.
*/ */
info("Using default log4j provided log configuration," + info("Using default log4j provided log configuration." +
"if unintended, check your dspace.cfg for (log.init.config)"); " If unintended, check your dspace.cfg for (log.init.config)");
} }
else else
{ {

View File

@@ -7,9 +7,12 @@
*/ */
package org.dspace.core; package org.dspace.core;
import java.io.BufferedReader;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import java.io.File; import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@@ -95,16 +98,6 @@ import javax.mail.internet.MimeMultipart;
*/ */
public class Email 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 */ /** The content of the message */
private String content; private String content;
@@ -366,6 +359,78 @@ public class Email
Transport.send(message); Transport.send(message);
} }
/**
* Get the template for an email message. The message is suitable for
* inserting values using <code>java.text.MessageFormat</code>.
*
* @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 * Test method to send an email to check email server settings
* *

View File

@@ -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)
{
}
}
}
}
}

View File

@@ -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;
}
}

View File

@@ -461,7 +461,7 @@ public class SolrServiceImpl implements SearchService, IndexingService {
if (recipient != null) if (recipient != null)
{ {
Email email = ConfigurationManager Email email = Email
.getEmail(I18nUtil.getEmailFilename( .getEmail(I18nUtil.getEmailFilename(
Locale.getDefault(), "internal_error")); Locale.getDefault(), "internal_error"));
email.addRecipient(recipient); email.addRecipient(recipient);

View File

@@ -255,7 +255,7 @@ public class AccountManager
.append("token=").append(rd.getStringColumn("token")) .append("token=").append(rd.getStringColumn("token"))
.toString(); .toString();
Locale locale = context.getCurrentLocale(); Locale locale = context.getCurrentLocale();
Email bean = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(locale, isRegister ? "register" Email bean = Email.getEmail(I18nUtil.getEmailFilename(locale, isRegister ? "register"
: "change_password")); : "change_password"));
bean.addRecipient(email); bean.addRecipient(email);
bean.addArgument(specialLink); bean.addArgument(specialLink);

View File

@@ -72,7 +72,7 @@ public class EPersonConsumer implements Consumer
try try
{ {
EPerson eperson = EPerson.find(context, id); 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.addRecipient(notifyRecipient);
adminEmail.addArgument(ConfigurationManager.getProperty("dspace.name")); adminEmail.addArgument(ConfigurationManager.getProperty("dspace.name"));

View File

@@ -471,7 +471,7 @@ public class Subscribe
} else { } else {
Email email = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(supportedLocale, "subscription")); Email email = Email.getEmail(I18nUtil.getEmailFilename(supportedLocale, "subscription"));
email.addRecipient(eperson.getEmail()); email.addRecipient(eperson.getEmail());
email.addArgument(emailText.toString()); email.addArgument(emailText.toString());
email.send(); email.send();

View File

@@ -825,7 +825,7 @@ public class OAIHarvester {
String recipient = ConfigurationManager.getProperty("alert.recipient"); String recipient = ConfigurationManager.getProperty("alert.recipient");
if (recipient != null) { if (recipient != null) {
Email email = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(Locale.getDefault(), "harvesting_error")); Email email = Email.getEmail(I18nUtil.getEmailFilename(Locale.getDefault(), "harvesting_error"));
email.addRecipient(recipient); email.addRecipient(recipient);
email.addArgument(targetCollection.getID()); email.addArgument(targetCollection.getID());
email.addArgument(new Date()); email.addArgument(new Date());

View File

@@ -844,7 +844,7 @@ public class DSIndexer
.getProperty("alert.recipient"); .getProperty("alert.recipient");
if (recipient != null) { if (recipient != null) {
Email email = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(Locale.getDefault(), "internal_error")); Email email = Email.getEmail(I18nUtil.getEmailFilename(Locale.getDefault(), "internal_error"));
email.addRecipient(recipient); email.addRecipient(recipient);
email.addArgument(ConfigurationManager email.addArgument(ConfigurationManager
.getProperty("dspace.url")); .getProperty("dspace.url"));

View File

@@ -742,7 +742,7 @@ public class WorkflowManager
EPerson ep = i.getSubmitter(); EPerson ep = i.getSubmitter();
// Get the Locale // Get the Locale
Locale supportedLocale = I18nUtil.getEPersonLocale(ep); Locale supportedLocale = I18nUtil.getEPersonLocale(ep);
Email email = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(supportedLocale, "submit_archive")); Email email = Email.getEmail(I18nUtil.getEmailFilename(supportedLocale, "submit_archive"));
// Get the item handle to email to user // Get the item handle to email to user
String handle = HandleManager.findHandle(c, i); String handle = HandleManager.findHandle(c, i);
@@ -921,7 +921,7 @@ public class WorkflowManager
for (int i = 0; i < epa.length; i++) for (int i = 0; i < epa.length; i++)
{ {
Locale supportedLocale = I18nUtil.getEPersonLocale(epa[i]); Locale supportedLocale = I18nUtil.getEPersonLocale(epa[i]);
Email email = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(supportedLocale, Email email = Email.getEmail(I18nUtil.getEmailFilename(supportedLocale,
"flowtask_notify")); "flowtask_notify"));
email.addArgument(title); email.addArgument(title);
email.addArgument(coll.getMetadata("name")); email.addArgument(coll.getMetadata("name"));
@@ -971,7 +971,7 @@ public class WorkflowManager
for (int i = 0; i < epa.length; i++) for (int i = 0; i < epa.length; i++)
{ {
Locale supportedLocale = I18nUtil.getEPersonLocale(epa[i]); Locale supportedLocale = I18nUtil.getEPersonLocale(epa[i]);
Email email = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(supportedLocale, "submit_task")); Email email = Email.getEmail(I18nUtil.getEmailFilename(supportedLocale, "submit_task"));
email.addArgument(title); email.addArgument(title);
email.addArgument(coll.getMetadata("name")); email.addArgument(coll.getMetadata("name"));
email.addArgument(submitter); email.addArgument(submitter);
@@ -1030,7 +1030,7 @@ public class WorkflowManager
// Get rejector's name // Get rejector's name
String rejector = getEPersonName(e); String rejector = getEPersonName(e);
Locale supportedLocale = I18nUtil.getEPersonLocale(e); Locale supportedLocale = I18nUtil.getEPersonLocale(e);
Email email = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(supportedLocale,"submit_reject")); Email email = Email.getEmail(I18nUtil.getEmailFilename(supportedLocale,"submit_reject"));
email.addRecipient(getSubmitterEPerson(wi).getEmail()); email.addRecipient(getSubmitterEPerson(wi).getEmail());
email.addArgument(title); email.addArgument(title);

View File

@@ -156,7 +156,7 @@ public class WorkflowUtils extends Util{
if (recipient != null) if (recipient != null)
{ {
Email email = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(c.getCurrentLocale(), "internal_error")); Email email = Email.getEmail(I18nUtil.getEmailFilename(c.getCurrentLocale(), "internal_error"));
email.addRecipient(recipient); email.addRecipient(recipient);
email.addArgument(ConfigurationManager email.addArgument(ConfigurationManager

View File

@@ -107,7 +107,7 @@ public class XmlWorkflowManager {
// suppress email, and delete key // suppress email, and delete key
noEMail.remove(wfi.getItem().getID()); noEMail.remove(wfi.getItem().getID());
} else { } else {
Email mail = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(c.getCurrentLocale(), emailTemplate)); Email mail = Email.getEmail(I18nUtil.getEmailFilename(c.getCurrentLocale(), emailTemplate));
for (String argument : arguments) { for (String argument : arguments) {
mail.addArgument(argument); mail.addArgument(argument);
} }
@@ -396,7 +396,7 @@ public class XmlWorkflowManager {
EPerson ep = i.getSubmitter(); EPerson ep = i.getSubmitter();
// Get the Locale // Get the Locale
Locale supportedLocale = I18nUtil.getEPersonLocale(ep); Locale supportedLocale = I18nUtil.getEPersonLocale(ep);
Email email = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(supportedLocale, "submit_archive")); Email email = Email.getEmail(I18nUtil.getEmailFilename(supportedLocale, "submit_archive"));
// Get the item handle to email to user // Get the item handle to email to user
String handle = HandleManager.findHandle(c, i); String handle = HandleManager.findHandle(c, i);
@@ -856,7 +856,7 @@ public class XmlWorkflowManager {
// Get rejector's name // Get rejector's name
String rejector = getEPersonName(e); String rejector = getEPersonName(e);
Locale supportedLocale = I18nUtil.getEPersonLocale(e); Locale supportedLocale = I18nUtil.getEPersonLocale(e);
Email email = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(supportedLocale,"submit_reject")); Email email = Email.getEmail(I18nUtil.getEmailFilename(supportedLocale,"submit_reject"));
email.addRecipient(wi.getSubmitter().getEmail()); email.addRecipient(wi.getSubmitter().getEmail());
email.addArgument(title); email.addArgument(title);

View File

@@ -20,8 +20,8 @@ import static org.hamcrest.CoreMatchers.*;
import mockit.*; import mockit.*;
import org.dspace.app.util.AuthorizeUtil; import org.dspace.app.util.AuthorizeUtil;
import org.dspace.authorize.AuthorizeManager; import org.dspace.authorize.AuthorizeManager;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.core.LicenseManager;
/** /**
* Unit Tests for class Collection * Unit Tests for class Collection
@@ -665,7 +665,7 @@ public class CollectionTest extends AbstractDSpaceObjectTest
public void testGetLicense() public void testGetLicense()
{ {
assertThat("testGetLicense 0", c.getLicense(), notNullValue()); assertThat("testGetLicense 0", c.getLicense(), notNullValue());
assertThat("testGetLicense 1", c.getLicense(), equalTo(ConfigurationManager.getDefaultSubmissionLicense())); assertThat("testGetLicense 1", c.getLicense(), equalTo(LicenseManager.getDefaultSubmissionLicense()));
} }
/** /**

View File

@@ -13,13 +13,13 @@ import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
import org.dspace.eperson.EPerson; import org.dspace.eperson.EPerson;
import org.dspace.core.ConfigurationManager;
import org.dspace.AbstractUnitTest; import org.dspace.AbstractUnitTest;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.dspace.core.LicenseManager;
import org.junit.*; import org.junit.*;
import static org.junit.Assert.* ; import static org.junit.Assert.* ;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
@@ -81,7 +81,7 @@ public class LicenseUtilsTest extends AbstractUnitTest
String templateLong = "Template license: %1$s %2$s %3$s %5$s %6$s %8$s %9$s %10$s %11$s"; String templateLong = "Template license: %1$s %2$s %3$s %5$s %6$s %8$s %9$s %10$s %11$s";
String templateResult = "Template license: first name last name test@email.com "; String templateResult = "Template license: first name last name test@email.com ";
String templateLongResult = "Template license: first name last name test@email.com arg1 arg2 arg3 arg4"; String templateLongResult = "Template license: first name last name test@email.com arg1 arg2 arg3 arg4";
String defaultLicense = ConfigurationManager.getDefaultSubmissionLicense(); String defaultLicense = LicenseManager.getDefaultSubmissionLicense();
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
//TODO: the tested method doesn't verify the input, will throw NPE if any parameter is null //TODO: the tested method doesn't verify the input, will throw NPE if any parameter is null
@@ -175,7 +175,7 @@ public class LicenseUtilsTest extends AbstractUnitTest
String template = "Template license: %1$s %2$s %3$s %5$s %6$s"; String template = "Template license: %1$s %2$s %3$s %5$s %6$s";
String templateResult = "Template license: first name last name test@email.com "; String templateResult = "Template license: first name last name test@email.com ";
String defaultLicense = ConfigurationManager.getDefaultSubmissionLicense(); String defaultLicense = LicenseManager.getDefaultSubmissionLicense();
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
//TODO: the tested method doesn't verify the input, will throw NPE if any parameter is null //TODO: the tested method doesn't verify the input, will throw NPE if any parameter is null
@@ -231,7 +231,7 @@ public class LicenseUtilsTest extends AbstractUnitTest
{ {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
Item item = Item.create(context); Item item = Item.create(context);
String defaultLicense = ConfigurationManager.getDefaultSubmissionLicense(); String defaultLicense = LicenseManager.getDefaultSubmissionLicense();
LicenseUtils.grantLicense(context, item, defaultLicense); LicenseUtils.grantLicense(context, item, defaultLicense);

View File

@@ -109,7 +109,7 @@ public class FeedbackServlet extends DSpaceServlet
// All data is there, send the email // All data is there, send the email
try try
{ {
Email email = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(context.getCurrentLocale(), "feedback")); Email email = Email.getEmail(I18nUtil.getEmailFilename(context.getCurrentLocale(), "feedback"));
email.addRecipient(ConfigurationManager email.addRecipient(ConfigurationManager
.getProperty("feedback.recipient")); .getProperty("feedback.recipient"));

View File

@@ -183,7 +183,7 @@ public class SuggestServlet extends DSpaceServlet
// All data is there, send the email // All data is there, send the email
try try
{ {
Email email = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(context.getCurrentLocale(), "suggest")); Email email = Email.getEmail(I18nUtil.getEmailFilename(context.getCurrentLocale(), "suggest"));
email.addRecipient(recipAddr); // recipient address email.addRecipient(recipAddr); // recipient address
email.addArgument(recipName); // 1st arg - recipient name email.addArgument(recipName); // 1st arg - recipient name
email.addArgument(senderName); // 2nd arg - sender name email.addArgument(senderName); // 2nd arg - sender name

View File

@@ -21,6 +21,7 @@ import org.dspace.authorize.AuthorizeException;
import org.dspace.core.ConfigurationManager; import org.dspace.core.ConfigurationManager;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.I18nUtil; import org.dspace.core.I18nUtil;
import org.dspace.core.LicenseManager;
/** /**
* Servlet for editing the default license * Servlet for editing the default license
@@ -59,7 +60,7 @@ public class LicenseEditServlet extends DSpaceServlet
else if (!button.equals("submit_save")) else if (!button.equals("submit_save"))
{ {
// Get the existing text from the ConfigurationManager // Get the existing text from the ConfigurationManager
String license = ConfigurationManager.getLicenseText(I18nUtil.getDefaultLicense(c)); String license = LicenseManager.getLicenseText(I18nUtil.getDefaultLicense(c));
// Pass the existing license back to the JSP // Pass the existing license back to the JSP
request.setAttribute("license", license); request.setAttribute("license", license);
@@ -76,7 +77,7 @@ public class LicenseEditServlet extends DSpaceServlet
if (license.trim().equals("")) if (license.trim().equals(""))
{ {
// Get the existing text from the ConfigurationManager // Get the existing text from the ConfigurationManager
license = ConfigurationManager.getLicenseText(I18nUtil.getDefaultLicense(c)); license = LicenseManager.getLicenseText(I18nUtil.getDefaultLicense(c));
// Pass the existing license back to the JSP // Pass the existing license back to the JSP
request.setAttribute("license", license); request.setAttribute("license", license);
@@ -90,7 +91,7 @@ public class LicenseEditServlet extends DSpaceServlet
else else
{ {
// Write the string out to file // Write the string out to file
ConfigurationManager.writeLicenseFile(I18nUtil.getDefaultLicense(c), license); LicenseManager.writeLicenseFile(I18nUtil.getDefaultLicense(c), license);
// Pass the existing license back to the JSP // Pass the existing license back to the JSP
request.setAttribute("license", license); request.setAttribute("license", license);

View File

@@ -20,6 +20,7 @@ import org.dspace.app.webui.util.UIUtil;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
import org.dspace.core.ConfigurationManager; import org.dspace.core.ConfigurationManager;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.NewsManager;
/** /**
* Servlet for editing the front page news * Servlet for editing the front page news
@@ -51,7 +52,7 @@ public class NewsEditServlet extends DSpaceServlet
if (button.equals("submit_edit")) if (button.equals("submit_edit"))
{ {
//get the existing text from the file //get the existing text from the file
news = ConfigurationManager.readNewsFile(position); news = NewsManager.readNewsFile(position);
//pass the position back to the JSP //pass the position back to the JSP
request.setAttribute("position", position); request.setAttribute("position", position);
@@ -69,7 +70,7 @@ public class NewsEditServlet extends DSpaceServlet
news = (String) request.getParameter("news"); news = (String) request.getParameter("news");
//write the string out to file //write the string out to file
ConfigurationManager.writeNewsFile(position, news); NewsManager.writeNewsFile(position, news);
JSPManager JSPManager
.showJSP(request, response, "/dspace-admin/news-main.jsp"); .showJSP(request, response, "/dspace-admin/news-main.jsp");

View File

@@ -374,7 +374,7 @@ public class UIUtil extends Util
if (recipient != null) 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.addRecipient(recipient);
email.addArgument(ConfigurationManager email.addArgument(ConfigurationManager
.getProperty("dspace.url")); .getProperty("dspace.url"));

View File

@@ -20,6 +20,8 @@ import org.dspace.authorize.AuthorizeManager;
import org.dspace.content.Community; import org.dspace.content.Community;
import org.dspace.core.ConfigurationManager; import org.dspace.core.ConfigurationManager;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.LicenseManager;
import org.dspace.core.NewsManager;
import org.jdom.Element; import org.jdom.Element;
@@ -143,15 +145,15 @@ class DAVSite extends DAVResource
} }
else if (elementsEqualIsh(property, news_topProperty)) else if (elementsEqualIsh(property, news_topProperty))
{ {
value = ConfigurationManager.readNewsFile("news-top.html"); value = NewsManager.readNewsFile("news-top.html");
} }
else if (elementsEqualIsh(property, news_sideProperty)) else if (elementsEqualIsh(property, news_sideProperty))
{ {
value = ConfigurationManager.readNewsFile("news-side.html"); value = NewsManager.readNewsFile("news-side.html");
} }
else if (elementsEqualIsh(property, default_licenseProperty)) else if (elementsEqualIsh(property, default_licenseProperty))
{ {
value = ConfigurationManager.getDefaultSubmissionLicense(); value = LicenseManager.getDefaultSubmissionLicense();
} }
else else
{ {
@@ -186,7 +188,7 @@ class DAVSite extends DAVResource
throw new DAVStatusException(HttpServletResponse.SC_FORBIDDEN, throw new DAVStatusException(HttpServletResponse.SC_FORBIDDEN,
"Not authorized to modify this property."); "Not authorized to modify this property.");
} }
ConfigurationManager.writeNewsFile("news-top.html", newValue); NewsManager.writeNewsFile("news-top.html", newValue);
} }
else if (elementsEqualIsh(prop, news_sideProperty)) else if (elementsEqualIsh(prop, news_sideProperty))
{ {
@@ -195,7 +197,7 @@ class DAVSite extends DAVResource
throw new DAVStatusException(HttpServletResponse.SC_FORBIDDEN, throw new DAVStatusException(HttpServletResponse.SC_FORBIDDEN,
"Not authorized to modify this property."); "Not authorized to modify this property.");
} }
ConfigurationManager.writeNewsFile("news-side.html", newValue); NewsManager.writeNewsFile("news-side.html", newValue);
} }
else if (elementsEqualIsh(prop, displaynameProperty)) else if (elementsEqualIsh(prop, displaynameProperty))
{ {

View File

@@ -128,7 +128,7 @@ public class SendFeedbackAction extends AbstractAction
} }
// All data is there, send the email // 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 email.addRecipient(ConfigurationManager
.getProperty("feedback.recipient")); .getProperty("feedback.recipient"));