KickJava   Java API By Example, From Geeks To Geeks.

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


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
17 package org.apache.cocoon.components.modules.input;
18
19 import org.apache.avalon.framework.configuration.Configuration;
20 import org.apache.avalon.framework.configuration.ConfigurationException;
21 import org.apache.avalon.framework.thread.ThreadSafe;
22 import org.apache.cocoon.environment.ObjectModelHelper;
23
24 import java.util.Iterator JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.Vector JavaDoc;
27
28 /**
29  * RequestURIModule accesses the request URI. The {@link
30  * RequestModule} provides similar functionality based on JXPath.
31  *
32  * @author <a HREF="mailto:haul@apache.org">Christian Haul</a>
33  * @version CVS $Id: RequestURIModule.java 30932 2004-07-29 17:35:38Z vgritsenko $
34  */

35 public class RequestURIModule extends AbstractInputModule implements ThreadSafe {
36
37     final static Vector JavaDoc returnNames;
38     static {
39         Vector JavaDoc tmp = new Vector JavaDoc();
40         tmp.add("requestURI");
41         returnNames = tmp;
42     }
43
44     public Object JavaDoc getAttribute( String JavaDoc name, Configuration modeConf, Map JavaDoc objectModel ) throws ConfigurationException {
45
46         String JavaDoc uri = ObjectModelHelper.getRequest(objectModel).getSitemapURI();
47
48         if (uri.startsWith("/")) {
49             uri = uri.substring(1);
50         }
51
52         return uri;
53     }
54
55
56     public Iterator JavaDoc getAttributeNames( Configuration modeConf, Map JavaDoc objectModel ) throws ConfigurationException {
57
58         return RequestURIModule.returnNames.iterator();
59     }
60
61
62     public Object JavaDoc[] getAttributeValues( String JavaDoc name, Configuration modeConf, Map JavaDoc objectModel )
63         throws ConfigurationException {
64
65             Object JavaDoc values = new Object JavaDoc[1];
66             values = this.getAttribute(name, modeConf, objectModel);
67
68             return (values == null? null : new Object JavaDoc[]{values});
69     }
70
71 }
72
Popular Tags