Merge branch 'develop' of https://github.com/vivo-project/Vitro into develop

This commit is contained in:
tworrall 2013-05-02 12:32:31 -04:00
commit 257f0c4c08
58 changed files with 1112 additions and 700 deletions

View file

@ -25,6 +25,8 @@ import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
import edu.cornell.mannlib.vitro.webapp.i18n.I18n;
import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle;
/**
* A base class with some utility routines for page handler (created by
@ -39,6 +41,7 @@ public abstract class AbstractPageHandler {
private static final Log log = LogFactory.getLog(AbstractPageHandler.class);
protected final VitroRequest vreq;
protected final I18nBundle i18n;
protected final ServletContext ctx;
protected final OntModel userAccountsModel;
protected final OntModel unionModel;
@ -50,6 +53,7 @@ public abstract class AbstractPageHandler {
protected AbstractPageHandler(VitroRequest vreq) {
this.vreq = vreq;
this.i18n = I18n.bundle(vreq);
this.ctx = vreq.getSession().getServletContext();
OntModelSelector oms = ModelContext.getUnionOntModelSelector(ctx);
@ -154,7 +158,8 @@ public abstract class AbstractPageHandler {
private static final String ATTRIBUTE = Message.class.getName();
public static void setMessage(HttpServletRequest req, Message message) {
log.debug("Added message to session: " + message.getMessageInfoMap());
log.debug("Added message to session: "
+ message.getMessageInfoMap());
req.getSession().setAttribute(ATTRIBUTE, message);
}

View file

@ -103,7 +103,7 @@ public abstract class UserAccountsAddPageStrategy extends UserAccountsPage {
FreemarkerEmailMessage email = FreemarkerEmailFactory
.createNewMessage(vreq);
email.addRecipient(TO, page.getAddedAccount().getEmailAddress());
email.setSubject("Your VIVO account has been created.");
email.setSubject(i18n.text("account_created_subject", getSiteName()));
if (page.isExternalAuthOnly()) {
email.setTemplate(EMAIL_TEMPLATE_NO_PASSWORD);
} else {

View file

@ -2,6 +2,8 @@
package edu.cornell.mannlib.vitro.webapp.controller.accounts.admin;
import static edu.cornell.mannlib.vitro.webapp.controller.accounts.user.UserAccountsUserController.getBogusStandardMessage;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@ -15,7 +17,6 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.ManageRoot
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.accounts.UserAccountsPage;
import edu.cornell.mannlib.vitro.webapp.controller.accounts.user.UserAccountsUserController;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
/**
@ -51,7 +52,7 @@ public class UserAccountsDeleter extends UserAccountsPage {
UserAccount loggedInAccount = LoginStatusBean.getCurrentUser(vreq);
if (loggedInAccount == null) {
log.warn("Trying to delete accounts while not logged in!");
bogusMessage = UserAccountsUserController.BOGUS_STANDARD_MESSAGE;
bogusMessage = getBogusStandardMessage(vreq);
return;
}
@ -61,14 +62,14 @@ public class UserAccountsDeleter extends UserAccountsPage {
if (u == null) {
log.warn("Delete account for '" + uri
+ "' is bogus: no such user");
bogusMessage = UserAccountsUserController.BOGUS_STANDARD_MESSAGE;
bogusMessage = getBogusStandardMessage(vreq);
return;
}
if (u.getUri().equals(loggedInAccount.getUri())) {
log.warn("'" + u.getUri()
+ "' is trying to delete his own account.");
bogusMessage = UserAccountsUserController.BOGUS_STANDARD_MESSAGE;
bogusMessage = getBogusStandardMessage(vreq);
return;
}
@ -78,7 +79,7 @@ public class UserAccountsDeleter extends UserAccountsPage {
log.warn("Attempting to delete the root account, "
+ "but not authorized. Logged in as "
+ LoginStatusBean.getCurrentUser(vreq));
bogusMessage = UserAccountsUserController.BOGUS_STANDARD_MESSAGE;
bogusMessage = getBogusStandardMessage(vreq);
return;
}
}

View file

@ -2,6 +2,8 @@
package edu.cornell.mannlib.vitro.webapp.controller.accounts.admin;
import static edu.cornell.mannlib.vitro.webapp.controller.accounts.user.UserAccountsUserController.getBogusStandardMessage;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -20,7 +22,6 @@ import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration;
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.accounts.UserAccountsPage;
import edu.cornell.mannlib.vitro.webapp.controller.accounts.user.UserAccountsUserController;
import edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
@ -116,7 +117,7 @@ public class UserAccountsEditPage extends UserAccountsPage {
if (userAccount == null) {
log.warn("Edit account for '" + userUri
+ "' is bogus: no such user");
bogusMessage = UserAccountsUserController.BOGUS_STANDARD_MESSAGE;
bogusMessage = getBogusStandardMessage(vreq);
return;
}
if (userAccount.isRootUser()) {
@ -125,7 +126,7 @@ public class UserAccountsEditPage extends UserAccountsPage {
log.warn("User is attempting to edit the root account, "
+ "but is not authorized to do so. Logged in as: "
+ LoginStatusBean.getCurrentUser(vreq));
bogusMessage = UserAccountsUserController.BOGUS_STANDARD_MESSAGE;
bogusMessage = getBogusStandardMessage(vreq);
return;
}
}

View file

@ -46,14 +46,12 @@ public class UserAccountsCreatePasswordPage extends
@Override
protected String alreadyLoggedInMessage(String currentUserEmail) {
return "You may not activate the account for " + userEmail
+ " while you are logged in as " + currentUserEmail
+ ". Please log out and try again.";
return i18n.text("cant_activate_while_logged_in", userEmail, currentUserEmail);
}
@Override
protected String passwordChangeNotPendingMessage() {
return "The account for " + userEmail + " has already been activated.";
return i18n.text("account_already_activated", userEmail);
}
@Override
@ -69,7 +67,7 @@ public class UserAccountsCreatePasswordPage extends
FreemarkerEmailMessage email = FreemarkerEmailFactory
.createNewMessage(vreq);
email.addRecipient(TO, userAccount.getEmailAddress());
email.setSubject("Password successfully created.");
email.setSubject(i18n.text("password_created_subject", getSiteName()));
email.setTemplate(EMAIL_TEMPLATE);
email.setBodyMap(body);
email.processTemplate();

View file

@ -115,18 +115,17 @@ public class UserAccountsFirstTimeExternalPage extends UserAccountsPage {
private void validateExternalAuthId() {
if (externalAuthId.isEmpty()) {
bogusMessage = "Login failed - External ID is not found.";
bogusMessage = i18n.text("external_id_not_provided");
return;
}
if (null != userAccountsDao
.getUserAccountByExternalAuthId(externalAuthId)) {
bogusMessage = "User account already exists for '" + externalAuthId
+ "'";
bogusMessage = i18n.text("external_id_already_in_use",
externalAuthId);
return;
}
if (!Authenticator.getInstance(vreq).isUserPermittedToLogin(null)) {
bogusMessage = "User logins are temporarily disabled "
+ "while the system is being maintained.";
bogusMessage = i18n.text("logins_disabled_for_maintenance");
return;
}
}

View file

@ -73,7 +73,7 @@ public abstract class UserAccountsFirstTimeExternalPageStrategy extends
FreemarkerEmailMessage email = FreemarkerEmailFactory
.createNewMessage(vreq);
email.addRecipient(TO, ua.getEmailAddress());
email.setSubject("Your VIVO account has been created.");
email.setSubject(i18n.text("account_created_subject", getSiteName()));
email.setTemplate(EMAIL_TEMPLATE);
email.setBodyMap(body);
email.processTemplate();

View file

@ -178,7 +178,7 @@ public abstract class UserAccountsMyAccountPageStrategy extends
FreemarkerEmailMessage email = FreemarkerEmailFactory
.createNewMessage(vreq);
email.addRecipient(TO, page.getUserAccount().getEmailAddress());
email.setSubject("Your VIVO email account has been changed.");
email.setSubject(i18n.text("email_changed_subject"));
email.setTemplate(EMAIL_TEMPLATE);
email.setBodyMap(body);
email.processTemplate();

View file

@ -23,8 +23,6 @@ public abstract class UserAccountsPasswordBasePage extends UserAccountsPage {
private static final Log log = LogFactory
.getLog(UserAccountsPasswordBasePage.class);
public static final String BOGUS_MESSAGE_NO_SUCH_ACCOUNT = "The account you are trying to set a password on is no longer available. Please contact your system administrator if you think this is an error.";
private static final String PARAMETER_SUBMIT = "submit";
private static final String PARAMETER_USER = "user";
private static final String PARAMETER_KEY = "key";
@ -79,7 +77,7 @@ public abstract class UserAccountsPasswordBasePage extends UserAccountsPage {
if (userAccount == null) {
log.warn("Password request for '" + userEmail
+ "' is bogus: no such user");
bogusMessage = BOGUS_MESSAGE_NO_SUCH_ACCOUNT;
bogusMessage = i18n.text("account_no_longer_exists");
return;
}
@ -170,9 +168,9 @@ public abstract class UserAccountsPasswordBasePage extends UserAccountsPage {
public String getSuccessMessage() {
if (loggedIn) {
return "Your password has been saved.";
return i18n.text("password_saved");
} else {
return "Your password has been saved. Please log in.";
return i18n.text("password_saved_please_login");
}
}

View file

@ -46,14 +46,13 @@ public class UserAccountsResetPasswordPage extends UserAccountsPasswordBasePage
@Override
protected String alreadyLoggedInMessage(String currentUserEmail) {
return "You may not reset the password for " + userEmail
+ " while you are logged in as " + currentUserEmail
+ ". Please log out and try again.";
return i18n.text("cant_change_password_while_logged_in", userEmail,
currentUserEmail);
}
@Override
protected String passwordChangeNotPendingMessage() {
return "The password for " + userEmail + " has already been reset.";
return i18n.text("password_change_not_pending", userEmail);
}
@Override
@ -69,7 +68,7 @@ public class UserAccountsResetPasswordPage extends UserAccountsPasswordBasePage
FreemarkerEmailMessage email = FreemarkerEmailFactory
.createNewMessage(vreq);
email.addRecipient(TO, userAccount.getEmailAddress());
email.setSubject("Password changed.");
email.setSubject(i18n.text("password_changed_subject"));
email.setTemplate(EMAIL_TEMPLATE);
email.setBodyMap(body);
email.processTemplate();

View file

@ -4,6 +4,8 @@ package edu.cornell.mannlib.vitro.webapp.controller.accounts.user;
import static edu.cornell.mannlib.vedit.beans.LoginStatusBean.AuthenticationSource.EXTERNAL;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -18,6 +20,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.authenticate.LoginRedirector;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.RedirectResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
import edu.cornell.mannlib.vitro.webapp.i18n.I18n;
/**
* Parcel out the different actions required of the UserAccounts GUI.
@ -26,8 +29,6 @@ public class UserAccountsUserController extends FreemarkerHttpServlet {
private static final Log log = LogFactory
.getLog(UserAccountsUserController.class);
public static final String BOGUS_STANDARD_MESSAGE = "Request failed. Please contact your system administrator.";
private static final String ACTION_CREATE_PASSWORD = "/createPassword";
private static final String ACTION_RESET_PASSWORD = "/resetPassword";
private static final String ACTION_MY_ACCOUNT = "/myAccount";
@ -116,7 +117,7 @@ public class UserAccountsUserController extends FreemarkerHttpServlet {
return showLoginRedirection(vreq, page.getAfterLoginUrl());
} catch (LoginNotPermitted e) {
// This should have been anticipated by the page.
return showHomePage(vreq, BOGUS_STANDARD_MESSAGE);
return showHomePage(vreq, getBogusStandardMessage(vreq));
}
} else {
return page.showPage();
@ -124,7 +125,7 @@ public class UserAccountsUserController extends FreemarkerHttpServlet {
}
private ResponseValues handleInvalidRequest(VitroRequest vreq) {
return showHomePage(vreq, BOGUS_STANDARD_MESSAGE);
return showHomePage(vreq, getBogusStandardMessage(vreq));
}
private ResponseValues showHomePage(VitroRequest vreq, String message) {
@ -159,4 +160,8 @@ public class UserAccountsUserController extends FreemarkerHttpServlet {
}
return uri;
}
public static String getBogusStandardMessage(HttpServletRequest req) {
return I18n.bundle(req).text("request_failed");
}
}

View file

@ -36,6 +36,7 @@ import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorageSetup;
import edu.cornell.mannlib.vitro.webapp.filestorage.model.FileInfo;
import edu.cornell.mannlib.vitro.webapp.filestorage.model.ImageInfo;
import edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest.FileUploadServletRequest;
import edu.cornell.mannlib.vitro.webapp.i18n.I18n;
import edu.cornell.mannlib.vitro.webapp.web.images.PlaceholderUtil;
/**
@ -48,6 +49,9 @@ public class ImageUploadController extends FreemarkerHttpServlet {
private static final String ATTRIBUTE_REFERRING_PAGE = "ImageUploadController.referringPage";
private static final String ERROR_CODE_UNRECOGNIZED_URI = "imageUpload.errorUnrecognizedURI";
private static final String ERROR_CODE_NO_URI = "imageUpload.errorNoURI";
/** Limit file size to 6 megabytes. */
public static final int MAXIMUM_FILE_SIZE = 6 * 1024 * 1024;
@ -97,6 +101,14 @@ public class ImageUploadController extends FreemarkerHttpServlet {
private static final String URL_HERE = UrlBuilder.getUrl("/uploadImages");
private static final String TEXT_BUNDLE = "imageUpload";
private static final String TEXT_STRING_UPLOAD_TITLE = "upload_page_title";
private static final String TEXT_STRING_UPLOAD_TITLE_WITH_NAME = "upload_page_title_with_name";
private static final String TEXT_STRING_REPLACE_TITLE = "replace_page_title";
private static final String TEXT_STRING_REPLACE_TITLE_WITH_NAME = "replace_page_title_with_name";
private static final String TEXT_STRING_CROP_TITLE = "crop_page_title";
private static final String TEXT_STRING_CROP_TITLE_WITH_NAME = "crop_page_title_with_name";
private FileStorage fileStorage;
/**
@ -218,7 +230,7 @@ public class ImageUploadController extends FreemarkerHttpServlet {
}
} catch (UserMistakeException e) {
// Can't find the entity? Complain.
return showAddImagePageWithError(vreq, null, e.getMessage());
return showAddImagePageWithError(vreq, null, e.formatMessage(vreq));
} catch (Exception e) {
// We weren't expecting this - log it, and apologize to the user.
return new ExceptionResponseValues(e);
@ -274,7 +286,7 @@ public class ImageUploadController extends FreemarkerHttpServlet {
return showCropImagePage(vreq, entity,
fileInfo.getBytestreamAliasUrl(), size);
} catch (UserMistakeException e) {
return showErrorMessage(vreq, entity, e.getMessage());
return showErrorMessage(vreq, entity, e.formatMessage(vreq));
}
}
@ -284,6 +296,7 @@ public class ImageUploadController extends FreemarkerHttpServlet {
*/
private ResponseValues showErrorMessage(VitroRequest vreq,
Individual entity, String message) {
ImageInfo imageInfo = ImageInfo.instanceFromEntityUri(
vreq.getFullWebappDaoFactory(), entity);
if (imageInfo == null) {
@ -313,7 +326,7 @@ public class ImageUploadController extends FreemarkerHttpServlet {
return showExitPage(vreq, entity);
} catch (UserMistakeException e) {
return showErrorMessage(vreq, entity, e.getMessage());
return showErrorMessage(vreq, entity, e.formatMessage(vreq));
}
}
@ -350,15 +363,14 @@ public class ImageUploadController extends FreemarkerHttpServlet {
throws UserMistakeException {
String entityUri = vreq.getParameter(PARAMETER_ENTITY_URI);
if (entityUri == null) {
throw new UserMistakeException("No entity URI was provided");
throw new UserMistakeException(ERROR_CODE_NO_URI);
}
Individual entity = vreq.getFullWebappDaoFactory().getIndividualDao()
.getIndividualByURI(entityUri);
if (entity == null) {
throw new UserMistakeException(
"This URI is not recognized as belonging to anyone: '"
+ entityUri + "'");
throw new UserMistakeException(ERROR_CODE_UNRECOGNIZED_URI,
entityUri);
}
return entity;
}
@ -416,7 +428,7 @@ public class ImageUploadController extends FreemarkerHttpServlet {
rv.put(BODY_THUMBNAIL_URL, placeholderUrl);
rv.put(BODY_FORM_ACTION, formAction);
rv.put(BODY_CANCEL_URL, cancelUrl);
rv.put(BODY_TITLE, "Upload image" + forName(entity));
rv.put(BODY_TITLE, figureUploadPageTitle(vreq, entity));
rv.put(BODY_MAX_FILE_SIZE, MAXIMUM_FILE_SIZE / (1024 * 1024));
rv.put(BODY_THUMBNAIL_HEIGHT, THUMBNAIL_HEIGHT);
rv.put(BODY_THUMBNAIL_WIDTH, THUMBNAIL_WIDTH);
@ -442,7 +454,7 @@ public class ImageUploadController extends FreemarkerHttpServlet {
rv.put(BODY_DELETE_URL, formAction(entity.getURI(), ACTION_DELETE_EDIT));
rv.put(BODY_FORM_ACTION, formAction(entity.getURI(), ACTION_UPLOAD));
rv.put(BODY_CANCEL_URL, exitPageUrl(vreq, entity.getURI()));
rv.put(BODY_TITLE, "Replace image" + forName(entity));
rv.put(BODY_TITLE, figureReplacePageTitle(vreq, entity));
rv.put(BODY_MAX_FILE_SIZE, MAXIMUM_FILE_SIZE / (1024 * 1024));
rv.put(BODY_THUMBNAIL_HEIGHT, THUMBNAIL_HEIGHT);
rv.put(BODY_THUMBNAIL_WIDTH, THUMBNAIL_WIDTH);
@ -472,7 +484,7 @@ public class ImageUploadController extends FreemarkerHttpServlet {
rv.put(BODY_MAIN_IMAGE_WIDTH, dimensions.width);
rv.put(BODY_FORM_ACTION, formAction(entity.getURI(), ACTION_SAVE));
rv.put(BODY_CANCEL_URL, exitPageUrl(vreq, entity.getURI()));
rv.put(BODY_TITLE, "Crop Photo" + forName(entity));
rv.put(BODY_TITLE, figureCropPageTitle(vreq, entity));
return rv;
}
@ -522,24 +534,59 @@ public class ImageUploadController extends FreemarkerHttpServlet {
}
/**
* Format the entity's name for display as part of the page title.
* Format the title for the Upload page.
*/
private String forName(Individual entity) {
private String figureUploadPageTitle(HttpServletRequest req,
Individual entity) {
return figurePageTitle(req, entity, TEXT_STRING_UPLOAD_TITLE,
TEXT_STRING_UPLOAD_TITLE_WITH_NAME);
}
/**
* Format the title for the Replace page.
*/
private String figureReplacePageTitle(HttpServletRequest req,
Individual entity) {
return figurePageTitle(req, entity, TEXT_STRING_REPLACE_TITLE,
TEXT_STRING_REPLACE_TITLE_WITH_NAME);
}
/**
* Format the title for the Crop page.
*/
private String figureCropPageTitle(HttpServletRequest req, Individual entity) {
return figurePageTitle(req, entity, TEXT_STRING_CROP_TITLE,
TEXT_STRING_CROP_TITLE_WITH_NAME);
}
/**
* Format one of two page titles, depending on whether the entity has a
* name.
*/
private String figurePageTitle(HttpServletRequest req, Individual entity,
String noNameTitleKey, String nameTitleKey) {
if (entity != null) {
String name = entity.getName();
if (name != null) {
return " for " + name;
return I18n.text(req, TEXT_BUNDLE, nameTitleKey, name);
}
}
return "";
return I18n.text(req, TEXT_BUNDLE, noNameTitleKey);
}
/**
* Holds an error message to use as a complaint to the user.
*/
static class UserMistakeException extends Exception {
UserMistakeException(String message) {
private final Object[] parameters;
UserMistakeException(String message, Object... parameters) {
super(message);
this.parameters = parameters;
}
public String formatMessage(HttpServletRequest req) {
return I18n.text(req, getMessage(), parameters);
}
}

View file

@ -49,6 +49,18 @@ import edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest.FileUploadServ
public class ImageUploadHelper {
private static final Log log = LogFactory.getLog(ImageUploadHelper.class);
/*
* Keys to text strings for error messages.
*/
private static final String ERROR_CODE_NO_IMAGE_TO_CROP = "imageUpload.errorNoImageForCropping";
private static final String ERROR_CODE_IMAGE_TOO_SMALL = "imageUpload.errorImageTooSmall";
private static final String ERROR_CODE_UNKNOWN = "imageUpload.errorUnknown";
private static final String ERROR_CODE_FILE_TOO_BIG = "imageUpload.errorFileTooBig";
private static final String ERROR_CODE_UNRECOGNIZED_FILE_TYPE = "imageUpload.errorUnrecognizedFileType";
private static final String ERROR_CODE_NO_PHOTO_SELECTED = "imageUpload.errorNoPhotoSelected";
private static final String ERROR_CODE_BAD_MULTIPART_REQUEST = "imageUpload.errorBadMultipartRequest";
private static final String ERROR_CODE_FORM_FIELD_MISSING = "imageUpload.errorFormFieldMissing";
/**
* When they upload a new image, store it as this session attribute until
* we're ready to attach it to the Individual.
@ -127,35 +139,31 @@ public class ImageUploadHelper {
Object exception = request.getAttribute(FILE_UPLOAD_EXCEPTION);
if (exception != null) {
int limit = MAXIMUM_FILE_SIZE / (1024 * 1024);
throw new UserMistakeException(
"Please upload an image smaller than " + limit
+ " megabytes");
throw new UserMistakeException(ERROR_CODE_FILE_TOO_BIG, limit);
}
Map<String, List<FileItem>> map = (Map<String, List<FileItem>>) request
.getAttribute(FILE_ITEM_MAP);
if (map == null) {
throw new IllegalStateException("Failed to parse the "
+ "multi-part request for uploading an image.");
throw new IllegalStateException(ERROR_CODE_BAD_MULTIPART_REQUEST);
}
List<FileItem> list = map.get(PARAMETER_UPLOADED_FILE);
if ((list == null) || list.isEmpty()) {
throw new UserMistakeException("The form did not contain a '"
+ PARAMETER_UPLOADED_FILE + "' field.");
throw new UserMistakeException(ERROR_CODE_FORM_FIELD_MISSING,
PARAMETER_UPLOADED_FILE);
}
FileItem file = list.get(0);
if (file.getSize() == 0) {
throw new UserMistakeException("Please browse and select a photo.");
throw new UserMistakeException(ERROR_CODE_NO_PHOTO_SELECTED);
}
String filename = getSimpleFilename(file);
String mimeType = getMimeType(file);
if (!RECOGNIZED_FILE_TYPES.containsValue(mimeType)) {
log.debug("Unrecognized MIME type: '" + mimeType + "'");
throw new UserMistakeException("'" + filename
+ "' is not a recognized image file type. "
+ "Please upload JPEG, GIF, or PNG files only.");
throw new UserMistakeException(ERROR_CODE_UNRECOGNIZED_FILE_TYPE,
filename);
}
return file;
@ -221,10 +229,8 @@ public class ImageUploadHelper {
if ((size.height < THUMBNAIL_HEIGHT)
|| (size.width < THUMBNAIL_WIDTH)) {
throw new UserMistakeException(
"The uploaded image should be at least "
+ THUMBNAIL_HEIGHT + " pixels high and "
+ THUMBNAIL_WIDTH + " pixels wide.");
throw new UserMistakeException(ERROR_CODE_IMAGE_TOO_SMALL,
THUMBNAIL_HEIGHT, THUMBNAIL_WIDTH);
}
return size;
@ -237,8 +243,7 @@ public class ImageUploadHelper {
throw e;
} catch (Exception e) {
log.warn("Unexpected exception in image handling", e);
throw new UserMistakeException("Sorry, we were unable to process "
+ "the photo you provided. Please try another photo.");
throw new UserMistakeException(ERROR_CODE_UNKNOWN);
} finally {
if (source != null) {
try {
@ -261,8 +266,7 @@ public class ImageUploadHelper {
ATTRIBUTE_TEMP_FILE);
if (fileInfo == null) {
throw new UserMistakeException(
"There is no image file to be cropped.");
throw new UserMistakeException(ERROR_CODE_NO_IMAGE_TO_CROP);
}
return fileInfo;

View file

@ -61,8 +61,8 @@ public class FreemarkerEmailFactory {
FreemarkerEmailFactory factory = getFactory(vreq);
FreemarkerConfiguration fConfig = FreemarkerConfigurationLoader
.getConfig(vreq);
return new FreemarkerEmailMessage(fConfig, factory.getEmailSession(),
factory.getReplyToAddress());
return new FreemarkerEmailMessage(vreq, fConfig,
factory.getEmailSession(), factory.getReplyToAddress());
}
/**

View file

@ -27,8 +27,10 @@ import javax.mail.internet.MimeMultipart;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfiguration;
import edu.cornell.mannlib.vitro.webapp.web.directives.EmailDirective;
import freemarker.core.Environment;
import freemarker.template.Template;
import freemarker.template.TemplateException;
@ -47,7 +49,8 @@ public class FreemarkerEmailMessage {
private static final Log log = LogFactory
.getLog(FreemarkerEmailMessage.class);
private final Session session;
private final VitroRequest vreq;
private final Session mailSession;
private final FreemarkerConfiguration config;
private final List<Recipient> recipients = new ArrayList<Recipient>();
@ -63,9 +66,10 @@ public class FreemarkerEmailMessage {
/**
* Package access - should only be created by the factory.
*/
FreemarkerEmailMessage(FreemarkerConfiguration fConfig, Session session,
InternetAddress replyToAddress) {
this.session = session;
FreemarkerEmailMessage(VitroRequest vreq, FreemarkerConfiguration fConfig,
Session mailSession, InternetAddress replyToAddress) {
this.vreq = vreq;
this.mailSession = mailSession;
this.replyToAddress = replyToAddress;
this.config = fConfig;
}
@ -141,7 +145,13 @@ public class FreemarkerEmailMessage {
try {
Template template = config.getTemplate(templateName);
template.process(bodyMap, new StringWriter());
Environment env = template.createProcessingEnvironment(bodyMap,
new StringWriter());
env.setCustomAttribute("request", vreq);
env.setCustomAttribute("context", vreq.getSession()
.getServletContext());
env.process();
} catch (TemplateException e) {
log.error(e, e);
} catch (IOException e) {
@ -151,7 +161,7 @@ public class FreemarkerEmailMessage {
public boolean send() {
try {
MimeMessage msg = new MimeMessage(session);
MimeMessage msg = new MimeMessage(mailSession);
msg.setReplyTo(new Address[] { replyToAddress });
if (fromAddress == null) {
@ -199,11 +209,11 @@ public class FreemarkerEmailMessage {
bodyPart.setContent(textBody, type);
content.addBodyPart(bodyPart);
}
public String getReplyToAddress() {
return replyToAddress.getAddress();
}
public String getReplyToAddress() {
return replyToAddress.getAddress();
}
private <T> T nonNull(T value, T defaultValue) {
return (value == null) ? defaultValue : value;
}

View file

@ -39,8 +39,9 @@ public class I18nBundle {
public I18nBundle(String bundleName, ResourceBundle resources) {
this(bundleName, resources, MESSAGE_KEY_NOT_FOUND);
}
private I18nBundle(String bundleName, ResourceBundle resources, String notFoundMessage) {
private I18nBundle(String bundleName, ResourceBundle resources,
String notFoundMessage) {
if (bundleName == null) {
throw new IllegalArgumentException("bundleName may not be null");
}
@ -49,20 +50,22 @@ public class I18nBundle {
}
if (resources == null) {
throw new NullPointerException("resources may not be null.");
}if (notFoundMessage == null) {
}
if (notFoundMessage == null) {
throw new NullPointerException("notFoundMessage may not be null.");
}
this.bundleName = bundleName;
this.resources = resources;
this.notFoundMessage = notFoundMessage;
}
public String text(String key, Object... parameters) {
log.debug("Asking for '" + key + "' from bundle '" + bundleName + "'");
String textString;
if (resources.containsKey(key)) {
textString = resources.getString(key);
log.debug("In '" + bundleName + "', " + key + "='" + textString
+ "')");
return formatString(textString, parameters);
} else {
String message = MessageFormat.format(notFoundMessage, bundleName,

View file

@ -60,7 +60,7 @@ public class VitroResourceBundle extends ResourceBundle {
return new VitroResourceBundle(bundleName, ctx, appI18nPath,
themeI18nPath, control);
} catch (FileNotFoundException e) {
log.debug(e);
log.info(e.getMessage());
return null;
} catch (Exception e) {
log.warn(e, e);