KickJava   Java API By Example, From Geeks To Geeks.

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


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.components.modules.input;
17
18 import java.io.UnsupportedEncodingException JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import org.apache.avalon.framework.configuration.Configuration;
22 import org.apache.avalon.framework.configuration.ConfigurationException;
23 import org.apache.avalon.framework.thread.ThreadSafe;
24 import org.apache.cocoon.util.NetUtils;
25
26 /**
27  * This module provides functionality for converting a String to the
28  * application/x-www-form-urlencoded MIME format. It is useful for example for
29  * calling remote services: <br/>
30  * &lt;map:generate SRC="http://remote/page?param1={url-encode:{request-param:param1}}"/&gt;<br/>
31  * Module configuration takes only one configuration parameter:
32  * "encoding" which is a target string encoding. This is utf-8 by default.
33  */

34 public final class URLEncodeModule extends AbstractInputModule
35                                    implements ThreadSafe {
36
37     public Object JavaDoc getAttribute(String JavaDoc name,
38                                Configuration modeConf,
39                                Map JavaDoc objectModel) throws ConfigurationException {
40         if (name == null) {
41             return null;
42         }
43
44         String JavaDoc encoding = (String JavaDoc) this.settings.get("encoding", "utf-8");
45         try {
46             return NetUtils.encode(name, encoding);
47         } catch (UnsupportedEncodingException JavaDoc e) {
48             throw new ConfigurationException("URLEncodeModule, invalid encoding: " + encoding);
49         }
50     }
51 }
52
Popular Tags