1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
package net.admin4j.util.notify; |
15 | |
|
16 | |
import java.util.Properties; |
17 | |
|
18 | |
import javax.servlet.FilterConfig; |
19 | |
import javax.servlet.ServletConfig; |
20 | |
import javax.servlet.ServletException; |
21 | |
|
22 | |
import net.admin4j.config.Admin4JConfiguration; |
23 | |
import net.admin4j.deps.commons.lang3.StringUtils; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | 0 | public class NotifierUtils { |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public static Notifier configure(FilterConfig config, String notifierClassName) |
43 | |
throws InstantiationException, IllegalAccessException, |
44 | |
ClassNotFoundException, ServletException { |
45 | 24 | Notifier notifier = null; |
46 | 0 | if ( !StringUtils.isEmpty(notifierClassName) ) { |
47 | 24 | notifier = (Notifier)Class.forName(notifierClassName).newInstance(); |
48 | 24 | notifier.configure(config); |
49 | |
} |
50 | 0 | else if (Admin4JConfiguration.getDefaultNotifier() != null) { |
51 | 0 | notifier = Admin4JConfiguration.getDefaultNotifier(); |
52 | |
} |
53 | 24 | return notifier; |
54 | |
} |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
public static Notifier configure(ServletConfig config, String notifierClassName) |
67 | |
throws InstantiationException, IllegalAccessException, |
68 | |
ClassNotFoundException, ServletException { |
69 | 9 | Notifier notifier = null; |
70 | 0 | if ( !StringUtils.isEmpty(notifierClassName) ) { |
71 | 9 | notifier = (Notifier)Class.forName(notifierClassName).newInstance(); |
72 | 9 | notifier.configure(config); |
73 | |
} |
74 | 0 | else if (Admin4JConfiguration.getDefaultNotifier() != null) { |
75 | 0 | notifier = Admin4JConfiguration.getDefaultNotifier(); |
76 | |
} |
77 | 9 | return notifier; |
78 | |
} |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
public static Notifier configure(String namePrefix, Properties config) |
91 | |
throws InstantiationException, IllegalAccessException, |
92 | |
ClassNotFoundException, ServletException { |
93 | 3 | String notifierClassName = config.getProperty(namePrefix + ".class"); |
94 | 3 | Notifier notifier = null; |
95 | 0 | if ( !StringUtils.isEmpty(notifierClassName) ) { |
96 | 0 | notifier = (Notifier)Class.forName(notifierClassName).newInstance(); |
97 | 0 | notifier.configure(namePrefix, config); |
98 | |
} |
99 | 3 | else if (Admin4JConfiguration.getDefaultNotifier() != null) { |
100 | 0 | notifier = Admin4JConfiguration.getDefaultNotifier(); |
101 | |
} |
102 | 3 | return notifier; |
103 | |
} |
104 | |
|
105 | |
} |