KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > util > DeliverContextListener


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.deliver.util;
25
26 import java.io.File JavaDoc;
27 import java.util.Enumeration JavaDoc;
28
29 import javax.servlet.ServletContext JavaDoc;
30 import javax.servlet.ServletContextEvent JavaDoc;
31 import javax.servlet.ServletContextListener JavaDoc;
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 /**
43  * This class functions as the entry-point for all initialization of the Cms-tool.
44  * The class responds to the startup or reload of a whole context.
45  */

46
47 public final class DeliverContextListener implements ServletContextListener JavaDoc
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 JavaDoc servletContext = null;
54     
55     public static ServletContext JavaDoc getServletContext()
56     {
57         return servletContext;
58     }
59     
60     /**
61      * This method is called when the servlet context is
62      * initialized(when the Web Application is deployed).
63      * You can initialize servlet context related data here.
64      */

65      
66     public void contextInitialized(ServletContextEvent JavaDoc event)
67     {
68         try
69         {
70             /*
71             String isHeadless = System.getProperty("java.awt.headless");
72             System.out.println("java.awt.headless=" + isHeadless);
73             if(isHeadless == null || !isHeadless.equalsIgnoreCase("true"))
74             {
75                 System.setProperty("java.awt.headless", "true");
76             }
77             */

78             
79             String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc statisticsLogPath = CmsPropertyHandler.getStatisticsLogPath();
112             if(statisticsLogPath == null || statisticsLogPath.equals(""))
113             {
114                 statisticsLogPath = contextRootPath + "logs";
115                 CmsPropertyHandler.setProperty("statisticsLogPath", statisticsLogPath);
116             }
117
118             String JavaDoc assetPath = CmsPropertyHandler.getDigitalAssetPath();
119             if(assetPath == null || assetPath.equals(""))
120             {
121                 assetPath = contextRootPath + "digitalAssets";
122                 CmsPropertyHandler.setProperty("digitalAssetPath", assetPath);
123             }
124
125             String JavaDoc digitalAssetPath0 = CmsPropertyHandler.getProperty("digitalAssetPath.0");
126             if(digitalAssetPath0 == null || digitalAssetPath0.equals(""))
127             {
128                 CmsPropertyHandler.setProperty("digitalAssetPath.0", assetPath);
129             }
130
131             String JavaDoc assetUploadPath = CmsPropertyHandler.getDigitalAssetUploadPath();
132             if(assetUploadPath == null || assetUploadPath.equals(""))
133             {
134                 assetUploadPath = contextRootPath + "uploads";
135                 CmsPropertyHandler.setProperty("digitalAssetUploadPath", assetUploadPath);
136             }
137
138             String JavaDoc expireCacheAutomaticallyString = CmsPropertyHandler.getExpireCacheAutomatically();
139             if(expireCacheAutomaticallyString != null)
140                 cacheController.setExpireCacheAutomatically(Boolean.getBoolean(expireCacheAutomaticallyString));
141
142             String JavaDoc intervalString = CmsPropertyHandler.getCacheExpireInterval();
143             if(intervalString != null)
144                 cacheController.setCacheExpireInterval(Integer.parseInt(intervalString));
145         
146             //Starting the cache-expire-thread
147
if(cacheController.getExpireCacheAutomatically())
148                 cacheController.start();
149             
150             InfoGlueAuthenticationFilter.initializeProperties();
151             
152             System.out.println("**************************************\n");
153         }
154         catch(Exception JavaDoc e)
155         {
156             e.printStackTrace();
157         }
158     }
159
160     /**
161      * This method is invoked when the Servlet Context
162      * (the Web Application) is undeployed or
163      * WebLogic Server shuts down.
164      */

165
166     public void contextDestroyed(ServletContextEvent JavaDoc event)
167     {
168         System.out.println("contextDestroyed....");
169         cacheController.stopThread();
170         cacheController.interrupt();
171     }
172 }
173
174
Popular Tags