Class ProcessFormAction
- java.lang.Object
-
- org.apache.avalon.framework.logger.AbstractLogEnabled
-
- org.apache.cocoon.acting.AbstractAction
-
- org.apache.cocoon.acting.ServiceableAction
-
- org.ametys.plugins.forms.processing.ProcessFormAction
-
- All Implemented Interfaces:
Component,Contextualizable,LogEnabled,Serviceable,Action
public class ProcessFormAction extends ServiceableAction implements Contextualizable
Action that processes the user submitted data on a form.
-
-
Field Summary
Fields Modifier and Type Field Description private static String__FORM_ENTRY_PATTERNprotected AmetysObjectResolver_ametysObjectResolverThe ametys object resolverprotected Context_contextThe contextprotected CurrentUserProvider_currentUserProviedcurrent user providerprotected static DateFormat_DATE_FORMATThe date format pattern.protected static Pattern_DATE_PATTERNThe integer validation pattern.protected static DateFormat_DATETIME_FORMATThe date and time format pattern.protected static Pattern_DATETIME_PATTERNThe integer validation pattern.protected static Pattern_EMAIL_PATTERNThe email validation pattern.protected static Pattern_FLOAT_PATTERNThe integer validation pattern.protected FormPropertiesManager_formPropertiesManagerForm properties manager.protected FormTableManager_formTableManagerForm table manager.protected static Pattern_INT_PATTERNThe integer validation pattern.protected static Pattern_PHONE_PATTERNThe phone validation pattern.protected String_pluginNameThe plugin name.protected URIPrefixHandler_prefixHandlerThe URI prefix handlerprotected RightManager_rightManagerRights managerprotected SiteManager_siteManagerThe site manager.protected SourceResolver_sourceResolverThe source resolver.protected SQLDatabaseTypeExtensionPoint_sqlDatabaseTypeExtensionPointThe SQLDatabaseTypeExtensionPoint instanceprotected static DateFormat_TIME_FORMATThe time format pattern.protected static Pattern_TIME_PATTERNThe integer validation pattern.protected WorkflowHelper_workflowHelperThe workflow helper componentprotected WorkflowProvider_workflowProviderThe workflow providerprivate static StringANTIVIRUS_RESULT_OKprotected static StringPARAM_CONTENT_IDThe content ID parameter.protected static StringPARAM_FORM_IDThe form ID parameter.-
Fields inherited from class org.apache.cocoon.acting.ServiceableAction
manager
-
Fields inherited from class org.apache.cocoon.acting.AbstractAction
EMPTY_MAP
-
-
Constructor Summary
Constructors Constructor Description ProcessFormAction()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean_analyseFile(File fileToAnalyse)Antivirus analysis.private boolean_createWorkflow(Form form, Map objectModel, String tableName, Connection connection, String dbType)private Date_getDate(String stringValue, Date defaultValue, DateFormat format)protected Collection<FieldValue>_getEntriesToInsert(Collection<FieldValue> entries)Retain only the entries that are to be inserted in the database.protected FieldValue_getFileEntry(Request request, Field field, String id, String name, FormErrors errors)Get a file entry from the request.protected Collection<File>_getFiles(Map<String,FieldValue> input)Get the files of a user input.private Float_getFloat(String stringValue, Float defaultValue)protected Map<String,FieldValue>_getInput(Form form, Request request, FormErrors errors)Get the user input.private Integer_getInteger(String stringValue, Integer defaultValue)protected String_getMail(String resource, Form form, Map<String,FieldValue> input)Get a mail pipeline's content.private Pattern_getPattern(String jsRegexp)Parses a JS pattern (i.e.private Site_getSiteFromSharedContent(SharedContent sharedContent)private String_getSiteNameFromSharedContent(SharedContent sharedContent)protected boolean_insertInput(Form form, Map<String,FieldValue> input, Map objectModel)Insert the user submission in the database.private boolean_removeFormEntry(String formId, String entryId)protected void_sendEmails(Form form, Map<String,FieldValue> input, Site site, Integer totalSubmissions)Send the receipt and notification emails.protected void_sendLimitEmail(Form form, Map<String,FieldValue> input, String sender)Send the limit email.protected void_sendNotificationEmails(Form form, Map<String,FieldValue> input, String sender)Send the notification emails.protected void_sendReceiptEmail(Form form, Map<String,FieldValue> input, String sender)Send the receipt email.protected void_setParameters(Form form, Map<String,FieldValue> input, PreparedStatement stmt, String dbType)Set the parameters into the prepared statement.private boolean_updateWorkflowId(String formId, String entryId, long workflowId)protected List<I18nizableText>_validateCaptcha(FieldValue entry, Request request)Validate a captcha.protected List<I18nizableText>_validateCheckbox(FieldValue entry, Request request)Validate a checkbox input.protected List<I18nizableText>_validateConfirmation(FieldValue entry, Request request, String keyPrefix)Validate a confirmation.private List<I18nizableText>_validateCustomRegexp(FieldValue entry, String keyPrefix)private List<I18nizableText>_validateDate(FieldValue entry, String keyPrefix)private List<I18nizableText>_validateDateTime(FieldValue entry, String keyPrefix)protected List<I18nizableText>_validateFile(FieldValue entry, Request request)Validate a file input.private List<I18nizableText>_validateFloat(FieldValue entry, String keyPrefix)protected void_validateInput(Form form, Map<String,FieldValue> input, FormErrors errors, Request request)Validate the user input.private List<I18nizableText>_validateInteger(FieldValue entry, String keyPrefix)protected List<I18nizableText>_validateMandatory(FieldValue entry, String keyPrefix)Validate a mandatory field.private void_validateNonblankRegexp(FieldValue entry, List<I18nizableText> errors, String value, String textPrefix, String regexpType)protected List<I18nizableText>_validatePassword(FieldValue entry, Request request)Validate a password field.protected List<I18nizableText>_validateRadio(FieldValue entry, Request request)Validate a radio input.protected List<I18nizableText>_validateSelect(FieldValue entry, Request request)Validate a select input.protected List<I18nizableText>_validateTextarea(FieldValue entry, Request request)Validate a textarea.protected List<I18nizableText>_validateTextField(FieldValue entry, Request request)Validate a text field.private List<I18nizableText>_validateTextLength(FieldValue entry, String keyPrefix)private List<I18nizableText>_validateTime(FieldValue entry, String keyPrefix)Mapact(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters)voidcontextualize(Context context)voidservice(ServiceManager serviceManager)-
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
-
-
-
Field Detail
-
PARAM_FORM_ID
protected static final String PARAM_FORM_ID
The form ID parameter.- See Also:
- Constant Field Values
-
PARAM_CONTENT_ID
protected static final String PARAM_CONTENT_ID
The content ID parameter.- See Also:
- Constant Field Values
-
_INT_PATTERN
protected static final Pattern _INT_PATTERN
The integer validation pattern.
-
_FLOAT_PATTERN
protected static final Pattern _FLOAT_PATTERN
The integer validation pattern.
-
_DATE_PATTERN
protected static final Pattern _DATE_PATTERN
The integer validation pattern.
-
_TIME_PATTERN
protected static final Pattern _TIME_PATTERN
The integer validation pattern.
-
_DATETIME_PATTERN
protected static final Pattern _DATETIME_PATTERN
The integer validation pattern.
-
_EMAIL_PATTERN
protected static final Pattern _EMAIL_PATTERN
The email validation pattern.
-
_PHONE_PATTERN
protected static final Pattern _PHONE_PATTERN
The phone validation pattern.
-
_DATE_FORMAT
protected static final DateFormat _DATE_FORMAT
The date format pattern.
-
_TIME_FORMAT
protected static final DateFormat _TIME_FORMAT
The time format pattern.
-
_DATETIME_FORMAT
protected static final DateFormat _DATETIME_FORMAT
The date and time format pattern.
-
__FORM_ENTRY_PATTERN
private static final String __FORM_ENTRY_PATTERN
- See Also:
- Constant Field Values
-
ANTIVIRUS_RESULT_OK
private static final String ANTIVIRUS_RESULT_OK
- See Also:
- Constant Field Values
-
_formPropertiesManager
protected FormPropertiesManager _formPropertiesManager
Form properties manager.
-
_formTableManager
protected FormTableManager _formTableManager
Form table manager.
-
_sourceResolver
protected SourceResolver _sourceResolver
The source resolver.
-
_ametysObjectResolver
protected AmetysObjectResolver _ametysObjectResolver
The ametys object resolver
-
_siteManager
protected SiteManager _siteManager
The site manager.
-
_pluginName
protected String _pluginName
The plugin name.
-
_prefixHandler
protected URIPrefixHandler _prefixHandler
The URI prefix handler
-
_workflowProvider
protected WorkflowProvider _workflowProvider
The workflow provider
-
_workflowHelper
protected WorkflowHelper _workflowHelper
The workflow helper component
-
_sqlDatabaseTypeExtensionPoint
protected SQLDatabaseTypeExtensionPoint _sqlDatabaseTypeExtensionPoint
The SQLDatabaseTypeExtensionPoint instance
-
_rightManager
protected RightManager _rightManager
Rights manager
-
_currentUserProvied
protected CurrentUserProvider _currentUserProvied
current user provider
-
-
Constructor Detail
-
ProcessFormAction
public ProcessFormAction()
-
-
Method Detail
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualizein interfaceContextualizable- Throws:
ContextException
-
service
public void service(ServiceManager serviceManager) throws ServiceException
- Specified by:
servicein interfaceServiceable- Overrides:
servicein classServiceableAction- Throws:
ServiceException
-
act
public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception
-
_getSiteNameFromSharedContent
private String _getSiteNameFromSharedContent(SharedContent sharedContent)
-
_getSiteFromSharedContent
private Site _getSiteFromSharedContent(SharedContent sharedContent)
-
_analyseFile
private boolean _analyseFile(File fileToAnalyse)
Antivirus analysis. Based on clamscan results.- Parameters:
fileToAnalyse- the file to analyse- Returns:
- true if the file is correct, false if a malware was discovered in the file
-
_getInput
protected Map<String,FieldValue> _getInput(Form form, Request request, FormErrors errors)
Get the user input.- Parameters:
form- the Form object.request- the user request.errors- the input errors.- Returns:
- the user data as a Map of column name -> column entry.
-
_getFileEntry
protected FieldValue _getFileEntry(Request request, Field field, String id, String name, FormErrors errors)
Get a file entry from the request.- Parameters:
request- the user request.field- the field.id- the entry ID.name- the field name.errors- the form errors.- Returns:
- the file entry.
-
_insertInput
protected boolean _insertInput(Form form, Map<String,FieldValue> input, Map objectModel) throws com.opensymphony.workflow.WorkflowException, InvalidModificationException
Insert the user submission in the database.- Parameters:
form- the Form object.input- the user input.objectModel- The object model- Returns:
- true if the insertion has succeed
- Throws:
com.opensymphony.workflow.WorkflowException- if an exception occurs while initializing a workflow instance for a form entryInvalidModificationException- If an error occurs
-
_createWorkflow
private boolean _createWorkflow(Form form, Map objectModel, String tableName, Connection connection, String dbType) throws SQLException, InvalidModificationException, com.opensymphony.workflow.InvalidActionException
- Throws:
SQLExceptionInvalidModificationExceptioncom.opensymphony.workflow.InvalidActionException
-
_removeFormEntry
private boolean _removeFormEntry(String formId, String entryId)
-
_updateWorkflowId
private boolean _updateWorkflowId(String formId, String entryId, long workflowId)
-
_setParameters
protected void _setParameters(Form form, Map<String,FieldValue> input, PreparedStatement stmt, String dbType) throws SQLException, com.opensymphony.workflow.WorkflowException
Set the parameters into the prepared statement.- Parameters:
form- the form.input- the user input.stmt- the prepared statement.dbType- the database type.- Throws:
SQLException- if a SQL error occurs.com.opensymphony.workflow.WorkflowException- if an exception occurs while initializing a workflow instance for a form entry
-
_validateInput
protected void _validateInput(Form form, Map<String,FieldValue> input, FormErrors errors, Request request)
Validate the user input.- Parameters:
form- the Form object.input- the user input.errors- the FormErrors object to fill.request- the user request.
-
_validateTextField
protected List<I18nizableText> _validateTextField(FieldValue entry, Request request)
Validate a text field.- Parameters:
entry- the text field entry.request- the user request.- Returns:
- the list of error messages.
-
_validateNonblankRegexp
private void _validateNonblankRegexp(FieldValue entry, List<I18nizableText> errors, String value, String textPrefix, String regexpType)
-
_validatePassword
protected List<I18nizableText> _validatePassword(FieldValue entry, Request request)
Validate a password field.- Parameters:
entry- the password field entry.request- the user request.- Returns:
- the list of error messages.
-
_validateSelect
protected List<I18nizableText> _validateSelect(FieldValue entry, Request request)
Validate a select input.- Parameters:
entry- the select input entry.request- the user request.- Returns:
- the list of error messages.
-
_validateTextarea
protected List<I18nizableText> _validateTextarea(FieldValue entry, Request request)
Validate a textarea.- Parameters:
entry- the textarea entry.request- the user request.- Returns:
- the list of error messages.
-
_validateRadio
protected List<I18nizableText> _validateRadio(FieldValue entry, Request request)
Validate a radio input.- Parameters:
entry- the radio input entry.request- the user request.- Returns:
- the list of error messages.
-
_validateCheckbox
protected List<I18nizableText> _validateCheckbox(FieldValue entry, Request request)
Validate a checkbox input.- Parameters:
entry- the checkbox entry.request- the user request.- Returns:
- the list of error messages.
-
_validateFile
protected List<I18nizableText> _validateFile(FieldValue entry, Request request)
Validate a file input.- Parameters:
entry- the file input entry.request- the user request.- Returns:
- the list of error messages.
-
_validateCaptcha
protected List<I18nizableText> _validateCaptcha(FieldValue entry, Request request)
Validate a captcha.- Parameters:
entry- the captcha entry.request- the user request.- Returns:
- the list of error messages.
-
_validateMandatory
protected List<I18nizableText> _validateMandatory(FieldValue entry, String keyPrefix)
Validate a mandatory field.- Parameters:
entry- the field valuekeyPrefix- the key profix- Returns:
- the list of error messages.
-
_validateConfirmation
protected List<I18nizableText> _validateConfirmation(FieldValue entry, Request request, String keyPrefix)
Validate a confirmation.- Parameters:
entry- the field valuerequest- the requestkeyPrefix- the key prefix- Returns:
- the list of error messages.
-
_validateTextLength
private List<I18nizableText> _validateTextLength(FieldValue entry, String keyPrefix)
-
_validateInteger
private List<I18nizableText> _validateInteger(FieldValue entry, String keyPrefix)
-
_validateFloat
private List<I18nizableText> _validateFloat(FieldValue entry, String keyPrefix)
-
_validateDate
private List<I18nizableText> _validateDate(FieldValue entry, String keyPrefix)
-
_validateTime
private List<I18nizableText> _validateTime(FieldValue entry, String keyPrefix)
-
_validateDateTime
private List<I18nizableText> _validateDateTime(FieldValue entry, String keyPrefix)
-
_validateCustomRegexp
private List<I18nizableText> _validateCustomRegexp(FieldValue entry, String keyPrefix)
-
_getPattern
private Pattern _getPattern(String jsRegexp)
Parses a JS pattern (i.e. "/^[a-z]+$/i")- Parameters:
jsRegexp- the JS regexp string- Returns:
- the compiled Pattern object.
-
_getInteger
private Integer _getInteger(String stringValue, Integer defaultValue)
-
_getDate
private Date _getDate(String stringValue, Date defaultValue, DateFormat format)
-
_getEntriesToInsert
protected Collection<FieldValue> _getEntriesToInsert(Collection<FieldValue> entries)
Retain only the entries that are to be inserted in the database.- Parameters:
entries- the entries to filter.- Returns:
- the entries to insert in the database.
-
_sendEmails
protected void _sendEmails(Form form, Map<String,FieldValue> input, Site site, Integer totalSubmissions)
Send the receipt and notification emails.- Parameters:
form- the Form object.input- the user input.site- the site.totalSubmissions- total number of submissions. Can be null if the form don't have limits.
-
_sendNotificationEmails
protected void _sendNotificationEmails(Form form, Map<String,FieldValue> input, String sender)
Send the notification emails.- Parameters:
form- the form.input- the user input.sender- the sender e-mail.
-
_sendReceiptEmail
protected void _sendReceiptEmail(Form form, Map<String,FieldValue> input, String sender)
Send the receipt email.- Parameters:
form- the form.input- the user input.sender- the sender e-mail.
-
_sendLimitEmail
protected void _sendLimitEmail(Form form, Map<String,FieldValue> input, String sender)
Send the limit email.- Parameters:
form- the form.input- the user input.sender- the sender e-mail.
-
_getMail
protected String _getMail(String resource, Form form, Map<String,FieldValue> input) throws IOException
Get a mail pipeline's content.- Parameters:
resource- the mail resource pipeline (i.e. "results.html" or "receipt.txt").form- the Form.input- the user input.- Returns:
- the mail content.
- Throws:
IOException- if an error occurs.
-
_getFiles
protected Collection<File> _getFiles(Map<String,FieldValue> input)
Get the files of a user input.- Parameters:
input- the user input.- Returns:
- the files submitted by the user.
-
-