1 package org.nextime.ion.backoffice.bean; 2 3 import java.util.Locale ; 4 import java.io.File ; 5 import java.io.FileInputStream ; 6 import java.util.Vector ; 7 import javax.servlet.http.HttpServlet ; 8 import org.apache.struts.action.Action; 9 import javax.servlet.http.HttpServletRequest ; 10 import javax.servlet.http.HttpSession ; 11 12 public class SectionTypes { 13 14 private static TypeBean bean; 15 16 private static TypeBean getLocalizedTypeBean (HttpServlet servlet, HttpServletRequest request) throws Exception { 17 HttpSession session = request.getSession(); 18 19 Locale locs[] = Locale.getAvailableLocales(); 20 Locale currentLocale = (Locale ) 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 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 ( f ); 36 } 37 else { 38 fis = new FileInputStream ( 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 servlet, String template, HttpServletRequest request) throws Exception { 48 bean = getLocalizedTypeBean(servlet, request); 49 return TypeBean.getBean(template); 50 } 51 52 public static Vector getSectionsBeans(HttpServlet servlet, HttpServletRequest request) throws Exception { 53 bean = getLocalizedTypeBean(servlet, request); 54 return bean.getItems(); 55 } 56 57 } 58 59 | Popular Tags |