KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > web > jsf > integration > config > JBossJSFConfigureListener


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2006, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22
23 package org.jboss.web.jsf.integration.config;
24
25 import com.sun.faces.config.ConfigureListener;
26 import com.sun.faces.util.Util;
27 import java.util.logging.Filter JavaDoc;
28 import javax.servlet.ServletContext JavaDoc;
29 import javax.servlet.ServletContextEvent JavaDoc;
30 import org.jboss.logging.Logger;
31
32 /**
33  * This ServletContextListener sets up a JBoss-specific environment for JSF
34  * and then delegates the rest of the setup to the JSF RI.
35  *
36  * @author Stan Silvert
37  */

38 public class JBossJSFConfigureListener extends ConfigureListener
39 {
40     
41     private static Logger LOG = Logger.getLogger(JBossJSFConfigureListener.class);
42     
43     public static final String JavaDoc SHOULD_LOG_CONFIG_MESSAGES = "com.sun.faces.displayConfiguration";
44     
45     private ServletContext JavaDoc servletContext;
46     
47     @Override JavaDoc
48     public void contextInitialized(ServletContextEvent JavaDoc event)
49     {
50         this.servletContext = event.getServletContext();
51         
52         // If the pluginClass is not set, assume Log4J
53
if (System.getProperty("org.jboss.logging.Logger.pluginClass") == null)
54         {
55             setLog4J();
56         }
57
58         super.contextInitialized(event);
59     }
60     
61     /**
62      * If Log4J is being used, set a filter that converts JSF RI java.util.logger
63      * messages to Log4J messages.
64      */

65     private void setLog4J()
66     {
67         Filter JavaDoc conversionFilter = new Log4JConversionFilter(logConfigMessages());
68         
69         java.util.logging.Logger.getLogger(Util.FACES_LOGGER)
70                                 .setFilter(conversionFilter);
71         java.util.logging.Logger.getLogger(Util.FACES_LOGGER + Util.APPLICATION_LOGGER)
72                                 .setFilter(conversionFilter);
73         java.util.logging.Logger.getLogger(Util.FACES_LOGGER + Util.CONFIG_LOGGER)
74                                 .setFilter(conversionFilter);
75         java.util.logging.Logger.getLogger(Util.FACES_LOGGER + Util.CONTEXT_LOGGER)
76                                 .setFilter(conversionFilter);
77         java.util.logging.Logger.getLogger(Util.FACES_LOGGER + Util.LIFECYCLE_LOGGER)
78                                 .setFilter(conversionFilter);
79         java.util.logging.Logger.getLogger(Util.FACES_LOGGER + Util.RENDERKIT_LOGGER)
80                                 .setFilter(conversionFilter);
81         java.util.logging.Logger.getLogger(Util.FACES_LOGGER + Util.TAGLIB_LOGGER)
82                                 .setFilter(conversionFilter);
83     }
84     
85     // should we log the configuration messages?
86
private boolean logConfigMessages()
87     {
88         String JavaDoc shouldLogConfigParam = this.servletContext.getInitParameter(SHOULD_LOG_CONFIG_MESSAGES);
89         return (shouldLogConfigParam != null) && (shouldLogConfigParam.equalsIgnoreCase("true"));
90     }
91     
92 }
93
Popular Tags