org.opencms.frontend.templateone
Class CmsTemplateForm

java.lang.Object
  extended by org.opencms.jsp.CmsJspBean
      extended by org.opencms.jsp.CmsJspActionElement
          extended by org.opencms.frontend.templateone.CmsTemplateBase
              extended by org.opencms.frontend.templateone.CmsTemplateBean
                  extended by org.opencms.frontend.templateone.CmsTemplateForm
Direct Known Subclasses:
CmsTemplateFormLetter, CmsTemplateFormRecommend

public abstract class CmsTemplateForm
extends CmsTemplateBean

Provides methods to build interactive JSP forms.

Since:
6.0.0

Field Summary
static java.lang.String MESSAGE_BUNDLE_FORM
          Name of the resource bundle containing the localized form messages.
static java.lang.String PARAM_ACTION
          Request parameter name for the action parameter to determine if the form has been submitted.
 
Fields inherited from class org.opencms.frontend.templateone.CmsTemplateBean
FILE_CONFIG_COMMON, FILE_CSS, FILE_CSS_ACCESSIBLE, FILE_LINKS_HEAD, FOLDER_ELEMENTS, MESSAGE_BUNDLE, MODULE_NAME, PARAM_ACCESSIBLE, PARAM_COMMON, PARAM_HELPURI, PARAM_LAYOUT, PARAM_LOGINURI, PARAM_PART, PARAM_PRINT, PARAM_SITE, PARAM_URI, PROPERTY_CONFIGPATH, PROPERTY_EXTENSIONMODULE, PROPERTY_HEAD_DEFAULTLINK, PROPERTY_HEAD_ELEMENTURI, PROPERTY_HEAD_IMGHEIGHT, PROPERTY_HEAD_IMGLINK, PROPERTY_HEAD_IMGURI, PROPERTY_LAYOUT_CENTER, PROPERTY_LAYOUT_RIGHT, PROPERTY_NAVLEFT_ELEMENTURI, PROPERTY_RESOURCEPATH, PROPERTY_SHOW_HEADNAV, PROPERTY_SHOW_NAVLEFT, PROPERTY_SHOWHEADIMAGE, PROPERTY_SHOWHEADLINKS, PROPERTY_SIDE_URI, PROPERTY_STARTFOLDER, PROPERTY_VALUE_NONE, RESOURCE_TYPE_MICROSITE_NAME
 
Fields inherited from class org.opencms.frontend.templateone.CmsTemplateBase
ATTRIBUTE_ORIGINAL_URI
 
Fields inherited from class org.opencms.jsp.CmsJspActionElement
NOT_INITIALIZED
 
Constructor Summary
CmsTemplateForm()
          Empty constructor, required for every JavaBean.
CmsTemplateForm(javax.servlet.jsp.PageContext context, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Constructor, with parameters.
 
Method Summary
protected abstract  java.lang.String checkTextsUri()
          Returns the text URI from the configuration file and checks the presence.
 java.lang.String getConfigPath()
          Returns the template configuration path in the OpenCms VFS.
 java.lang.String getError(java.lang.String key)
          Returns the error message for the specified key or an empty String if no error is present for the key.
 java.util.Map getErrors()
          Returns the error Map holding the validation errors.
static java.lang.String getFormattedString(java.lang.String inputString, char sepChar, int lineLength, java.lang.String separator)
          Returns the input String with line breaks added at the specified separator character.
 java.lang.String getFormText(java.lang.String element, boolean stripHtml)
          Returns the content of the specified page element from the defined text page.
 java.lang.String getFormUri()
          Returns the subsituted link to the JSP form.
 java.lang.String getPageTitle()
          Returns the title of the recommended page.
 java.lang.String getPageUri()
          Returns the (not substituted) URI to the page that called the form.
 java.lang.String getPageUri(boolean removeParams)
          Returns the (not substituted) URI to the page that called the form.
 java.lang.String getPageUrl()
          Returns the URL of the page to be displayed on the form.
 java.lang.String getTextsUri()
          Returns the URI of the page containing the texts for the form.
 boolean hasValidationErrors()
          Checks if the input form has validation errors.
 void init(javax.servlet.jsp.PageContext context, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Initialize this bean with the current page context, request and response.
 java.lang.String isChecked(java.lang.String fieldValue)
          Checks if the given String is true and returns the "checked" attribute for checkboxes and radiobuttons.
 boolean isSelected(java.lang.String fieldValue, java.lang.String requestValue)
          Returns true if the two parameters are equal.
 boolean isSubmitted()
          Returns if the form has been submitted or not.
static boolean isValidEmailAddress(java.lang.String theAddress)
          Oversimplistic method to validate email addresses.
protected  java.lang.String removeHtmlTags(java.lang.String content)
          Removes all HTML tags from the given String by using a regular expression.
 void setErrors(java.util.Map errors)
          Sets the error Map holding the validation errors.
abstract  boolean validate()
          Validates the values of the input fields and creates error messages, if necessary.
 
Methods inherited from class org.opencms.frontend.templateone.CmsTemplateBean
buildHtmlBodyEnd, getAreaName, getConfiguration, getConfigurationFile, getConfigurationValue, getConfigurationValue, getDescription, getEncoding, getExtensionModuleFileUri, getHeadElementUri, getHeadLinks, getKeywords, getLayout, getLeftNavigationElementUri, getNavigationStartFolder, getProperties, getResourcePath, getSearchIndexName, getStartFolder, getStyleSheetConfigUri, getStyleSheetUri, getStyleSheetUri, getTemplateParts, getTitle, includeElements, includePopup, includeRightLists, key, keyDefault, messages, messages, putNavigationProperties, setLayout, showAccessibleVersion, showHeadImage, showHeadLinks, showHeadNavigation, showLeftNavigation, showPrintVersion
 
Methods inherited from class org.opencms.frontend.templateone.CmsTemplateBase
getOriginalUri, initUri, isUriChanged
 
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, 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

MESSAGE_BUNDLE_FORM

public static final java.lang.String MESSAGE_BUNDLE_FORM
Name of the resource bundle containing the localized form messages.

See Also:
Constant Field Values

PARAM_ACTION

public static final java.lang.String PARAM_ACTION
Request parameter name for the action parameter to determine if the form has been submitted.

See Also:
Constant Field Values
Constructor Detail

CmsTemplateForm

public CmsTemplateForm()
Empty constructor, required for every JavaBean.


CmsTemplateForm

public CmsTemplateForm(javax.servlet.jsp.PageContext context,
                       javax.servlet.http.HttpServletRequest req,
                       javax.servlet.http.HttpServletResponse res)
Constructor, with parameters.

Use this constructor for the template.

Parameters:
context - the JSP page context object
req - the JSP request
res - the JSP response
Method Detail

getFormattedString

public static java.lang.String getFormattedString(java.lang.String inputString,
                                                  char sepChar,
                                                  int lineLength,
                                                  java.lang.String separator)
Returns the input String with line breaks added at the specified separator character.

Parameters:
inputString - the input String to modify
sepChar - the separator character to look up in the input String
lineLength - the line length after which a break should occur
separator - the separator String to append as line breaks, e.g. <br>
Returns:
the modified input String with line breaks added

isValidEmailAddress

public static boolean isValidEmailAddress(java.lang.String theAddress)
Oversimplistic method to validate email addresses.

Parameters:
theAddress - the email address to validate
Returns:
true if theAddress is at least a String of the form xx@yy.zz

getConfigPath

public java.lang.String getConfigPath()
Returns the template configuration path in the OpenCms VFS.

Overwrites the method in the super class because the uri is set to the form uri in the module.

Overrides:
getConfigPath in class CmsTemplateBean
Returns:
the template configuration path

getError

public java.lang.String getError(java.lang.String key)
Returns the error message for the specified key or an empty String if no error is present for the key.

Parameters:
key - error key to look up
Returns:
the error message for the specified key or an empty String

getErrors

public java.util.Map getErrors()
Returns the error Map holding the validation errors.

Returns:
the error Map holding the validation errors

getFormText

public java.lang.String getFormText(java.lang.String element,
                                    boolean stripHtml)
Returns the content of the specified page element from the defined text page.

Parameters:
element - the name of the element to display
stripHtml - indicates if HTML tags should be filtered from the element contents
Returns:
the content of the specified page element from the defined text page

getFormUri

public java.lang.String getFormUri()
Returns the subsituted link to the JSP form.

This can be used for the "action" attribute value of the <form> tag.

Returns:
the subsituted link to the JSP form

getPageTitle

public java.lang.String getPageTitle()
Returns the title of the recommended page.

If the title property is not found, the page URI is returned instead.

Returns:
the title of the recommended page

getPageUri

public java.lang.String getPageUri()
Returns the (not substituted) URI to the page that called the form.

Includes all request parameters of the page, too.

Returns:
the (not substituted) URI to the page that called the form

getPageUri

public java.lang.String getPageUri(boolean removeParams)
Returns the (not substituted) URI to the page that called the form.

Removes all request parameters from the page URI, if specified.

Parameters:
removeParams - if true, all request parameters will be removed from the URI
Returns:
the (not substituted) URI to the page that called the form

getPageUrl

public java.lang.String getPageUrl()
Returns the URL of the page to be displayed on the form.

Returns:
the URL of the page

getTextsUri

public java.lang.String getTextsUri()
Returns the URI of the page containing the texts for the form.

Returns:
the URI of the page containing the texts for the form

hasValidationErrors

public boolean hasValidationErrors()
Checks if the input form has validation errors.

Returns:
true if at least one validation error was found, otherwise false

init

public void init(javax.servlet.jsp.PageContext context,
                 javax.servlet.http.HttpServletRequest req,
                 javax.servlet.http.HttpServletResponse res)
Initialize this bean with the current page context, request and response.

It is required to call one of the init() methods before you can use the instance of this bean.

Overrides:
init in class CmsTemplateBean
Parameters:
context - the JSP page context object
req - the JSP request
res - the JSP response

isChecked

public java.lang.String isChecked(java.lang.String fieldValue)
Checks if the given String is true and returns the "checked" attribute for checkboxes and radiobuttons.

Parameters:
fieldValue - the value of the field to test
Returns:
the "checked" attribute or an empty String

isSelected

public boolean isSelected(java.lang.String fieldValue,
                          java.lang.String requestValue)
Returns true if the two parameters are equal.

Use this method to determine which entry of a select box or radio buttons is selected.

Parameters:
fieldValue - the current option or radio button value to check
requestValue - the current request value
Returns:
true if the two parameters are equal

isSubmitted

public boolean isSubmitted()
Returns if the form has been submitted or not.

Checks the presence of the "action" request parameter.

Returns:
true if the form has been submitted, otherwise false

setErrors

public void setErrors(java.util.Map errors)
Sets the error Map holding the validation errors.

Parameters:
errors - error Map

validate

public abstract boolean validate()
Validates the values of the input fields and creates error messages, if necessary.

Returns:
true if all checked input values are valid, otherwise false

checkTextsUri

protected abstract java.lang.String checkTextsUri()
Returns the text URI from the configuration file and checks the presence.

Returns the default texts URI if the file specified in the configuration can not be found.

Returns:
the text URI from the configuration file

removeHtmlTags

protected java.lang.String removeHtmlTags(java.lang.String content)
Removes all HTML tags from the given String by using a regular expression.

Parameters:
content - the String to scan for HTML tags
Returns:
the content without HTML tags