Package org.jzonic.jlo.filter

Source Code of org.jzonic.jlo.filter.RegExFilter

/*
* RegExFilter.java
*
* Created on 28. August 2003, 22:09
*/

package org.jzonic.jlo.filter;

import gnu.regexp.RE;
import gnu.regexp.REMatch;

import java.util.Map;
/**
* This is a filter that uses a regular expression to find out
* if the given message and the expression matches.
*
* @author  Andreas Mecky andreasmecky@yahoo.de
*/
public class RegExFilter implements LogFilter {
   
    private String expression;
   
    public RegExFilter() {
    }
   
    public boolean match(String message) {       
        if ( message != null && expression != null ) {                   
            try {               
                RE re = new RE(expression,RE.REG_ICASE);
                REMatch[] matches = re.getAllMatches(message);           
                if ( matches.length > 0 ) {
                    return true;
                }                           
            }
            catch (Exception e) {
                // TODO: do some error reporting
            }
        }
        return false;
    }
   
    public void setParameters(Map parameter) {
        if ( parameter.containsKey("expression") ) {
            expression = (String)parameter.get("expression");           
        }
    }
   
}
TOP

Related Classes of org.jzonic.jlo.filter.RegExFilter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.