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

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

public class FilterRuleChainXmlParser
extends Object

This class allows to parse a list of including and excluding regex PatternFilterRules from XML 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:

 <filter-chain id="default-filter" default-result="true">
 <!-- 1. rule says that all strings that start (^) with "/doc/" will be accepted -->
 <include pattern="^/doc/"/>
 <!-- 2. rule says that all strings that end ($) with ".pdf" ignoring the case  
 of the characters will be rejected -->
 <exclude pattern="(?i)\.pdf$"/>
 <!-- 3. rule says that all strings that start with "/data/" will be accepted -->
 <include pattern="^/data/"/>
 <!-- 4. rule says that all string that end ($) with ".xml" or ".xsl" ignoring 
 the case (?i) of the characters will be rejected: -->
 <exclude pattern="(?i)\.(xml|xsl)$"/>
 </filter-chain>
 

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

Field Summary
private  DomUtil domUtil
           
static String XML_ATR_CHAIN_DEFAULT
          The name of the XML attribute for the default-result.
static String XML_ATR_CHAIN_ID
          The name of the XML attribute for the ID of a chain.
static String XML_ATR_CHAIN_PARENT
          The name of the XML attribute for the parent of a chain.
static String XML_ATR_RULE_PATTERN
          The name of the XML attribute for the pattern of a (include or exclude) rule.
static String XML_TAG_CHAIN
          The name of the XML element for a FilterRuleChain.
static String XML_TAG_RULE_EXCLUDE
          The name of the XML element for an excluding rule.
static String XML_TAG_RULE_INCLUDE
          The name of the XML element for an including rule.
 
Constructor Summary
FilterRuleChainXmlParser()
          The constructor.
FilterRuleChainXmlParser(DomUtil domUtil)
          The constructor.
 
Method Summary
 FilterRuleChain<String> parseChain(Element xmlElement)
          This method parses a chain given by xmlElement.
 FilterRuleChain<String> parseChain(Element xmlElement, FilterRuleChain<String> parent)
          This method parses a chain given as XML via xmlElement.
 FilterRuleChain<String> parseChain(InputStream inStream)
          This method parses the chain from the given inStream.
 Map<String,FilterRuleChain<String>> parseChains(Element xmlElement)
          This method parses a map of chains given by xmlElement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XML_TAG_CHAIN

public static final String XML_TAG_CHAIN
The name of the XML element for a FilterRuleChain.

See Also:
Constant Field Values

XML_ATR_CHAIN_ID

public static final String XML_ATR_CHAIN_ID
The name of the XML attribute for the ID of a chain.

See Also:
Constant Field Values

XML_ATR_CHAIN_PARENT

public static final String XML_ATR_CHAIN_PARENT
The name of the XML attribute for the parent of a chain.

See Also:
Constant Field Values

XML_ATR_CHAIN_DEFAULT

public static final String XML_ATR_CHAIN_DEFAULT
The name of the XML attribute for the default-result.

See Also:
Constant Field Values

XML_TAG_RULE_INCLUDE

public static final String XML_TAG_RULE_INCLUDE
The name of the XML element for an including rule.

See Also:
Constant Field Values

XML_TAG_RULE_EXCLUDE

public static final String XML_TAG_RULE_EXCLUDE
The name of the XML element for an excluding rule.

See Also:
Constant Field Values

XML_ATR_RULE_PATTERN

public static final String XML_ATR_RULE_PATTERN
The name of the XML attribute for the pattern of a (include or exclude) rule.

See Also:
Constant Field Values

domUtil

private final DomUtil domUtil
See Also:
FilterRuleChainXmlParser(DomUtil)
Constructor Detail

FilterRuleChainXmlParser

public FilterRuleChainXmlParser()
The constructor.


FilterRuleChainXmlParser

public FilterRuleChainXmlParser(DomUtil domUtil)
The constructor.

Parameters:
domUtil - is the DomUtil to use.
Method Detail

parseChain

public FilterRuleChain<String> parseChain(InputStream inStream)
                                   throws IOException,
                                          SAXException
This method parses the chain from the given inStream. The XML contained in inStream needs to contain the chain rules as child-nodes of the root-element. The name of the root-element is ignored (use e.g. "chain").

Parameters:
inStream - is the stream containing the XML to parse. It will be closed by this method (on success as well as in an exceptional state).
Returns:
the parsed filter rule.
Throws:
IOException - if an input/output error occurred.
SAXException - if the inStream contains invalid XML.

parseChains

public Map<String,FilterRuleChain<String>> parseChains(Element xmlElement)
This method parses a map of chains given by xmlElement.

Parameters:
xmlElement - is the XML element containing the filter-chains (see XML_TAG_CHAIN) as children and puts them into a map with the ID as key. Unknown child elements or attributes are simply ignored.
Returns:
the map of all parsed chains.

parseChain

public FilterRuleChain<String> parseChain(Element xmlElement)
This method parses a chain given by xmlElement.

Parameters:
xmlElement - is the XML element containing the filter-rules (see XML_TAG_RULE_INCLUDE and XML_TAG_RULE_EXCLUDE) as children.
Returns:
the parsed filter-chain.
See Also:
XML_TAG_CHAIN

parseChain

public FilterRuleChain<String> parseChain(Element xmlElement,
                                          FilterRuleChain<String> parent)
This method parses a chain given as XML via xmlElement.

Parameters:
xmlElement - is the XML element containing the filter-rules (see XML_TAG_RULE_INCLUDE and XML_TAG_RULE_EXCLUDE) as children. Unknown child elements or attributes are simply ignored.
parent - is the parent chain that is to be extended by the chain to parse.
Returns:
the parsed filter-chain.


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