KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > acting > URLAction


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.portal.acting;
17
18 import java.util.Collections JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import org.apache.avalon.framework.parameters.Parameters;
22 import org.apache.avalon.framework.thread.ThreadSafe;
23 import org.apache.cocoon.acting.ServiceableAction;
24 import org.apache.cocoon.environment.Redirector;
25 import org.apache.cocoon.environment.SourceResolver;
26 import org.apache.cocoon.util.NetUtils;
27
28 /**
29  * This action builds correct urls. It uses the src parameter as the base url
30  * and adds all sitemap parameters as request parameters.
31  *
32  * @version $Id: URLAction.java 155907 2005-03-02 11:01:18Z cziegeler $
33 */

34 public class URLAction
35 extends ServiceableAction
36 implements ThreadSafe {
37
38     public Map JavaDoc act(Redirector redirector,
39                    SourceResolver resolver,
40                    Map JavaDoc objectModel,
41                    String JavaDoc source,
42                    Parameters par)
43     throws Exception JavaDoc {
44         if (this.getLogger().isDebugEnabled() ) {
45             this.getLogger().debug("BEGIN act resolver="+resolver+
46                                    ", objectModel="+objectModel+
47                                    ", source="+source+
48                                    ", par="+par);
49         }
50
51         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(source);
52         boolean hasParams = (source.indexOf('?') != -1);
53         final String JavaDoc[] names = par.getNames();
54         for( int i=0; i<names.length; i++ ) {
55             final String JavaDoc key = names[i];
56             final String JavaDoc value = par.getParameter(key);
57             if ( hasParams ) {
58                 buffer.append('&');
59             } else {
60                 buffer.append('?');
61                 hasParams = true;
62             }
63             buffer.append(key);
64             buffer.append('=');
65             buffer.append(NetUtils.encode(value, "utf-8"));
66         }
67         final Map JavaDoc result = Collections.singletonMap("url", buffer.toString());
68         if (this.getLogger().isDebugEnabled() ) {
69             this.getLogger().debug("END act map={}");
70         }
71
72         return result;
73     }
74
75 }
76
Popular Tags