KickJava   Java API By Example, From Geeks To Geeks.

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


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.parameters.ParameterException;
19 import org.apache.avalon.framework.parameters.Parameterizable;
20 import org.apache.avalon.framework.parameters.Parameters;
21 import org.apache.avalon.framework.thread.ThreadSafe;
22
23 import org.apache.cocoon.environment.ObjectModelHelper;
24 import org.apache.cocoon.environment.Redirector;
25 import org.apache.cocoon.environment.Request;
26 import org.apache.cocoon.environment.SourceResolver;
27
28 import java.util.Map JavaDoc;
29
30 /**
31  * Sets the character encoding of parameters.
32  * Components use this encoding as default after the action.
33  * <p>
34  * <b>Configuration parameters:</b>
35  * <dl>
36  * <dt><i>form-encoding</i> (optional)
37  * <dd>The supposed encoding of the request parameter.
38  * </dl>
39  * These configuration options supported in both declaration and use time.
40  * <p>If no encoding specified, the action does nothing.
41  *
42  * @author <a HREF="mailto:miyabe@jzf.co.jp">MIYABE Tatsuhiko</a>
43  * @version CVS $Id: SetCharacterEncodingAction.java 30932 2004-07-29 17:35:38Z vgritsenko $
44  */

45 public class SetCharacterEncodingAction extends ServiceableAction implements ThreadSafe, Parameterizable {
46     private String JavaDoc global_form_encoding = null;
47
48     public void parameterize(Parameters parameters)
49     throws ParameterException {
50         // super.parameterize(parameters);
51

52         global_form_encoding = parameters.getParameter("form-encoding", null);
53     }
54
55     /**
56      * Set character encoding of current request.
57      */

58     public Map JavaDoc act (Redirector redirector, SourceResolver resolver, Map JavaDoc objectModel, String JavaDoc src, Parameters par) throws Exception JavaDoc {
59         Request request = ObjectModelHelper.getRequest(objectModel);
60         if (request != null) {
61             String JavaDoc form_encoding = par.getParameter("form-encoding", global_form_encoding);
62             if (form_encoding != null) {
63                 request.setCharacterEncoding(form_encoding);
64             }
65         }
66
67         return null;
68     }
69 }
70
Popular Tags