1 package com.opensymphony.webwork.dispatcher.mapper; 2 3 import com.opensymphony.webwork.config.Configuration; 4 5 import javax.servlet.http.HttpServletRequest ; 6 import java.util.Iterator ; 7 import java.util.Map ; 8 9 16 public class DefaultActionMapper implements ActionMapper { 17 public ActionMapping getMapping(HttpServletRequest request) { 18 String uri = request.getServletPath(); 19 if (uri == null) { 20 uri = request.getRequestURI(); 21 uri = uri.substring(request.getContextPath().length()); 22 } 23 String includeUri = (String ) request.getAttribute("javax.servlet.include.servlet_path"); 24 if (includeUri != null) { 25 uri = includeUri; 26 } 27 28 if (!uri.endsWith("." + Configuration.get("webwork.action.extension"))) { 29 return null; 30 } 31 32 String namespace = uri.substring(0, uri.lastIndexOf("/")); 34 35 int beginIdx = uri.lastIndexOf("/"); 37 int endIdx = uri.lastIndexOf("."); 38 String name = uri.substring(((beginIdx == -1) ? 0 : (beginIdx + 1)), (endIdx == -1) ? uri.length() : endIdx); 39 40 String method = ""; 41 if (name.indexOf("!") != -1) { 42 endIdx = name.lastIndexOf("!"); 43 method = name.substring(endIdx + 1, name.length()); 44 name = name.substring(0, endIdx); 45 } else { 46 for (Iterator iterator = request.getParameterMap().entrySet().iterator(); iterator.hasNext();) { 47 Map.Entry entry = (Map.Entry ) iterator.next(); 48 String key = (String ) entry.getKey(); 49 if (key.startsWith("method:")) { 50 method = key.substring("method:".length()); 51 } else if (key.startsWith("action:")) { 52 name = key.substring("action:".length()); 53 } 54 } 55 } 56 57 return new ActionMapping(name, namespace, method, null); 58 } 59 60 public String getUriFromActionMapping(ActionMapping mapping) { 61 StringBuffer uri = new StringBuffer (); 62 63 uri.append(mapping.getNamespace()).append("/").append(mapping.getName()); 64 if (null != mapping.getMethod() && !"".equals(mapping.getMethod())) { 65 uri.append("!").append(mapping.getMethod()); 66 } 67 68 uri.append(".").append(Configuration.get("webwork.action.extension")); 69 70 return uri.toString(); 71 } 72 } 73 | Popular Tags |