001: /*
002: * File : $Source: /usr/local/cvs/alkacon/com.alkacon.opencms.formgenerator/src/com/alkacon/opencms/formgenerator/CmsFieldValue.java,v $
003: * Date : $Date: 2007-12-21 14:34:00 $
004: * Version: $Revision: 1.1 $
005: *
006: * This file is part of the Alkacon OpenCms Add-On Module Package
007: *
008: * Copyright (c) 2007 Alkacon Software GmbH (http://www.alkacon.com)
009: *
010: * The Alkacon OpenCms Add-On Module Package is free software:
011: * you can redistribute it and/or modify
012: * it under the terms of the GNU General Public License as published by
013: * the Free Software Foundation, either version 3 of the License, or
014: * (at your option) any later version.
015: *
016: * The Alkacon OpenCms Add-On Module Package is distributed
017: * in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with the Alkacon OpenCms Add-On Module Package.
024: * If not, see http://www.gnu.org/licenses/.
025: *
026: * For further information about Alkacon Software GmbH, please see the
027: * company website: http://www.alkacon.com.
028: *
029: * For further information about OpenCms, please see the
030: * project website: http://www.opencms.org.
031: */
032: package com.alkacon.opencms.formgenerator;
033:
034: import java.util.Iterator;
035:
036: /**
037: * Represents a single input field value of a submitted form.<p>
038: *
039: * This object is needed to create the output for the optional confirmation page, the notification email
040: * or the final page after submission.<p>
041: *
042: * @author Andreas Zahner
043: *
044: * @version $Revision: 1.1 $
045: *
046: * @since 7.0.4
047: */
048: public class CmsFieldValue {
049:
050: /** The label of the field. */
051: private String m_label;
052:
053: /** A flag indicating if the field is shown. */
054: private boolean m_show;
055:
056: /** The value of the field. */
057: private String m_value;
058:
059: /**
060: * Constructor that creates an initialized field item.<p>
061: *
062: * @param field the form field to create the value from
063: */
064: public CmsFieldValue(I_CmsField field) {
065:
066: if (field.needsItems()) {
067: // check which item has been selected
068: StringBuffer fieldValue = new StringBuffer(8);
069: Iterator k = field.getItems().iterator();
070: boolean isSelected = false;
071: while (k.hasNext()) {
072: CmsFieldItem currentItem = (CmsFieldItem) k.next();
073: if (currentItem.isSelected()) {
074: if (isSelected) {
075: fieldValue.append(", ");
076: }
077: fieldValue.append(currentItem.getLabel());
078: isSelected = true;
079: }
080: }
081: m_value = fieldValue.toString();
082: } else {
083: // for other field types, append value
084: m_value = field.getValue();
085: }
086:
087: if (CmsHiddenField.class.isAssignableFrom(field.getClass())) {
088: // for hidden fields, set show field flag to false
089: m_show = false;
090: } else {
091: // all other fields are shown
092: m_show = true;
093: }
094:
095: // set the label String of current field
096: m_label = field.getLabel();
097: }
098:
099: /**
100: * Returns the label text of the field item.<p>
101: *
102: * @return the label text of the field item
103: */
104: public String getLabel() {
105:
106: return m_label;
107: }
108:
109: /**
110: * Returns the value of the field item.<p>
111: *
112: * @return the value of the field item
113: */
114: public String getValue() {
115:
116: return m_value;
117: }
118:
119: /**
120: * Returns if the current item is shown or not.<p>
121: *
122: * @return true if the current item is shown, otherwise false
123: */
124: public boolean isShow() {
125:
126: return m_show;
127: }
128:
129: /**
130: * Sets the label text of the field item.<p>
131: *
132: * @param label the label text of the field item
133: */
134: protected void setLabel(String label) {
135:
136: m_label = label;
137: }
138:
139: /**
140: * Sets if the current item is shown or not.<p>
141: *
142: * @param show true if the current item is shown, otherwise false
143: */
144: protected void setShow(boolean show) {
145:
146: m_show = show;
147: }
148:
149: /**
150: * Sets the value of the field item.<p>
151: *
152: * @param value the value of the field item
153: */
154: protected void setValue(String value) {
155:
156: m_value = value;
157: }
158: }
|