com.jmw.tzap.filters
Class ReplaceFilterPlus

java.lang.Object
  extended by com.jmw.tzap.AbstractFilter
      extended by com.jmw.tzap.IteratingFilter
          extended by com.jmw.tzap.filters.ReplaceFilterPlus
Direct Known Subclasses:
ReverseFilter

public abstract class ReplaceFilterPlus
extends IteratingFilter

Abstract filter that allows some work to be done to part of a regex before replacement.
This filter divides the supplied regex into three user supplied groups.

  1. The modifyGroup is the one that is changed
  2. The preGroup is placed before the modified group in the output
  3. The postGroup which is placed after the modified group in the output
By default the modifiedGroup refers to the entire regex, but if desired the user can supply a specific group that the modifier can change.

Note: ReplaceFilterPlus works best if the regex is divided into at least three capturing groups. One before (the preGroup), the modifyGroup, and one after (the postGroup). If these three are not specified, the entire regex will be replaced even if the modifyGroup is not 0!


Field Summary
protected  java.util.regex.Matcher matcher
           
protected  int modifyGroup
           
protected  java.util.regex.Pattern pattern
           
protected  int postGroup
           
protected  int preGroup
           
 
Fields inherited from class com.jmw.tzap.AbstractFilter
encoding, MSG_DEBUG, MSG_ERR, MSG_INFO, MSG_VERBOSE, MSG_WARN, task
 
Constructor Summary
ReplaceFilterPlus()
           
 
Method Summary
 java.lang.StringBuffer doFilter(java.lang.StringBuffer sb, java.lang.String fileName)
          Does the actual filtering.
 void load()
          Does any initilaztion of the filter before it can be used.
protected abstract  java.lang.String modifiedReplacment()
           
 void setModifyGroup(int g)
          Sets the group that will be modified by the classes that extend ReplaceFilterPlus.
 void setPostGroup(int g)
          Sets the group that will be inserted after the midified group.
 void setPreGroup(int g)
          Sets the group that will be inserted before the midified group.
 void setRegex(java.lang.String regexp)
          Sets the regular expression to be replaced.
 void unload()
          Does any clean up after the filter has been finished.
 void validateParameters()
          Validates any parameters needed by the child filters.
 
Methods inherited from class com.jmw.tzap.IteratingFilter
execute
 
Methods inherited from class com.jmw.tzap.AbstractFilter
getName, log, log, setEncoding, setTask
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pattern

protected java.util.regex.Pattern pattern

modifyGroup

protected int modifyGroup

preGroup

protected int preGroup

postGroup

protected int postGroup

matcher

protected java.util.regex.Matcher matcher
Constructor Detail

ReplaceFilterPlus

public ReplaceFilterPlus()
Method Detail

load

public void load()
Description copied from class: AbstractFilter
Does any initilaztion of the filter before it can be used. Note; Only called once, before any filters are run.

Overrides:
load in class IteratingFilter

unload

public void unload()
Description copied from class: AbstractFilter
Does any clean up after the filter has been finished. Note; Only called once, when all files have been filtered.

Overrides:
unload in class IteratingFilter

doFilter

public java.lang.StringBuffer doFilter(java.lang.StringBuffer sb,
                                       java.lang.String fileName)
Description copied from class: IteratingFilter
Does the actual filtering.

Specified by:
doFilter in class IteratingFilter
Parameters:
sb - the file to be filtered as a StringBuffer
fileName - the name that this file is called on disk
Returns:
the filtered file as a StringBuffer

modifiedReplacment

protected abstract java.lang.String modifiedReplacment()

validateParameters

public void validateParameters()
                        throws java.lang.Exception
Description copied from class: AbstractFilter
Validates any parameters needed by the child filters.

Specified by:
validateParameters in class AbstractFilter
Throws:
java.lang.Exception

setRegex

public void setRegex(java.lang.String regexp)
Sets the regular expression to be replaced.

Parameters:
regex - the regex

setModifyGroup

public void setModifyGroup(int g)
Sets the group that will be modified by the classes that extend ReplaceFilterPlus.

Parameters:
g - the group number

setPreGroup

public void setPreGroup(int g)
Sets the group that will be inserted before the midified group.

Parameters:
g - the group number

setPostGroup

public void setPostGroup(int g)
Sets the group that will be inserted after the midified group.

Parameters:
g - the group number