1 package org.nextime.ion.backoffice.action; 2 3 4 import java.io.IOException ; 5 import java.io.File ; 6 import java.util.Locale ; 7 8 import javax.servlet.ServletException ; 9 import javax.servlet.http.HttpServletRequest ; 10 import javax.servlet.http.HttpServletResponse ; 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 ; 17 18 19 20 public class MenuAction extends Action { 21 22 public ActionForward perform(ActionMapping mapping, 23 ActionForm form, 24 HttpServletRequest request, 25 HttpServletResponse response) 26 throws IOException , ServletException { 27 28 HttpSession session = request.getSession(); 29 30 Locale newLocale = request.getLocale(); 31 if (newLocale != null){ 32 session.setAttribute(Action.LOCALE_KEY, newLocale); 33 34 Locale 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 lMenu = "/xml/localizedMenu/menu_" + newLocale.getLanguage() + ".xml"; 44 File f = new File (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 return (mapping.findForward("view")); 59 60 } 61 62 } 63 | Popular Tags |