KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portal > portlet > struts > ExoRequestProcessor


1 package org.exoplatform.portal.portlet.struts;
2
3 import java.io.IOException JavaDoc ;
4 import java.util.* ;
5 import javax.servlet.ServletException JavaDoc;
6 import javax.servlet.RequestDispatcher JavaDoc ;
7 import javax.servlet.http.HttpServletRequest JavaDoc;
8 import javax.servlet.http.HttpServletResponse JavaDoc;
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 JavaDoc uri, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
17     throws IOException JavaDoc, ServletException JavaDoc
18   {
19     // Unwrap the multipart request, if there is one.
20
if (request instanceof MultipartRequestWrapper) {
21       request = ((MultipartRequestWrapper) request).getRequest();
22     }
23     CustomRequestWrapper requestWrapper = (CustomRequestWrapper)request;
24     int question = uri.indexOf("?") ;
25     String JavaDoc actionPath = null ;
26     String JavaDoc params = "" ;
27     if (question > 0) {
28       //Map paramMap = requestWrapper.getParameterMap() ;
29
actionPath = uri.substring(0, question) ;
30       params = uri.substring (question, uri.length()) ;
31       //requestWrapper.setParameterMap(parseParams(params)) ;
32
} else {
33       actionPath = uri ;
34     }
35
36     String JavaDoc 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 JavaDoc rd = getServletContext().getRequestDispatcher(path);
45     if (rd == null) {
46       throw new ServletException JavaDoc("Cannot find " + path) ;
47     }
48     requestWrapper.setRedirected(true);
49     rd.include(requestWrapper, response);
50   }
51
52   private Map parseParams(String JavaDoc params) {
53     HashMap map = new HashMap(5) ;
54     String JavaDoc[] param = StringUtils.split(params, "&") ;
55     for (int i = 0; i < param.length; i++) {
56       String JavaDoc[] tmp = StringUtils.split(param[i], "=") ;
57       String JavaDoc 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 JavaDoc key = (String JavaDoc) keys.next() ;
69       List list = (List) map.get(key) ;
70       String JavaDoc[] values = new String JavaDoc[list.size()] ;
71       for (int i = 0; i < list.size(); i++) {
72         values[i] = (String JavaDoc) list.get(i) ;
73       }
74       paramMap.put(key, values) ;
75     }
76     return paramMap ;
77   }
78 }
79
Popular Tags