1 23 24 package org.infoglue.deliver.util; 25 26 import java.io.File ; 27 import java.util.Enumeration ; 28 29 import javax.servlet.ServletContext ; 30 import javax.servlet.ServletContextEvent ; 31 import javax.servlet.ServletContextListener ; 32 33 import org.apache.log4j.Appender; 34 import org.apache.log4j.Category; 35 import org.apache.log4j.Logger; 36 import org.apache.log4j.RollingFileAppender; 37 import org.infoglue.cms.security.InfoGlueAuthenticationFilter; 38 import org.infoglue.cms.util.CmsPropertyHandler; 39 import org.infoglue.deliver.invokers.ComponentBasedHTMLPageInvoker; 40 import org.infoglue.deliver.invokers.DecoratedComponentBasedHTMLPageInvoker; 41 42 46 47 public final class DeliverContextListener implements ServletContextListener 48 { 49 private final static Logger logger = Logger.getLogger(DeliverContextListener.class.getName()); 50 51 private static CacheController cacheController = new CacheController(); 52 53 private static ServletContext servletContext = null; 54 55 public static ServletContext getServletContext() 56 { 57 return servletContext; 58 } 59 60 65 66 public void contextInitialized(ServletContextEvent event) 67 { 68 try 69 { 70 78 79 String contextRootPath = event.getServletContext().getRealPath("/"); 80 if(!contextRootPath.endsWith("/") && !contextRootPath.endsWith("\\")) 81 contextRootPath = contextRootPath + "/"; 82 83 System.out.println("\n**************************************"); 84 System.out.println("Initializing deliver context for directory:" + contextRootPath); 85 86 CmsPropertyHandler.setApplicationName("deliver"); 87 88 CmsPropertyHandler.setContextRootPath(contextRootPath); 89 CmsPropertyHandler.setOperatingMode(CmsPropertyHandler.getProperty("operatingMode")); 90 91 String logPath = CmsPropertyHandler.getLogPath(); 92 if(logPath == null || logPath.equals("")) 93 { 94 logPath = contextRootPath + "logs" + File.separator + "infoglueDeliver.log"; 95 CmsPropertyHandler.setProperty("logPath", logPath); 96 } 97 98 Enumeration enumeration = Logger.getLogger("org.infoglue.cms").getAllAppenders(); 99 while(enumeration.hasMoreElements()) 100 { 101 RollingFileAppender appender = (RollingFileAppender)enumeration.nextElement(); 102 if(appender.getName().equalsIgnoreCase("INFOGLUE-FILE")) 103 { 104 appender.setFile(logPath); 105 appender.activateOptions(); 106 Logger.getLogger(ComponentBasedHTMLPageInvoker.class).addAppender(appender); 107 break; 108 } 109 } 110 111 String statisticsLogPath = CmsPropertyHandler.getStatisticsLogPath(); 112 if(statisticsLogPath == null || statisticsLogPath.equals("")) 113 { 114 statisticsLogPath = contextRootPath + "logs"; 115 CmsPropertyHandler.setProperty("statisticsLogPath", statisticsLogPath); 116 } 117 118 String assetPath = CmsPropertyHandler.getDigitalAssetPath(); 119 if(assetPath == null || assetPath.equals("")) 120 { 121 assetPath = contextRootPath + "digitalAssets"; 122 CmsPropertyHandler.setProperty("digitalAssetPath", assetPath); 123 } 124 125 String digitalAssetPath0 = CmsPropertyHandler.getProperty("digitalAssetPath.0"); 126 if(digitalAssetPath0 == null || digitalAssetPath0.equals("")) 127 { 128 CmsPropertyHandler.setProperty("digitalAssetPath.0", assetPath); 129 } 130 131 String assetUploadPath = CmsPropertyHandler.getDigitalAssetUploadPath(); 132 if(assetUploadPath == null || assetUploadPath.equals("")) 133 { 134 assetUploadPath = contextRootPath + "uploads"; 135 CmsPropertyHandler.setProperty("digitalAssetUploadPath", assetUploadPath); 136 } 137 138 String expireCacheAutomaticallyString = CmsPropertyHandler.getExpireCacheAutomatically(); 139 if(expireCacheAutomaticallyString != null) 140 cacheController.setExpireCacheAutomatically(Boolean.getBoolean(expireCacheAutomaticallyString)); 141 142 String intervalString = CmsPropertyHandler.getCacheExpireInterval(); 143 if(intervalString != null) 144 cacheController.setCacheExpireInterval(Integer.parseInt(intervalString)); 145 146 if(cacheController.getExpireCacheAutomatically()) 148 cacheController.start(); 149 150 InfoGlueAuthenticationFilter.initializeProperties(); 151 152 System.out.println("**************************************\n"); 153 } 154 catch(Exception e) 155 { 156 e.printStackTrace(); 157 } 158 } 159 160 165 166 public void contextDestroyed(ServletContextEvent event) 167 { 168 System.out.println("contextDestroyed...."); 169 cacheController.stopThread(); 170 cacheController.interrupt(); 171 } 172 } 173 174 | Popular Tags |