KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > modules > input > RawRequestParameterModule


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
17 package org.apache.cocoon.components.modules.input;
18
19 import org.apache.avalon.framework.configuration.Configuration;
20 import org.apache.avalon.framework.configuration.ConfigurationException;
21 import org.apache.avalon.framework.thread.ThreadSafe;
22 import org.apache.cocoon.environment.ObjectModelHelper;
23
24 import java.util.Iterator JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.Vector JavaDoc;
27
28 /**
29  * RawRequestParameterModule accesses request parameters without
30  * decoding to the specified <code>form-encoding</code> or casting. It uses the
31  * {@link org.apache.cocoon.environment.Request#get} method instead of the
32  * {@link org.apache.cocoon.environment.Request#getParameter} method of the
33  * {@link org.apache.cocoon.environment.Request Request} This is useful for example
34  * in conjunction with uploads.
35  *
36  * <p>If <code>get()</code> returns a Vector, <code>getAttribute()</code> will return
37  * the first element, otherwise it will return the same as <code>get()</code>.
38  * <code>getAttributeValues()</code> will either convert the Vector to an array,
39  * place the result in a new array, or return the array as is.</p>
40  *
41  * @author <a HREF="mailto:haul@apache.org">Christian Haul</a>
42  * @version CVS $Id: RawRequestParameterModule.java 159644 2005-03-31 21:33:39Z vgritsenko $
43  */

44 public class RawRequestParameterModule extends AbstractInputModule implements ThreadSafe {
45
46     public Object JavaDoc getAttribute( String JavaDoc name, Configuration modeConf, Map JavaDoc objectModel ) throws ConfigurationException {
47
48         String JavaDoc pname = (String JavaDoc) this.settings.get("parameter",name);
49         if ( modeConf != null ) {
50             pname = modeConf.getAttribute( "parameter", pname );
51             // preferred
52
pname = modeConf.getChild("parameter").getValue(pname);
53         }
54         Object JavaDoc obj = ObjectModelHelper.getRequest(objectModel).get( pname );
55         if (obj instanceof Vector JavaDoc) {
56             return ((Vector JavaDoc) obj).firstElement();
57         } else {
58             return obj;
59         }
60
61     }
62
63
64     public Iterator JavaDoc getAttributeNames( Configuration modeConf, Map JavaDoc objectModel ) throws ConfigurationException {
65
66         return new IteratorHelper(ObjectModelHelper.getRequest(objectModel).getParameterNames());
67     }
68
69
70     public Object JavaDoc[] getAttributeValues( String JavaDoc name, Configuration modeConf, Map JavaDoc objectModel )
71         throws ConfigurationException {
72
73         Object JavaDoc obj = getAttribute(name, modeConf, objectModel);
74         if (obj instanceof Vector JavaDoc) {
75            return ((Vector JavaDoc)obj).toArray();
76         } else if (obj.getClass().isArray()) {
77             return (Object JavaDoc[]) obj;
78         } else {
79             Object JavaDoc[] tmp = new Object JavaDoc[1];
80             tmp[0] = obj;
81             return tmp;
82         }
83     }
84
85 }
86
Popular Tags