magoffin.matt.ma2.aop
Class UserEmailInterceptor

java.lang.Object
  extended by magoffin.matt.ma2.aop.AbstractMailTemplateInterceptor
      extended by magoffin.matt.ma2.aop.UserEmailInterceptor
All Implemented Interfaces:
org.aopalliance.aop.Advice, org.aopalliance.intercept.Interceptor, org.aopalliance.intercept.MethodInterceptor
Direct Known Subclasses:
UserLoginEmailInterceptor

public class UserEmailInterceptor
extends AbstractMailTemplateInterceptor

Handle emailing user emails.

This interceptor requires the intercepted method to have a User object as a parameter, from which the email will be sent to. If the method also has a BizContext parameter, the interceptor will look for a WebBizContext.URL_BASE attribute to prepend to the confirmUrl.

The confirmUrl field is used to construct a URL to include in the merged email body. The value of this field can contain any variables available in the email body merge model object (except itself, of course). Note that due to possible unattended variable processing of variables derived from property files, the variables in this field may be specified with $[var] instead of the normal ${var} syntax.

The mail merge model will be set up with the following attributes:

user
The User object intercepted from the method parameter.
result
The result of the intercepted method.
confirmUrl
A URL itself merged from the user and result attributes with the confirmUrl field.

See the AbstractMailTemplateInterceptor class for more information about the email fields (like subject).

The configurable properties of this class are:

confirmUrl
A URL to add to the mail merge model map. This URL can be used to supply a link for the user to perform some action. For example during registration the registration confirmation email must contain a URL for the user to go to to confirm their registration.

Version:
$Revision: 43 $ $Date: 2007-10-21 11:10:01 +1300 (Sun, 21 Oct 2007) $
Author:
Matt Magoffin (spamsqr@msqr.us)

Field Summary
static java.lang.String CONFIRM_URL_KEY
          The model key for the confirmation URL.
static java.lang.String RESULT_KEY
          The model key for the result object.
static java.lang.String USER_KEY
          The model key for the User object.
 
Fields inherited from class magoffin.matt.ma2.aop.AbstractMailTemplateInterceptor
log
 
Constructor Summary
UserEmailInterceptor()
           
 
Method Summary
 java.lang.String getConfirmUrl()
           
protected  java.util.Map<java.lang.String,java.lang.Object> getInitialModel(org.aopalliance.intercept.MethodInvocation invocation)
          Get an initial Map object to use for the model data for the mail merge.
protected  java.util.Locale getLocale(org.aopalliance.intercept.MethodInvocation invocation, java.util.Map<java.lang.String,java.lang.Object> model, java.lang.Object result)
          Get the locale for the email message.
protected  org.springframework.mail.SimpleMailMessage postProcessModel(org.aopalliance.intercept.MethodInvocation invocation, java.util.Map<java.lang.String,java.lang.Object> model, java.lang.Object result)
          Get a SimpleMailMessage object based on the result of the method invocation.
 void setConfirmUrl(java.lang.String confirmUrl)
           
 
Methods inherited from class magoffin.matt.ma2.aop.AbstractMailTemplateInterceptor
getMailMergeSupport, invoke, setMailMergeSupport
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USER_KEY

public static final java.lang.String USER_KEY
The model key for the User object.

See Also:
Constant Field Values

RESULT_KEY

public static final java.lang.String RESULT_KEY
The model key for the result object.

See Also:
Constant Field Values

CONFIRM_URL_KEY

public static final java.lang.String CONFIRM_URL_KEY
The model key for the confirmation URL.

See Also:
Constant Field Values
Constructor Detail

UserEmailInterceptor

public UserEmailInterceptor()
Method Detail

getInitialModel

protected java.util.Map<java.lang.String,java.lang.Object> getInitialModel(org.aopalliance.intercept.MethodInvocation invocation)
Description copied from class: AbstractMailTemplateInterceptor
Get an initial Map object to use for the model data for the mail merge.

Specified by:
getInitialModel in class AbstractMailTemplateInterceptor
Parameters:
invocation - the current method invocation
Returns:
Map

postProcessModel

protected org.springframework.mail.SimpleMailMessage postProcessModel(org.aopalliance.intercept.MethodInvocation invocation,
                                                                      java.util.Map<java.lang.String,java.lang.Object> model,
                                                                      java.lang.Object result)
Description copied from class: AbstractMailTemplateInterceptor
Get a SimpleMailMessage object based on the result of the method invocation.

You can use the MailMergeHelper instance's MailMergeHelper.getMessageTemplate() method to obtain a mail message template, and use the SimpleMailMessage.SimpleMailMessage(org.springframework.mail.SimpleMailMessage) copy constructor to create the SimpleMailMessage to return here. Most likely the only property you'll need to set on the result if the to property.

Specified by:
postProcessModel in class AbstractMailTemplateInterceptor
Parameters:
invocation - the current method invocation
model - the model Map
result - the method invocation result object
Returns:
a SimpleMailMessage object with appropriate information set, i.e. the to property

getLocale

protected java.util.Locale getLocale(org.aopalliance.intercept.MethodInvocation invocation,
                                     java.util.Map<java.lang.String,java.lang.Object> model,
                                     java.lang.Object result)
Description copied from class: AbstractMailTemplateInterceptor
Get the locale for the email message.

This implementation simply returns Locale.getDefault(). Extending implementations can use the invocation and invocation result to provide a custom Locale as deisred.

Overrides:
getLocale in class AbstractMailTemplateInterceptor
Parameters:
invocation - the current method invocation
model - the model
result - the resut of the current modthod invocation
Returns:
a Locale to use for the mail merge

getConfirmUrl

public java.lang.String getConfirmUrl()
Returns:
Returns the confirmUrl.

setConfirmUrl

public void setConfirmUrl(java.lang.String confirmUrl)
Parameters:
confirmUrl - The confirmUrl to set.