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.components.modules.input;
18:
19: import java.io.UnsupportedEncodingException;
20: import java.util.Map;
21:
22: import org.apache.avalon.framework.configuration.Configuration;
23: import org.apache.avalon.framework.configuration.ConfigurationException;
24: import org.apache.avalon.framework.thread.ThreadSafe;
25: import org.apache.cocoon.util.NetUtils;
26:
27: /**
28: * This module provides functionality for converting a String to the
29: * application/x-www-form-urlencoded MIME format. It is useful for example for
30: * calling remote services: <br/>
31: * <map:generate src="http://remote/page?param1={url-encode:{request-param:param1}}"/><br/>
32: * Module configuration takes only one configuration parameter:
33: * "encoding" which is a target string encoding. This is utf-8 by default.
34: *
35: * @version $Id$
36: */
37: public final class URLEncodeModule extends AbstractInputModule
38: implements ThreadSafe {
39:
40: public Object getAttribute(String name, Configuration modeConf,
41: Map objectModel) throws ConfigurationException {
42: if (name == null) {
43: return null;
44: }
45:
46: String encoding = (String) this .settings.get("encoding",
47: "utf-8");
48: try {
49: return NetUtils.encode(name, encoding);
50: } catch (UnsupportedEncodingException e) {
51: throw new ConfigurationException(
52: "URLEncodeModule, invalid encoding: " + encoding);
53: }
54: }
55: }
|