fr.paris.lutece.plugins.form.utils
Class FormUtils

java.lang.Object
  extended by fr.paris.lutece.plugins.form.utils.FormUtils

public final class FormUtils
extends Object

Utility class for plugin Form


Field Summary
static String BEAN_ENTRY_TYPE_SERVICE
           
static String BEAN_EXPORT_DAEMON_TYPE_FACTORY
           
static String BEAN_FORM_RESPONSE_SERVICE
           
static String CONSTANT_GROUP_BY_DAY
           
static String CONSTANT_GROUP_BY_MONTH
           
static String CONSTANT_GROUP_BY_WEEK
           
static String CONSTANT_UNDERSCORE
           
static String PARAMETER_ID_ENTRY
           
static String PARAMETER_KEY
           
static String PROPERTY_CLEAN_FORM_ANSWERS_KEY
           
static String PROPERTY_CLEAN_FORM_ANSWERS_RETURN_CODE_KO
           
static String PROPERTY_CLEAN_FORM_ANSWERS_RETURN_CODE_OK
           
static String PROPERTY_CLEAN_FORM_ANSWERS_RETURN_CODE_UNAUTHORIZED
           
static String SESSION_FORM_ERRORS
           
static String SESSION_FORM_LIST_SUBMITTED_RESPONSES
           
static String SESSION_VALIDATE_REQUIREMENT
           
 
Method Summary
static void activateMyLuteceAuthentification(Form form, fr.paris.lutece.portal.service.plugin.Plugin plugin, Locale locale, javax.servlet.http.HttpServletRequest request)
          Activate MyLutece authentication for the form
static void addHeaderResponse(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String strFileName, String strFileExtension)
          Write the HTTP header in the response
static Timestamp addStatisticInterval(Timestamp timestamp, String strTimesUnit, int nDecal)
          Return a timestamp Object which correspond to the timestamp in parameter add with a number of times unit (day,week,month)specify in strTimesUnit .
static String buildRequestWithFilter(String strSelect, List<String> listStrFilter, List<String> listStrGroupBy, String strOrder)
          Builds a query with filters placed in parameters
static fr.paris.lutece.plugins.genericattributes.business.Entry createEntryByType(javax.servlet.http.HttpServletRequest request, fr.paris.lutece.portal.service.plugin.Plugin plugin)
          Return an instance of IEntry function of type entry
static org.jfree.chart.JFreeChart createXYGraph(List<StatisticFormSubmit> listStatistic, String strLabelX, String strLableY, String strTimesUnit)
          Create a JFreeChart Graph function of the statistic form submit
static void deactivateMyLuteceAuthentification(Form form, fr.paris.lutece.portal.service.plugin.Plugin plugin)
          Deactivate MyLutece authentication for the form
static String getAdminBaseUrl(javax.servlet.http.HttpServletRequest request)
          Get the base URL
static List<fr.paris.lutece.plugins.genericattributes.business.Entry> getAllQuestionList(int nIdForm, fr.paris.lutece.portal.service.plugin.Plugin plugin)
          Return the questions list
static Date getCurrentDate()
          Return current date without hours, minutes and milliseconds
static Timestamp getCurrentTimestamp()
          Return current Timestamp
static Timestamp getDateFirstMinute(Date date, Locale locale)
          Return a timestamp Object which correspond with the string specified in parameter.
static Timestamp getDateLastMinute(Date date, Locale locale)
          Return a timestamp Object which correspond with the string specified in parameter.
static String getDateString(Timestamp date, Locale locale)
          Deprecated. Deprecated
static int getDay(Timestamp timestamp)
          Return the day of the timestamp in parameter
static List<fr.paris.lutece.plugins.genericattributes.business.Entry> getEntriesList(int nIdForm, fr.paris.lutece.portal.service.plugin.Plugin plugin)
          Return all entries of form
static fr.paris.lutece.plugins.genericattributes.business.EntryType getEntryTypeMyLuteceUser(fr.paris.lutece.portal.service.plugin.Plugin plugin)
          Get entry type mylutece user
static String getEntryUrl(fr.paris.lutece.plugins.genericattributes.business.Entry entry)
          Get the url to modify an entry of the form in front office
static List<fr.paris.lutece.plugins.genericattributes.business.GenericAttributeError> getFormErrors(javax.servlet.http.HttpSession session)
          Gets the form errors bound to the session
static fr.paris.lutece.util.ReferenceList getFormList(fr.paris.lutece.portal.service.plugin.Plugin plugin, fr.paris.lutece.portal.business.user.AdminUser user)
          Load the data of all form that the user is authorized to see depends workgroups user
static void getHtmlEntry(int nIdEntry, StringBuffer stringBuffer, Locale locale, boolean bDisplayFront, javax.servlet.http.HttpServletRequest request)
          Insert in the string buffer the content of the HTML code of the entry
static String getHtmlForm(Form form, String strUrlAction, Locale locale, boolean bDisplayFront)
          Return the HTML code of the form
static String getHtmlForm(Form form, String strUrlAction, Locale locale, boolean bDisplayFront, javax.servlet.http.HttpServletRequest request)
          Return the HTML code of the form
static int getIndexFieldInTheFieldList(int nIdField, List<fr.paris.lutece.plugins.genericattributes.business.Field> listField)
          Return the index in the list of the field whose key is specified in parameter
static int getMonth(Timestamp timestamp)
          Return the month of the timestamp in parameter
static fr.paris.lutece.portal.service.plugin.Plugin getPlugin()
          Gets the form plugin
static fr.paris.lutece.util.ReferenceList getRefListAllQuestions(int nIdForm, fr.paris.lutece.portal.service.plugin.Plugin plugin)
          Get the ReferenceList associated to all questions
static fr.paris.lutece.util.ReferenceList getRefListCategory(List<Category> listCategories)
          Initialize a reference list with the different categories
static List<fr.paris.lutece.plugins.genericattributes.business.GenericAttributeError> getResponseEntry(javax.servlet.http.HttpServletRequest request, int nIdEntry, fr.paris.lutece.portal.service.plugin.Plugin plugin, FormSubmit formSubmit, boolean bResponseNull, boolean bReturnErrors, Locale locale)
          Perform in the object formSubmit the responses associates with a entry specify in parameter.
static Map<Integer,List<fr.paris.lutece.plugins.genericattributes.business.Response>> getResponses(javax.servlet.http.HttpSession session)
          Gets the responses bound to the session
static int getWeek(Timestamp timestamp)
          Return the week of the timestamp in parameter
static String getXmlResponses(javax.servlet.http.HttpServletRequest request, Form form, FormSubmit formSubmit, Locale locale, fr.paris.lutece.portal.service.plugin.Plugin plugin)
          Get the XML responses for a single form submit
static String getXmlResponses(javax.servlet.http.HttpServletRequest request, Form form, List<FormSubmit> listFormSubmit, Locale locale, fr.paris.lutece.portal.service.plugin.Plugin plugin)
          Return the XML of form's response
static int getYear(Timestamp timestamp)
          Return the year of the timestamp in parameter
static Boolean isFieldInTheResponseList(int nIdField, List<fr.paris.lutece.plugins.genericattributes.business.Response> listResponse)
          Return true if the field which key is specified in parameter is in the response list
static void removeFormErrors(javax.servlet.http.HttpSession session)
          Removes submitted responses
static void removeResponses(javax.servlet.http.HttpSession session)
          Removes submitted responses
static void restoreFormErrors(javax.servlet.http.HttpSession session, List<fr.paris.lutece.plugins.genericattributes.business.GenericAttributeError> listFormErrors)
          Restores form errors
static void restoreResponses(javax.servlet.http.HttpSession session, Map<Integer,List<fr.paris.lutece.plugins.genericattributes.business.Response>> mapResponses)
          Restores submitted responses
static boolean sameDate(Timestamp timestamp1, Timestamp timestamp2, String strTimesUnit)
          Compare two timestamps and return true if they have the same times unit(Day,week,month)
static void sendNotificationMailEndDisponibility(Form form, Locale locale)
          Send a mail of end of availability to the mailing list associate with the form
static void sendNotificationMailFormSubmit(FormSubmit formSubmit, Locale locale)
          SendMail to the mailing list associate to the form a mail of new form submit.
static String trim(String strParameter)
          Returns a copy of the string , with leading and trailing whitespace omitted.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONSTANT_GROUP_BY_DAY

public static final String CONSTANT_GROUP_BY_DAY
See Also:
Constant Field Values

CONSTANT_GROUP_BY_WEEK

public static final String CONSTANT_GROUP_BY_WEEK
See Also:
Constant Field Values

CONSTANT_GROUP_BY_MONTH

public static final String CONSTANT_GROUP_BY_MONTH
See Also:
Constant Field Values

BEAN_ENTRY_TYPE_SERVICE

public static final String BEAN_ENTRY_TYPE_SERVICE
See Also:
Constant Field Values

BEAN_FORM_RESPONSE_SERVICE

public static final String BEAN_FORM_RESPONSE_SERVICE
See Also:
Constant Field Values

BEAN_EXPORT_DAEMON_TYPE_FACTORY

public static final String BEAN_EXPORT_DAEMON_TYPE_FACTORY
See Also:
Constant Field Values

CONSTANT_UNDERSCORE

public static final String CONSTANT_UNDERSCORE
See Also:
Constant Field Values

SESSION_FORM_LIST_SUBMITTED_RESPONSES

public static final String SESSION_FORM_LIST_SUBMITTED_RESPONSES
See Also:
Constant Field Values

SESSION_VALIDATE_REQUIREMENT

public static final String SESSION_VALIDATE_REQUIREMENT
See Also:
Constant Field Values

SESSION_FORM_ERRORS

public static final String SESSION_FORM_ERRORS
See Also:
Constant Field Values

PARAMETER_ID_ENTRY

public static final String PARAMETER_ID_ENTRY
See Also:
Constant Field Values

PARAMETER_KEY

public static final String PARAMETER_KEY
See Also:
Constant Field Values

PROPERTY_CLEAN_FORM_ANSWERS_KEY

public static final String PROPERTY_CLEAN_FORM_ANSWERS_KEY
See Also:
Constant Field Values

PROPERTY_CLEAN_FORM_ANSWERS_RETURN_CODE_UNAUTHORIZED

public static final String PROPERTY_CLEAN_FORM_ANSWERS_RETURN_CODE_UNAUTHORIZED
See Also:
Constant Field Values

PROPERTY_CLEAN_FORM_ANSWERS_RETURN_CODE_OK

public static final String PROPERTY_CLEAN_FORM_ANSWERS_RETURN_CODE_OK
See Also:
Constant Field Values

PROPERTY_CLEAN_FORM_ANSWERS_RETURN_CODE_KO

public static final String PROPERTY_CLEAN_FORM_ANSWERS_RETURN_CODE_KO
See Also:
Constant Field Values
Method Detail

sendNotificationMailEndDisponibility

public static void sendNotificationMailEndDisponibility(Form form,
                                                        Locale locale)
Send a mail of end of availability to the mailing list associate with the form

Parameters:
form - the form
locale - the locale

sendNotificationMailFormSubmit

public static void sendNotificationMailFormSubmit(FormSubmit formSubmit,
                                                  Locale locale)
SendMail to the mailing list associate to the form a mail of new form submit. It will also display the answers submitted by the user.

Parameters:
formSubmit - the submit form
locale - Locale

getDateLastMinute

public static Timestamp getDateLastMinute(Date date,
                                          Locale locale)
Return a timestamp Object which correspond with the string specified in parameter.

Parameters:
date - the date who must convert
locale - the locale
Returns:
a timestamp Object which correspond with the string specified in parameter.

getDateFirstMinute

public static Timestamp getDateFirstMinute(Date date,
                                           Locale locale)
Return a timestamp Object which correspond with the string specified in parameter.

Parameters:
date - the date who must convert
locale - the locale
Returns:
a timestamp Object which correspond with the string specified in parameter.

getDay

public static int getDay(Timestamp timestamp)
Return the day of the timestamp in parameter

Parameters:
timestamp - date
Returns:
the day of the timestamp in parameter

getWeek

public static int getWeek(Timestamp timestamp)
Return the week of the timestamp in parameter

Parameters:
timestamp - date
Returns:
the week of the timestamp in parameter

getMonth

public static int getMonth(Timestamp timestamp)
Return the month of the timestamp in parameter

Parameters:
timestamp - date
Returns:
the month of the timestamp in parameter

getYear

public static int getYear(Timestamp timestamp)
Return the year of the timestamp in parameter

Parameters:
timestamp - date
Returns:
the year of the timestamp in parameter

addStatisticInterval

public static Timestamp addStatisticInterval(Timestamp timestamp,
                                             String strTimesUnit,
                                             int nDecal)
Return a timestamp Object which correspond to the timestamp in parameter add with a number of times unit (day,week,month)specify in strTimesUnit .

Parameters:
timestamp - date
strTimesUnit - (day,week,month)
nDecal - the number of timesUnit
Returns:
a timestamp Object which correspond with the string specified in parameter add with a number of times unit (day,week,month)specify in strTimesUnit.

sameDate

public static boolean sameDate(Timestamp timestamp1,
                               Timestamp timestamp2,
                               String strTimesUnit)
Compare two timestamps and return true if they have the same times unit(Day,week,month)

Parameters:
timestamp1 - timestamp1
timestamp2 - timestamp2
strTimesUnit - (day,week,month)
Returns:
Compare two timestamp and return true if they have the same times unit(Day,week,month)

getDateString

public static String getDateString(Timestamp date,
                                   Locale locale)
Deprecated. Deprecated

Converts a java.sql.Timestamp date in a String date in a "jj/mm/aaaa" format

Parameters:
date - java.sql.Timestamp date to convert
locale - the locale
Returns:
strDate The String date in the short locale format or the empty String if the date is null

getCurrentTimestamp

public static Timestamp getCurrentTimestamp()
Return current Timestamp

Returns:
return current Timestamp

getCurrentDate

public static Date getCurrentDate()
Return current date without hours, minutes and milliseconds

Returns:
return current date

createEntryByType

public static fr.paris.lutece.plugins.genericattributes.business.Entry createEntryByType(javax.servlet.http.HttpServletRequest request,
                                                                                         fr.paris.lutece.portal.service.plugin.Plugin plugin)
Return an instance of IEntry function of type entry

Parameters:
request - the request
plugin - the plugin
Returns:
an instance of IEntry function of type entry

getIndexFieldInTheFieldList

public static int getIndexFieldInTheFieldList(int nIdField,
                                              List<fr.paris.lutece.plugins.genericattributes.business.Field> listField)
Return the index in the list of the field whose key is specified in parameter

Parameters:
nIdField - the key of the field
listField - the list of field
Returns:
the index in the list of the field whose key is specified in parameter

getHtmlForm

public static String getHtmlForm(Form form,
                                 String strUrlAction,
                                 Locale locale,
                                 boolean bDisplayFront,
                                 javax.servlet.http.HttpServletRequest request)
Return the HTML code of the form

Parameters:
form - the form which HTML code must be return
strUrlAction - the URL who must be call after the form submit
locale - the locale
bDisplayFront - True if the entry will be displayed in Front Office, false if it will be displayed in Back Office.
request - HttpServletRequest
Returns:
the HTML code of the form

getRefListCategory

public static fr.paris.lutece.util.ReferenceList getRefListCategory(List<Category> listCategories)
Initialize a reference list with the different categories

Parameters:
listCategories - the list of categories
Returns:
reference list of category

getHtmlForm

public static String getHtmlForm(Form form,
                                 String strUrlAction,
                                 Locale locale,
                                 boolean bDisplayFront)
Return the HTML code of the form

Parameters:
form - the form which HTML code must be return
strUrlAction - the URL who must be call after the form submit
locale - the locale
bDisplayFront - True if the entry will be displayed in Front Office, false if it will be displayed in Back Office.
Returns:
the HTML code of the form

getHtmlEntry

public static void getHtmlEntry(int nIdEntry,
                                StringBuffer stringBuffer,
                                Locale locale,
                                boolean bDisplayFront,
                                javax.servlet.http.HttpServletRequest request)
Insert in the string buffer the content of the HTML code of the entry

Parameters:
nIdEntry - the key of the entry which HTML code must be insert in the stringBuffer
stringBuffer - the buffer which contains the HTML code
locale - the locale
bDisplayFront - True if the entry will be displayed in Front Office, false if it will be displayed in Back Office.
request - HttpServletRequest

getResponseEntry

public static List<fr.paris.lutece.plugins.genericattributes.business.GenericAttributeError> getResponseEntry(javax.servlet.http.HttpServletRequest request,
                                                                                                              int nIdEntry,
                                                                                                              fr.paris.lutece.portal.service.plugin.Plugin plugin,
                                                                                                              FormSubmit formSubmit,
                                                                                                              boolean bResponseNull,
                                                                                                              boolean bReturnErrors,
                                                                                                              Locale locale)
Perform in the object formSubmit the responses associates with a entry specify in parameter.
Return null if there is no error in the response else return a FormError Object

Parameters:
request - the request
nIdEntry - the key of the entry
plugin - the plugin
formSubmit - Form Submit Object
bResponseNull - true if the response create must be null
bReturnErrors - true if errors must be returned
locale - the locale
Returns:
null if there is no error in the response else return a FormError Object

getEntryUrl

public static String getEntryUrl(fr.paris.lutece.plugins.genericattributes.business.Entry entry)
Get the url to modify an entry of the form in front office

Parameters:
entry - the entry
Returns:
The url to modify the entry in front office

isFieldInTheResponseList

public static Boolean isFieldInTheResponseList(int nIdField,
                                               List<fr.paris.lutece.plugins.genericattributes.business.Response> listResponse)
Return true if the field which key is specified in parameter is in the response list

Parameters:
nIdField - the id of the field who is search
listResponse - the list of object Response
Returns:
true if the field which key is specified in parameter is in the response list

getXmlResponses

public static String getXmlResponses(javax.servlet.http.HttpServletRequest request,
                                     Form form,
                                     List<FormSubmit> listFormSubmit,
                                     Locale locale,
                                     fr.paris.lutece.portal.service.plugin.Plugin plugin)
Return the XML of form's response

Parameters:
request - the request
form - the form
listFormSubmit - the form submit list
locale - the locale
plugin - the plugin
Returns:
the XML of the response of a form

getXmlResponses

public static String getXmlResponses(javax.servlet.http.HttpServletRequest request,
                                     Form form,
                                     FormSubmit formSubmit,
                                     Locale locale,
                                     fr.paris.lutece.portal.service.plugin.Plugin plugin)
Get the XML responses for a single form submit

Parameters:
request - the HTTP request
form - the form
formSubmit - the form submit
locale - the locale
plugin - the plugin
Returns:
the XML

addHeaderResponse

public static void addHeaderResponse(javax.servlet.http.HttpServletRequest request,
                                     javax.servlet.http.HttpServletResponse response,
                                     String strFileName,
                                     String strFileExtension)
Write the HTTP header in the response

Parameters:
request - the httpServletRequest
response - the HTTP response
strFileName - the name of the file who must insert in the response
strFileExtension - the file extension

createXYGraph

public static org.jfree.chart.JFreeChart createXYGraph(List<StatisticFormSubmit> listStatistic,
                                                       String strLabelX,
                                                       String strLableY,
                                                       String strTimesUnit)
Create a JFreeChart Graph function of the statistic form submit

Parameters:
listStatistic - the list of statistic of form submit
strLabelX - the label of axis x
strLableY - the label of axis x
strTimesUnit - the times unit of axis x(Day,Week,Month)
Returns:
a JFreeChart Graph function of the statistic form submit

getFormList

public static fr.paris.lutece.util.ReferenceList getFormList(fr.paris.lutece.portal.service.plugin.Plugin plugin,
                                                             fr.paris.lutece.portal.business.user.AdminUser user)
Load the data of all form that the user is authorized to see depends workgroups user

Parameters:
plugin - the plugin
user - the current user
Returns:
a reference list of form

getRefListAllQuestions

public static fr.paris.lutece.util.ReferenceList getRefListAllQuestions(int nIdForm,
                                                                        fr.paris.lutece.portal.service.plugin.Plugin plugin)
Get the ReferenceList associated to all questions

Parameters:
nIdForm - the id form
plugin - the Plugin
Returns:
a ReferenceList

getAllQuestionList

public static List<fr.paris.lutece.plugins.genericattributes.business.Entry> getAllQuestionList(int nIdForm,
                                                                                                fr.paris.lutece.portal.service.plugin.Plugin plugin)
Return the questions list

Parameters:
nIdForm - the form id
plugin - the plugin
Returns:
the questions list

getEntriesList

public static List<fr.paris.lutece.plugins.genericattributes.business.Entry> getEntriesList(int nIdForm,
                                                                                            fr.paris.lutece.portal.service.plugin.Plugin plugin)
Return all entries of form

Parameters:
nIdForm - the form id
plugin - the plugin
Returns:
the all entries of form

buildRequestWithFilter

public static String buildRequestWithFilter(String strSelect,
                                            List<String> listStrFilter,
                                            List<String> listStrGroupBy,
                                            String strOrder)
Builds a query with filters placed in parameters

Parameters:
strSelect - the select of the query
listStrFilter - the list of filter to add in the query
listStrGroupBy - the list of group by to add in the query
strOrder - the order by of the query
Returns:
a query

getEntryTypeMyLuteceUser

public static fr.paris.lutece.plugins.genericattributes.business.EntryType getEntryTypeMyLuteceUser(fr.paris.lutece.portal.service.plugin.Plugin plugin)
Get entry type mylutece user

Parameters:
plugin - Plugin
Returns:
entry type

activateMyLuteceAuthentification

public static void activateMyLuteceAuthentification(Form form,
                                                    fr.paris.lutece.portal.service.plugin.Plugin plugin,
                                                    Locale locale,
                                                    javax.servlet.http.HttpServletRequest request)
Activate MyLutece authentication for the form

Parameters:
form - form
plugin - Plugin
locale - Locale
request - HttpServletRequest

deactivateMyLuteceAuthentification

public static void deactivateMyLuteceAuthentification(Form form,
                                                      fr.paris.lutece.portal.service.plugin.Plugin plugin)
Deactivate MyLutece authentication for the form

Parameters:
form - Form
plugin - Plugin

restoreResponses

public static void restoreResponses(javax.servlet.http.HttpSession session,
                                    Map<Integer,List<fr.paris.lutece.plugins.genericattributes.business.Response>> mapResponses)
Restores submitted responses

Parameters:
session - the session
mapResponses - response list, key is entry id

removeResponses

public static void removeResponses(javax.servlet.http.HttpSession session)
Removes submitted responses

Parameters:
session - the session

getResponses

public static Map<Integer,List<fr.paris.lutece.plugins.genericattributes.business.Response>> getResponses(javax.servlet.http.HttpSession session)
Gets the responses bound to the session

Parameters:
session - the session
Returns:
the responses if any, null otherwise.

restoreFormErrors

public static void restoreFormErrors(javax.servlet.http.HttpSession session,
                                     List<fr.paris.lutece.plugins.genericattributes.business.GenericAttributeError> listFormErrors)
Restores form errors

Parameters:
session - the session
listFormErrors - the form errosr

removeFormErrors

public static void removeFormErrors(javax.servlet.http.HttpSession session)
Removes submitted responses

Parameters:
session - the session

getFormErrors

public static List<fr.paris.lutece.plugins.genericattributes.business.GenericAttributeError> getFormErrors(javax.servlet.http.HttpSession session)
Gets the form errors bound to the session

Parameters:
session - the session
Returns:
the form errors

getPlugin

public static fr.paris.lutece.portal.service.plugin.Plugin getPlugin()
Gets the form plugin

Returns:
the plugin

trim

public static String trim(String strParameter)
Returns a copy of the string , with leading and trailing whitespace omitted.

Parameters:
strParameter - the string parameter to convert
Returns:
null if the strParameter is null other return with leading and trailing whitespace omitted.

getAdminBaseUrl

public static String getAdminBaseUrl(javax.servlet.http.HttpServletRequest request)
Get the base URL

Parameters:
request - the HTTP request
Returns:
the base URL


Copyright © 2014 Mairie de Paris. All Rights Reserved.