KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > frontend > templateone > form > CmsFormHandler


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/frontend/templateone/form/CmsFormHandler.java,v $
3  * Date : $Date: 2006/03/27 14:52:20 $
4  * Version: $Revision: 1.24 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.frontend.templateone.form;
33
34 import org.opencms.i18n.CmsEncoder;
35 import org.opencms.i18n.CmsMessages;
36 import org.opencms.jsp.CmsJspActionElement;
37 import org.opencms.mail.CmsHtmlMail;
38 import org.opencms.mail.CmsSimpleMail;
39 import org.opencms.main.CmsLog;
40 import org.opencms.util.CmsStringUtil;
41
42 import java.util.ArrayList JavaDoc;
43 import java.util.Collections JavaDoc;
44 import java.util.HashMap JavaDoc;
45 import java.util.Iterator JavaDoc;
46 import java.util.List JavaDoc;
47 import java.util.Map JavaDoc;
48 import java.util.StringTokenizer JavaDoc;
49
50 import javax.mail.internet.AddressException JavaDoc;
51 import javax.mail.internet.InternetAddress JavaDoc;
52 import javax.servlet.http.HttpServletRequest JavaDoc;
53 import javax.servlet.http.HttpServletResponse JavaDoc;
54 import javax.servlet.jsp.PageContext JavaDoc;
55
56 import org.apache.commons.logging.Log;
57
58 /**
59  * The form handler controls the html or mail output of a configured email form.<p>
60  *
61  * Provides methods to determine the action that takes place and methods to create different
62  * output formats of a submitted form.<p>
63  *
64  * @author Andreas Zahner
65  * @author Thomas Weckert
66  * @author Jan Baudisch
67  *
68  * @version $Revision: 1.24 $
69  *
70  * @since 6.0.0
71  */

72 public class CmsFormHandler extends CmsJspActionElement {
73
74     /** Request parameter value for the form action parameter: correct the input. */
75     public static final String JavaDoc ACTION_CONFIRMED = "confirmed";
76     
77     /** Request parameter value for the form action parameter: correct the input. */
78     public static final String JavaDoc ACTION_CORRECT_INPUT = "correct";
79     
80     /** Request parameter value for the form action parameter: form submitted. */
81     public static final String JavaDoc ACTION_SUBMIT = "submit";
82
83     /** Form error: mandatory field not filled out. */
84     public static final String JavaDoc ERROR_MANDATORY = "mandatory";
85     
86     /** Form error: validation error of input. */
87     public static final String JavaDoc ERROR_VALIDATION = "validation";
88
89     /** Request parameter name for the hidden form action parameter to determine the action. */
90     public static final String JavaDoc PARAM_FORMACTION = "formaction";
91
92     /** The log object for this class. */
93     private static final Log LOG = CmsLog.getLog(CmsFormHandler.class);
94
95     /** Contains eventual validation errors. */
96     private Map JavaDoc m_errors;
97
98     /** The form configuration object. */
99     private CmsForm m_formConfiguration;
100
101     /** Temporarily stores the fields as hidden fields in the String. */
102     private String JavaDoc m_hiddenFields;
103
104     /** Flag indicating if the form is displayed for the first time. */
105     private boolean m_initial;
106
107     /** The localized messages for the form handler. */
108     private CmsMessages m_messages;
109     
110     private Boolean JavaDoc m_isValidatedCorrect;
111
112     /**
113      * Constructor, creates the necessary form configuration objects.<p>
114      *
115      * @param context the JSP page context object
116      * @param req the JSP request
117      * @param res the JSP response
118      * @throws Exception if creating the form configuration objects fails
119      */

120     public CmsFormHandler(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res)
121     throws Exception JavaDoc {
122
123         super(context, req, res);
124         init(req, null);
125     }
126
127     /**
128      * Constructor, creates the necessary form configuration objects using a given configuration file URI.<p>
129      *
130      * @param context the JSP page context object
131      * @param req the JSP request
132      * @param res the JSP response
133      * @param formConfigUri URI of the form configuration file, if not provided, current URI is used for configuration
134      * @throws Exception if creating the form configuration objects fails
135      */

136     public CmsFormHandler(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res, String JavaDoc formConfigUri)
137     throws Exception JavaDoc {
138
139         super(context, req, res);
140         init(req, formConfigUri);
141     }
142
143     /**
144      * Replaces line breaks with html &lt;br&gt;.<p>
145      *
146      * @param value the value to substitute
147      * @return the substituted value
148      */

149     public String JavaDoc convertToHtmlValue(String JavaDoc value) {
150
151         return convertValue(value, "html");
152     }
153
154     /**
155      * Replaces html &lt;br&gt; with line breaks.<p>
156      *
157      * @param value the value to substitute
158      * @return the substituted value
159      */

160     public String JavaDoc convertToPlainValue(String JavaDoc value) {
161
162         return convertValue(value, "");
163     }
164
165     /**
166      * Converts a given String value to the desired output format.<p>
167      *
168      * The following output formats are possible:
169      * <ul>
170      * <li>"html" meaning that &lt;br&gt; tags are added</li>
171      * <li>"plain" or any other String value meaning that &lt;br&gt; tags are removed</li>
172      * </ul>
173      *
174      * @param value the String value to convert
175      * @param outputType the type of the resulting output
176      * @return the converted String in the desired output format
177      */

178     public String JavaDoc convertValue(String JavaDoc value, String JavaDoc outputType) {
179
180         if ("html".equalsIgnoreCase(outputType)) {
181             // output should be html, add line break tags and characters
182
value = CmsStringUtil.escapeHtml(value);
183         } else {
184             // output should be plain, remove html line break tags and characters
185
value = CmsStringUtil.substitute(value, "<br>", "\n");
186         }
187         return value;
188     }
189
190     /**
191      * Returns the configured form field values as hidden input fields.<p>
192      *
193      * @return the configured form field values as hidden input fields
194      */

195     public String JavaDoc createHiddenFields() {
196
197         if (CmsStringUtil.isEmpty(m_hiddenFields)) {
198             List JavaDoc fields = getFormConfiguration().getFields();
199             StringBuffer JavaDoc result = new StringBuffer JavaDoc(fields.size() * 8);
200             // iterate the form fields
201
for (int i = 0, n = fields.size(); i < n; i++) {
202                 
203                 I_CmsField currentField = (I_CmsField)fields.get(i);
204                 
205                 if (currentField == null) {
206                     continue;
207                 } else if (CmsCheckboxField.class.isAssignableFrom(currentField.getClass())) {
208                     // special case: checkbox, can have more than one value
209
Iterator JavaDoc k = currentField.getItems().iterator();
210                     while (k.hasNext()) {
211                         CmsFieldItem item = (CmsFieldItem)k.next();
212                         if (item.isSelected()) {
213                             result.append("<input type=\"hidden\" name=\"");
214                             result.append(currentField.getName());
215                             result.append("\" value=\"");
216                             result.append(CmsEncoder.escapeXml(item.getValue()));
217                             result.append("\">\n");
218                         }
219                     }
220                 } else if (CmsStringUtil.isNotEmpty(currentField.getValue())) {
221                     // all other fields are converted to a simple hidden field
222
result.append("<input type=\"hidden\" name=\"");
223                     result.append(currentField.getName());
224                     result.append("\" value=\"");
225                     result.append(CmsEncoder.escapeXml(currentField.getValue()));
226                     result.append("\">\n");
227                 }
228
229             }
230             // store the generated input fields for further usage to avoid unnecessary rebuilding
231
m_hiddenFields = result.toString();
232         }
233         // return generated result list
234
return m_hiddenFields;
235     }
236
237     /**
238      * Returns the errors found when validating the form.<p>
239      *
240      * @return the errors found when validating the form
241      */

242     public Map JavaDoc getErrors() {
243
244         return m_errors;
245     }
246
247     /**
248      * Returns the form configuration.<p>
249      *
250      * @return the form configuration
251      */

252     public CmsForm getFormConfiguration() {
253
254         return m_formConfiguration;
255     }
256
257     /**
258      * Returns the localized messages.<p>
259      *
260      * @return the localized messages
261      */

262     public CmsMessages getMessages() {
263
264         return m_messages;
265     }
266
267     /**
268      * Returns if the submitted values contain validation errors.<p>
269      *
270      * @return true if the submitted values contain validation errors, otherwise false
271      */

272     public boolean hasValidationErrors() {
273
274         return (!isInitial() && getErrors().size() > 0);
275     }
276
277     /**
278      * Initializes the form handler and creates the necessary configuration objects.<p>
279      *
280      * @param req the JSP request
281      * @param formConfigUri URI of the form configuration file, if not provided, current URI is used for configuration
282      * @throws Exception if creating the form configuration objects fails
283      */

284     public void init(HttpServletRequest JavaDoc req, String JavaDoc formConfigUri) throws Exception JavaDoc {
285
286         String JavaDoc formAction = req.getParameter(PARAM_FORMACTION);
287         
288         setErrors(new HashMap JavaDoc());
289         m_isValidatedCorrect = null;
290         setInitial(CmsStringUtil.isEmpty(formAction));
291         // get the localized messages
292
setMessages(new CmsMessages("/org/opencms/frontend/templateone/form/workplace", getRequestContext().getLocale()));
293         // get the form configuration
294
setFormConfiguration(new CmsForm(this, getMessages(), isInitial(), formConfigUri, formAction));
295     }
296
297     /**
298      * Returns if the form is displayed for the first time.<p>
299      *
300      * @return true if the form is displayed for the first time, otherwise false
301      */

302     public boolean isInitial() {
303
304         return m_initial;
305     }
306
307     /**
308      * Sends the confirmation mail with the form data to the specified email address.<p>
309      *
310      * @throws Exception if sending the confirmation mail fails
311      */

312     public void sendConfirmationMail() throws Exception JavaDoc {
313
314         // get the field which contains the confirmation email address
315
I_CmsField mailField = (I_CmsField)getFormConfiguration().getFields().get(
316             getFormConfiguration().getConfirmationMailField());
317         String JavaDoc mailTo = mailField.getValue();
318
319         // create the new confirmation mail message depending on the configured email type
320
if (getFormConfiguration().getMailType().equals(CmsForm.MAILTYPE_HTML)) {
321             // create a HTML email
322
CmsHtmlMail theMail = new CmsHtmlMail();
323             theMail.setCharset(getCmsObject().getRequestContext().getEncoding());
324             if (CmsStringUtil.isNotEmpty(getFormConfiguration().getMailFrom())) {
325                 theMail.setFrom(getFormConfiguration().getMailFrom());
326             }
327             theMail.setTo(createInternetAddresses(mailTo));
328             theMail.setSubject(getFormConfiguration().getMailSubjectPrefix()
329                 + getFormConfiguration().getConfirmationMailSubject());
330             theMail.setHtmlMsg(createMailTextFromFields(true, true));
331             theMail.setTextMsg(createMailTextFromFields(false, true));
332             // send the mail
333
theMail.send();
334         } else {
335             // create a plain text email
336
CmsSimpleMail theMail = new CmsSimpleMail();
337             theMail.setCharset(getCmsObject().getRequestContext().getEncoding());
338             if (CmsStringUtil.isNotEmpty(getFormConfiguration().getMailFrom())) {
339                 theMail.setFrom(getFormConfiguration().getMailFrom());
340             }
341             theMail.setTo(createInternetAddresses(mailTo));
342             theMail.setSubject(getFormConfiguration().getMailSubjectPrefix()
343                 + getFormConfiguration().getConfirmationMailSubject());
344             theMail.setMsg(createMailTextFromFields(false, true));
345             // send the mail
346
theMail.send();
347         }
348     }
349
350     /**
351      * Sends the mail with the form data to the specified recipients.<p>
352      *
353      * If configured, sends also a confirmation mail to the form submitter.<p>
354      *
355      * @return true if the mail has been successfully sent, otherwise false
356      */

357     public boolean sendMail() {
358
359         try {
360             // send optional confirmation mail
361
if (getFormConfiguration().isConfirmationMailEnabled()) {
362                 if (!getFormConfiguration().isConfirmationMailOptional()
363                     || Boolean.valueOf(getRequest().getParameter(CmsForm.PARAM_SENDCONFIRMATION)).booleanValue()) {
364                     sendConfirmationMail();
365                 }
366             }
367             // create the new mail message depending on the configured email type
368
if (getFormConfiguration().getMailType().equals(CmsForm.MAILTYPE_HTML)) {
369                 // create a HTML email
370
CmsHtmlMail theMail = new CmsHtmlMail();
371                 theMail.setCharset(getCmsObject().getRequestContext().getEncoding());
372                 if (CmsStringUtil.isNotEmpty(getFormConfiguration().getMailFrom())) {
373                     theMail.setFrom(getFormConfiguration().getMailFrom());
374                 }
375                 theMail.setTo(createInternetAddresses(getFormConfiguration().getMailTo()));
376                 theMail.setCc(createInternetAddresses(getFormConfiguration().getMailCC()));
377                 theMail.setBcc(createInternetAddresses(getFormConfiguration().getMailBCC()));
378                 theMail.setSubject(getFormConfiguration().getMailSubjectPrefix()
379                     + getFormConfiguration().getMailSubject());
380                 theMail.setHtmlMsg(createMailTextFromFields(true, false));
381                 theMail.setTextMsg(createMailTextFromFields(false, false));
382                 // send the mail
383
theMail.send();
384             } else {
385                 // create a plain text email
386
CmsSimpleMail theMail = new CmsSimpleMail();
387                 theMail.setCharset(getCmsObject().getRequestContext().getEncoding());
388                 if (CmsStringUtil.isNotEmpty(getFormConfiguration().getMailFrom())) {
389                     theMail.setFrom(getFormConfiguration().getMailFrom());
390                 }
391                 theMail.setTo(createInternetAddresses(getFormConfiguration().getMailTo()));
392                 theMail.setCc(createInternetAddresses(getFormConfiguration().getMailCC()));
393                 theMail.setBcc(createInternetAddresses(getFormConfiguration().getMailBCC()));
394                 theMail.setSubject(getFormConfiguration().getMailSubjectPrefix()
395                     + getFormConfiguration().getMailSubject());
396                 theMail.setMsg(createMailTextFromFields(false, false));
397                 // send the mail
398
theMail.send();
399             }
400         } catch (Exception JavaDoc e) {
401             // an error occured during mail creation
402
if (LOG.isErrorEnabled()) {
403                 LOG.error(e);
404             }
405             m_errors.put("sendmail", e.getMessage());
406             return false;
407         }
408         return true;
409     }
410
411     /**
412      * Returns if the optional check page should be displayed.<p>
413      *
414      * @return true if the optional check page should be displayed, otherwise false
415      */

416     public boolean showCheck() {
417         
418         boolean result = false;
419         
420         if (getFormConfiguration().getShowCheck() && ACTION_SUBMIT.equals(getRequest().getParameter(PARAM_FORMACTION))) {
421             result = true;
422         } else if (getFormConfiguration().captchaFieldIsOnCheckPage() && ACTION_CONFIRMED.equals(getRequest().getParameter(PARAM_FORMACTION)) && !validate()) {
423             result = true;
424         }
425         
426         return result;
427     }
428
429     /**
430      * Returns if the input form should be displayed.<p>
431      *
432      * @return true if the input form should be displayed, otherwise false
433      */

434     public boolean showForm() {
435
436         boolean result = false;
437         
438         if (isInitial()) {
439             // inital call
440
result = true;
441         } else if (ACTION_CORRECT_INPUT.equalsIgnoreCase(getRequest().getParameter(PARAM_FORMACTION))) {
442             // user decided to modify his inputs
443
result = true;
444         } else if (ACTION_SUBMIT.equalsIgnoreCase(getRequest().getParameter(PARAM_FORMACTION)) && !validate()) {
445             // input field validation failed
446
result = true;
447             
448             if (getFormConfiguration().hasCaptchaField() && getFormConfiguration().captchaFieldIsOnCheckPage()) {
449                 // if there is a captcha field and a check page configured, we do have to remove the already
450
// initialized captcha field from the form again. the captcha field gets initialized together with
451
// the form, in this moment it is not clear yet whether we have validation errors or and need to
452
// to go back to the input form...
453
getFormConfiguration().removeCaptchaField();
454             }
455         } else if (ACTION_CONFIRMED.equalsIgnoreCase(getRequest().getParameter(PARAM_FORMACTION)) && getFormConfiguration().captchaFieldIsOnCheckPage() && !validate()) {
456             // captcha field validation on check page failed- redisplay the check page, not the input page!
457
result = false;
458         }
459         
460         return result;
461     }
462
463     /**
464      * Validation method that checks the given input fields.<p>
465      *
466      * All errors are stored in the member m_errors Map, with the input field name as key
467      * and the error message String as value.<p>
468      *
469      * @return true if all neccessary fields can be validated, otherwise false
470      */

471     public boolean validate() {
472         
473         if (m_isValidatedCorrect != null) {
474             return m_isValidatedCorrect.booleanValue();
475         }
476
477         boolean allOk = true;
478         // iterate the form fields
479
List JavaDoc fields = getFormConfiguration().getFields();
480
481         // validate each form field
482
for (int i = 0, n = fields.size(); i < n; i++) {
483             
484             I_CmsField currentField = (I_CmsField)fields.get(i);
485             
486             if (currentField == null) {
487                 continue;
488             }
489             
490             if (CmsCaptchaField.class.isAssignableFrom(currentField.getClass())) {
491                 // the captcha field doesn't get validated here...
492
continue;
493             }
494             
495             String JavaDoc validationError = currentField.validate(this);
496             if (CmsStringUtil.isNotEmpty(validationError)) {
497                 getErrors().put(currentField.getName(), validationError);
498                 allOk = false;
499             }
500         }
501                 
502         CmsCaptchaField captchaField = m_formConfiguration.getCaptchaField();
503         if (captchaField != null) {
504             
505             boolean captchaFieldIsOnInputPage = getFormConfiguration().captchaFieldIsOnInputPage() && getFormConfiguration().isInputFormSubmitted();
506             boolean captchaFieldIsOnCheckPage = getFormConfiguration().captchaFieldIsOnCheckPage() && getFormConfiguration().isCheckPageSubmitted();
507
508             if (captchaFieldIsOnInputPage || captchaFieldIsOnCheckPage) {
509                 if (!captchaField.validateCaptchaPhrase(this, captchaField.getValue())) {
510                     getErrors().put(captchaField.getName(), ERROR_VALIDATION);
511                     allOk = false;
512                 }
513             }
514         }
515         
516         m_isValidatedCorrect = new Boolean JavaDoc(allOk);
517         return allOk;
518     }
519
520     /**
521      * Creates a list of internet addresses (email) from a semicolon separated String.<p>
522      *
523      * @param mailAddresses a semicolon separated String with email addresses
524      * @return list of internet addresses (email)
525      * @throws AddressException if an email address is not correct
526      */

527     protected List JavaDoc createInternetAddresses(String JavaDoc mailAddresses) throws AddressException JavaDoc {
528
529         if (CmsStringUtil.isNotEmpty(mailAddresses)) {
530             // at least one email address is present, generate list
531
StringTokenizer JavaDoc T = new StringTokenizer JavaDoc(mailAddresses, ";");
532             List JavaDoc addresses = new ArrayList JavaDoc(T.countTokens());
533             while (T.hasMoreTokens()) {
534                 InternetAddress JavaDoc address = new InternetAddress JavaDoc(T.nextToken());
535                 addresses.add(address);
536             }
537             return addresses;
538         } else {
539             // no address given, return empty list
540
return Collections.EMPTY_LIST;
541         }
542     }
543
544     /**
545      * Creates the output String of the submitted fields for email creation.<p>
546      *
547      * @param isHtmlMail if true, the output is formatted as HTML, otherwise as plain text
548      * @param isConfirmationMail if true, the text for the confirmation mail is created, otherwise the text for mail receiver
549      * @return the output String of the submitted fields for email creation
550      */

551     protected String JavaDoc createMailTextFromFields(boolean isHtmlMail, boolean isConfirmationMail) {
552
553         List JavaDoc fieldValues = getFormConfiguration().getFields();
554         StringBuffer JavaDoc result = new StringBuffer JavaDoc(fieldValues.size() * 8);
555         if (isHtmlMail) {
556             // create html head with style definitions and body
557
result.append("<html><head>\n");
558             result.append("<style type=\"text/css\"><!--\n");
559             String JavaDoc style = getMessages().key("form.email.style.body");
560             if (CmsStringUtil.isNotEmpty(style)) {
561                 result.append("body,h1,p,td { ");
562                 result.append(style);
563                 result.append(" }\n");
564             }
565             style = getMessages().key("form.email.style.h1");
566             if (CmsStringUtil.isNotEmpty(style)) {
567                 result.append("h1 { ");
568                 result.append(style);
569                 result.append(" }\n");
570             }
571             style = getMessages().key("form.email.style.p");
572             if (CmsStringUtil.isNotEmpty(style)) {
573                 result.append("p { ");
574                 result.append(style);
575                 result.append(" }\n");
576             }
577             style = getMessages().key("form.email.style.fields");
578             if (CmsStringUtil.isNotEmpty(style)) {
579                 result.append("table.fields { ");
580                 result.append(style);
581                 result.append(" }\n");
582             }
583             style = getMessages().key("form.email.style.fieldlabel");
584             if (CmsStringUtil.isNotEmpty(style)) {
585                 result.append("td.fieldlabel { ");
586                 result.append(style);
587                 result.append(" }\n");
588             }
589             style = getMessages().key("form.email.style.fieldvalue");
590             if (CmsStringUtil.isNotEmpty(style)) {
591                 result.append("td.fieldvalue { ");
592                 result.append(style);
593                 result.append(" }\n");
594             }
595             style = getMessages().key("form.email.style.misc");
596             if (CmsStringUtil.isNotEmpty(style)) {
597                 result.append(getMessages().key("form.email.style.misc"));
598             }
599             result.append("//--></style>\n");
600             result.append("</head><body>\n");
601             if (isConfirmationMail) {
602                 // append the confirmation mail text
603
result.append(getFormConfiguration().getConfirmationMailText());
604             } else {
605                 // append the email text
606
result.append(getFormConfiguration().getMailText());
607             }
608             result.append("<table border=\"0\" class=\"fields\">\n");
609         } else {
610             // generate simple text mail
611
if (isConfirmationMail) {
612                 // append the confirmation mail text
613
result.append(getFormConfiguration().getConfirmationMailTextPlain());
614             } else {
615                 // append the email text
616
result.append(getFormConfiguration().getMailTextPlain());
617             }
618             result.append("\n\n");
619         }
620         // generate output for submitted form fields
621
Iterator JavaDoc i = fieldValues.iterator();
622         while (i.hasNext()) {
623             I_CmsField current = (I_CmsField)i.next();
624             if (isHtmlMail) {
625                 // format output as HTML
626
result.append("<tr><td class=\"fieldlabel\">");
627                 result.append(current.getLabel());
628                 result.append("</td><td class=\"fieldvalue\">");
629                 result.append(convertToHtmlValue(current.toString()));
630                 result.append("</td></tr>\n");
631             } else {
632                 // format output as plain text
633
result.append(current.getLabel());
634                 result.append("\t");
635                 result.append(current.toString());
636                 result.append("\n");
637             }
638         }
639         if (isHtmlMail) {
640             // create html table closing tag
641
result.append("</table>\n");
642             if (!isConfirmationMail && getFormConfiguration().hasConfigurationErrors()) {
643                 // write form configuration errors to html mail
644
result.append("<h1>");
645                 result.append(getMessages().key("form.configuration.error.headline"));
646                 result.append("</h1>\n<p>");
647                 for (int k = 0; k < getFormConfiguration().getConfigurationErrors().size(); k++) {
648                     result.append(getFormConfiguration().getConfigurationErrors().get(k));
649                     result.append("<br>");
650                 }
651                 result.append("</p>\n");
652             }
653             // create body and html closing tags
654
result.append("</body></html>");
655         } else if (!isConfirmationMail && getFormConfiguration().hasConfigurationErrors()) {
656             // write form configuration errors to text mail
657
result.append("\n");
658             result.append(getMessages().key("form.configuration.error.headline"));
659             result.append("\n");
660             for (int k = 0; k < getFormConfiguration().getConfigurationErrors().size(); k++) {
661                 result.append(getFormConfiguration().getConfigurationErrors().get(k));
662                 result.append("\n");
663             }
664         }
665
666         return result.toString();
667     }
668
669     /**
670      * Sets the errors found when validating the form.<p>
671      *
672      * @param errors the errors found when validating the form
673      */

674     protected void setErrors(Map JavaDoc errors) {
675
676         m_errors = errors;
677     }
678
679     /**
680      * Sets the form configuration.<p>
681      *
682      * @param configuration the form configuration
683      */

684     protected void setFormConfiguration(CmsForm configuration) {
685
686         m_formConfiguration = configuration;
687     }
688
689     /**
690      * Sets if the form is displayed for the first time.<p>
691      * @param initial true if the form is displayed for the first time, otherwise false
692      */

693     protected void setInitial(boolean initial) {
694
695         m_initial = initial;
696     }
697
698     /**
699      * Sets the localized messages.<p>
700      *
701      * @param messages the localized messages
702      */

703     protected void setMessages(CmsMessages messages) {
704
705         m_messages = messages;
706     }
707
708 }
709
Popular Tags