LogFilter is a basic implementation of Filter interface. This implementation
will keep a record of the filtered strings to avoid repeating the process
unnecessarily.
The current implementation supports replacing the file extension. The reason
for supporting this is from first hand experience porting an existing website
to Tomcat + JSP. Later on we may want to provide the ability to replace the
whole filename. If the need materializes, we can add it later.
Example of how to use it is provided in the main method. An example is
provided below.
As a general note. Both isFiltered and filter() have to be called. Calling
either one will not produce the desired result. isFiltered(string) will tell
you if a string should be filtered. The second step is to filter the string,
which will return null if it is filtered and replace any part of the string
that should be replaced.
LogFilter is a basic implementation of Filter interface. This implementation will keep a record of the filtered strings to avoid repeating the process unnecessarily.
The current implementation supports replacing the file extension. The reason for supporting this is from first hand experience porting an existing website to Tomcat + JSP. Later on we may want to provide the ability to replace the whole filename. If the need materializes, we can add it later.
Example of how to use it is provided in the main method. An example is provided below.
testf = new LogFilter(); String[] incl = { "hello.html", "index.html", "/index.jsp" }; String[] thefiles = { "/test/hello.jsp", "/test/one/hello.html", "hello.jsp", "hello.htm", "/test/open.jsp", "/test/open.html", "/index.jsp", "/index.jhtml", "newindex.jsp", "oldindex.jsp", "oldindex1.jsp", "oldindex2.jsp", "oldindex3.jsp", "oldindex4.jsp", "oldindex5.jsp", "oldindex6.jsp", "/test/index.htm" }; testf.excludeFiles(incl); System.out.println(" ------------ exclude test -------------"); for (int idx = 0; idx < thefiles.length; idx++) { boolean fl = testf.isFiltered(thefiles[idx]); String line = testf.filter(thefiles[idx]); if (line != null) { System.out.println("the file: " + line); } }As a general note. Both isFiltered and filter() have to be called. Calling either one will not produce the desired result. isFiltered(string) will tell you if a string should be filtered. The second step is to filter the string, which will return null if it is filtered and replace any part of the string that should be replaced.