1 package org.exoplatform.portal.portlet.struts; 2 3 import java.io.IOException ; 4 import java.util.* ; 5 import javax.servlet.ServletException ; 6 import javax.servlet.RequestDispatcher ; 7 import javax.servlet.http.HttpServletRequest ; 8 import javax.servlet.http.HttpServletResponse ; 9 import org.apache.struts.upload.MultipartRequestWrapper; 10 import org.apache.commons.lang.StringUtils ; 11 12 import org.apache.struts.action.RequestProcessor ; 13 import org.exoplatform.services.portletcontainer.impl.portletAPIImp.helpers.CustomRequestWrapper; 14 15 public class ExoRequestProcessor extends RequestProcessor { 16 protected void doForward( String uri, HttpServletRequest request, HttpServletResponse response) 17 throws IOException , ServletException 18 { 19 if (request instanceof MultipartRequestWrapper) { 21 request = ((MultipartRequestWrapper) request).getRequest(); 22 } 23 CustomRequestWrapper requestWrapper = (CustomRequestWrapper)request; 24 int question = uri.indexOf("?") ; 25 String actionPath = null ; 26 String params = "" ; 27 if (question > 0) { 28 actionPath = uri.substring(0, question) ; 30 params = uri.substring (question, uri.length()) ; 31 } else { 33 actionPath = uri ; 34 } 35 36 String path = "/struts-controller" ; 37 if (actionPath.endsWith(".do")) { 38 path += params ; 39 requestWrapper.setRedirectedPath(path); 40 requestWrapper.setAttribute("exo.forward", actionPath) ; 41 } else { 42 path = uri ; 43 } 44 RequestDispatcher rd = getServletContext().getRequestDispatcher(path); 45 if (rd == null) { 46 throw new ServletException ("Cannot find " + path) ; 47 } 48 requestWrapper.setRedirected(true); 49 rd.include(requestWrapper, response); 50 } 51 52 private Map parseParams(String params) { 53 HashMap map = new HashMap(5) ; 54 String [] param = StringUtils.split(params, "&") ; 55 for (int i = 0; i < param.length; i++) { 56 String [] tmp = StringUtils.split(param[i], "=") ; 57 String key = tmp[0] ; 58 List values = (List) map.get(key) ; 59 if (values == null) { 60 values = new ArrayList(3) ; 61 } 62 values.add(tmp[1]) ; 63 map.put(key, values) ; 64 } 65 Iterator keys = map.keySet().iterator() ; 66 Map paramMap = new HashMap() ; 67 while (keys.hasNext()) { 68 String key = (String ) keys.next() ; 69 List list = (List) map.get(key) ; 70 String [] values = new String [list.size()] ; 71 for (int i = 0; i < list.size(); i++) { 72 values[i] = (String ) list.get(i) ; 73 } 74 paramMap.put(key, values) ; 75 } 76 return paramMap ; 77 } 78 } 79 | Popular Tags |