Home| Design| License| Regex| Download| Credits| Contact
Text-Zap Info
› Overview› Text-Zap Ant Task» Expand Text-Zap› API Docs
Components
› Filters› Savers› Groupers› Sequencers
Filters
› Append Filter› Append File Filter› Extract Lines Filter› Find Filter› Insert References› Merge Filter› Replace Filter› Replace List Filter› Replace Filter Plus› Reverse Filter› Split By Regex Filter› XSLT Filter

Creating your own filters

Creating your own filters is very simple, write a class that extends either IteratingFilter, or AbstractFilter and implement the necessary functions.

Example

Let's say you want to create a new filter that adds the words Text-Zap to the beginning and end of each file. Here is how building this new filter should be approached. The code for this demo can be found below.

  1. First, create a new class lets call it AddText_Filter, and have it extend the IteratingFilter class (see the API docs for more details about this class).
  2. Next, implement the doFilter method. This method takes two parameters a StringBuffer containing the text of the file, and a String which represents the files name. The file name can be ignored. Append "Text-Zap" to beginning and end of the StringBuffer, and return it.
  3. Compile your new class and add it to an Ant build file, and you are all done.

^topCode

Here is the code that this example should look like:

 package mypackage;
 import com.jmw.tzap.IteratingFilter;

 public class AddText_Filter extends IteratingFilter{
    public StringBuffer doFilter(StringBuffer buffer, String fileName){
 		 buffer.append(0, "Text-Zap"); //add text-zap to the beginning of the buffer
		 buffer.append("Text-Zap");    //add text-zap to the end of the buffer
		 return buffer;
    }
 }

Add the following line to your build file:

<taskdef name="addtext" classname="mypackage.AddText_Filter"/>

Here is what your new filter element should look like:

<addtext/>

^topFilters meant for extension

The following filters are meant to be extended:

AbstractFilter
This is the base class for all filters. It does not provide any services other than loging back to Ant. View API.

IteratingFilter
This is the base class of most Text-Zap filters. It sequentially iterates over each file. With this filter one need only implement the doFilter function. View API.

ReplaceFilterPlus
A base filter that takes a regular expression and then does some processing to it before replacing it. For a full treatment of this base class see ReplaceFilterPlus View API.

SplitFilter
This filter breaks up each file into a number of others. To extend this filter one must implment the split function which takes a single file and should return an ArrayList of FilterFiles. View API.

SourceForge.net Logo