org.opencms.frontend.templateone.form
Class CmsFormHandler

java.lang.Object
  extended by org.opencms.jsp.CmsJspBean
      extended by org.opencms.jsp.CmsJspActionElement
          extended by org.opencms.frontend.templateone.form.CmsFormHandler

public class CmsFormHandler
extends org.opencms.jsp.CmsJspActionElement

The form handler controls the html or mail output of a configured email form.

Provides methods to determine the action that takes place and methods to create different output formats of a submitted form.

Since:
6.0.0

Field Summary
static java.lang.String ACTION_CONFIRMED
          Request parameter value for the form action parameter: correct the input.
static java.lang.String ACTION_CORRECT_INPUT
          Request parameter value for the form action parameter: correct the input.
static java.lang.String ACTION_SUBMIT
          Request parameter value for the form action parameter: form submitted.
static java.lang.String ATTRIBUTE_FILEITEMS
          Name of the file item session attribute.
static java.lang.String ERROR_MANDATORY
          Form error: mandatory field not filled out.
static java.lang.String ERROR_VALIDATION
          Form error: validation error of input.
static java.lang.String PARAM_FORMACTION
          Request parameter name for the hidden form action parameter to determine the action.
 
Fields inherited from class org.opencms.jsp.CmsJspActionElement
NOT_INITIALIZED
 
Constructor Summary
CmsFormHandler(javax.servlet.jsp.PageContext context, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Constructor, creates the necessary form configuration objects.
CmsFormHandler(javax.servlet.jsp.PageContext context, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.lang.String formConfigUri)
          Constructor, creates the necessary form configuration objects using a given configuration file URI.
 
Method Summary
 java.lang.String convertToHtmlValue(java.lang.String value)
          Replaces line breaks with html <br>.
 java.lang.String convertToPlainValue(java.lang.String value)
          Replaces html <br> with line breaks.
 java.lang.String convertValue(java.lang.String value, java.lang.String outputType)
          Converts a given String value to the desired output format.
 java.lang.String createHiddenFields()
          Returns the configured form field values as hidden input fields.
protected  java.util.List createInternetAddresses(java.lang.String mailAddresses)
          Creates a list of internet addresses (email) from a semicolon separated String.
protected  java.lang.String createMailTextFromFields(boolean isHtmlMail, boolean isConfirmationMail)
          Creates the output String of the submitted fields for email creation.
 java.util.Map getErrors()
          Returns the errors found when validating the form.
 CmsForm getFormConfiguration()
          Returns the form configuration.
 org.opencms.i18n.CmsMessages getMessages()
          Returns the localized messages.
 java.util.Map getParameterMap()
          Returns the map of request parameters.
 boolean hasValidationErrors()
          Returns if the submitted values contain validation errors.
 void init(javax.servlet.http.HttpServletRequest req, java.lang.String formConfigUri)
          Initializes the form handler and creates the necessary configuration objects.
 boolean isInitial()
          Returns if the form is displayed for the first time.
 void sendConfirmationMail()
          Sends the confirmation mail with the form data to the specified email address.
 boolean sendMail()
          Sends the mail with the form data to the specified recipients.
protected  void setErrors(java.util.Map errors)
          Sets the errors found when validating the form.
protected  void setFormConfiguration(CmsForm configuration)
          Sets the form configuration.
protected  void setInitial(boolean initial)
          Sets if the form is displayed for the first time.
protected  void setMessages(org.opencms.i18n.CmsMessages messages)
          Sets the localized messages.
 boolean showCheck()
          Returns if the optional check page should be displayed.
 boolean showForm()
          Returns if the input form should be displayed.
 boolean validate()
          Validation method that checks the given input fields.
 
Methods inherited from class org.opencms.jsp.CmsJspActionElement
editable, editable, editable, editableManualClose, editableManualOpen, getContent, getContent, getMessages, getMessages, getMessages, getMessages, getNavigation, getNavigationUri, img, img, include, include, include, include, include, include, includeSilent, includeSilent, includeSilent, includeSilent, info, label, link, link, properties, properties, property, property, property, property, template, template, template, toAbsolute, user
 
Methods inherited from class org.opencms.jsp.CmsJspBean
getCmsObject, getController, getJspContext, getMessage, getRequest, getRequestContext, getResponse, handleException, init, isNotInitialized, isSupressingExceptions, setContentType, setStatus, setSupressingExceptions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACTION_CONFIRMED

public static final java.lang.String ACTION_CONFIRMED
Request parameter value for the form action parameter: correct the input.

See Also:
Constant Field Values

ACTION_CORRECT_INPUT

public static final java.lang.String ACTION_CORRECT_INPUT
Request parameter value for the form action parameter: correct the input.

See Also:
Constant Field Values

ACTION_SUBMIT

public static final java.lang.String ACTION_SUBMIT
Request parameter value for the form action parameter: form submitted.

See Also:
Constant Field Values

ERROR_MANDATORY

public static final java.lang.String ERROR_MANDATORY
Form error: mandatory field not filled out.

See Also:
Constant Field Values

ERROR_VALIDATION

public static final java.lang.String ERROR_VALIDATION
Form error: validation error of input.

See Also:
Constant Field Values

PARAM_FORMACTION

public static final java.lang.String PARAM_FORMACTION
Request parameter name for the hidden form action parameter to determine the action.

See Also:
Constant Field Values

ATTRIBUTE_FILEITEMS

public static final java.lang.String ATTRIBUTE_FILEITEMS
Name of the file item session attribute.

See Also:
Constant Field Values
Constructor Detail

CmsFormHandler

public CmsFormHandler(javax.servlet.jsp.PageContext context,
                      javax.servlet.http.HttpServletRequest req,
                      javax.servlet.http.HttpServletResponse res)
               throws java.lang.Exception
Constructor, creates the necessary form configuration objects.

Parameters:
context - the JSP page context object
req - the JSP request
res - the JSP response
Throws:
java.lang.Exception - if creating the form configuration objects fails

CmsFormHandler

public CmsFormHandler(javax.servlet.jsp.PageContext context,
                      javax.servlet.http.HttpServletRequest req,
                      javax.servlet.http.HttpServletResponse res,
                      java.lang.String formConfigUri)
               throws java.lang.Exception
Constructor, creates the necessary form configuration objects using a given configuration file URI.

Parameters:
context - the JSP page context object
req - the JSP request
res - the JSP response
formConfigUri - URI of the form configuration file, if not provided, current URI is used for configuration
Throws:
java.lang.Exception - if creating the form configuration objects fails
Method Detail

convertToHtmlValue

public java.lang.String convertToHtmlValue(java.lang.String value)
Replaces line breaks with html <br>.

Parameters:
value - the value to substitute
Returns:
the substituted value

convertToPlainValue

public java.lang.String convertToPlainValue(java.lang.String value)
Replaces html <br> with line breaks.

Parameters:
value - the value to substitute
Returns:
the substituted value

convertValue

public java.lang.String convertValue(java.lang.String value,
                                     java.lang.String outputType)
Converts a given String value to the desired output format.

The following output formats are possible:

Parameters:
value - the String value to convert
outputType - the type of the resulting output
Returns:
the converted String in the desired output format

createHiddenFields

public java.lang.String createHiddenFields()
Returns the configured form field values as hidden input fields.

Returns:
the configured form field values as hidden input fields

getErrors

public java.util.Map getErrors()
Returns the errors found when validating the form.

Returns:
the errors found when validating the form

getFormConfiguration

public CmsForm getFormConfiguration()
Returns the form configuration.

Returns:
the form configuration

getMessages

public org.opencms.i18n.CmsMessages getMessages()
Returns the localized messages.

Returns:
the localized messages

hasValidationErrors

public boolean hasValidationErrors()
Returns if the submitted values contain validation errors.

Returns:
true if the submitted values contain validation errors, otherwise false

init

public void init(javax.servlet.http.HttpServletRequest req,
                 java.lang.String formConfigUri)
          throws java.lang.Exception
Initializes the form handler and creates the necessary configuration objects.

Parameters:
req - the JSP request
formConfigUri - URI of the form configuration file, if not provided, current URI is used for configuration
Throws:
java.lang.Exception - if creating the form configuration objects fails

isInitial

public boolean isInitial()
Returns if the form is displayed for the first time.

Returns:
true if the form is displayed for the first time, otherwise false

getParameterMap

public java.util.Map getParameterMap()
Returns the map of request parameters.

Returns:
the map of request parameters

sendConfirmationMail

public void sendConfirmationMail()
                          throws java.lang.Exception
Sends the confirmation mail with the form data to the specified email address.

Throws:
java.lang.Exception - if sending the confirmation mail fails

sendMail

public boolean sendMail()
Sends the mail with the form data to the specified recipients.

If configured, sends also a confirmation mail to the form submitter.

Returns:
true if the mail has been successfully sent, otherwise false

showCheck

public boolean showCheck()
Returns if the optional check page should be displayed.

Returns:
true if the optional check page should be displayed, otherwise false

showForm

public boolean showForm()
Returns if the input form should be displayed.

Returns:
true if the input form should be displayed, otherwise false

validate

public boolean validate()
Validation method that checks the given input fields.

All errors are stored in the member m_errors Map, with the input field name as key and the error message String as value.

Returns:
true if all neccessary fields can be validated, otherwise false

createInternetAddresses

protected java.util.List createInternetAddresses(java.lang.String mailAddresses)
                                          throws javax.mail.internet.AddressException
Creates a list of internet addresses (email) from a semicolon separated String.

Parameters:
mailAddresses - a semicolon separated String with email addresses
Returns:
list of internet addresses (email)
Throws:
javax.mail.internet.AddressException - if an email address is not correct

createMailTextFromFields

protected java.lang.String createMailTextFromFields(boolean isHtmlMail,
                                                    boolean isConfirmationMail)
Creates the output String of the submitted fields for email creation.

Parameters:
isHtmlMail - if true, the output is formatted as HTML, otherwise as plain text
isConfirmationMail - if true, the text for the confirmation mail is created, otherwise the text for mail receiver
Returns:
the output String of the submitted fields for email creation

setErrors

protected void setErrors(java.util.Map errors)
Sets the errors found when validating the form.

Parameters:
errors - the errors found when validating the form

setFormConfiguration

protected void setFormConfiguration(CmsForm configuration)
Sets the form configuration.

Parameters:
configuration - the form configuration

setInitial

protected void setInitial(boolean initial)
Sets if the form is displayed for the first time.

Parameters:
initial - true if the form is displayed for the first time, otherwise false

setMessages

protected void setMessages(org.opencms.i18n.CmsMessages messages)
Sets the localized messages.

Parameters:
messages - the localized messages