net.sf.mmm.util.filter.base
Class FilterRuleChainPlainParser

java.lang.Object
  extended by net.sf.mmm.util.filter.base.FilterRuleChainPlainParser

public class FilterRuleChainPlainParser
extends Object

This class allows to parse a list of including and excluding regex PatternFilterRules and build an according FilterRuleChain. The rules (include/exclude patterns) are proceeded in the order of their appearance in the list.
Here is an example of a configuration (rule list) parsed by this class:

 # This file contains a filter-chain. Such chain is build of a list of 
 # filter-rules. Each rule starts with a character that determines if an 
 # inclusion (+) or an exclusion (-) is defined. This character must be followed
 # by a regex pattern. To make it easier for you a simple pre-processing is 
 # performed on the pattern string before it is compiled as 
 # java.util.regex.Pattern:
 # If the pattern does NOT start with "^" or ".*" the prefix ".*" is 
 # automatically added. If the pattern does NOT end with "$" or ".*" the suffix
 # ".*" is automatically appended.
 # The pre-processing should safe you some typing and make it a little easier for
 # users of the GNU command "grep".
 #
 # The filter-rules in the chain are processed in the order of their occurrence.
 # The first rule that matches makes the decision according to the first 
 # character (+/-).
 # A list starting with the '#' character indicates a comment and is therefore 
 # ignored. The same applies for empty lines.
  
 # 1. rule says that all strings that start with "/doc/" will be accepted:
 +^/doc/
  
 # 2. rule says that all strings that end ($) with ".pdf" ignoring the case (?i)  
 # of the characters will be rejected:
 -(?i)\.pdf$
 
 # 3. rule says that all string that start with "/data/" will be accepted:
 +^/data/
 
 # 4. rule says that all string that end ($) with ".xml" or ".xsl" ignoring the 
 # case (?i) of the characters will be rejected:
 -(?i)\.(xml|xsl)$
 
 # 5. rule says that everything else is accepted
 +.*
 

Since:
1.0.2
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)
See Also:
FilterRuleChainXmlParser

Field Summary
private  char acceptChar
           
private  char commentChar
           
private  char denyChar
           
 
Constructor Summary
FilterRuleChainPlainParser()
          The constructor.
 
Method Summary
 char getAcceptChar()
          This method gets the character used to identify an accept pattern.
 char getCommentChar()
          This method gets the character used to identify a comment.
 char getDenyChar()
          This method gets the character used to identify a deny pattern.
 FilterRuleChain<String> parse(BufferedReader reader, boolean defaultResult)
          This method parses the content of the given reader as FilterRuleChain as described above.
 FilterRuleChain<String> parse(Reader reader, boolean defaultResult)
          This method parses the content of the given reader as FilterRuleChain as described above.
 void setAcceptChar(char acceptChar)
           
 void setCommentChar(char commentChar)
           
 void setDenyChar(char denyChar)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

acceptChar

private char acceptChar
See Also:
getAcceptChar()

denyChar

private char denyChar
See Also:
getDenyChar()

commentChar

private char commentChar
See Also:
getCommentChar()
Constructor Detail

FilterRuleChainPlainParser

public FilterRuleChainPlainParser()
The constructor.

Method Detail

getAcceptChar

public char getAcceptChar()
This method gets the character used to identify an accept pattern. The default value is '+'.

Returns:
the accept character

setAcceptChar

public void setAcceptChar(char acceptChar)
Parameters:
acceptChar - the acceptChar to set

getDenyChar

public char getDenyChar()
This method gets the character used to identify a deny pattern. The default value is '-'.

Returns:
the deny character

setDenyChar

public void setDenyChar(char denyChar)
Parameters:
denyChar - the denyChar to set

getCommentChar

public char getCommentChar()
This method gets the character used to identify a comment. If a line starts with this character it is ignored. The default value is '#'.

Returns:
the comment character

setCommentChar

public void setCommentChar(char commentChar)
Parameters:
commentChar - the commentChar to set

parse

public FilterRuleChain<String> parse(Reader reader,
                                     boolean defaultResult)
                              throws IOException
This method parses the content of the given reader as FilterRuleChain as described above.

Parameters:
reader - is where to read from. It will be closed at the end of this method (on success and in an exceptional state).
defaultResult - is the default-result of the chain.
Returns:
the parsed configuration as filter-chain.
Throws:
IOException - if an I/O error occurred while parsing.

parse

public FilterRuleChain<String> parse(BufferedReader reader,
                                     boolean defaultResult)
                              throws IOException
This method parses the content of the given reader as FilterRuleChain as described above.

Parameters:
reader - is where to read from. It will be closed at the end of this method (on success and in an exceptional state).
defaultResult - is the default-result of the chain.
Returns:
the parsed configuration as filter-chain.
Throws:
IOException - if an I/O error occurred while parsing.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.