KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > acting > FormValidatorAction


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 org.apache.cocoon.acting;
17
18 import org.apache.avalon.framework.configuration.Configuration;
19 import org.apache.avalon.framework.thread.ThreadSafe;
20
21 import org.apache.cocoon.environment.ObjectModelHelper;
22 import org.apache.cocoon.environment.Request;
23
24 import java.util.Collection JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.Map JavaDoc;
28
29 /**
30  * This is the action used to validate Request parameters.
31  * The parameters are described via the external xml
32  * file (its format is defined in AbstractValidatorAction).
33  * @see org.apache.cocoon.acting.AbstractValidatorAction
34  *
35  * @author <a HREF="mailto:Martin.Man@seznam.cz">Martin Man</a>
36  * @author <a HREF="mailto:haul@apache.org">Christian Haul</a>
37  * @version CVS $Id: FormValidatorAction.java 30932 2004-07-29 17:35:38Z vgritsenko $
38  */

39 public class FormValidatorAction extends AbstractValidatorAction implements ThreadSafe {
40
41     /**
42      * Reads parameter values from request parameters for all parameters
43      * that are contained in the active constraint list. If a parameter
44      * has multiple values, all are stored in the resulting map.
45      *
46      * @param objectModel the object model
47      * @param set a collection of parameter names
48      * @return HashMap of required parameters
49      */

50     protected HashMap JavaDoc createMapOfParameters(Map JavaDoc objectModel, Collection JavaDoc set) {
51         String JavaDoc name;
52         HashMap JavaDoc params = new HashMap JavaDoc(set.size());
53         // put required params into hash
54
Request request = ObjectModelHelper.getRequest(objectModel);
55         for (Iterator JavaDoc i = set.iterator(); i.hasNext();) {
56             name = ((Configuration) i.next()).getAttribute("name", "").trim();
57             Object JavaDoc[] values = request.getParameterValues(name);
58             if (values != null) {
59                 switch (values.length) {
60                     case 0 :
61                         params.put(name, null);
62                         break;
63                     case 1 :
64                         params.put(name, values[0]);
65                         break;
66                     default :
67                         params.put(name, values);
68                 }
69             } else {
70                 params.put(name, values);
71             }
72         }
73         return params;
74     }
75
76     /* (non-Javadoc)
77      * @see org.apache.cocoon.acting.AbstractValidatorAction#isStringEncoded()
78      */

79     boolean isStringEncoded() {
80         return true;
81     }
82
83
84 }
85
Popular Tags