1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
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 |
| } |