KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/frontend/templateone/form/CmsFieldValue.java,v $
3  * Date : $Date: 2005/09/09 10:31:59 $
4  * Version: $Revision: 1.10 $
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
35 import java.util.Iterator JavaDoc;
36
37 /**
38  * Represents a single input field value of a submitted form.<p>
39  *
40  * This object is needed to create the output for the optional confirmation page, the notification email
41  * or the final page after submission.<p>
42  *
43  * @author Andreas Zahner
44  *
45  * @version $Revision: 1.10 $
46  *
47  * @since 6.0.0
48  */

49 public class CmsFieldValue {
50
51     private String JavaDoc m_label;
52     private boolean m_show;
53     private String JavaDoc m_value;
54
55     /**
56      * Constructor that creates an initialized field item.<p>
57      *
58      * @param field the form field to create the value from
59      */

60     public CmsFieldValue(I_CmsField field) {
61
62         if (field.needsItems()) {
63             // check which item has been selected
64
StringBuffer JavaDoc fieldValue = new StringBuffer JavaDoc(8);
65             Iterator JavaDoc k = field.getItems().iterator();
66             boolean isSelected = false;
67             while (k.hasNext()) {
68                 CmsFieldItem currentItem = (CmsFieldItem)k.next();
69                 if (currentItem.isSelected()) {
70                     if (isSelected) {
71                         fieldValue.append(", ");
72                     }
73                     fieldValue.append(currentItem.getLabel());
74                     isSelected = true;
75                 }
76             }
77             m_value = fieldValue.toString();
78         } else {
79             // for other field types, append value
80
m_value = field.getValue();
81         }
82
83         if (CmsHiddenField.class.isAssignableFrom(field.getClass())) {
84             // for hidden fields, set show field flag to false
85
m_show = false;
86         } else {
87             // all other fields are shown
88
m_show = true;
89         }
90
91         // set the label String of current field
92
m_label = field.getLabel();
93     }
94
95     /**
96      * Returns the label text of the field item.<p>
97      *
98      * @return the label text of the field item
99      */

100     public String JavaDoc getLabel() {
101
102         return m_label;
103     }
104
105     /**
106      * Returns the value of the field item.<p>
107      *
108      * @return the value of the field item
109      */

110     public String JavaDoc getValue() {
111
112         return m_value;
113     }
114
115     /**
116      * Returns if the current item is shown or not.<p>
117      *
118      * @return true if the current item is shown, otherwise false
119      */

120     public boolean isShow() {
121
122         return m_show;
123     }
124
125     /**
126      * Sets the label text of the field item.<p>
127      *
128      * @param label the label text of the field item
129      */

130     protected void setLabel(String JavaDoc label) {
131
132         m_label = label;
133     }
134
135     /**
136      * Sets if the current item is shown or not.<p>
137      *
138      * @param show true if the current item is shown, otherwise false
139      */

140     protected void setShow(boolean show) {
141
142         m_show = show;
143     }
144
145     /**
146      * Sets the value of the field item.<p>
147      *
148      * @param value the value of the field item
149      */

150     protected void setValue(String JavaDoc value) {
151
152         m_value = value;
153     }
154 }
155
Popular Tags