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 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
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 }