1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.mwolff.struts.back;
24
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.apache.struts.action.Action;
31 import org.apache.struts.action.ActionForm;
32 import org.apache.struts.action.ActionForward;
33 import org.apache.struts.action.ActionMapping;
34
35 /***
36 * .
37 * @author mwolff
38 *
39 */
40 public class BackRequestAction extends Action {
41
42 /***
43 * <p>Commons Logging instance.</p>
44 */
45 protected static Log log = LogFactory.getLog(BackRequestAction.class);
46
47 /***
48 * Original method from the struts-framework. This method pops the
49 * lastpath from the stack. If there is no back possible the method
50 * forwards to the original site, where the request come from
51 *
52 * @param mapping The ActionMapping class of this call.
53 * @param form The associated ActionForm class
54 * @param request The Request
55 * @param response The Response
56 * @return Must return an ActionForward
57 * @throws java.lang.Exception
58 */
59 public ActionForward execute(ActionMapping mapping,
60 ActionForm form,
61 HttpServletRequest request,
62 HttpServletResponse response)
63 throws Exception {
64
65 String lastPath = null;
66
67
68 RingBuffer buffer = (RingBuffer) request.getSession().getAttribute("org.mwolff.struts.back.RingBuffer");
69 ArrayEntry entry = buffer.back();
70
71 if (entry == null) {
72 entry = buffer.getLastPushed();
73 }
74
75 lastPath = (String) entry.getValue();
76 if (lastPath != null) {
77 buffer.setNoPush(true);
78 buffer.setWereInvolved(true);
79 }
80
81 request.getSession().setAttribute("org.mwolff.struts.back.RingBuffer", buffer);
82 return new ActionForward(lastPath, true);
83 }
84
85
86 }