001: /*
002: * File : $Source: /usr/local/cvs/alkacon/com.alkacon.opencms.formgenerator/src/com/alkacon/opencms/formgenerator/database/CmsFormDataBean.java,v $
003: * Date : $Date: 2008-02-28 08:16:45 $
004: * Version: $Revision: 1.3 $
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:
033: package com.alkacon.opencms.formgenerator.database;
034:
035: import java.util.Collection;
036: import java.util.Set;
037: import java.util.SortedMap;
038: import java.util.TreeMap;
039:
040: /**
041: * Represents a single set / record of data that has been entered by a single
042: * user that filled out a form. <p>
043: *
044: * @author Achim Westermann
045: * @author Michael Moossen
046: *
047: * @version $Revision: 1.3 $
048: *
049: * @since 7.0.4
050: */
051: public class CmsFormDataBean {
052:
053: /** The creation date. */
054: private long m_dateCreated;
055:
056: /** The <code>SortedMap<{@link String}, {@link java.util.Map.Entry}></code> with all field entries. */
057: private SortedMap m_fieldEntries;
058:
059: /** The resource path. */
060: private String m_resourcePath;
061:
062: /**
063: * Default constructor.<p>
064: */
065: protected CmsFormDataBean() {
066:
067: m_fieldEntries = new TreeMap();
068: }
069:
070: /**
071: * Returns a set of all field labels in this form.<p>
072: *
073: * @return a set of all field labels
074: *
075: * @see java.util.Map#keySet()
076: */
077: public Set getAllFieldLabels() {
078:
079: return m_fieldEntries.keySet();
080: }
081:
082: /**
083: * Returns a set of {@link java.util.Map.Entry} objects, where the key is
084: * the field name and the value the field value, with all fields
085: * in the form.<p>
086: *
087: * @return all fields in the form
088: *
089: * @see java.util.Map#entrySet()
090: */
091: public Set getAllFields() {
092:
093: return m_fieldEntries.entrySet();
094: }
095:
096: /**
097: * Returns a collection of all field values in this form.<p>
098: *
099: * @return a collection of all field values
100: *
101: * @see java.util.Map#values()
102: */
103: public Collection getAllFieldValues() {
104:
105: return m_fieldEntries.values();
106: }
107:
108: /**
109: * Returns the creation date.<p>
110: *
111: * @return the creation date
112: */
113: public long getDateCreated() {
114:
115: return m_dateCreated;
116: }
117:
118: /**
119: * Returns the value of the given field, or <code>null</code>
120: * if no field with the given name exists.<p>
121: *
122: * @param fieldLabel the field label to get the value for
123: *
124: * @return the value of the given field
125: *
126: * @see java.util.Map#get(java.lang.Object)
127: */
128: public String getFieldValue(String fieldLabel) {
129:
130: return (String) m_fieldEntries.get(fieldLabel);
131: }
132:
133: /**
134: * Returns the resource Path.<p>
135: *
136: * @return the resource Path
137: */
138: public String getResourcePath() {
139:
140: return m_resourcePath;
141: }
142:
143: /**
144: * Checks if the form has the given field.<p>
145: *
146: * @param fieldLabel the field label to look for
147: *
148: * @return <code>true</code> if the form has the given field
149: *
150: * @see java.util.Map#containsKey(java.lang.Object)
151: */
152: public boolean hasField(String fieldLabel) {
153:
154: return m_fieldEntries.containsKey(fieldLabel);
155: }
156:
157: /**
158: * Checks if the form has the given field value.<p>
159: *
160: * @param fieldValue the field value to look for
161: *
162: * @return <code>true</code> if the form has the given field value
163: *
164: * @see java.util.Map#containsValue(java.lang.Object)
165: */
166: public boolean hasValue(String fieldValue) {
167:
168: return m_fieldEntries.containsValue(fieldValue);
169: }
170:
171: /**
172: * Returns the total number of fields in this form.<p>
173: *
174: * @return the total number of fields
175: *
176: * @see java.util.Map#size()
177: */
178: public int size() {
179:
180: return m_fieldEntries.size();
181: }
182:
183: /**
184: * Adds a new field to this form.<p>
185: *
186: * @param fieldLabel the label of the field
187: * @param fieldValue the value of the field
188: *
189: * @see java.util.Map#put(java.lang.Object, java.lang.Object)
190: */
191: protected void addField(String fieldLabel, String fieldValue) {
192:
193: m_fieldEntries.put(fieldLabel, fieldValue);
194: }
195:
196: /**
197: * Sets the creation date.<p>
198: *
199: * @param dateCreated the creation date to set
200: */
201: protected void setDateCreated(long dateCreated) {
202:
203: m_dateCreated = dateCreated;
204: }
205:
206: /**
207: * Sets the resource Path.<p>
208: *
209: * @param resourcePath the resource Path to set
210: */
211: protected void setResourcePath(String resourcePath) {
212:
213: m_resourcePath = resourcePath;
214: }
215: }
|