KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/frontend/templateone/form/CmsForm.java,v $
3  * Date : $Date: 2006/03/27 14:52:20 $
4  * Version: $Revision: 1.27 $
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.configuration.CmsConfigurationException;
35 import org.opencms.file.CmsFile;
36 import org.opencms.file.CmsObject;
37 import org.opencms.i18n.CmsMessages;
38 import org.opencms.jsp.CmsJspActionElement;
39 import org.opencms.util.CmsMacroResolver;
40 import org.opencms.util.CmsStringUtil;
41 import org.opencms.xml.content.CmsXmlContent;
42 import org.opencms.xml.content.CmsXmlContentFactory;
43 import org.opencms.xml.types.CmsXmlHtmlValue;
44 import org.opencms.xml.types.I_CmsXmlContentValue;
45
46 import java.util.ArrayList JavaDoc;
47 import java.util.HashMap JavaDoc;
48 import java.util.List JavaDoc;
49 import java.util.Locale JavaDoc;
50 import java.util.Map JavaDoc;
51 import java.util.StringTokenizer JavaDoc;
52
53 import javax.servlet.http.HttpServletRequest JavaDoc;
54
55 /**
56  * Represents an input form with all configured fields and options.<p>
57  *
58  * Provides the necessary information to create an input form, email messages and confirmation outputs.<p>
59  *
60  * @author Andreas Zahner
61  * @author Thomas Weckert
62  * @author Jan Baudisch
63  *
64  * @version $Revision: 1.27 $
65  *
66  * @since 6.0.0
67  */

68 public class CmsForm {
69     
70     /** Mail type: html mail. */
71     public static final String JavaDoc MAILTYPE_HTML = "html";
72
73     /** Mail type: text mail. */
74     public static final String JavaDoc MAILTYPE_TEXT = "text";
75     
76     /** Configuration node name for the optional captcha. */
77     public static final String JavaDoc NODE_CAPTCHA = "FormCaptcha";
78
79     /** Configuration node name for the confirmation mail checkbox label text. */
80     public static final String JavaDoc NODE_CONFIRMATIONMAILCHECKBOXLABEL = "ConfirmationCheckboxLabel";
81     
82     /** Configuration node name for the confirmation mail enabled node. */
83     public static final String JavaDoc NODE_CONFIRMATIONMAILENABLED = "ConfirmationMailEnabled";
84
85     /** Configuration node name for the confirmation mail input field node. */
86     public static final String JavaDoc NODE_CONFIRMATIONMAILFIELD = "ConfirmationField";
87     
88     /** Configuration node name for the confirmation mail optional flag node. */
89     public static final String JavaDoc NODE_CONFIRMATIONMAILOPTIONAL = "ConfirmationMailOptional";
90     
91     /** Configuration node name for the confirmation mail subject node. */
92     public static final String JavaDoc NODE_CONFIRMATIONMAILSUBJECT = "ConfirmationMailSubject";
93     
94     /** Configuration node name for the confirmation mail text node. */
95     public static final String JavaDoc NODE_CONFIRMATIONMAILTEXT = "ConfirmationMailText";
96     
97     /** Configuration node name for the Email node. */
98     public static final String JavaDoc NODE_EMAIL = "Email";
99
100     /** Configuration node name for the field value node. */
101     public static final String JavaDoc NODE_FIELDDEFAULTVALUE = "FieldDefault";
102     
103     /** Configuration node name for the field error message node. */
104     public static final String JavaDoc NODE_FIELDERRORMESSAGE = "FieldErrorMessage";
105     
106     /** Configuration node name for the field item node. */
107     public static final String JavaDoc NODE_FIELDITEM = "FieldItem";
108     
109     /** Configuration node name for the field description node. */
110     public static final String JavaDoc NODE_FIELDLABEL = "FieldLabel";
111     
112     /** Configuration node name for the field mandatory node. */
113     public static final String JavaDoc NODE_FIELDMANDATORY = "FieldMandatory";
114
115     /** Configuration node name for the field type node. */
116     public static final String JavaDoc NODE_FIELDTYPE = "FieldType";
117
118     /** Configuration node name for the field validation node. */
119     public static final String JavaDoc NODE_FIELDVALIDATION = "FieldValidation";
120     
121     /** Configuration node name for the form attributes node. */
122     public static final String JavaDoc NODE_FORMATTRIBUTES = "FormAttributes";
123     
124     /** Configuration node name for the form check page text node. */
125     public static final String JavaDoc NODE_FORMCHECKTEXT = "CheckText";
126
127     /** Configuration node name for the form confirmation text node. */
128     public static final String JavaDoc NODE_FORMCONFIRMATION = "FormConfirmation";
129     
130     /** Configuration node name for the form field attributes node. */
131     public static final String JavaDoc NODE_FORMFIELDATTRIBUTES = "FormFieldAttributes";
132     
133     /** Configuration node name for the form text node. */
134     public static final String JavaDoc NODE_FORMTEXT = "FormText";
135     
136     /** Configuration node name for the input field node. */
137     public static final String JavaDoc NODE_INPUTFIELD = "InputField";
138     
139     /** Configuration node name for the item description node. */
140     public static final String JavaDoc NODE_ITEMDESCRIPTION = "ItemDescription";
141     
142     /** Configuration node name for the item selected node. */
143     public static final String JavaDoc NODE_ITEMSELECTED = "ItemSelected";
144     
145     /** Configuration node name for the item value node. */
146     public static final String JavaDoc NODE_ITEMVALUE = "ItemValue";
147     
148     /** Configuration node name for the Email bcc recipient(s) node. */
149     public static final String JavaDoc NODE_MAILBCC = "MailBCC";
150     
151     /** Configuration node name for the Email cc recipient(s) node. */
152     public static final String JavaDoc NODE_MAILCC = "MailCC";
153     
154     /** Configuration node name for the Email sender address node. */
155     public static final String JavaDoc NODE_MAILFROM = "MailFrom";
156
157     /** Configuration node name for the Email subject node. */
158     public static final String JavaDoc NODE_MAILSUBJECT = "MailSubject";
159     
160     /** Configuration node name for the Email text node. */
161     public static final String JavaDoc NODE_MAILTEXT = "MailText";
162     
163     /** Configuration node name for the Email recipient(s) node. */
164     public static final String JavaDoc NODE_MAILTO = "MailTo";
165     
166     /** Configuration node name for the Email type node. */
167     public static final String JavaDoc NODE_MAILTYPE = "MailType";
168     
169     /** Configuration node name for the optional form configuration. */
170     public static final String JavaDoc NODE_OPTIONALCONFIGURATION = "OptionalFormConfiguration";
171     
172     /** Configuration node name for the optional confirmation mail configuration. */
173     public static final String JavaDoc NODE_OPTIONALCONFIRMATION = "OptionalConfirmationMail";
174     
175     /** Configuration node name for the Show check page node. */
176     public static final String JavaDoc NODE_SHOWCHECK = "ShowCheck";
177     
178     /** Configuration node name for the optional target URI. */
179     public static final String JavaDoc NODE_TARGET_URI = "TargetUri";
180     
181     /** Request parameter name for the optional send confirmation email checkbox. */
182     public static final String JavaDoc PARAM_SENDCONFIRMATION = "sendconfirmation";
183     
184     /** Resource type ID of XML content forms. */
185     private static final String JavaDoc TYPE_NAME = "emailform";
186
187     private CmsCaptchaField m_captchaField;
188
189     private List JavaDoc m_configurationErrors;
190     private String JavaDoc m_confirmationMailCheckboxLabel;
191     private boolean m_confirmationMailEnabled;
192     private int m_confirmationMailField;
193     private boolean m_confirmationMailOptional;
194     private String JavaDoc m_confirmationMailSubject;
195     private String JavaDoc m_confirmationMailText;
196
197     private String JavaDoc m_confirmationMailTextPlain;
198     
199     /** Stores the form input fields. */
200     private List JavaDoc m_fields;
201
202     /** Allows to access form fields internally by name. */
203     private Map JavaDoc m_fieldsByName;
204     private String JavaDoc m_formAction;
205     private String JavaDoc m_formAttributes;
206     private String JavaDoc m_formCheckText;
207     private String JavaDoc m_formConfirmationText;
208     private String JavaDoc m_formFieldAttributes;
209
210     private String JavaDoc m_formText;
211
212     private boolean m_hasMandatoryFields;
213     private String JavaDoc m_mailBCC;
214     private String JavaDoc m_mailCC;
215     private String JavaDoc m_mailFrom;
216     private String JavaDoc m_mailSubject;
217     private String JavaDoc m_mailSubjectPrefix;
218     private String JavaDoc m_mailText;
219     private String JavaDoc m_mailTextPlain;
220     private String JavaDoc m_mailTo;
221
222     private String JavaDoc m_mailType;
223     
224     private boolean m_showCheck;
225     private String JavaDoc m_targetUri;
226
227     /** Configuration node name for the optional captcha. */
228     public static final String JavaDoc NODE_CAPTCHA_PRESET = "Preset";
229
230     /** Configuration node name for the optional captcha. */
231     public static final String JavaDoc NODE_CAPTCHA_CHARACTERS = "Characters";
232
233     /**
234      * Default constructor which parses the configuration file.<p>
235      *
236      * @param jsp the initialized CmsJspActionElement to access the OpenCms API
237      * @param messages the localized messages
238      * @param initial if true, field values are filled with values specified in the configuration file, otherwise from the request
239      * @throws Exception if parsing the configuration fails
240      */

241     public CmsForm(CmsJspActionElement jsp, CmsMessages messages, boolean initial)
242     throws Exception JavaDoc {
243
244         init(jsp, messages, initial, null, null);
245     }
246
247     /**
248      * Constructor which parses the configuration file using a given configuration file URI.<p>
249      *
250      * @param jsp the initialized CmsJspActionElement to access the OpenCms API
251      * @param messages the localized messages
252      * @param initial if true, field values are filled with values specified in the configuration file, otherwise from the request
253      * @param formConfigUri URI of the form configuration file, if not provided, current URI is used for configuration
254      * @param formAction the desired action submiktted by the form
255      *
256      * @throws Exception if parsing the configuration fails
257      */

258     public CmsForm(CmsJspActionElement jsp, CmsMessages messages, boolean initial, String JavaDoc formConfigUri, String JavaDoc formAction)
259     throws Exception JavaDoc {
260
261         init(jsp, messages, initial, formConfigUri, formAction);
262     }
263     
264     /**
265      * Returns the resource type name of XML content forms.<p>
266      *
267      * @return the resource type name of XML content forms
268      */

269     public static String JavaDoc getStaticType() {
270         return TYPE_NAME;
271     }
272
273     /**
274      * Tests, if the captcha field (if configured at all) should be displayed on the check page.<p>
275      *
276      * @return true, if the captcha field should be displayed on the check page
277      */

278     public boolean captchaFieldIsOnCheckPage() {
279         return getShowCheck();
280     }
281
282     /**
283      * Tests, if the captcha field (if configured at all) should be displayed on the input page.<p>
284      *
285      * @return true, if the captcha field should be displayed on the input page
286      */

287     public boolean captchaFieldIsOnInputPage() {
288         return !getShowCheck();
289     }
290
291     /**
292      * Returns the (opt.) captcha field of this form.<p>
293      *
294      * @return the (opt.) captcha field of this form
295      */

296     public CmsCaptchaField getCaptchaField() {
297         
298         return m_captchaField;
299     }
300
301     /**
302      * Returns the form configuration errors.<p>
303      *
304      * @return the form configuration errors
305      */

306     public List JavaDoc getConfigurationErrors() {
307
308         return m_configurationErrors;
309     }
310
311     /**
312      * Returns the label for the optional confirmation mail checkbox on the input form.<p>
313      *
314      * @return the label for the optional confirmation mail checkbox on the input form
315      */

316     public String JavaDoc getConfirmationMailCheckboxLabel() {
317
318         return m_confirmationMailCheckboxLabel;
319     }
320
321     /**
322      * Returns the index number of the input field containing the email address for the optional confirmation mail.<p>
323      *
324      * @return the index number of the input field containing the email address for the optional confirmation mail
325      */

326     public int getConfirmationMailField() {
327
328         return m_confirmationMailField;
329     }
330
331     /**
332      * Returns the subject of the optional confirmation mail.<p>
333      *
334      * @return the subject of the optional confirmation mail
335      */

336     public String JavaDoc getConfirmationMailSubject() {
337
338         return m_confirmationMailSubject;
339     }
340
341     /**
342      * Returns the text of the optional confirmation mail.<p>
343      *
344      * @return the text of the optional confirmation mail
345      */

346     public String JavaDoc getConfirmationMailText() {
347
348         return m_confirmationMailText;
349     }
350
351     /**
352      * Returns the plain text of the optional confirmation mail.<p>
353      *
354      * @return the plain text of the optional confirmation mail
355      */

356     public String JavaDoc getConfirmationMailTextPlain() {
357
358         return m_confirmationMailTextPlain;
359     }
360
361     /**
362      * Returns a list of field objects for the online form.<p>
363      *
364      * @return a list of field objects for the online form
365      */

366     public List JavaDoc getFields() {
367
368         return m_fields;
369     }
370
371     /**
372      * Returns the value for a field specified by it's name (Xpath).<p>
373      *
374      * @param fieldName the field's name (Xpath)
375      * @return the field value, or null
376      */

377     public String JavaDoc getFieldStringValueByName(String JavaDoc fieldName) {
378         
379         I_CmsField field = (I_CmsField)m_fieldsByName.get(fieldName);
380         if (field != null) {
381             
382             String JavaDoc fieldValue = field.getValue();
383             return (fieldValue != null) ? fieldValue.trim() : "";
384         }
385         
386         return "";
387     }
388
389     /**
390      * Returns the global form attributes.<p>
391      *
392      * @return the global form attributes
393      */

394     public String JavaDoc getFormAttributes() {
395
396         return m_formAttributes;
397     }
398
399     /**
400      * Returns the form check text.<p>
401      *
402      * @return the form check text
403      */

404     public String JavaDoc getFormCheckText() {
405
406         return m_formCheckText;
407     }
408
409     /**
410      * Returns the form confirmation text.<p>
411      *
412      * @return the form confirmation text
413      */

414     public String JavaDoc getFormConfirmationText() {
415
416         return m_formConfirmationText;
417     }
418
419     /**
420      * Returns the optional form input field attributes.<p>
421      *
422      * @return the optional form input field attributes
423      */

424     public String JavaDoc getFormFieldAttributes() {
425
426         return m_formFieldAttributes;
427     }
428
429     /**
430      * Returns the form text.<p>
431      *
432      * @return the form text
433      */

434     public String JavaDoc getFormText() {
435
436         return m_formText;
437     }
438
439     /**
440      * Returns the mail bcc recipient(s).<p>
441      *
442      * @return the mail bcc recipient(s)
443      */

444     public String JavaDoc getMailBCC() {
445
446         return m_mailBCC;
447     }
448
449     /**
450      * Returns the mail cc recipient(s).<p>
451      *
452      * @return the mail cc recipient(s)
453      */

454     public String JavaDoc getMailCC() {
455
456         return m_mailCC;
457     }
458
459     /**
460      * Returns the mail sender address.<p>
461      *
462      * @return the mail sender address
463      */

464     public String JavaDoc getMailFrom() {
465
466         return m_mailFrom;
467     }
468
469     /**
470      * Returns the mail subject.<p>
471      *
472      * @return the mail subject
473      */

474     public String JavaDoc getMailSubject() {
475
476         return m_mailSubject;
477     }
478
479     /**
480      * Returns the mail subject prefix.<p>
481      *
482      * @return the mail subject prefix
483      */

484     public String JavaDoc getMailSubjectPrefix() {
485
486         return m_mailSubjectPrefix;
487     }
488
489     /**
490      * Returns the mail text.<p>
491      *
492      * @return the mail text
493      */

494     public String JavaDoc getMailText() {
495
496         return m_mailText;
497     }
498
499     /**
500      * Returns the mail text as plain text.<p>
501      *
502      * @return the mail text as plain text
503      */

504     public String JavaDoc getMailTextPlain() {
505
506         return m_mailTextPlain;
507     }
508
509     /**
510      * Returns the mail recipient(s).<p>
511      *
512      * @return the mail recipient(s)
513      */

514     public String JavaDoc getMailTo() {
515
516         return m_mailTo;
517     }
518
519     /**
520      * Returns the mail type ("text" or "html").<p>
521      *
522      * @return the mail type
523      */

524     public String JavaDoc getMailType() {
525
526         return m_mailType;
527     }
528
529     /**
530      * Returns if the check page should be shown.<p>
531      *
532      * @return true if the check page should be shown, otherwise false
533      */

534     public boolean getShowCheck() {
535
536         return m_showCheck;
537     }
538
539     /**
540      * Returns the target URI of this form.<p>
541      *
542      * This optional target URI can be used to redirect the user to an OpenCms page instead of displaying a confirmation
543      * text from the form's XML content.<p>
544      *
545      * @return the target URI
546      */

547     public String JavaDoc getTargetUri() {
548         return m_targetUri;
549     }
550
551     /**
552      * Tests if a captcha field is configured for this form.<p>
553      *
554      * @return true, if a captcha field is configured for this form
555      */

556     public boolean hasCaptchaField() {
557         return m_captchaField != null;
558     }
559
560     /**
561      * Returns if the form has configuration errors.<p>
562      *
563      * @return true if the form has configuration errors, otherwise false
564      */

565     public boolean hasConfigurationErrors() {
566
567         return m_configurationErrors.size() > 0;
568     }
569
570     /**
571      * Returns true if at least one of the configured fields is mandatory.<p>
572      *
573      * @return true if at least one of the configured fields is mandatory, otherwise false
574      */

575     public boolean hasMandatoryFields() {
576
577         return m_hasMandatoryFields;
578     }
579
580     /**
581      * Tests if this form has a target URI specified.<p>
582      *
583      * This optional target URI can be used to redirect the user to an OpenCms page instead of displaying a confirmation
584      * text from the form's XML content.<p>
585      *
586      * @return the target URI
587      */

588     public boolean hasTargetUri() {
589         return CmsStringUtil.isNotEmpty(m_targetUri);
590     }
591
592     /**
593      * Initializes the form configuration and creates the necessary form field objects.<p>
594      *
595      * @param jsp the initialized CmsJspActionElement to access the OpenCms API
596      * @param messages the localized messages
597      * @param initial if true, field values are filled with values specified in the XML configuration
598      * @param formConfigUri URI of the form configuration file, if not provided, current URI is used for configuration
599      * @param formAction the desired action submiktted by the form
600      *
601      * @throws Exception if parsing the configuration fails
602      */

603     public void init(CmsJspActionElement jsp, CmsMessages messages, boolean initial, String JavaDoc formConfigUri, String JavaDoc formAction)
604     throws Exception JavaDoc {
605
606         // read the form configuration file from VFS
607
if (CmsStringUtil.isEmpty(formConfigUri)) {
608             formConfigUri = jsp.getRequestContext().getUri();
609         }
610         CmsFile file = jsp.getCmsObject().readFile(formConfigUri);
611         CmsXmlContent content = CmsXmlContentFactory.unmarshal(jsp.getCmsObject(), file);
612
613         // get current Locale
614
Locale JavaDoc locale = jsp.getRequestContext().getLocale();
615
616         // init member variables
617
initMembers();
618         
619         m_formAction = formAction;
620         m_fields = new ArrayList JavaDoc();
621         m_fieldsByName = new HashMap JavaDoc();
622
623         // initialize general form configuration
624
initFormGlobalConfiguration(content, jsp.getCmsObject(), locale, messages);
625
626         // initialize the form input fields
627
initInputFields(content, jsp, locale, messages, initial);
628         
629         // init. the optional captcha field
630
initCaptchaField(jsp, content, locale, initial);
631         
632         // add the captcha field to the list of all fields, if the form has no check page
633
if (captchaFieldIsOnInputPage() && m_captchaField != null) {
634             addField(m_captchaField);
635         }
636     }
637
638     /**
639      * Tests if the check page was submitted.<p>
640      *
641      * @return true, if the check page was submitted
642      */

643     public boolean isCheckPageSubmitted() {
644         return CmsFormHandler.ACTION_CONFIRMED.equals(m_formAction);
645     }
646
647     /**
648      * Returns if the optional confirmation mail is enabled.<p>
649      *
650      * @return true if the optional confirmation mail is enabled, otherwise false
651      */

652     public boolean isConfirmationMailEnabled() {
653
654         return m_confirmationMailEnabled;
655     }
656
657     /**
658      * Returns if the confirmation mail if optional, i.e. selectable by the form submitter.<p>
659      *
660      * @return true if the confirmation mail if optional, i.e. selectable by the form submitter, otherwise false
661      */

662     public boolean isConfirmationMailOptional() {
663
664         return m_confirmationMailOptional;
665     }
666
667     /**
668      * Tests if the input page was submitted.<p>
669      *
670      * @return true, if the input page was submitted
671      */

672     public boolean isInputFormSubmitted() {
673         return CmsFormHandler.ACTION_SUBMIT.equals(m_formAction);
674     }
675
676     /**
677      * Removes the captcha field from the list of all fields, if present.<p>
678      *
679      * @return the removed captcha field, or null
680      */

681     public I_CmsField removeCaptchaField() {
682         
683         for (int i = 0, n = m_fields.size(); i < n; i++) {
684             
685             I_CmsField field = (I_CmsField)m_fields.get(i);
686             if (field != null && CmsCaptchaField.class.isAssignableFrom(getClass())) {
687                 
688                 removeField(field);
689                 return field;
690             }
691         }
692
693         return null;
694     }
695
696     /**
697      * Adds a field to the form.<p>
698      *
699      * @param field the field to be added to the form
700      */

701     protected void addField(I_CmsField field) {
702         
703         m_fields.add(field);
704         
705         // the fields are also internally backed in a map keyed by their field name
706
m_fieldsByName.put(field.getName(), field);
707     }
708
709     /**
710      * Marks the individual items of checkboxes, selectboxes and radiobuttons as selected depending on the given request parameters.<p>
711      *
712      * @param request the current request
713      * @param field the current field
714      * @param value the value of the input field
715      *
716      * @return <code>"true"</code> if the current item is selected or checked, otherwise false
717      */

718     protected String JavaDoc readSelectedFromRequest(HttpServletRequest JavaDoc request, I_CmsField field, String JavaDoc value) {
719
720         String JavaDoc result = "";
721         if (CmsCheckboxField.class.isAssignableFrom(field.getClass())) {
722             // this is a checkbox
723
String JavaDoc[] values = request.getParameterValues(field.getName());
724             if (values != null) {
725                 for (int i = 0; i < values.length; i++) {
726                     if (value.equals(values[i])) {
727                         return Boolean.toString(true);
728                     }
729                 }
730             }
731         } else if (CmsSelectionField.class.isAssignableFrom(field.getClass()) || CmsRadioButtonField.class.isAssignableFrom(field.getClass())) {
732             // select box or radio button
733
String JavaDoc fieldValue = request.getParameter(field.getName());
734             if (CmsStringUtil.isNotEmpty(fieldValue) && fieldValue.equals(value) && !"".equals(value)) {
735                 // mark this as selected
736
result = Boolean.toString(true);
737             } else {
738                 // do not mark it as selected
739
result = "";
740             }
741         } else {
742             // always display fields value arrays
743
result = Boolean.toString(true);
744         }
745         return result;
746     }
747
748     /**
749      * Removes a field from the form fields.<p>
750      *
751      * @param field the field to be removed
752      */

753     protected void removeField(I_CmsField field) {
754         
755         m_fields.remove(field);
756         
757         // the fields are also internally backed in a map keyed by their field name
758
m_fieldsByName.remove(field);
759     }
760
761     /**
762      * Sets the form configuration errors.<p>
763      *
764      * @param configurationErrors the form configuration errors
765      */

766     protected void setConfigurationErrors(List JavaDoc configurationErrors) {
767
768         m_configurationErrors = configurationErrors;
769     }
770
771     /**
772      * Sets the label for the optional confirmation mail checkbox on the input form.<p>
773      *
774      * @param confirmationMailCheckboxLabel the label for the optional confirmation mail checkbox on the input form
775      */

776     protected void setConfirmationMailCheckboxLabel(String JavaDoc confirmationMailCheckboxLabel) {
777
778         m_confirmationMailCheckboxLabel = confirmationMailCheckboxLabel;
779     }
780
781     /**
782      * Sets if the optional confirmation mail is enabled.<p>
783      *
784      * @param confirmationMailEnabled true if the optional confirmation mail is enabled, otherwise false
785      */

786     protected void setConfirmationMailEnabled(boolean confirmationMailEnabled) {
787
788         m_confirmationMailEnabled = confirmationMailEnabled;
789     }
790
791     /**
792      * Sets the index number of the input field containing the email address for the optional confirmation mail.<p>
793      *
794      * @param confirmationMailFieldName the name of the input field containing the email address for the optional confirmation mail
795      */

796     protected void setConfirmationMailField(int confirmationMailFieldName) {
797
798         m_confirmationMailField = confirmationMailFieldName;
799     }
800
801     /**
802      * Sets if the confirmation mail if optional, i.e. selectable by the form submitter.<p>
803      *
804      * @param confirmationMailOptional true if the confirmation mail if optional, i.e. selectable by the form submitter, otherwise false
805      */

806     protected void setConfirmationMailOptional(boolean confirmationMailOptional) {
807
808         m_confirmationMailOptional = confirmationMailOptional;
809     }
810
811     /**
812      * Sets the subject of the optional confirmation mail.<p>
813      *
814      * @param confirmationMailSubject the subject of the optional confirmation mail
815      */

816     protected void setConfirmationMailSubject(String JavaDoc confirmationMailSubject) {
817
818         m_confirmationMailSubject = confirmationMailSubject;
819     }
820
821     /**
822      * Sets the text of the optional confirmation mail.<p>
823      *
824      * @param confirmationMailText the text of the optional confirmation mail
825      */

826     protected void setConfirmationMailText(String JavaDoc confirmationMailText) {
827
828         m_confirmationMailText = confirmationMailText;
829     }
830
831     /**
832      * Sets the plain text of the optional confirmation mail.<p>
833      *
834      * @param confirmationMailTextPlain the plain text of the optional confirmation mail
835      */

836     protected void setConfirmationMailTextPlain(String JavaDoc confirmationMailTextPlain) {
837
838         m_confirmationMailTextPlain = confirmationMailTextPlain;
839     }
840
841     /**
842      * Sets the global form attributes.<p>
843      *
844      * @param formAttributes the global form attributes
845      */

846     protected void setFormAttributes(String JavaDoc formAttributes) {
847
848         m_formAttributes = formAttributes;
849     }
850
851     /**
852      * Sets the form check text.<p>
853      *
854      * @param formCheckText the form confirmation text
855      */

856     protected void setFormCheckText(String JavaDoc formCheckText) {
857
858         m_formCheckText = formCheckText;
859     }
860
861     /**
862      * Sets the form confirmation text.<p>
863      *
864      * @param formConfirmationText the form confirmation text
865      */

866     protected void setFormConfirmationText(String JavaDoc formConfirmationText) {
867
868         m_formConfirmationText = formConfirmationText;
869     }
870
871     /**
872      * Sets the optional form input field attributes.<p>
873      *
874      * @param formFieldAttributes the optional form input field attributes
875      */

876     protected void setFormFieldAttributes(String JavaDoc formFieldAttributes) {
877
878         m_formFieldAttributes = formFieldAttributes;
879     }
880
881     /**
882      * Sets the form text.<p>
883      *
884      * @param formText the form text
885      */

886     protected void setFormText(String JavaDoc formText) {
887
888         m_formText = formText;
889     }
890
891     /**
892      * Sets if at least one of the configured fields is mandatory.<p>
893      *
894      * @param hasMandatoryFields true if at least one of the configured fields is mandatory, otherwise false
895      */

896     protected void setHasMandatoryFields(boolean hasMandatoryFields) {
897
898         m_hasMandatoryFields = hasMandatoryFields;
899     }
900
901     /**
902      * Sets the mail bcc recipient(s).<p>
903      *
904      * @param mailBCC the mail bcc recipient(s)
905      */

906     protected void setMailBCC(String JavaDoc mailBCC) {
907
908         m_mailBCC = mailBCC;
909     }
910
911     /**
912      * Sets the mail cc recipient(s).<p>
913      *
914      * @param mailCC the mail cc recipient(s)
915      */

916     protected void setMailCC(String JavaDoc mailCC) {
917
918         m_mailCC = mailCC;
919     }
920
921     /**
922      * Sets the mail sender address.<p>
923      *
924      * @param mailFrom the mail sender address
925      */

926     protected void setMailFrom(String JavaDoc mailFrom) {
927
928         m_mailFrom = mailFrom;
929     }
930     
931     /**
932      * Sets the mail subject.<p>
933      *
934      * @param mailSubject the mail subject
935      */

936     protected void setMailSubject(String JavaDoc mailSubject) {
937
938         m_mailSubject = mailSubject;
939     }
940
941     /**
942      * Sets the mail subject prefix.<p>
943      *
944      * @param mailSubjectPrefix the mail subject prefix
945      */

946     protected void setMailSubjectPrefix(String JavaDoc mailSubjectPrefix) {
947
948         m_mailSubjectPrefix = mailSubjectPrefix;
949     }
950
951     /**
952      * Sets the mail text.<p>
953      *
954      * @param mailText the mail text
955      */

956     protected void setMailText(String JavaDoc mailText) {
957
958         m_mailText = mailText;
959     }
960     
961     /**
962      * Sets the mail text as plain text.<p>
963      *
964      * @param mailTextPlain the mail text as plain text
965      */

966     protected void setMailTextPlain(String JavaDoc mailTextPlain) {
967
968         m_mailTextPlain = mailTextPlain;
969     }
970     
971     /**
972      * Sets the mail recipient(s).<p>
973      *
974      * @param mailTo the mail recipient(s)
975      */

976     protected void setMailTo(String JavaDoc mailTo) {
977
978         m_mailTo = mailTo;
979     }
980     
981     /**
982      * Sets the mail type ("text" or "html").<p>
983      *
984      * @param mailType the mail type
985      */

986     protected void setMailType(String JavaDoc mailType) {
987
988         m_mailType = mailType;
989     }
990     
991     /**
992      * Sets if the check page should be shown.<p>
993      *
994      * @param showCheck true if the check page should be shown, otherwise false
995      */

996     protected void setShowCheck(boolean showCheck) {
997
998         m_showCheck = showCheck;
999     }
1000    
1001    /**
1002     * Sets the target URI of this form.<p>
1003     *
1004     * This optional target URI can be used to redirect the user to an OpenCms page instead of displaying a confirmation
1005     * text from the form's XML content.<p>
1006     *
1007     * @param targetUri the target URI
1008     */

1009    protected void setTargetUri(String JavaDoc targetUri) {
1010        m_targetUri = targetUri;
1011    }
1012    
1013    /**
1014     * Creates the checkbox field to activate the confirmation mail in the input form.<p>
1015     *
1016     * @param jsp the initialized CmsJspActionElement to access the OpenCms API
1017     * @param messages the localized messages
1018     * @param initial if true, field values are filled with values specified in the XML configuration, otherwise values are read from the request
1019     * @return the checkbox field to activate the confirmation mail in the input form
1020     */

1021    private I_CmsField createConfirmationMailCheckbox(CmsJspActionElement jsp, CmsMessages messages, boolean initial) {
1022
1023        A_CmsField field = new CmsCheckboxField();
1024        field.setName(PARAM_SENDCONFIRMATION);
1025        field.setLabel(messages.key("form.confirmation.label"));
1026        // check the field status
1027
boolean isChecked = false;
1028        if (!initial && Boolean.valueOf(jsp.getRequest().getParameter(PARAM_SENDCONFIRMATION)).booleanValue()) {
1029            // checkbox is checked by user
1030
isChecked = true;
1031        }
1032        // create item for field
1033
CmsFieldItem item = new CmsFieldItem(Boolean.toString(true), getConfirmationMailCheckboxLabel(), isChecked);
1034        List JavaDoc items = new ArrayList JavaDoc(1);
1035        items.add(item);
1036        field.setItems(items);
1037        return field;
1038    }
1039    
1040    /**
1041     * Checks if the given value is empty and returns in that case the default value.<p>
1042     *
1043     * @param value the configuration value to check
1044     * @param defaultValue the default value to return in case the value is empty
1045     * @return the checked value
1046     */

1047    private String JavaDoc getConfigurationValue(String JavaDoc value, String JavaDoc defaultValue) {
1048
1049        if (CmsStringUtil.isNotEmpty(value)) {
1050            return value;
1051        }
1052        return defaultValue;
1053    }
1054    
1055    /**
1056     * Initializes the optional captcha field.<p>
1057     *
1058     * @param jsp the initialized CmsJspActionElement to access the OpenCms API
1059     * @param xmlContent the XML configuration content
1060     * @param locale the currently active Locale
1061     * @param initial if true, field values are filled with values specified in the XML configuration, otherwise values are read from the request
1062     */

1063    private void initCaptchaField(CmsJspActionElement jsp, CmsXmlContent xmlContent, Locale JavaDoc locale, boolean initial) {
1064        
1065        boolean captchaFieldIsOnInputPage = captchaFieldIsOnInputPage();
1066        boolean displayCheckPage = captchaFieldIsOnCheckPage() && isInputFormSubmitted();
1067        boolean submittedCheckPage = captchaFieldIsOnCheckPage() && isCheckPageSubmitted();
1068
1069        // Todo: read the captcha settings here, don't provide xmlcontent with form!!!
1070
if (captchaFieldIsOnInputPage || displayCheckPage || submittedCheckPage) {
1071
1072            CmsObject cms = jsp.getCmsObject();
1073            
1074            I_CmsXmlContentValue xmlValueCaptcha = xmlContent.getValue(NODE_CAPTCHA, locale);
1075            if (xmlValueCaptcha != null) {
1076
1077                // get the field label
1078
String JavaDoc xPathCaptcha = xmlValueCaptcha.getPath() + "/";
1079                String JavaDoc stringValue = xmlContent.getStringValue(cms, xPathCaptcha + NODE_FIELDLABEL, locale);
1080                String JavaDoc fieldLabel = getConfigurationValue(stringValue, "");
1081
1082                // get the field value
1083
String JavaDoc fieldValue = "";
1084                if (!initial) {
1085                    fieldValue = jsp.getRequest().getParameter(CmsCaptchaField.C_PARAM_CAPTCHA_PHRASE);
1086                    if (fieldValue == null) {
1087                        fieldValue = "";
1088                    }
1089                }
1090
1091                // get the image settings from the XML content
1092
CmsCaptchaSettings captchaSettings = CmsCaptchaSettings.getInstance(jsp);
1093                captchaSettings.init(cms, xmlContent, locale);
1094                m_captchaField = new CmsCaptchaField(captchaSettings, fieldLabel, fieldValue);
1095            }
1096        }
1097    }
1098    
1099    /**
1100     * Initializes the general online form settings.<p>
1101     *
1102     * @param content the XML configuration content
1103     * @param cms the CmsObject to access the content values
1104     * @param locale the currently active Locale
1105     * @param messages the localized messages
1106     * @throws Exception if initializing the form settings fails
1107     */

1108    private void initFormGlobalConfiguration(CmsXmlContent content, CmsObject cms, Locale JavaDoc locale, CmsMessages messages)
1109    throws Exception JavaDoc {
1110
1111        // get the form text
1112
String JavaDoc stringValue = content.getStringValue(cms, NODE_FORMTEXT, locale);
1113        setFormText(getConfigurationValue(stringValue, ""));
1114        // get the form confirmation text
1115
stringValue = content.getStringValue(cms, NODE_FORMCONFIRMATION, locale);
1116        setFormConfirmationText(getConfigurationValue(stringValue, ""));
1117        // get the optional target URI
1118
stringValue = content.getStringValue(cms, NODE_TARGET_URI, locale);
1119        setTargetUri(getConfigurationValue(stringValue, ""));
1120        // get the mail from address
1121
stringValue = content.getStringValue(cms, NODE_MAILFROM, locale);
1122        setMailFrom(getConfigurationValue(stringValue, ""));
1123        // get the mail to address(es)
1124
stringValue = content.getStringValue(cms, NODE_MAILTO, locale);
1125        setMailTo(getConfigurationValue(stringValue, ""));
1126        // get the mail subject
1127
stringValue = content.getStringValue(cms, NODE_MAILSUBJECT, locale);
1128        setMailSubject(getConfigurationValue(stringValue, ""));
1129        // get the optional mail subject prefix from localized messages
1130
stringValue = messages.key("form.mailsubject.prefix");
1131        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(stringValue)) {
1132            // prefix present, set it
1133
setMailSubjectPrefix(stringValue + " ");
1134        } else {
1135            // no prefix present
1136
setMailSubjectPrefix("");
1137        }
1138        
1139        CmsXmlHtmlValue mailTextValue = (CmsXmlHtmlValue)content.getValue(NODE_MAILTEXT, locale);
1140        if (mailTextValue != null) {
1141            // get the mail text as plain text
1142
stringValue = mailTextValue.getPlainText(cms);
1143            setMailTextPlain(getConfigurationValue(stringValue, ""));
1144            // get the mail text
1145
stringValue = mailTextValue.getStringValue(cms);
1146            setMailText(getConfigurationValue(stringValue, ""));
1147        } else {
1148            setMailTextPlain("");
1149            setMailText("");
1150        }
1151
1152        // optional configuration options
1153
String JavaDoc pathPrefix = NODE_OPTIONALCONFIGURATION + "/";
1154
1155        // get the mail type
1156
stringValue = content.getStringValue(cms, pathPrefix + NODE_MAILTYPE, locale);
1157        setMailType(getConfigurationValue(stringValue, MAILTYPE_HTML));
1158        // get the mail CC recipient(s)
1159
stringValue = content.getStringValue(cms, pathPrefix + NODE_MAILCC, locale);
1160        setMailCC(getConfigurationValue(stringValue, ""));
1161        // get the mail BCC recipient(s)
1162
stringValue = content.getStringValue(cms, pathPrefix + NODE_MAILBCC, locale);
1163        setMailBCC(getConfigurationValue(stringValue, ""));
1164        // get the form check page flag
1165
stringValue = content.getStringValue(cms, pathPrefix + NODE_SHOWCHECK, locale);
1166        setShowCheck(Boolean.valueOf(stringValue).booleanValue());
1167        // get the check page text
1168
stringValue = content.getStringValue(cms, pathPrefix + NODE_FORMCHECKTEXT, locale);
1169        setFormCheckText(getConfigurationValue(stringValue, ""));
1170        // get the form attributes
1171
stringValue = content.getStringValue(cms, pathPrefix + NODE_FORMATTRIBUTES, locale);
1172        if (CmsStringUtil.isNotEmpty(stringValue)) {
1173            setFormAttributes(" " + stringValue);
1174        }
1175        // get the field attributes
1176
stringValue = content.getStringValue(cms, pathPrefix + NODE_FORMFIELDATTRIBUTES, locale);
1177        if (CmsStringUtil.isNotEmpty(stringValue)) {
1178            setFormFieldAttributes(" " + stringValue);
1179        } else {
1180            // no field attributes specified, check default field attributes
1181
String JavaDoc defaultAttributes = messages.key("form.field.default.attributes");
1182            if (CmsStringUtil.isNotEmpty(defaultAttributes)) {
1183                setFormFieldAttributes(" " + defaultAttributes);
1184            }
1185        }
1186
1187        // optional confirmation mail nodes
1188
pathPrefix = NODE_OPTIONALCONFIRMATION + "/";
1189
1190        // get the confirmation mail enabled flag
1191
stringValue = content.getStringValue(cms, pathPrefix + NODE_CONFIRMATIONMAILENABLED, locale);
1192        setConfirmationMailEnabled(Boolean.valueOf(stringValue).booleanValue());
1193        // get other confirmation mail nodes only if confirmation mail is enabled
1194
if (isConfirmationMailEnabled()) {
1195            // get the confirmation mail subject
1196
stringValue = content.getStringValue(cms, pathPrefix + NODE_CONFIRMATIONMAILSUBJECT, locale);
1197            setConfirmationMailSubject(getConfigurationValue(stringValue, ""));
1198           
1199            mailTextValue = (CmsXmlHtmlValue)content.getValue(pathPrefix + NODE_CONFIRMATIONMAILTEXT, locale);
1200            if (mailTextValue != null) {
1201                // get the confirmation mail text
1202
stringValue = mailTextValue.getPlainText(cms);
1203                setConfirmationMailTextPlain(getConfigurationValue(stringValue, ""));
1204                stringValue = mailTextValue.getStringValue(cms);
1205                setConfirmationMailText(getConfigurationValue(stringValue, ""));
1206            } else {
1207                setConfirmationMailTextPlain("");
1208                setConfirmationMailText("");
1209            }
1210            
1211            // get the confirmation mail field index number
1212
stringValue = content.getStringValue(cms, pathPrefix + NODE_CONFIRMATIONMAILFIELD, locale);
1213            int fieldIndex = 1;
1214            try {
1215                fieldIndex = Integer.parseInt(getConfigurationValue(stringValue, "1")) - 1;
1216            } catch (Exception JavaDoc e) {
1217                // ignore this exception, use first field
1218
}
1219            setConfirmationMailField(fieldIndex);
1220            // get the confirmation mail optional flag
1221
stringValue = content.getStringValue(cms, pathPrefix + NODE_CONFIRMATIONMAILOPTIONAL, locale);
1222            setConfirmationMailOptional(Boolean.valueOf(stringValue).booleanValue());
1223            // get the confirmation mail checkbox label text
1224
stringValue = content.getStringValue(cms, pathPrefix + NODE_CONFIRMATIONMAILCHECKBOXLABEL, locale);
1225            setConfirmationMailCheckboxLabel(getConfigurationValue(
1226                stringValue,
1227                messages.key("form.confirmation.checkbox")));
1228        }
1229    }
1230    
1231    /**
1232     * Initializes the field objects of the form.<p>
1233     *
1234     * @param content the XML configuration content
1235     * @param jsp the initialized CmsJspActionElement to access the OpenCms API
1236     * @param locale the currently active Locale
1237     * @param messages the localized messages
1238     * @param initial if true, field values are filled with values specified in the XML configuration, otherwise values are read from the request
1239     * @throws CmsConfigurationException if parsing the configuration fails
1240     */

1241    private void initInputFields(
1242        CmsXmlContent content,
1243        CmsJspActionElement jsp,
1244        Locale JavaDoc locale,
1245        CmsMessages messages,
1246        boolean initial) throws CmsConfigurationException {
1247
1248        CmsObject cms = jsp.getCmsObject();
1249        List JavaDoc fieldValues = content.getValues(NODE_INPUTFIELD, locale);
1250        int fieldValueSize = fieldValues.size();
1251        CmsFieldFactory fieldFactory = CmsFieldFactory.getSharedInstance();
1252        
1253        for (int i = 0; i < fieldValueSize; i++) {
1254            I_CmsXmlContentValue inputField = (I_CmsXmlContentValue)fieldValues.get(i);
1255            String JavaDoc inputFieldPath = inputField.getPath() + "/";
1256            A_CmsField field = null;
1257
1258            // get the field from the factory for the specified type
1259
String JavaDoc stringValue = content.getStringValue(cms, inputFieldPath + NODE_FIELDTYPE, locale);
1260            field = fieldFactory.getField(stringValue);
1261            
1262            // create the field name
1263
field.setName(inputFieldPath.substring(0, inputFieldPath.length() - 1));
1264            // get the field label
1265
stringValue = content.getStringValue(cms, inputFieldPath + NODE_FIELDLABEL, locale);
1266            field.setLabel(getConfigurationValue(stringValue, ""));
1267            // validation error message
1268
stringValue = content.getStringValue(cms, inputFieldPath + NODE_FIELDERRORMESSAGE, locale);
1269            field.setErrorMessage(stringValue);
1270            // get the field value
1271
if (initial && CmsStringUtil.isEmpty(jsp.getRequest().getParameter(field.getName()))) {
1272                // only fill in values from configuration file if called initially
1273
String JavaDoc fieldValue = content.getStringValue(cms, inputFieldPath + NODE_FIELDDEFAULTVALUE, locale);
1274                if (CmsStringUtil.isNotEmpty(fieldValue)) {
1275                    CmsMacroResolver resolver = CmsMacroResolver.newInstance().setCmsObject(cms).setJspPageContext(
1276                        jsp.getJspContext());
1277                    field.setValue(resolver.resolveMacros(fieldValue));
1278                }
1279            } else {
1280                // get field value from request for standard fields
1281
if (!CmsCheckboxField.class.isAssignableFrom(field.getClass())) {
1282                    String JavaDoc[] parameterValues = jsp.getRequest().getParameterValues(field.getName());
1283                    StringBuffer JavaDoc value = new StringBuffer JavaDoc();
1284                    if (parameterValues != null) {
1285                        for (int j = 0; j < parameterValues.length; j++) {
1286                            if (j != 0) {
1287                                value.append(", ");
1288                            }
1289                            value.append(parameterValues[j]);
1290                        }
1291                    }
1292                    field.setValue(value.toString());
1293                }
1294            }
1295
1296            // fill object members in case this is no hidden field
1297
if (!CmsHiddenField.class.isAssignableFrom(field.getClass())) {
1298                // get the field validation regular expression
1299
stringValue = content.getStringValue(cms, inputFieldPath + NODE_FIELDVALIDATION, locale);
1300                if (CmsEmailField.class.isAssignableFrom(field.getClass()) && CmsStringUtil.isEmpty(stringValue)) {
1301                    // set default email validation expression for confirmation email address input field
1302
field.setValidationExpression(CmsEmailField.VALIDATION_REGEX);
1303                } else {
1304                    field.setValidationExpression(getConfigurationValue(stringValue, ""));
1305                }
1306                // get the field mandatory flag
1307
stringValue = content.getStringValue(cms, inputFieldPath + NODE_FIELDMANDATORY, locale);
1308                boolean isMandatory = Boolean.valueOf(stringValue).booleanValue();
1309                field.setMandatory(isMandatory);
1310                if (isMandatory) {
1311                    // set flag that determines if mandatory fields are present
1312
setHasMandatoryFields(true);
1313                }
1314
1315                if (field.needsItems()) {
1316                    // create items for checkboxes, radio buttons and selectboxes
1317
String JavaDoc fieldValue = content.getStringValue(cms, inputFieldPath + NODE_FIELDDEFAULTVALUE, locale);
1318                    if (CmsStringUtil.isNotEmpty(fieldValue)) {
1319                        // get items from String
1320
StringTokenizer JavaDoc T = new StringTokenizer JavaDoc(fieldValue, "|");
1321                        List JavaDoc items = new ArrayList JavaDoc(T.countTokens());
1322                        while (T.hasMoreTokens()) {
1323                            String JavaDoc part = T.nextToken();
1324                            // check preselection of current item
1325
boolean isPreselected = part.indexOf('*') != -1;
1326                            String JavaDoc value = "";
1327                            String JavaDoc label = "";
1328                            String JavaDoc selected = "";
1329                            int delimPos = part.indexOf(':');
1330                            if (delimPos != -1) {
1331                                // a special label text is given
1332
value = part.substring(0, delimPos);
1333                                label = part.substring(delimPos + 1);
1334                            } else {
1335                                // no special label text present, use complete String
1336
value = part;
1337                                label = value;
1338                            }
1339
1340                            if (isPreselected) {
1341                                // remove preselected flag marker from Strings
1342
value = CmsStringUtil.substitute(value, "*", "");
1343                                label = CmsStringUtil.substitute(label, "*", "");
1344                            }
1345
1346                            if (initial) {
1347                                // only fill in values from configuration file if called initially
1348
if (isPreselected) {
1349                                    selected = Boolean.toString(true);
1350                                }
1351                            } else {
1352                                // get selected flag from request for current item
1353
selected = readSelectedFromRequest(
1354                                    jsp.getRequest(),
1355                                    field,
1356                                    value);
1357                            }
1358                            // add new item object
1359
items.add(new CmsFieldItem(value, label, Boolean.valueOf(selected).booleanValue()));
1360                        }
1361                        field.setItems(items);
1362                    } else {
1363                        // no items specified for checkbox, radio button or selectbox
1364
throw new CmsConfigurationException(Messages.get().container(
1365                            Messages.ERR_INIT_INPUT_FIELD_MISSING_ITEM_2,
1366                            field.getName(),
1367                            field.getType()));
1368                    }
1369                }
1370            }
1371
1372            addField(field);
1373        }
1374
1375        // validate the form configuration
1376
validateFormConfiguration(messages);
1377
1378        if (isConfirmationMailEnabled() && isConfirmationMailOptional()) {
1379            
1380            // add the checkbox to activate confirmation mail for customer
1381
I_CmsField confirmationMailCheckbox = createConfirmationMailCheckbox(jsp, messages, initial);
1382            addField(confirmationMailCheckbox);
1383        }
1384    }
1385    
1386    /**
1387     * Initializes the member variables.<p>
1388     */

1389    private void initMembers() {
1390
1391        setConfigurationErrors(new ArrayList JavaDoc());
1392        setFormAttributes("");
1393        setFormCheckText("");
1394        setFormConfirmationText("");
1395        setFormFieldAttributes("");
1396        setFormText("");
1397        setMailBCC("");
1398        setMailCC("");
1399        setMailFrom("");
1400        setMailSubject("");
1401        setMailText("");
1402        setMailTextPlain("");
1403        setMailTo("");
1404        setMailType(MAILTYPE_HTML);
1405        setConfirmationMailSubject("");
1406        setConfirmationMailText("");
1407        setConfirmationMailTextPlain("");
1408    }
1409    
1410    /**
1411     * Validates the loaded online form configuration and creates a list of error messages, if necessary.<p>
1412     *
1413     * @param messages the localized messages
1414     */

1415    private void validateFormConfiguration(CmsMessages messages) {
1416
1417        if (isConfirmationMailEnabled()) {
1418            // confirmation mail is enabled, make simple field check to avoid errors
1419
I_CmsField confirmField = new CmsTextField();
1420            try {
1421                // try to get the confirmation email field
1422
confirmField = (I_CmsField)getFields().get(getConfirmationMailField());
1423            } catch (IndexOutOfBoundsException JavaDoc e) {
1424                // specified confirmation email field does not exist
1425
getConfigurationErrors().add(messages.key("form.configuration.error.emailfield.notfound"));
1426                setConfirmationMailEnabled(false);
1427                return;
1428            }
1429            if (!CmsEmailField.class.isAssignableFrom(confirmField.getClass())) {
1430                // specified confirmation mail input field has wrong field type
1431
getConfigurationErrors().add(messages.key("form.configuration.error.emailfield.type"));
1432            }
1433        }
1434    }
1435
1436}
1437
Popular Tags