KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nextime > ion > frontoffice > servlet > ChangeLocaleServlet


1 package org.nextime.ion.frontoffice.servlet;
2
3 import java.io.IOException JavaDoc;
4 import java.util.Iterator JavaDoc;
5
6 import javax.servlet.ServletException JavaDoc;
7 import javax.servlet.http.HttpServlet JavaDoc;
8 import javax.servlet.http.HttpServletRequest JavaDoc;
9 import javax.servlet.http.HttpServletResponse JavaDoc;
10
11 import org.nextime.ion.framework.locale.Locale;
12 import org.nextime.ion.framework.locale.LocaleList;
13
14 /**
15  * @author gbort
16  */

17 public class ChangeLocaleServlet extends HttpServlet JavaDoc {
18
19     public void service(
20         HttpServletRequest JavaDoc request,
21         HttpServletResponse JavaDoc response)
22         throws ServletException JavaDoc, IOException JavaDoc {
23
24         String JavaDoc 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         // check if locale is supported
36
Iterator JavaDoc it = LocaleList.getInstance().getLocales().iterator();
37         while (it.hasNext()) {
38             if (((Locale) it.next()).getLocale().equals(requestedLocale)) {
39                 request.getSession().setAttribute("currentLocale", requestedLocale);
40                 //request.getSession().setAttribute("javax.servlet.jsp.jstl.fmt.locale", requestedLocale);
41

42             }
43         }
44         
45         request.getRequestDispatcher("/changeLocale.jsp").forward(request,response);
46             
47     }
48
49 }
50
Popular Tags