📄 cmsform.java
字号:
/**
* Returns a list of field objects for the online form.<p>
*
* @return a list of field objects for the online form
*/
public List getFields() {
return m_fields;
}
/**
* Returns the value for a field specified by it's name (Xpath).<p>
*
* @param fieldName the field's name (Xpath)
* @return the field value, or null
*/
public String getFieldStringValueByName(String fieldName) {
I_CmsField field = (I_CmsField)m_fieldsByName.get(fieldName);
if (field != null) {
String fieldValue = field.getValue();
return (fieldValue != null) ? fieldValue.trim() : "";
}
return "";
}
/**
* Returns the global form attributes.<p>
*
* @return the global form attributes
*/
public String getFormAttributes() {
return m_formAttributes;
}
/**
* Returns the form check text.<p>
*
* @return the form check text
*/
public String getFormCheckText() {
return m_formCheckText;
}
/**
* Returns the form confirmation text.<p>
*
* @return the form confirmation text
*/
public String getFormConfirmationText() {
return m_formConfirmationText;
}
/**
* Returns the optional form input field attributes.<p>
*
* @return the optional form input field attributes
*/
public String getFormFieldAttributes() {
return m_formFieldAttributes;
}
/**
* Returns the form text.<p>
*
* @return the form text
*/
public String getFormText() {
return m_formText;
}
/**
* Returns the mail bcc recipient(s).<p>
*
* @return the mail bcc recipient(s)
*/
public String getMailBCC() {
return m_mailBCC;
}
/**
* Returns the mail cc recipient(s).<p>
*
* @return the mail cc recipient(s)
*/
public String getMailCC() {
return m_mailCC;
}
/**
* Returns the mail sender address.<p>
*
* @return the mail sender address
*/
public String getMailFrom() {
return m_mailFrom;
}
/**
* Returns the mail subject.<p>
*
* @return the mail subject
*/
public String getMailSubject() {
return m_mailSubject;
}
/**
* Returns the mail subject prefix.<p>
*
* @return the mail subject prefix
*/
public String getMailSubjectPrefix() {
return m_mailSubjectPrefix;
}
/**
* Returns the mail text.<p>
*
* @return the mail text
*/
public String getMailText() {
return m_mailText;
}
/**
* Returns the mail text as plain text.<p>
*
* @return the mail text as plain text
*/
public String getMailTextPlain() {
return m_mailTextPlain;
}
/**
* Returns the mail recipient(s).<p>
*
* @return the mail recipient(s)
*/
public String getMailTo() {
return m_mailTo;
}
/**
* Returns the mail type ("text" or "html").<p>
*
* @return the mail type
*/
public String getMailType() {
return m_mailType;
}
/**
* Returns if the check page should be shown.<p>
*
* @return true if the check page should be shown, otherwise false
*/
public boolean getShowCheck() {
return m_showCheck;
}
/**
* Returns the target URI of this form.<p>
*
* This optional target URI can be used to redirect the user to an OpenCms page instead of displaying a confirmation
* text from the form's XML content.<p>
*
* @return the target URI
*/
public String getTargetUri() {
return m_targetUri;
}
/**
* Tests if a captcha field is configured for this form.<p>
*
* @return true, if a captcha field is configured for this form
*/
public boolean hasCaptchaField() {
return m_captchaField != null;
}
/**
* Returns if the form has configuration errors.<p>
*
* @return true if the form has configuration errors, otherwise false
*/
public boolean hasConfigurationErrors() {
return m_configurationErrors.size() > 0;
}
/**
* Returns true if at least one of the configured fields is mandatory.<p>
*
* @return true if at least one of the configured fields is mandatory, otherwise false
*/
public boolean hasMandatoryFields() {
return m_hasMandatoryFields;
}
/**
* Tests if this form has a target URI specified.<p>
*
* This optional target URI can be used to redirect the user to an OpenCms page instead of displaying a confirmation
* text from the form's XML content.<p>
*
* @return the target URI
*/
public boolean hasTargetUri() {
return CmsStringUtil.isNotEmpty(m_targetUri);
}
/**
* Initializes the form configuration and creates the necessary form field objects.<p>
*
* @param jsp the initialized CmsJspActionElement to access the OpenCms API
* @param messages the localized messages
* @param initial if true, field values are filled with values specified in the XML configuration
* @param formConfigUri URI of the form configuration file, if not provided, current URI is used for configuration
* @param formAction the desired action submiktted by the form
*
* @throws Exception if parsing the configuration fails
*/
public void init(CmsJspActionElement jsp, CmsMessages messages, boolean initial, String formConfigUri, String formAction)
throws Exception {
// read the form configuration file from VFS
if (CmsStringUtil.isEmpty(formConfigUri)) {
formConfigUri = jsp.getRequestContext().getUri();
}
CmsFile file = jsp.getCmsObject().readFile(formConfigUri);
CmsXmlContent content = CmsXmlContentFactory.unmarshal(jsp.getCmsObject(), file);
// get current Locale
Locale locale = jsp.getRequestContext().getLocale();
// init member variables
initMembers();
m_formAction = formAction;
m_fields = new ArrayList();
m_fieldsByName = new HashMap();
// initialize general form configuration
initFormGlobalConfiguration(content, jsp.getCmsObject(), locale, messages);
// initialize the form input fields
initInputFields(content, jsp, locale, messages, initial);
// init. the optional captcha field
initCaptchaField(jsp, content, locale, initial);
// add the captcha field to the list of all fields, if the form has no check page
if (captchaFieldIsOnInputPage() && m_captchaField != null) {
addField(m_captchaField);
}
}
/**
* Tests if the check page was submitted.<p>
*
* @return true, if the check page was submitted
*/
public boolean isCheckPageSubmitted() {
return CmsFormHandler.ACTION_CONFIRMED.equals(m_formAction);
}
/**
* Returns if the optional confirmation mail is enabled.<p>
*
* @return true if the optional confirmation mail is enabled, otherwise false
*/
public boolean isConfirmationMailEnabled() {
return m_confirmationMailEnabled;
}
/**
* Returns if the confirmation mail if optional, i.e. selectable by the form submitter.<p>
*
* @return true if the confirmation mail if optional, i.e. selectable by the form submitter, otherwise false
*/
public boolean isConfirmationMailOptional() {
return m_confirmationMailOptional;
}
/**
* Tests if the input page was submitted.<p>
*
* @return true, if the input page was submitted
*/
public boolean isInputFormSubmitted() {
return CmsFormHandler.ACTION_SUBMIT.equals(m_formAction);
}
/**
* Removes the captcha field from the list of all fields, if present.<p>
*
* @return the removed captcha field, or null
*/
public I_CmsField removeCaptchaField() {
for (int i = 0, n = m_fields.size(); i < n; i++) {
I_CmsField field = (I_CmsField)m_fields.get(i);
if (field != null && CmsCaptchaField.class.isAssignableFrom(getClass())) {
removeField(field);
return field;
}
}
return null;
}
/**
* Adds a field to the form.<p>
*
* @param field the field to be added to the form
*/
protected void addField(I_CmsField field) {
m_fields.add(field);
// the fields are also internally backed in a map keyed by their field name
m_fieldsByName.put(field.getName(), field);
}
/**
* Marks the individual items of checkboxes, selectboxes and radiobuttons as selected depending on the given request parameters.<p>
*
* @param request the current request
* @param field the current field
* @param value the value of the input field
*
* @return <code>"true"</code> if the current item is selected or checked, otherwise false
*/
protected String readSelectedFromRequest(HttpServletRequest request, I_CmsField field, String value) {
String result = "";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -