EMMA Coverage Report (generated Tue Feb 12 22:23:49 ICT 2008)
[all classes][net.sourceforge.hiveutils.web.util]

COVERAGE SUMMARY FOR SOURCE FILE [SystemPropertyInitListener.java]

nameclass, %method, %block, %line, %
SystemPropertyInitListener.java0%   (0/1)0%   (0/3)0%   (0/36)0%   (0/12)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SystemPropertyInitListener0%   (0/1)0%   (0/3)0%   (0/36)0%   (0/12)
SystemPropertyInitListener (): void 0%   (0/1)0%   (0/3)0%   (0/1)
contextDestroyed (ServletContextEvent): void 0%   (0/1)0%   (0/1)0%   (0/1)
contextInitialized (ServletContextEvent): void 0%   (0/1)0%   (0/32)0%   (0/10)

1//  Copyright 2004-2007 Jean-Francois Poilpret
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14 
15package net.sourceforge.hiveutils.web.util;
16 
17import java.util.Enumeration;
18 
19import javax.servlet.ServletContext;
20import javax.servlet.ServletContextEvent;
21import javax.servlet.ServletContextListener;
22 
23/**
24 * ServletContextListener that will initialize System properties with values
25 * that are provided as parameters to the listener.
26 * <p>
27 * This allows to use the container mechanisms (like context.xml in Tomcat) to
28 * externalize these properties outside of the war file.
29 * <p>
30 * This listener will put all parameters with a name starting with "init." into
31 * the System properties.
32 *
33 * @author Jean-Francois Poilpret
34 */
35public class SystemPropertyInitListener implements ServletContextListener 
36{
37        static final private String        INIT_PREFIX = "init.";
38        
39        public void contextInitialized(ServletContextEvent evt)
40        {
41                // Get information from init parameters
42                ServletContext context = evt.getServletContext();
43                Enumeration params = context.getInitParameterNames();
44                while (params.hasMoreElements())
45                {
46                        String name = (String) params.nextElement();
47                        if (name.startsWith(INIT_PREFIX))
48                        {
49                                String value = context.getInitParameter(name);
50                                name = name.substring(INIT_PREFIX.length());
51                                System.setProperty(name, value);
52                        }
53                }
54        }
55 
56        public void contextDestroyed(ServletContextEvent evt)
57        {
58        }
59}

[all classes][net.sourceforge.hiveutils.web.util]
EMMA 2.0.5312 (C) Vladimir Roubtsov