Clover coverage report - [ini4j]
Coverage timestamp: Sze nov. 30 2005 08:31:05 CET
file stats: LOC: 73   Methods: 4
NCLOC: 46   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
IniPreferencesFactoryListener.java 83,3% 92,3% 100% 91,3%
coverage coverage
 1    /*
 2    * Copyright 2005 [ini4j] Development Team
 3    *
 4    * Licensed under the Apache License, Version 2.0 (the "License");
 5    * you may not use this file except in compliance with the License.
 6    * You may obtain a copy of the License at
 7    *
 8    * http://www.apache.org/licenses/LICENSE-2.0
 9    *
 10    * Unless required by applicable law or agreed to in writing, software
 11    * distributed under the License is distributed on an "AS IS" BASIS,
 12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13    * See the License for the specific language governing permissions and
 14    * limitations under the License.
 15    */
 16   
 17    package org.ini4j;
 18   
 19    import java.net.URL;
 20    import java.net.MalformedURLException;
 21   
 22    import javax.servlet.ServletContext;
 23    import javax.servlet.ServletContextEvent;
 24    import javax.servlet.ServletContextListener;
 25   
 26    public class IniPreferencesFactoryListener extends IniPreferencesFactory implements ServletContextListener
 27    {
 28    public static final String DEFAULT_USER_LOCATION = "/WEB-INF/user.ini";
 29    public static final String DEFAULT_SYSTEM_LOCATION = "/WEB-INF/system.ini";
 30    private ServletContext _context;
 31   
 32  2 public void contextInitialized(ServletContextEvent event)
 33    {
 34  2 _context = event.getServletContext();
 35  2 System.setProperty("java.util.prefs.PreferencesFactory", getClass().getName());
 36    }
 37   
 38  2 public void contextDestroyed(ServletContextEvent event)
 39    {
 40  2 _context = null;
 41    }
 42   
 43  3 protected String getIniLocation(String key)
 44    {
 45  3 String location = _context.getInitParameter(key);
 46   
 47  3 if ( location == null )
 48    {
 49  2 location = key.equals(KEY_USER) ? DEFAULT_USER_LOCATION : DEFAULT_SYSTEM_LOCATION;
 50    }
 51   
 52  3 return location;
 53    }
 54   
 55  1 protected URL getResource(String location) throws IllegalArgumentException
 56    {
 57  1 try
 58    {
 59  1 URL url = _context.getResource(location);
 60   
 61  1 if ( url == null )
 62    {
 63  1 url = super.getResource(location);
 64    }
 65   
 66  1 return url;
 67    }
 68    catch (MalformedURLException x)
 69    {
 70  0 throw (IllegalArgumentException)new IllegalArgumentException().initCause(x);
 71    }
 72    }
 73    }