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.parameters.ParameterException;
20: import org.apache.avalon.framework.parameters.Parameterizable;
21: import org.apache.avalon.framework.parameters.Parameters;
22: import org.apache.avalon.framework.thread.ThreadSafe;
23:
24: import org.apache.cocoon.environment.ObjectModelHelper;
25: import org.apache.cocoon.environment.Redirector;
26: import org.apache.cocoon.environment.Request;
27: import org.apache.cocoon.environment.SourceResolver;
28:
29: import java.util.Map;
30:
31: /**
32: * Sets the character encoding of parameters.
33: * Components use this encoding as default after the action.
34: * <p>
35: * <b>Configuration parameters:</b>
36: * <dl>
37: * <dt><i>form-encoding</i> (optional)
38: * <dd>The supposed encoding of the request parameter.
39: * </dl>
40: * These configuration options supported in both declaration and use time.
41: * <p>If no encoding specified, the action does nothing.
42: *
43: * @author <a href="mailto:miyabe@jzf.co.jp">MIYABE Tatsuhiko</a>
44: * @version CVS $Id: SetCharacterEncodingAction.java 433543 2006-08-22 06:22:54Z crossley $
45: */
46: public class SetCharacterEncodingAction extends ServiceableAction
47: implements ThreadSafe, Parameterizable {
48: private String global_form_encoding = null;
49:
50: public void parameterize(Parameters parameters)
51: throws ParameterException {
52: // super.parameterize(parameters);
53:
54: global_form_encoding = parameters.getParameter("form-encoding",
55: null);
56: }
57:
58: /**
59: * Set character encoding of current request.
60: */
61: public Map act(Redirector redirector, SourceResolver resolver,
62: Map objectModel, String src, Parameters par)
63: throws Exception {
64: Request request = ObjectModelHelper.getRequest(objectModel);
65: if (request != null) {
66: String form_encoding = par.getParameter("form-encoding",
67: global_form_encoding);
68: if (form_encoding != null) {
69: request.setCharacterEncoding(form_encoding);
70: }
71: }
72:
73: return null;
74: }
75: }
|