1 25 29 package org.jresearch.gossip.plugin; 30 31 import java.io.IOException ; 32 import java.sql.SQLException ; 33 import java.util.ArrayList ; 34 import java.util.Date ; 35 import java.util.Locale ; 36 import java.util.ResourceBundle ; 37 38 import javax.naming.InitialContext ; 39 import javax.servlet.ServletContext ; 40 import javax.servlet.ServletException ; 41 import javax.sql.DataSource ; 42 43 import org.apache.log.Logger; 44 import org.apache.struts.action.ActionServlet; 45 import org.apache.struts.action.PlugIn; 46 import org.apache.struts.config.ModuleConfig; 47 import org.jresearch.gossip.IConst; 48 import org.jresearch.gossip.am.StrutsConfigurationHelperAction; 49 import org.jresearch.gossip.configuration.Configurator; 50 import org.jresearch.gossip.dao.ForumDAO; 51 import org.jresearch.gossip.dao.UserDAO; 52 import org.jresearch.gossip.exception.SystemException; 53 import org.jresearch.gossip.log.avalon.JGossipLog; 54 import org.jresearch.gossip.mail.MailProcessor; 55 import org.jresearch.gossip.mail.MailQueue; 56 import org.jresearch.gossip.scheduler.Scheduler; 57 import org.jresearch.gossip.tags.userstatus.Ranks; 58 import org.jresearch.gossip.util.MessageProcessor; 59 import org.quartz.SchedulerException; 60 61 65 public class JGossipStartUp implements PlugIn, IConst { 66 67 private Scheduler scheduler = null; 68 69 74 public void destroy() { 75 try { 76 scheduler.shutdown(); 77 } catch (SchedulerException e) { 78 try { 79 JGossipLog.getInstance().getAppLogger().error( 80 "Failed to shutdown a cheduler instance", e); 81 } catch (SystemException e1) { 82 e1.printStackTrace(); 83 } 84 } 85 } 86 87 93 public void init(ActionServlet servlet, ModuleConfig moduleconfig) 94 throws ServletException { 95 Logger log = null; 96 try { 97 log = JGossipLog.getInstance().getAppLogger(); 98 } catch (SystemException e) { 99 throw new ServletException (e); 100 } 101 if (log.isInfoEnabled()) { 102 log.info("init is started"); 103 } 104 ServletContext app = servlet.getServletContext(); 105 Locale [] list = Locale.getAvailableLocales(); 107 ArrayList avaibleTranslations = new ArrayList (); 108 for (int i = 0; i < list.length; i++) { 109 ResourceBundle bundle = ResourceBundle.getBundle( 110 "org/jresearch/gossip/resources/lang/lang", list[i]); 111 String curr = bundle.getLocale().toString(); 112 if (i == 0 || !avaibleTranslations.contains(curr)) { 113 avaibleTranslations.add(curr); 114 } 115 } 116 if (log.isDebugEnabled()) { 117 log 118 .debug("avaible translations :" 119 + avaibleTranslations.toString()); 120 } 121 app.setAttribute(IConst.CONTEXT.AVAIBLE_TRANSLATIONS, 122 avaibleTranslations); 123 125 app.setAttribute(IConst.CONTEXT.LAST_UPDATE_DATE, new Date ()); 126 app.setAttribute(IConst.CONTEXT.MAIL_QUEUE, new MailQueue( 127 new MailProcessor())); 128 DataSource ds; 129 try { 131 ds = setupDataSource(); 132 ForumDAO dao = ForumDAO.getInstance(); 133 dao.setDataSource(ds); 134 UserDAO udao = UserDAO.getInstance(); 135 udao.setDataSource(ds); 136 } catch (IOException e) { 137 throw new ServletException (e); 138 } catch (Exception e) { 139 throw new ServletException (e); 140 } 141 MessageProcessor.setEmoticonsMap(ResourceBundle 143 .getBundle("org/jresearch/gossip/resources/emoticon")); 144 Configurator conf = Configurator.getInstance(); 146 conf.setDataSource(ds); 147 try { 148 conf.load(app); 149 } catch (SQLException e) { 150 if (log.isErrorEnabled()) { 151 log.error("jGossip Configurator is not loaded"); 152 } 153 throw new ServletException (e); 154 } catch (IOException e) { 155 if (log.isErrorEnabled()) { 156 log.error("jGossip Configurator is not loaded"); 157 } 158 throw new ServletException (e); 159 } catch (SystemException e) { 160 throw new ServletException (e); 161 } 162 try { 164 StrutsConfigurationHelperAction.retrieveStrutsActionMapping(app); 165 } catch (SystemException e) { 166 throw new ServletException (e); 167 } 168 try { 169 Ranks.getInstance().load(); 171 } catch (SystemException e) { 172 throw new ServletException (e); 173 } 174 try { 175 scheduler = initScheduler(); 177 } catch (java.security.AccessControlException e) { 178 } catch (IOException e) { 180 throw new ServletException (e); 181 } catch (SchedulerException e) { 182 throw new ServletException (e); 183 } 184 } 185 186 private DataSource setupDataSource() throws IOException , Exception { 188 InitialContext ic = new InitialContext (); 189 DataSource ds = (DataSource ) ic.lookup("jgossip_db"); 190 return ds; 191 } 192 193 199 private Scheduler initScheduler() throws SchedulerException, IOException { 200 Scheduler sched = new Scheduler(); 201 sched.start(); 202 return sched; 203 } 204 }
| Popular Tags
|