01: package org.gomba.domains;
02:
03: import org.gomba.ParameterDefinition;
04: import org.gomba.ParameterDomain;
05: import org.gomba.ParameterResolver;
06:
07: /**
08: * This domain contains properties extracted from the servlet request
09: * parameters. All values for that parameter can be accessed.
10: * paramValues.myParam.0
11: *
12: * @author Flavio Tordini
13: * @version $Id: ParamValuesDomain.java,v 1.1.1.1 2004/06/16 13:15:12
14: * flaviotordini Exp $
15: */
16: public class ParamValuesDomain implements ParameterDomain {
17:
18: /**
19: * @see org.gomba.ParameterDomain#getParameterValue(org.gomba.ParameterResolver,
20: * org.gomba.ParameterDefinition)
21: */
22: public Object getParameterValue(ParameterResolver context,
23: ParameterDefinition parameter) throws Exception {
24: final String name = parameter.getName();
25: int separatorIndex = name.indexOf('.');
26: if (separatorIndex < 0 || separatorIndex == name.length() - 1) {
27: throw new Exception("Syntax error in parameter: "
28: + parameter);
29: }
30: String paramName = name.substring(0, separatorIndex);
31: int index = Integer
32: .parseInt(name.substring(separatorIndex + 1));
33:
34: String[] values = context.getRequest().getParameterValues(
35: paramName);
36: if (values != null) {
37: return values[index];
38: }
39: return null;
40:
41: }
42:
43: /**
44: * @see org.gomba.ParameterDomain#getName()
45: */
46: public String getName() {
47: return "paramValues";
48: }
49:
50: }
|