1 23 24 package org.infoglue.cms.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.Logger; 34 import org.apache.log4j.RollingFileAppender; 35 import org.infoglue.deliver.invokers.ComponentBasedHTMLPageInvoker; 36 import org.infoglue.deliver.util.CacheController; 37 import org.infoglue.deliver.util.DeliverContextListener; 38 39 40 41 45 46 public final class CmsContextListener implements ServletContextListener 47 { 48 private final static Logger logger = Logger.getLogger(CmsContextListener.class.getName()); 49 50 private static CacheController cacheController = new CacheController(); 51 52 57 58 public void contextInitialized(ServletContextEvent event) 59 { 60 try 61 { 62 70 71 String contextRootPath = event.getServletContext().getRealPath("/"); 72 if(!contextRootPath.endsWith("/") && !contextRootPath.endsWith("\\")) 73 contextRootPath = contextRootPath + "/"; 74 75 System.out.println("\n**************************************"); 76 System.out.println("Initializing cms context for directory:" + contextRootPath); 77 78 CmsPropertyHandler.setApplicationName("cms"); 79 82 CmsPropertyHandler.setProperty("contextRootPath", contextRootPath); 83 CmsPropertyHandler.setContextRootPath(contextRootPath); 84 85 String logPath = CmsPropertyHandler.getLogPath(); 86 if(logPath == null || logPath.equals("")) 87 { 88 logPath = contextRootPath + "logs" + File.separator + "infoglueCMS.log"; 89 CmsPropertyHandler.setProperty("logPath", logPath); 90 } 91 92 Enumeration enumeration = Logger.getLogger("org.infoglue.cms").getAllAppenders(); 93 while(enumeration.hasMoreElements()) 94 { 95 RollingFileAppender appender = (RollingFileAppender)enumeration.nextElement(); 96 if(appender.getName().equalsIgnoreCase("INFOGLUE-FILE")) 97 { 98 appender.setFile(logPath); 99 appender.activateOptions(); 100 Logger.getLogger("org.infoglue.deliver.invokers.ComponentBasedHTMLPageInvoker").addAppender(appender); 101 break; 102 } 103 } 104 105 String URIEncoding = CmsPropertyHandler.getURIEncoding(); 106 if(URIEncoding == null || URIEncoding.equals("")) 107 { 108 URIEncoding = "ISO-8859-1"; 109 CmsPropertyHandler.setProperty("URIEncoding", URIEncoding); 110 } 111 112 String assetPath = CmsPropertyHandler.getDigitalAssetPath(); 113 if(assetPath == null || assetPath.equals("")) 114 { 115 assetPath = contextRootPath + "digitalAssets"; 116 CmsPropertyHandler.setProperty("digitalAssetPath", assetPath); 117 118 String digitalAssetPath0 = CmsPropertyHandler.getProperty("digitalAssetPath.0"); 119 if(digitalAssetPath0 == null || digitalAssetPath0.equals("")) 120 { 121 CmsPropertyHandler.setProperty("digitalAssetPath.0", assetPath); 122 } 123 } 124 125 String expireCacheAutomaticallyString = CmsPropertyHandler.getExpireCacheAutomatically(); 126 if(expireCacheAutomaticallyString != null) 127 cacheController.setExpireCacheAutomatically(Boolean.getBoolean(expireCacheAutomaticallyString)); 128 129 String intervalString = CmsPropertyHandler.getCacheExpireInterval(); 130 if(intervalString != null) 131 cacheController.setCacheExpireInterval(Integer.parseInt(intervalString)); 132 133 if(cacheController.getExpireCacheAutomatically()) 135 cacheController.start(); 136 137 System.out.println("**************************************\n"); 138 } 139 catch(Exception e) 140 { 141 e.printStackTrace(); 142 } 143 } 144 145 150 151 public void contextDestroyed(ServletContextEvent event) 152 { 153 System.out.println("contextDestroyed...."); 154 155 } 156 } 157 158 | Popular Tags |