01: /*
02: * $Id: SelectAction.java 508312 2007-02-16 04:56:54Z pbenedict $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21: package org.apache.struts.chain.commands.servlet;
22:
23: import org.apache.struts.chain.Constants;
24: import org.apache.struts.chain.commands.AbstractSelectAction;
25: import org.apache.struts.chain.contexts.ActionContext;
26: import org.apache.struts.chain.contexts.ServletActionContext;
27: import org.apache.struts.config.ModuleConfig;
28:
29: import javax.servlet.http.HttpServletRequest;
30:
31: /**
32: * <p>Cache the <code>ActionConfig</code> instance for the action to be used
33: * for processing this request.</p>
34: *
35: * @version $Rev: 508312 $ $Date: 2005-05-07 12:11:38 -0400 (Sat, 07 May 2005)
36: * $
37: */
38: public class SelectAction extends AbstractSelectAction {
39: // ------------------------------------------------------- Protected Methods
40: protected String getPath(ActionContext context) {
41: ServletActionContext saContext = (ServletActionContext) context;
42: HttpServletRequest request = saContext.getRequest();
43: String path = null;
44: boolean extension = false;
45:
46: // For prefix matching, match on the path info
47: path = (String) request
48: .getAttribute(Constants.INCLUDE_PATH_INFO);
49:
50: if ((path == null) || (path.length() == 0)) {
51: path = request.getPathInfo();
52: }
53:
54: // For extension matching, match on the servlet path
55: if ((path == null) || (path.length() == 0)) {
56: path = (String) request
57: .getAttribute(Constants.INCLUDE_SERVLET_PATH);
58:
59: if ((path == null) || (path.length() == 0)) {
60: path = request.getServletPath();
61: }
62:
63: if ((path == null) || (path.length() == 0)) {
64: throw new IllegalArgumentException(
65: "No path information in request");
66: }
67:
68: extension = true;
69: }
70:
71: // Strip the module prefix and extension (if any)
72: ModuleConfig moduleConfig = saContext.getModuleConfig();
73: String prefix = moduleConfig.getPrefix();
74:
75: if (!path.startsWith(prefix)) {
76: throw new IllegalArgumentException(
77: "Path does not start with '" + prefix + "'");
78: }
79:
80: path = path.substring(prefix.length());
81:
82: if (extension) {
83: int slash = path.lastIndexOf("/");
84: int period = path.lastIndexOf(".");
85:
86: if ((period >= 0) && (period > slash)) {
87: path = path.substring(0, period);
88: }
89: }
90:
91: return (path);
92: }
93: }
|