KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nextime > ion > backoffice > action > MenuAction


1 package org.nextime.ion.backoffice.action;
2
3
4 import java.io.IOException JavaDoc;
5 import java.io.File JavaDoc;
6 import java.util.Locale JavaDoc;
7
8 import javax.servlet.ServletException JavaDoc;
9 import javax.servlet.http.HttpServletRequest JavaDoc;
10 import javax.servlet.http.HttpServletResponse JavaDoc;
11 import org.apache.struts.action.Action;
12 import org.apache.struts.action.ActionForm;
13 import org.apache.struts.action.ActionForward;
14 import org.apache.struts.action.ActionMapping;
15
16 import javax.servlet.http.HttpSession JavaDoc;
17
18
19
20 public class MenuAction extends Action {
21
22     public ActionForward perform(ActionMapping mapping,
23                                  ActionForm form,
24                                  HttpServletRequest JavaDoc request,
25                                  HttpServletResponse JavaDoc response)
26         throws IOException JavaDoc, ServletException JavaDoc {
27             
28             HttpSession JavaDoc session = request.getSession();
29             
30             Locale JavaDoc newLocale = request.getLocale();
31                 if (newLocale != null){
32                     session.setAttribute(Action.LOCALE_KEY, newLocale);
33                     
34                     Locale JavaDoc locs[] = Locale.getAvailableLocales();
35                     boolean b = false;
36                     for (int i=0; i < locs.length; i++) {
37                         if (newLocale.equals(locs[i])) {
38                             b = true;
39                             break;
40                         }
41                     }
42                     
43                     String JavaDoc lMenu = "/xml/localizedMenu/menu_" + newLocale.getLanguage() + ".xml";
44                     File JavaDoc f = new File JavaDoc(servlet.getServletContext().getRealPath(lMenu));
45                     
46                     if (b && f.exists()) {
47                         request.getSession().setAttribute("localizedMenu", lMenu);
48                     }
49                     else {
50                         request.getSession().setAttribute("localizedMenu", "/xml/menu.xml");
51                     }
52                 }
53                 else {
54                     request.getSession().setAttribute("localizedMenu", "/xml/menu.xml");
55                 }
56         
57         // Forward to the next page
58
return (mapping.findForward("view"));
59
60     }
61
62 }
63
Popular Tags