|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
Log4jInitFilter.java | 0% | 0% | 0% | 0% |
|
1 |
/*
|
|
2 |
* Joey and its relative products are published under the terms
|
|
3 |
* of the Apache Software License.
|
|
4 |
*/
|
|
5 |
/*
|
|
6 |
* Created on 2003/12/27
|
|
7 |
*/
|
|
8 |
package org.asyrinx.brownie.log.log4j.servlet;
|
|
9 |
|
|
10 |
import java.io.IOException;
|
|
11 |
|
|
12 |
import javax.servlet.Filter;
|
|
13 |
import javax.servlet.FilterChain;
|
|
14 |
import javax.servlet.FilterConfig;
|
|
15 |
import javax.servlet.ServletContext;
|
|
16 |
import javax.servlet.ServletException;
|
|
17 |
import javax.servlet.ServletRequest;
|
|
18 |
import javax.servlet.ServletResponse;
|
|
19 |
|
|
20 |
import org.apache.log4j.BasicConfigurator;
|
|
21 |
import org.asyrinx.brownie.core.io.FileConstants;
|
|
22 |
import org.asyrinx.brownie.core.io.FileNameUtils;
|
|
23 |
import org.asyrinx.brownie.servlet.FileNameResolver;
|
|
24 |
|
|
25 |
/**
|
|
26 |
* @author akima
|
|
27 |
*/
|
|
28 |
public class Log4jInitFilter implements Filter { |
|
29 |
|
|
30 |
/**
|
|
31 |
*
|
|
32 |
*/
|
|
33 | 0 |
public Log4jInitFilter() {
|
34 | 0 |
super();
|
35 |
} |
|
36 |
|
|
37 |
/**
|
|
38 |
* @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
|
|
39 |
*/
|
|
40 | 0 |
public void init(FilterConfig config) throws ServletException { |
41 | 0 |
initLog4j(config); |
42 |
} |
|
43 |
|
|
44 |
public static final String CONFIG_KEY_LOG4J = "log4j"; |
|
45 |
|
|
46 |
public static final String CONFIG_KEY_FILE_WATCH = "file_watch"; |
|
47 |
|
|
48 |
/**
|
|
49 |
* @param config
|
|
50 |
*/
|
|
51 | 0 |
protected void initLog4j(FilterConfig config) { |
52 | 0 |
final ServletContext context = config.getServletContext(); |
53 | 0 |
if (context == null) |
54 | 0 |
throw new RuntimeException( |
55 |
"ServletContext which was obtained from FilterConfig is null !!! why!!!!!!!!!!!!??????????? ");
|
|
56 | 0 |
final FileNameResolver resolver = new FileNameResolver(context);
|
57 | 0 |
final String configFile = resolver.toRealPath(config |
58 |
.getInitParameter(CONFIG_KEY_LOG4J)); |
|
59 |
|
|
60 | 0 |
final boolean fileWatch = "true".equalsIgnoreCase(config |
61 |
.getInitParameter(CONFIG_KEY_FILE_WATCH)); |
|
62 | 0 |
if (FileConstants.EXT_XML.equalsIgnoreCase(FileNameUtils
|
63 |
.getExtension(configFile))) { |
|
64 | 0 |
if (fileWatch)
|
65 | 0 |
ServletDOMConfigurator.configureAndWatch(configFile, context); |
66 |
else
|
|
67 | 0 |
ServletDOMConfigurator.configure(configFile, context); |
68 | 0 |
} else if (FileConstants.EXT_PROPERTIES.equalsIgnoreCase(FileNameUtils |
69 |
.getExtension(configFile))) { |
|
70 | 0 |
if (fileWatch)
|
71 | 0 |
ServletPropertyConfigurator.configureAndWatch(configFile, |
72 |
context); |
|
73 |
else
|
|
74 | 0 |
ServletPropertyConfigurator.configure(configFile, context); |
75 |
} else {
|
|
76 | 0 |
context.log(BasicConfigurator.class.getName() + "#configure()"); |
77 | 0 |
BasicConfigurator.configure(); |
78 |
} |
|
79 |
} |
|
80 |
|
|
81 | 0 |
protected final void log(ServletContext context, String message) { |
82 | 0 |
context.log(this.getClass().getName() + ": " + message); |
83 |
} |
|
84 |
|
|
85 |
/**
|
|
86 |
* @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
|
|
87 |
* javax.servlet.ServletResponse, javax.servlet.FilterChain)
|
|
88 |
*/
|
|
89 | 0 |
public void doFilter(ServletRequest req, ServletResponse res, |
90 |
FilterChain chain) throws IOException, ServletException {
|
|
91 | 0 |
chain.doFilter(req, res); |
92 |
} |
|
93 |
|
|
94 |
/**
|
|
95 |
* @see javax.servlet.Filter#destroy()
|
|
96 |
*/
|
|
97 | 0 |
public void destroy() { |
98 |
//do nothing
|
|
99 |
} |
|
100 |
|
|
101 |
} |
|