View Javadoc

1   /*
2    * $Revision: 1.1 $
3    * $Date: 2006/02/24 16:50:42 $
4    *
5    * ====================================================================
6    * Struts back mechanism
7    * Copyright (C) 2006 - Manfred Wolff
8    * 
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   *
21   * created: 21-01-2006 Manfred Wolff (wolff@mwolff.org)
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 ForwardRequestAction extends Action {
41  
42      /***
43       * <p>Commons Logging instance.</p>
44       */
45      protected static Log log = LogFactory.getLog(ForwardRequestAction.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          // find last path
68          RingBuffer buffer = (RingBuffer) request.getSession().getAttribute("org.mwolff.struts.back.RingBuffer");
69          ArrayEntry entry = buffer.forward();
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  }