01: /*
02: * Copyright 2004, 2005, 2006 Odysseus Software GmbH
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package de.odysseus.calyxo.forms;
17:
18: import javax.servlet.http.HttpServletRequest;
19: import javax.servlet.jsp.el.VariableResolver;
20:
21: /**
22: * Form input interface.
23: * A form input can validate its parameter from a
24: * {@link de.odysseus.calyxo.forms.FormInputValues} object and
25: * format its mapped property from a
26: * {@link de.odysseus.calyxo.forms.FormData} object.
27: * <p/>
28: * The property, the input get mapped to, could depend on input values,
29: * so it is not part of this interface. Rather, it appears in the
30: * input validation result.
31: *
32: * @see de.odysseus.calyxo.forms.FormInputResult
33: * @author Christoph Beck
34: */
35: public interface FormInput {
36: /**
37: * Get the input parameter name
38: */
39: public String getName();
40:
41: /**
42: * True iff this input represents an array parameter
43: */
44: public boolean isArray();
45:
46: /**
47: * Validate.
48: * @param request the request we process
49: * @param params the input parameters
50: * @param resolver variable resolver used to evaluate expressions
51: * @return input validation result
52: */
53: public FormInputResult validate(HttpServletRequest request,
54: FormInputValues params, VariableResolver resolver);
55:
56: /**
57: * Format property.
58: * @param request the request we process
59: * @param bean form data
60: * @return if this is an array input, an array of strings; a string else
61: * @throws Exception if form data access failes
62: */
63: public Object format(HttpServletRequest request, FormData bean)
64: throws Exception;
65:
66: /**
67: * Format indexed property.
68: * @param request the request we process
69: * @param bean form data
70: * @param index index used to access property
71: * @param notAvailableResult returned if the property value is not available for the specified index
72: * @return formatted string
73: * @throws Exception if form data access failes
74: */
75: public String format(HttpServletRequest request, FormData bean,
76: int index, String notAvailableResult) throws Exception;
77:
78: /**
79: * Answer true iff the input should be treated "relaxed" if invalid.
80: * This information may be used to suppress error messages for an input.
81: *
82: * @param variables the variable resolver
83: * @return true iff the input should be treated "relaxed" if invalid.
84: */
85: public boolean isRelaxed(VariableResolver variables);
86:
87: /**
88: * Answer true iff the input should be "ignored".
89: * For an ignored input, no validation is done at all.
90: *
91: * @param variables the variable resolver
92: * @return true iff the input should be treated "ignored" if invalid.
93: */
94: public boolean isIgnored(VariableResolver variables);
95: }
|