2
* $Header: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/FormSet.java,v 1.15 2004/02/21 17:10:29 rleland Exp $
4
* $Date: 2004/02/21 17:10:29 $
6
* ====================================================================
7
* Copyright 2001-2004 The Apache Software Foundation
9
* Licensed under the Apache License, Version 2.0 (the "License");
10
* you may not use this file except in compliance with the License.
11
* You may obtain a copy of the License at
13
* http://www.apache.org/licenses/LICENSE-2.0
15
* Unless required by applicable law or agreed to in writing, software
16
* distributed under the License is distributed on an "AS IS" BASIS,
17
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
* See the License for the specific language governing permissions and
19
* limitations under the License.
22
package org.apache.commons.validator;
24
import java.io.Serializable;
25
import java.util.Collections;
26
import java.util.HashMap;
27
import java.util.Iterator;
31
* Holds a set of <code>Form</code>s stored associated with a
32
* <code>Locale</code> based on the country, language, and variant specified.
33
* Instances of this class are configured with a <formset> xml element.
35
public class FormSet implements Serializable {
38
* Whether or not the this <code>FormSet</code> was processed
39
* for replacing variables in strings with their values.
41
private boolean processed = false;
44
* Language component of <code>Locale</code> (required).
46
private String language = null;
49
* Country component of <code>Locale</code> (optional).
51
private String country = null;
54
* Variant component of <code>Locale</code> (optional).
56
private String variant = null;
59
* A <code>Map</code> of <code>Form</code>s
60
* using the name field of the <code>Form</code> as the key.
62
private Map forms = new HashMap();
65
* A <code>Map</code> of <code>Constant</code>s
66
* using the name field of the <code>Constant</code> as the key.
68
private Map constants = new HashMap();
71
* Whether or not the this <code>FormSet</code> was processed
72
* for replacing variables in strings with their values.
74
public boolean isProcessed() {
79
* Gets the equivalent of the language component of <code>Locale</code>.
81
public String getLanguage() {
86
* Sets the equivalent of the language component of <code>Locale</code>.
88
public void setLanguage(String language) {
89
this.language = language;
93
* Gets the equivalent of the country component of <code>Locale</code>.
95
public String getCountry() {
100
* Sets the equivalent of the country component of <code>Locale</code>.
102
public void setCountry(String country) {
103
this.country = country;
107
* Gets the equivalent of the variant component of <code>Locale</code>.
109
public String getVariant() {
114
* Sets the equivalent of the variant component of <code>Locale</code>.
116
public void setVariant(String variant) {
117
this.variant = variant;
121
* Add a <code>Constant</code> (locale level).
122
* @deprecated Use addConstant(String, String) instead.
124
public void addConstant(Constant c) {
125
if (c.getName() != null && c.getName().length() > 0 &&
126
c.getValue() != null && c.getValue().length() > 0) {
128
constants.put(c.getName(), c.getValue());
133
* Add a <code>Constant</code> to the locale level.
134
* @deprecated Use addConstant(String, String) instead.
136
public void addConstantParam(String name, String value) {
137
if (name != null && name.length() > 0 &&
138
value != null && value.length() > 0) {
140
constants.put(name, value);
145
* Add a <code>Constant</code> to the locale level.
147
public void addConstant(String name, String value) {
148
this.constants.put(name, value);
152
* Add a <code>Form</code> to the <code>FormSet</code>.
154
public void addForm(Form f) {
155
forms.put(f.getName(), f);
159
* Retrieve a <code>Form</code> based on the form name.
160
* @deprecated Use getForm(String) instead.
162
public Form getForm(Object key) {
163
return (Form) this.forms.get(key);
167
* Retrieve a <code>Form</code> based on the form name.
169
public Form getForm(String formName) {
170
return (Form) this.forms.get(formName);
174
* A <code>Map</code> of <code>Form</code>s is returned as an
175
* unmodifiable <code>Map</code> with the key based on the form name.
177
public Map getForms() {
178
return Collections.unmodifiableMap(forms);
182
* Processes all of the <code>Form</code>s.
183
* @deprecated This method is called by the framework. It will be made protected
184
* in a future release. TODO
186
public synchronized void process(Map globalConstants) {
187
for (Iterator i = forms.values().iterator(); i.hasNext();) {
188
Form f = (Form) i.next();
189
f.process(globalConstants, constants);
196
* Returns a string representation of the object.
198
public String toString() {
199
StringBuffer results = new StringBuffer();
201
results.append("FormSet: language=");
202
results.append(language);
203
results.append(" country=");
204
results.append(country);
205
results.append(" variant=");
206
results.append(variant);
207
results.append("\n");
209
for (Iterator i = getForms().values().iterator(); i.hasNext();) {
211
results.append(i.next());
212
results.append("\n");
215
return results.toString();
b'\\ No newline at end of file'