org.iscreen.impl
Class OgnlMessage

java.lang.Object
  extended by org.iscreen.impl.OgnlMessage
All Implemented Interfaces:
FailureMessage
Direct Known Subclasses:
OgnlResourceMessage

public class OgnlMessage
extends java.lang.Object
implements FailureMessage

An OGNL message wraps a "template" that is a String of characters. This template may contain "OGNL tags" that look like this: ${some ognl}. When a ${} is found within the template, it's removed, and the contents are considered an OGNL expression, which is evaluated based upon an OGNL root (either set separately or passed in when generating the message).

Author:
Shellman, Dan

Field Summary
protected  java.lang.Object root
           
protected  java.lang.String template
           
 
Constructor Summary
protected OgnlMessage()
          For sub-classes to over-ride how this works.
  OgnlMessage(java.lang.String theTemplate)
          Constructor taking the template of this message.
 
Method Summary
protected  java.lang.String constructMessage(java.lang.String theTemplate, java.lang.Object ognlRoot)
          Searches through the template and replaces all ${} with the evaluation of their OGNL expressions.
 java.lang.String getMessage()
          Generates a message based upon the template of this message and the OGNL root passed in to the setOgnlRoot() method.
 java.lang.String getMessage(java.lang.Object ognlRoot, java.util.Locale locale)
          Generates a message based upon the template of this message and the OGNL root passed in.
 java.lang.Object getOgnlRoot()
          Returns the OGNL root previously set using the setOgnlRoot() method.
 java.lang.String getTemplate(java.util.Locale locale)
          Returns the template previously set during construction.
 void setOgnlRoot(java.lang.Object ognlRoot)
          Sets the OGNL root to be used when getMessage() is called.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

template

protected java.lang.String template

root

protected java.lang.Object root
Constructor Detail

OgnlMessage

public OgnlMessage(java.lang.String theTemplate)
Constructor taking the template of this message. The template should never be null.

Parameters:
theTemplate - The template (which may or may not contain OGNL tags)

OgnlMessage

protected OgnlMessage()
For sub-classes to over-ride how this works.

Method Detail

setOgnlRoot

public void setOgnlRoot(java.lang.Object ognlRoot)
Sets the OGNL root to be used when getMessage() is called.

Parameters:
ognlRoot - The OGNL root object.

getMessage

public java.lang.String getMessage()
Generates a message based upon the template of this message and the OGNL root passed in to the setOgnlRoot() method. If the OGNL root object is null, then this method will return the template unchanged.

Returns:
Returns the message, which is constructed based upon the OGNL root and the template.

getMessage

public java.lang.String getMessage(java.lang.Object ognlRoot,
                                   java.util.Locale locale)
Generates a message based upon the template of this message and the OGNL root passed in. If the OGNL root is null, then the OGNL root passed in to the setOgnlRoot() method is used. If that's null, then the template is returned unchanged.

Specified by:
getMessage in interface FailureMessage
Parameters:
ognlRoot - The OGNL root to use for generating the message.
locale - The locale use for localizing the message.
Returns:
Returns the message, which is constructed based upon the OGNL root passed in and the template.

getOgnlRoot

public java.lang.Object getOgnlRoot()
Returns the OGNL root previously set using the setOgnlRoot() method.

Returns:
Returns the OGNL root for this message.

getTemplate

public java.lang.String getTemplate(java.util.Locale locale)
Returns the template previously set during construction.

Parameters:
locale - The locale to use.
Returns:
Returns the template.

constructMessage

protected java.lang.String constructMessage(java.lang.String theTemplate,
                                            java.lang.Object ognlRoot)
Searches through the template and replaces all ${} with the evaluation of their OGNL expressions.

Parameters:
theTemplate - The template to use.
ognlRoot - The OGNL root.
Returns:
Returns the constructed String.