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.Globals; 24 import org.apache.struts.chain.AbstractSelectModule; 25 import org.apache.struts.chain.Constants; 26 27 28 36 37 public class SelectModule extends AbstractSelectModule { 38 39 40 42 43 protected String getPrefix(Context context) { 44 45 ServletWebContext swcontext = (ServletWebContext) context; 47 HttpServletRequest request = swcontext.getRequest(); 48 String uri = 49 (String ) request.getAttribute(Constants.INCLUDE_SERVLET_PATH); 50 if (uri == null) { 51 uri = request.getServletPath(); 52 } 53 if (uri == null) { 54 throw new IllegalArgumentException 55 ("No path information in request"); 56 } 57 58 String prefix = ""; String prefixes[] = (String []) 61 swcontext.getApplicationScope().get(Globals.MODULE_PREFIXES_KEY); 62 int lastSlash = 0; 63 while (prefix.equals("") && 64 ((lastSlash = uri.lastIndexOf("/")) > 0)) { 65 uri = uri.substring(0, lastSlash); 66 for (int i = 0; i < prefixes.length; i++) { 67 if (uri.equals(prefixes[i])) { 68 prefix = prefixes[i]; 69 break; 70 } 71 } 72 } 73 74 return (prefix); 75 76 } 77 78 79 } 80 | Popular Tags |