KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > util > CmsContextListener


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.cms.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.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 /**
42  * This class functions as the entry-point for all initialization of the Cms-tool.
43  * The class responds to the startup or reload of a whole context.
44  */

45
46 public final class CmsContextListener implements ServletContextListener JavaDoc
47 {
48     private final static Logger logger = Logger.getLogger(CmsContextListener.class.getName());
49
50     private static CacheController cacheController = new CacheController();
51     
52     /**
53      * This method is called when the servlet context is
54      * initialized(when the Web Application is deployed).
55      * You can initialize servlet context related data here.
56      */

57      
58     public void contextInitialized(ServletContextEvent JavaDoc event)
59     {
60         try
61         {
62             /*
63             String isHeadless = System.getProperty("java.awt.headless");
64             System.out.println("java.awt.headless=" + isHeadless);
65             if(isHeadless == null || !isHeadless.equalsIgnoreCase("true"))
66             {
67                 System.setProperty("java.awt.headless", "true");
68             }
69             */

70
71             String JavaDoc 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             // String up2datePath = event.getServletContext().getRealPath("/") + "ut2date" + File.separator;
80
// CmsPropertyHandler.setProperty("up2datePath", up2datePath);
81

82             CmsPropertyHandler.setProperty("contextRootPath", contextRootPath);
83             CmsPropertyHandler.setContextRootPath(contextRootPath);
84             
85             String JavaDoc 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 JavaDoc 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 JavaDoc URIEncoding = CmsPropertyHandler.getURIEncoding();
106             if(URIEncoding == null || URIEncoding.equals(""))
107             {
108                 URIEncoding = "ISO-8859-1";
109                 CmsPropertyHandler.setProperty("URIEncoding", URIEncoding);
110             }
111             
112             String JavaDoc assetPath = CmsPropertyHandler.getDigitalAssetPath();
113             if(assetPath == null || assetPath.equals(""))
114             {
115                 assetPath = contextRootPath + "digitalAssets";
116                 CmsPropertyHandler.setProperty("digitalAssetPath", assetPath);
117
118                 String JavaDoc digitalAssetPath0 = CmsPropertyHandler.getProperty("digitalAssetPath.0");
119                 if(digitalAssetPath0 == null || digitalAssetPath0.equals(""))
120                 {
121                     CmsPropertyHandler.setProperty("digitalAssetPath.0", assetPath);
122                 }
123             }
124
125             String JavaDoc expireCacheAutomaticallyString = CmsPropertyHandler.getExpireCacheAutomatically();
126             if(expireCacheAutomaticallyString != null)
127                 cacheController.setExpireCacheAutomatically(Boolean.getBoolean(expireCacheAutomaticallyString));
128
129             String JavaDoc intervalString = CmsPropertyHandler.getCacheExpireInterval();
130             if(intervalString != null)
131                 cacheController.setCacheExpireInterval(Integer.parseInt(intervalString));
132         
133             //Starting the cache-expire-thread
134
if(cacheController.getExpireCacheAutomatically())
135                 cacheController.start();
136
137             System.out.println("**************************************\n");
138         }
139         catch(Exception JavaDoc e)
140         {
141             e.printStackTrace();
142         }
143     }
144
145     /**
146      * This method is invoked when the Servlet Context
147      * (the Web Application) is undeployed or
148      * WebLogic Server shuts down.
149      */

150
151     public void contextDestroyed(ServletContextEvent JavaDoc event)
152     {
153         System.out.println("contextDestroyed....");
154
155     }
156 }
157
158
Popular Tags