KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nextime > ion > backoffice > bean > SectionTypes


1 package org.nextime.ion.backoffice.bean;
2
3 import java.util.Locale JavaDoc;
4 import java.io.File JavaDoc;
5 import java.io.FileInputStream JavaDoc;
6 import java.util.Vector JavaDoc;
7 import javax.servlet.http.HttpServlet JavaDoc;
8 import org.apache.struts.action.Action;
9 import javax.servlet.http.HttpServletRequest JavaDoc;
10 import javax.servlet.http.HttpSession JavaDoc;
11
12 public class SectionTypes {
13
14     private static TypeBean bean;
15     
16     private static TypeBean getLocalizedTypeBean (HttpServlet JavaDoc servlet, HttpServletRequest JavaDoc request) throws Exception JavaDoc {
17         HttpSession JavaDoc session = request.getSession();
18         
19         Locale JavaDoc locs[] = Locale.getAvailableLocales();
20         Locale JavaDoc currentLocale = (Locale JavaDoc) session.getAttribute(Action.LOCALE_KEY);
21         
22         boolean b = false;
23         
24         for (int i=0; i < locs.length; i++) {
25             if (currentLocale.equals(locs[i])) {
26                 b = true;
27                 break;
28             }
29         }
30         
31         FileInputStream JavaDoc fis;
32         File f = new File(servlet.getServletContext().getRealPath("../../../conf/localizedTemplates/templates_" + currentLocale.getLanguage() + ".xml"));
33         
34         if (b && f.exists()) {
35             fis = new FileInputStream JavaDoc( f );
36             }
37         else {
38             fis = new FileInputStream JavaDoc( new File(servlet.getServletContext().getRealPath("../../../conf/templates.xml")) );
39         }
40         
41         bean = TypeBean.parse(fis);
42         fis.close();
43         
44         return bean;
45     }
46     
47     public static TypeBean getSectionBean(HttpServlet JavaDoc servlet, String JavaDoc template, HttpServletRequest JavaDoc request) throws Exception JavaDoc {
48         bean = getLocalizedTypeBean(servlet, request);
49         return TypeBean.getBean(template);
50     }
51     
52     public static Vector JavaDoc getSectionsBeans(HttpServlet JavaDoc servlet, HttpServletRequest JavaDoc request) throws Exception JavaDoc {
53         bean = getLocalizedTypeBean(servlet, request);
54         return bean.getItems();
55     }
56
57 }
58
59
Popular Tags