1 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 34 35 public class SelectAction extends AbstractSelectAction { 36 37 38 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 path = (String ) request.getAttribute(Constants.INCLUDE_PATH_INFO); 50 if (path == null) { 51 path = request.getPathInfo(); 52 } 53 54 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 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 } 90 | Popular Tags |