| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.ini4j; |
| 17 | |
|
| 18 | |
import java.net.MalformedURLException; |
| 19 | |
import java.net.URL; |
| 20 | |
|
| 21 | |
import javax.servlet.ServletContext; |
| 22 | |
import javax.servlet.ServletContextEvent; |
| 23 | |
import javax.servlet.ServletContextListener; |
| 24 | |
|
| 25 | 2 | public class IniPreferencesFactoryListener extends IniPreferencesFactory implements ServletContextListener |
| 26 | |
{ |
| 27 | |
public static final String DEFAULT_USER_LOCATION = "/WEB-INF/user.ini"; |
| 28 | |
public static final String DEFAULT_SYSTEM_LOCATION = "/WEB-INF/system.ini"; |
| 29 | |
private ServletContext _context; |
| 30 | |
|
| 31 | |
@Override public void contextDestroyed(ServletContextEvent event) |
| 32 | |
{ |
| 33 | 2 | _context = null; |
| 34 | 2 | } |
| 35 | |
|
| 36 | |
@Override public void contextInitialized(ServletContextEvent event) |
| 37 | |
{ |
| 38 | 2 | _context = event.getServletContext(); |
| 39 | 2 | System.setProperty("java.util.prefs.PreferencesFactory", getClass().getName()); |
| 40 | 2 | } |
| 41 | |
|
| 42 | |
@Override protected String getIniLocation(String key) |
| 43 | |
{ |
| 44 | 3 | String location = _context.getInitParameter(key); |
| 45 | |
|
| 46 | 3 | if (location == null) |
| 47 | |
{ |
| 48 | 2 | location = key.equals(KEY_USER) ? DEFAULT_USER_LOCATION : DEFAULT_SYSTEM_LOCATION; |
| 49 | |
} |
| 50 | |
|
| 51 | 3 | return location; |
| 52 | |
} |
| 53 | |
|
| 54 | |
@Override protected URL getResource(String location) throws IllegalArgumentException |
| 55 | |
{ |
| 56 | |
try |
| 57 | |
{ |
| 58 | 1 | URL url = _context.getResource(location); |
| 59 | |
|
| 60 | 1 | if (url == null) |
| 61 | |
{ |
| 62 | 1 | url = super.getResource(location); |
| 63 | |
} |
| 64 | |
|
| 65 | 1 | return url; |
| 66 | |
} |
| 67 | 0 | catch (MalformedURLException x) |
| 68 | |
{ |
| 69 | 0 | throw (IllegalArgumentException) new IllegalArgumentException().initCause(x); |
| 70 | |
} |
| 71 | |
} |
| 72 | |
} |