com.devsphere.mapping
Class FormUtils

java.lang.Object
  |
  +--com.devsphere.mapping.FormUtils

public class FormUtils
extends java.lang.Object

Utility class that implements form related operations.

See Also:
CharacterEncoding, FormData, FormDocument, FormTemplate, AbstractLogger

Method Summary
static void beanToForm(java.lang.Object bean, java.util.Hashtable errorTable, FormDocument document)
          Inserts the values of the properties of a bean within a form document as the default values of the form elements.
static void beanToForm(java.lang.Object bean, java.util.Hashtable errorTable, FormDocument document, AbstractLogger logger)
          Inserts the values of the properties of a bean within a form document as the default values of the form elements.
static void beanToForm(java.lang.Object bean, java.util.Hashtable errorTable, FormDocument document, java.lang.String formName)
          Inserts the values of the properties of a bean within a form document as the default values of the form elements.
static void beanToForm(java.lang.Object bean, java.util.Hashtable errorTable, FormDocument document, java.lang.String formName, AbstractLogger logger)
          Inserts the values of the properties of a bean within a form document as the default values of the form elements.
static void beanToForm(java.lang.Object bean, java.util.Hashtable errorTable, FormDocument document, java.lang.String formName, AbstractLogger logger, java.util.Locale locale)
          Inserts the values of the properties of a bean within a form document as the default values of the form elements.
static void beanToForm(java.lang.Object bean, java.util.Hashtable errorTable, FormDocument document, java.lang.String formName, AbstractLogger logger, java.lang.String prefix)
          Inserts the values of the properties of a bean within a form document as the default values of the form elements.
static void beanToForm(java.lang.Object bean, java.util.Hashtable errorTable, FormDocument document, java.lang.String formName, AbstractLogger logger, java.lang.String prefix, java.util.Locale locale)
          Inserts the values of the properties of a bean within a form document as the default values of the form elements.
static java.util.Hashtable formToBean(FormData formData, java.lang.Object bean)
          Fills the properties of a bean with the values of the parameters of an HTTP request.
static java.util.Hashtable formToBean(FormData formData, java.lang.Object bean, AbstractLogger logger)
          Fills the properties of a bean with the values of the parameters of an HTTP request.
static java.util.Hashtable formToBean(FormData formData, java.lang.Object bean, AbstractLogger logger, java.util.Locale locale)
          Fills the properties of a bean with the values of the parameters of an HTTP request.
static java.util.Hashtable formToBean(FormData formData, java.lang.Object bean, AbstractLogger logger, java.lang.String prefix)
          Fills the properties of a bean with the values of the parameters of an HTTP request.
static java.util.Hashtable formToBean(FormData formData, java.lang.Object bean, AbstractLogger logger, java.lang.String prefix, java.util.Locale locale)
          Fills the properties of a bean with the values of the parameters of an HTTP request.
static FormTemplate getTemplate(java.io.File file)
          Loads the content of an HTML file, parses it and creates a form template.
static FormTemplate getTemplate(java.io.File file, boolean useCache)
          Loads the content of an HTML file, parses it and creates a form template.
static FormTemplate getTemplate(java.io.File file, int encoding)
          Loads the content of an HTML file, parses it and creates a form template.
static FormTemplate getTemplate(java.io.File file, int encoding, boolean useCache)
          Loads the content of an HTML file, parses it and creates a form template.
static FormTemplate getTemplate(java.io.InputStream input)
          Loads the content of an input stream, parses it and creates a form template.
static FormTemplate getTemplate(java.io.InputStream input, int encoding)
          Loads the content of an input stream, parses it and creates a form template.
static FormTemplate getTemplate(java.io.Reader reader)
          Loads the content of a reader, parses it and creates a form template.
static FormTemplate getTemplate(java.lang.String content)
          Parses the given HTML content and creates a form template.
static FormTemplate getTemplate(java.net.URL url)
          Loads the content of a URL, parses it and creates a form template.
static FormTemplate getTemplate(java.net.URL url, int encoding)
          Loads the content of a URL, parses it and creates a form template.
static java.lang.String messageToHTML(java.lang.String message)
          Processes the parameter so that the returned string can be inserted in an HTML document as text.
static void removeAllTemplatesFromCache()
          Removes all templates from the cache.
static FormTemplate removeTemplateFromCache(java.io.File file)
          Removes a template from the cache.
static java.lang.String valueToHTML(java.lang.String value)
          Processes the parameter so that the returned string can be inserted in an HTML document as an attribute's value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getTemplate

public static FormTemplate getTemplate(java.lang.String content)
Parses the given HTML content and creates a form template.
Parameters:
content - the HTML content that will be parsed in order to build the form template.
Returns:
the form template.
Throws:
NullPointerException - if content is null.

getTemplate

public static FormTemplate getTemplate(java.io.InputStream input)
                                throws java.io.IOException
Loads the content of an input stream, parses it and creates a form template.
Parameters:
input - the input stream whose HTML content will be parsed in order to build the form template.
Returns:
the form template.
Throws:
NullPointerException - if input is null.
java.io.IOException - if an I/O error occurs.

getTemplate

public static FormTemplate getTemplate(java.io.InputStream input,
                                       int encoding)
                                throws java.io.IOException
Loads the content of an input stream, parses it and creates a form template.
Parameters:
input - the input stream whose HTML content will be parsed in order to build the form template.
encoding - the character encoding. See the constants declared by CharacterEncoding.
Returns:
the form template.
Throws:
NullPointerException - if input is null.
java.lang.IllegalArgumentException - if encoding has an invalid value.
java.io.IOException - if an I/O error occurs.

getTemplate

public static FormTemplate getTemplate(java.io.Reader reader)
                                throws java.io.IOException
Loads the content of a reader, parses it and creates a form template.
Parameters:
reader - the reader whose HTML content will be parsed in order to build the form template.
Returns:
the form template.
Throws:
NullPointerException - if reader is null.
java.io.IOException - if an I/O error occurs.

getTemplate

public static FormTemplate getTemplate(java.net.URL url)
                                throws java.io.IOException
Loads the content of a URL, parses it and creates a form template.
Parameters:
url - the URL of the HTML document that will be parsed in order to build the form template.
Returns:
the form template.
Throws:
NullPointerException - if url is null.
java.io.IOException - if an I/O error occurs.

getTemplate

public static FormTemplate getTemplate(java.net.URL url,
                                       int encoding)
                                throws java.io.IOException
Loads the content of a URL, parses it and creates a form template.
Parameters:
url - the URL of the HTML document that will be parsed in order to build the form template.
encoding - the character encoding. See the constants declared by CharacterEncoding.
Returns:
the form template.
Throws:
NullPointerException - if url is null.
java.lang.IllegalArgumentException - if encoding has an invalid value.
java.io.IOException - if an I/O error occurs.

getTemplate

public static FormTemplate getTemplate(java.io.File file)
                                throws java.io.IOException
Loads the content of an HTML file, parses it and creates a form template. Templates loaded by this method are cached.
Parameters:
file - the HTML document that will be parsed in order to build the form template.
Returns:
the form template.
Throws:
NullPointerException - if file is null.
java.io.IOException - if an I/O error occurs.

getTemplate

public static FormTemplate getTemplate(java.io.File file,
                                       int encoding)
                                throws java.io.IOException
Loads the content of an HTML file, parses it and creates a form template. Templates loaded by this method are cached.
Parameters:
file - the HTML document that will be parsed in order to build the form template.
encoding - the character encoding. See the constants declared by CharacterEncoding.
Returns:
the form template.
Throws:
NullPointerException - if file is null.
java.lang.IllegalArgumentException - if encoding has an invalid value.
java.io.IOException - if an I/O error occurs.

getTemplate

public static FormTemplate getTemplate(java.io.File file,
                                       boolean useCache)
                                throws java.io.IOException
Loads the content of an HTML file, parses it and creates a form template. Templates loaded by this method are cached if useCache is true.
Parameters:
file - the HTML document that will be parsed in order to build the form template.
useCache - flag that enables or disables the caching mechanism of the templates that are created from files.
Returns:
the form template.
Throws:
NullPointerException - if file is null.
java.io.IOException - if an I/O error occurs.

getTemplate

public static FormTemplate getTemplate(java.io.File file,
                                       int encoding,
                                       boolean useCache)
                                throws java.io.IOException
Loads the content of an HTML file, parses it and creates a form template. Templates loaded by this method are cached if useCache is true.
Parameters:
file - the HTML document that will be parsed in order to build the form template.
encoding - the character encoding. See the constants declared by CharacterEncoding.
useCache - flag that enables or disables the caching mechanism of the templates that are created from files.
Returns:
the form template.
Throws:
NullPointerException - if file is null.
java.lang.IllegalArgumentException - if encoding has an invalid value.
java.io.IOException - if an I/O error occurs.

removeTemplateFromCache

public static FormTemplate removeTemplateFromCache(java.io.File file)
Removes a template from the cache.
Parameters:
file - the HTML document that was parsed in order to build the form template.
Returns:
the form template in case it is found in cache or null otherwise.
Throws:
NullPointerException - if file is null.

removeAllTemplatesFromCache

public static void removeAllTemplatesFromCache()
Removes all templates from the cache.

formToBean

public static java.util.Hashtable formToBean(FormData formData,
                                             java.lang.Object bean)
Fills the properties of a bean with the values of the parameters of an HTTP request. All errors that occur during the mapping process are stored in a hashtable.
Parameters:
formData - the objects that contains the form data.
bean - the bean instance whose properties must be filled with form data.
Returns:
an hashtable containing the application and user errors or null if no error occurred.
Throws:
NullPointerException - if formData is null or bean is null.

formToBean

public static java.util.Hashtable formToBean(FormData formData,
                                             java.lang.Object bean,
                                             AbstractLogger logger)
Fills the properties of a bean with the values of the parameters of an HTTP request. All errors that occur during the mapping process are stored in a hashtable.
Parameters:
formData - the objects that contains the form data.
bean - the bean instance whose properties must be filled with form data.
logger - logging mechanism for application errors.
Returns:
an hashtable containing the application and user errors or null if no error occurred.
Throws:
NullPointerException - if formData is null or bean is null.

formToBean

public static java.util.Hashtable formToBean(FormData formData,
                                             java.lang.Object bean,
                                             AbstractLogger logger,
                                             java.lang.String prefix)
Fills the properties of a bean with the values of the parameters of an HTTP request. All errors that occur during the mapping process are stored in a hashtable.
Parameters:
formData - the objects that contains the form data.
bean - the bean instance whose properties must be filled with form data.
logger - logging mechanism for application errors.
prefix - the prefix of the names of the form parameters.
Returns:
an hashtable containing the application and user errors or null if no error occurred.
Throws:
NullPointerException - if formData is null or bean is null.

formToBean

public static java.util.Hashtable formToBean(FormData formData,
                                             java.lang.Object bean,
                                             AbstractLogger logger,
                                             java.util.Locale locale)
Fills the properties of a bean with the values of the parameters of an HTTP request. All errors that occur during the mapping process are stored in a hashtable.
Parameters:
formData - the objects that contains the form data.
bean - the bean instance whose properties must be filled with form data.
logger - logging mechanism for application errors.
locale - internationalization support parameter.
Returns:
an hashtable containing the application and user errors or null if no error occurred.
Throws:
NullPointerException - if formData is null or bean is null.

formToBean

public static java.util.Hashtable formToBean(FormData formData,
                                             java.lang.Object bean,
                                             AbstractLogger logger,
                                             java.lang.String prefix,
                                             java.util.Locale locale)
Fills the properties of a bean with the values of the parameters of an HTTP request. All errors that occur during the mapping process are stored in a hashtable.
Parameters:
formData - the objects that contains the form data.
bean - the bean instance whose properties must be filled with form data.
logger - logging mechanism for application errors.
prefix - the prefix of the names of the form parameters.
locale - internationalization support parameter.
Returns:
an hashtable containing the application and user errors or null if no error occurred.
Throws:
NullPointerException - if formData is null or bean is null.

beanToForm

public static void beanToForm(java.lang.Object bean,
                              java.util.Hashtable errorTable,
                              FormDocument document)
Inserts the values of the properties of a bean within a form document as the default values of the form elements. The errorTable parameter may be null or it must be a hashtable returned by one of the mapping methods of the framework. In the latter case, the error messages are inserted within the form document too.
Parameters:
bean - the bean instance whose properties must be inserted within the form document.
errorTable - hashtable containing mapping errors.
document - object created by getDocument() of FormTemplate.
Throws:
NullPointerException - if bean is null or document is null.
java.lang.IllegalArgumentException - if errorTable wasn't created by this framework or document wasn't created by this framework or the HTML form isn't found within the document.

beanToForm

public static void beanToForm(java.lang.Object bean,
                              java.util.Hashtable errorTable,
                              FormDocument document,
                              java.lang.String formName)
Inserts the values of the properties of a bean within a form document as the default values of the form elements. The errorTable parameter may be null or it must be a hashtable returned by one of the mapping methods of the framework. In the latter case, the error messages are inserted within the form document too.
Parameters:
bean - the bean instance whose properties must be inserted within the form document.
errorTable - hashtable containing mapping errors.
document - object created by getDocument() of FormTemplate.
formName - the optional name of the form, which should be used if the document contains multiple forms.
Throws:
NullPointerException - if bean is null or document is null.
java.lang.IllegalArgumentException - if errorTable wasn't created by this framework or document wasn't created by this framework or the HTML form isn't found within the document.

beanToForm

public static void beanToForm(java.lang.Object bean,
                              java.util.Hashtable errorTable,
                              FormDocument document,
                              AbstractLogger logger)
Inserts the values of the properties of a bean within a form document as the default values of the form elements. The errorTable parameter may be null or it must be a hashtable returned by one of the mapping methods of the framework. In the latter case, the error messages are inserted within the form document too.
Parameters:
bean - the bean instance whose properties must be inserted within the form document.
errorTable - hashtable containing mapping errors.
document - object created by getDocument() of FormTemplate.
logger - logging mechanism for application errors.
Throws:
NullPointerException - if bean is null or document is null.
java.lang.IllegalArgumentException - if errorTable wasn't created by this framework or document wasn't created by this framework or the HTML form isn't found within the document.

beanToForm

public static void beanToForm(java.lang.Object bean,
                              java.util.Hashtable errorTable,
                              FormDocument document,
                              java.lang.String formName,
                              AbstractLogger logger)
Inserts the values of the properties of a bean within a form document as the default values of the form elements. The errorTable parameter may be null or it must be a hashtable returned by one of the mapping methods of the framework. In the latter case, the error messages are inserted within the form document too.
Parameters:
bean - the bean instance whose properties must be inserted within the form document.
errorTable - hashtable containing mapping errors.
document - object created by getDocument() of FormTemplate.
formName - the optional name of the form, which should be used if the document contains multiple forms.
logger - logging mechanism for application errors.
Throws:
NullPointerException - if bean is null or document is null.
java.lang.IllegalArgumentException - if errorTable wasn't created by this framework or document wasn't created by this framework or the HTML form isn't found within the document.

beanToForm

public static void beanToForm(java.lang.Object bean,
                              java.util.Hashtable errorTable,
                              FormDocument document,
                              java.lang.String formName,
                              AbstractLogger logger,
                              java.lang.String prefix)
Inserts the values of the properties of a bean within a form document as the default values of the form elements. The errorTable parameter may be null or it must be a hashtable returned by one of the mapping methods of the framework. In the latter case, the error messages are inserted within the form document too.
Parameters:
bean - the bean instance whose properties must be inserted within the form document.
errorTable - hashtable containing mapping errors.
document - object created by getDocument() of FormTemplate.
formName - the optional name of the form, which should be used if the document contains multiple forms.
logger - logging mechanism for application errors.
prefix - the prefix of the names of the form parameters.
Throws:
NullPointerException - if bean is null or document is null.
java.lang.IllegalArgumentException - if errorTable wasn't created by this framework or document wasn't created by this framework or the HTML form isn't found within the document.

beanToForm

public static void beanToForm(java.lang.Object bean,
                              java.util.Hashtable errorTable,
                              FormDocument document,
                              java.lang.String formName,
                              AbstractLogger logger,
                              java.util.Locale locale)
Inserts the values of the properties of a bean within a form document as the default values of the form elements. The errorTable parameter may be null or it must be a hashtable returned by one of the mapping methods of the framework. In the latter case, the error messages are inserted within the form document too.
Parameters:
bean - the bean instance whose properties must be inserted within the form document.
errorTable - hashtable containing mapping errors.
document - object created by getDocument() of FormTemplate.
formName - the optional name of the form, which should be used if the document contains multiple forms.
logger - logging mechanism for application errors.
locale - internationalization support parameter.
Throws:
NullPointerException - if bean is null or document is null.
java.lang.IllegalArgumentException - if errorTable wasn't created by this framework or document wasn't created by this framework or the HTML form isn't found within the document.

beanToForm

public static void beanToForm(java.lang.Object bean,
                              java.util.Hashtable errorTable,
                              FormDocument document,
                              java.lang.String formName,
                              AbstractLogger logger,
                              java.lang.String prefix,
                              java.util.Locale locale)
Inserts the values of the properties of a bean within a form document as the default values of the form elements. The errorTable parameter may be null or it must be a hashtable returned by one of the mapping methods of the framework. In the latter case, the error messages are inserted within the form document too.
Parameters:
bean - the bean instance whose properties must be inserted within the form document.
errorTable - hashtable containing mapping errors.
document - object created by getDocument() of FormTemplate.
formName - the optional name of the form, which should be used if the document contains multiple forms.
logger - logging mechanism for application errors.
prefix - the prefix of the names of the form parameters.
locale - internationalization support parameter.
Throws:
NullPointerException - if bean is null or document is null.
java.lang.IllegalArgumentException - if errorTable wasn't created by this framework or document wasn't created by this framework or the HTML form isn't found within the document.

messageToHTML

public static java.lang.String messageToHTML(java.lang.String message)
Processes the parameter so that the returned string can be inserted in an HTML document as text. The '&', '<', and '>' characters are replaced with '&amp;', '&lt;' and '&gt;'.
Parameters:
message - the text that has to be inserted within the HTML document.
Returns:
the encoded text.
Throws:
NullPointerException - if message is null.

valueToHTML

public static java.lang.String valueToHTML(java.lang.String value)
Processes the parameter so that the returned string can be inserted in an HTML document as an attribute's value. The '&', '<', '>', space, quote, aphostrofe, cr, lf and tab characters are encoded.
Parameters:
value - the text that has to be inserted within the HTML document.
Returns:
the encoded text.
Throws:
NullPointerException - if value is null.