1 /* 2 * Copyright 2003,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.struts.chain.servlet; 18 19 20 import javax.servlet.http.HttpServletRequest; 21 import org.apache.commons.chain.Context; 22 import org.apache.commons.chain.web.servlet.ServletWebContext; 23 import org.apache.struts.chain.AbstractSelectAction; 24 import org.apache.struts.chain.Constants; 25 import org.apache.struts.config.ModuleConfig; 26 27 28 /** 29 * <p>Cache the <code>ActionConfig</code> instance for the 30 * action to be used for processing this request.</p> 31 * 32 * @version $Rev: 54933 $ $Date: 2004-10-16 18:04:52 +0100 (Sat, 16 Oct 2004) $ 33 */ 34 35 public class SelectAction extends AbstractSelectAction { 36 37 38 // ------------------------------------------------------- Protected Methods 39 40 41 protected String getPath(Context context) { 42 43 ServletWebContext swcontext = (ServletWebContext) context; 44 HttpServletRequest request = swcontext.getRequest(); 45 String path = null; 46 boolean extension = false; 47 48 // For prefix matching, match on the path info 49 path = (String) request.getAttribute(Constants.INCLUDE_PATH_INFO); 50 if (path == null) { 51 path = request.getPathInfo(); 52 } 53 54 // For extension matching, match on the servlet path 55 if (path == null) { 56 path = 57 (String) request.getAttribute(Constants.INCLUDE_SERVLET_PATH); 58 if (path == null) { 59 path = request.getServletPath(); 60 } 61 if (path == null) { 62 throw new IllegalArgumentException 63 ("No path information in request"); 64 } 65 extension = true; 66 } 67 68 // Strip the module prefix and extension (if any) 69 ModuleConfig moduleConfig = (ModuleConfig) 70 swcontext.get(getModuleConfigKey()); 71 String prefix = moduleConfig.getPrefix(); 72 if (!path.startsWith(prefix)) { 73 throw new IllegalArgumentException("Path does not start with '" + 74 prefix + "'"); 75 } 76 path = path.substring(prefix.length()); 77 if (extension) { 78 int slash = path.lastIndexOf("/"); 79 int period = path.lastIndexOf("."); 80 if ((period >= 0) && (period > slash)) { 81 path = path.substring(0, period); 82 } 83 } 84 return (path); 85 86 } 87 88 89 }