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:
18: package org.apache.cocoon.components.modules.input;
19:
20: import org.apache.avalon.framework.configuration.Configuration;
21: import org.apache.avalon.framework.configuration.ConfigurationException;
22: import org.apache.avalon.framework.thread.ThreadSafe;
23: import org.apache.cocoon.environment.ObjectModelHelper;
24:
25: import java.util.Iterator;
26: import java.util.Map;
27: import java.util.Vector;
28:
29: /**
30: * RequestURIModule accesses the request URI. The {@link
31: * RequestModule} provides similar functionality based on JXPath.
32: *
33: * @author <a href="mailto:haul@apache.org">Christian Haul</a>
34: * @version $Id: RequestURIModule.java 433543 2006-08-22 06:22:54Z crossley $
35: */
36: public class RequestURIModule extends AbstractInputModule implements
37: ThreadSafe {
38:
39: final static Vector returnNames;
40: static {
41: Vector tmp = new Vector();
42: tmp.add("requestURI");
43: returnNames = tmp;
44: }
45:
46: public Object getAttribute(String name, Configuration modeConf,
47: Map objectModel) throws ConfigurationException {
48:
49: String uri = ObjectModelHelper.getRequest(objectModel)
50: .getSitemapURI();
51:
52: if (uri.startsWith("/")) {
53: uri = uri.substring(1);
54: }
55:
56: return uri;
57: }
58:
59: public Iterator getAttributeNames(Configuration modeConf,
60: Map objectModel) throws ConfigurationException {
61:
62: return RequestURIModule.returnNames.iterator();
63: }
64:
65: public Object[] getAttributeValues(String name,
66: Configuration modeConf, Map objectModel)
67: throws ConfigurationException {
68:
69: Object values = new Object[1];
70: values = this .getAttribute(name, modeConf, objectModel);
71:
72: return (values == null ? null : new Object[] { values });
73: }
74:
75: }
|