public class LogFilter extends Object implements Filter, Serializable
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.
Modifier and Type | Field and Description |
---|---|
protected boolean |
CHANGEEXT |
protected String[] |
EXCFILE |
protected ArrayList<org.apache.oro.text.regex.Pattern> |
EXCPATTERNS |
protected String[] |
EXCPTRN |
protected boolean |
FILEFILTER |
protected String[] |
INCFILE |
protected ArrayList<org.apache.oro.text.regex.Pattern> |
INCPATTERNS |
protected String[] |
INCPTRN |
protected String |
NEWEXT |
protected String |
NEWFILE |
protected String |
OLDEXT |
protected boolean |
PTRNFILTER |
protected boolean |
USEFILE |
Constructor and Description |
---|
LogFilter()
The default constructor is empty
|
Modifier and Type | Method and Description |
---|---|
org.apache.oro.text.regex.Pattern |
createPattern(String pattern)
create a new pattern object from the string.
|
boolean |
excFile(String text)
Method implements the logic for filtering file name exclusion.
|
void |
excludeFiles(String[] filenames)
Give the filter a list of files to exclude
|
void |
excludePattern(String[] regexp)
Give the filter a set of regular expressions to filter with for
exclusion.
|
protected boolean |
excPattern(String text)
The method assumes by default the text is not excluded.
|
String |
filter(String text)
The current implementation checks the boolean if the text should be used
or not. isFilter( string) has to be called first.
|
protected boolean |
filterFile(String file)
Filter the file.
|
protected boolean |
filterPattern(String text)
The current implementation assumes the user has checked the regular
expressions so that they don't cancel each other.
|
boolean |
incFile(String text)
Method implements the logic for filtering file name inclusion.
|
void |
includeFiles(String[] filenames)
Give the filter a list of files to include
|
void |
includePattern(String[] regexp)
Give the filter a set of regular expressions to filter with for
inclusion.
|
protected boolean |
incPattern(String text)
By default, the method assumes the entry is not included, unless it
matches.
|
boolean |
isFiltered(String path,
TestElement el)
In the case of log filtering the important thing is whether the log entry
should be used.
|
boolean |
replaceExtension(String text)
Method uses indexOf to replace the old extension with the new extension.
|
void |
reset()
Tell the filter when the parsing has reached the end of the log file and
is about to begin again.
|
void |
setReplaceExtension(String oldext,
String newext)
The method will replace the file extension with the new one.
|
protected boolean CHANGEEXT
protected String OLDEXT
protected String NEWEXT
protected String[] INCFILE
protected String[] EXCFILE
protected boolean FILEFILTER
protected boolean USEFILE
protected String[] INCPTRN
protected String[] EXCPTRN
protected boolean PTRNFILTER
protected ArrayList<org.apache.oro.text.regex.Pattern> EXCPATTERNS
protected ArrayList<org.apache.oro.text.regex.Pattern> INCPATTERNS
protected String NEWFILE
public void setReplaceExtension(String oldext, String newext)
setReplaceExtension
in interface Filter
oldext
- old extensionnewext
- new extensionFilter.setReplaceExtension(java.lang.String,
java.lang.String)
public void includeFiles(String[] filenames)
includeFiles
in interface Filter
filenames
- list of files to includeFilter.includeFiles(java.lang.String[])
public void excludeFiles(String[] filenames)
excludeFiles
in interface Filter
filenames
- list of files to excludeFilter.excludeFiles(java.lang.String[])
public void includePattern(String[] regexp)
includePattern
in interface Filter
regexp
- list of regular expressionsFilter.includePattern(String[])
public void excludePattern(String[] regexp)
excludePattern
in interface Filter
regexp
- list of regular expressionsFilter.excludePattern(String[])
public boolean isFiltered(String path, TestElement el)
isFiltered
in interface Filter
path
- path to be testedel
- TestElement
in which the line would be addedtrue
if entry should be excludedFilter.isFiltered(String, TestElement)
protected boolean filterFile(String file)
file
- the file to filterpublic boolean incFile(String text)
text
- name of the file to tested (must not be null
)public boolean excFile(String text)
text
- name of the file to be tested (must not be null)protected boolean filterPattern(String text)
text
- text to be checkedprotected boolean incPattern(String text)
text
- text to be checkedtrue
if text is includedprotected boolean excPattern(String text)
text
- text to be checkedtrue
if text is excludedpublic boolean replaceExtension(String text)
text
- name of the file in which the extension should be replaced
(must not be null)true
if the extension could be replaced,
false
otherwisepublic String filter(String text)
filter
in interface Filter
text
- log line to be filteredFilter.filter(java.lang.String)
public org.apache.oro.text.regex.Pattern createPattern(String pattern)
pattern
- string representation of the perl5 compatible regex patternnull
if no pattern could be
compiledCopyright © 1998-2016 Apache Software Foundation. All Rights Reserved.