1 package org.nextime.ion.frontoffice.servlet; 2 3 import java.io.IOException ; 4 import java.util.Iterator ; 5 6 import javax.servlet.ServletException ; 7 import javax.servlet.http.HttpServlet ; 8 import javax.servlet.http.HttpServletRequest ; 9 import javax.servlet.http.HttpServletResponse ; 10 11 import org.nextime.ion.framework.locale.Locale; 12 import org.nextime.ion.framework.locale.LocaleList; 13 14 17 public class ChangeLocaleServlet extends HttpServlet { 18 19 public void service( 20 HttpServletRequest request, 21 HttpServletResponse response) 22 throws ServletException , IOException { 23 24 String requestedLocale = 25 (request.getPathInfo() != null) 26 ? request.getPathInfo().substring(1) 27 : null; 28 if (requestedLocale != null) { 29 if (requestedLocale.indexOf(".") != -1) { 30 requestedLocale = 31 requestedLocale.substring(0, requestedLocale.indexOf(".")); 32 } 33 } 34 35 Iterator it = LocaleList.getInstance().getLocales().iterator(); 37 while (it.hasNext()) { 38 if (((Locale) it.next()).getLocale().equals(requestedLocale)) { 39 request.getSession().setAttribute("currentLocale", requestedLocale); 40 42 } 43 } 44 45 request.getRequestDispatcher("/changeLocale.jsp").forward(request,response); 46 47 } 48 49 } 50 | Popular Tags |