01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.acting;
18:
19: import org.apache.avalon.framework.configuration.Configuration;
20: import org.apache.avalon.framework.thread.ThreadSafe;
21:
22: import org.apache.cocoon.environment.ObjectModelHelper;
23: import org.apache.cocoon.environment.Request;
24:
25: import java.util.Collection;
26: import java.util.HashMap;
27: import java.util.Iterator;
28: import java.util.Map;
29:
30: /**
31: * This is the action used to validate Request parameters.
32: * The parameters are described via the external xml
33: * file (its format is defined in AbstractValidatorAction).
34: * @see org.apache.cocoon.acting.AbstractValidatorAction
35: *
36: * @author <a href="mailto:Martin.Man@seznam.cz">Martin Man</a>
37: * @author <a href="mailto:haul@apache.org">Christian Haul</a>
38: * @version CVS $Id: FormValidatorAction.java 433543 2006-08-22 06:22:54Z crossley $
39: */
40: public class FormValidatorAction extends AbstractValidatorAction
41: implements ThreadSafe {
42:
43: /**
44: * Reads parameter values from request parameters for all parameters
45: * that are contained in the active constraint list. If a parameter
46: * has multiple values, all are stored in the resulting map.
47: *
48: * @param objectModel the object model
49: * @param set a collection of parameter names
50: * @return HashMap of required parameters
51: */
52: protected HashMap createMapOfParameters(Map objectModel,
53: Collection set) {
54: String name;
55: HashMap params = new HashMap(set.size());
56: // put required params into hash
57: Request request = ObjectModelHelper.getRequest(objectModel);
58: for (Iterator i = set.iterator(); i.hasNext();) {
59: name = ((Configuration) i.next()).getAttribute("name", "")
60: .trim();
61: Object[] values = request.getParameterValues(name);
62: if (values != null) {
63: switch (values.length) {
64: case 0:
65: params.put(name, null);
66: break;
67: case 1:
68: params.put(name, values[0]);
69: break;
70: default:
71: params.put(name, values);
72: }
73: } else {
74: params.put(name, values);
75: }
76: }
77: return params;
78: }
79:
80: /* (non-Javadoc)
81: * @see org.apache.cocoon.acting.AbstractValidatorAction#isStringEncoded()
82: */
83: boolean isStringEncoded() {
84: return true;
85: }
86:
87: }
|