View Javadoc

1   /*
2    * $Revision: 1.2 $
3    * $Date: 2006/02/28 18:33:34 $
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 java.util.Locale;
26  
27  import javax.servlet.http.HttpServletRequest;
28  import javax.servlet.http.HttpServletResponse;
29  
30  import org.apache.commons.logging.Log;
31  import org.apache.commons.logging.LogFactory;
32  import org.apache.struts.Globals;
33  import org.apache.struts.action.Action;
34  import org.apache.struts.action.ActionForm;
35  import org.apache.struts.action.ActionForward;
36  import org.apache.struts.action.ActionMapping;
37  
38  /***
39   * .
40   * 
41   * @author mwolff
42   */
43  public class LanguageSwitchAction extends Action {
44  
45      /***
46       * <p>
47       * Commons Logging instance.
48       * </p>
49       */
50      protected static Log log = LogFactory.getLog(LanguageSwitchAction.class);
51  
52      /***
53       * Original method from the struts-framework. This method pops the lastpath
54       * from the stack. If there is no back possible the method forwards to the
55       * original site, where the request come from
56       * 
57       * @param mapping
58       *            The ActionMapping class of this call.
59       * @param form
60       *            The associated ActionForm class
61       * @param request
62       *            The Request
63       * @param response
64       *            The Response
65       * @return Must return an ActionForward
66       * @throws java.lang.Exception
67       */
68      public ActionForward execute(ActionMapping mapping, ActionForm form,
69          HttpServletRequest request, HttpServletResponse response)
70          throws Exception {
71  
72          String lastPath = null;
73  
74          // find last path
75          RingBuffer buffer = (RingBuffer) request.getSession().getAttribute(
76              "org.mwolff.struts.back.RingBuffer");
77          ArrayEntry entry = buffer.getActIndex();
78  
79          lastPath = (String) entry.getValue();
80          if (lastPath != null) {
81              buffer.setNoPush(true);
82              buffer.setWereInvolved(true);
83          }
84  
85          String language = (String) request.getParameter("language");
86  
87          if (language != null) {
88              Locale locale = new Locale(language);
89              request.getSession().setAttribute(Globals.LOCALE_KEY, locale);
90          }
91  
92          request.getSession().setAttribute("org.mwolff.struts.back.RingBuffer",
93              buffer);
94          return new ActionForward(lastPath, true);
95      }
96  
97  }