terp - the ANT Tasks
v1.3.304

com.codemesh.terp.ant
Class ReplacePatternFilter

java.lang.Object
  extended by java.io.Reader
      extended by java.io.FilterReader
          extended by org.apache.tools.ant.filters.BaseFilterReader
              extended by org.apache.tools.ant.filters.BaseParamFilterReader
                  extended by com.codemesh.terp.ant.ReplacePatternFilter
All Implemented Interfaces:
java.io.Closeable, java.lang.Readable, org.apache.tools.ant.filters.ChainableReader, org.apache.tools.ant.types.Parameterizable

public class ReplacePatternFilter
extends org.apache.tools.ant.filters.BaseParamFilterReader
implements org.apache.tools.ant.filters.ChainableReader

A filter that replaces certain patterns in a file when applied to it. This filter is subclassed to provide specific services like stripping leading copyright notices or file history comments. A stripping filter is simply a replacement filter that replaces the search pattern with nothing. Please make sure to enclose the search pattern(s) in capturing group markers. This filter allows you to search for a complex pattern and only replace parts of it with the specified replacements, but in exchange for this feature, it requires you to enclose the entire pattern in a cpaturing group if you indeed want to replace the entire pattern.


Nested Class Summary
static class ReplacePatternFilter.StringValue
           
 
Field Summary
static java.lang.String PATTERN_KEY
           
static java.lang.String POSITION_KEY
           
static java.lang.String REPEAT_KEY
           
static java.lang.String REPLACEMENT_KEY
           
 
Fields inherited from class java.io.FilterReader
in
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
ReplacePatternFilter()
           
ReplacePatternFilter(java.io.Reader in)
          Creates a new filtered reader.
 
Method Summary
 java.io.Reader chain(java.io.Reader rdr)
           
 ReplacePatternFilter.StringValue createReplacement()
           
 java.lang.String getPattern()
          Returns the search pattern's string representation.
 java.lang.String getPosition()
          Returns the starting position for replacements.
 java.lang.String getRepeat()
          Returns the number of repetitions for the replacement action.
protected  void initialize()
          Scans the parameters list for the known parameters.
 int read()
           
protected  void replace(java.io.Reader rdr)
           
 void setPattern(java.lang.String pattern)
          Sets the search pattern as a Java regular expression.
 void setPosition(java.lang.String position)
          Sets the starting position for replacements.
 void setRepeat(java.lang.String repeat)
          Sets the number of repetitions for the replacement action.
 
Methods inherited from class org.apache.tools.ant.filters.BaseParamFilterReader
getParameters, setParameters
 
Methods inherited from class org.apache.tools.ant.filters.BaseFilterReader
getInitialized, getProject, read, readFully, readLine, setInitialized, setProject, skip
 
Methods inherited from class java.io.FilterReader
close, mark, markSupported, ready, reset
 
Methods inherited from class java.io.Reader
read, read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PATTERN_KEY

public static final java.lang.String PATTERN_KEY
See Also:
Constant Field Values

POSITION_KEY

public static final java.lang.String POSITION_KEY
See Also:
Constant Field Values

REPEAT_KEY

public static final java.lang.String REPEAT_KEY
See Also:
Constant Field Values

REPLACEMENT_KEY

public static final java.lang.String REPLACEMENT_KEY
See Also:
Constant Field Values
Constructor Detail

ReplacePatternFilter

public ReplacePatternFilter()

ReplacePatternFilter

public ReplacePatternFilter(java.io.Reader in)
Creates a new filtered reader.

Parameters:
in - A Reader object providing the underlying stream. Must not be null.
Method Detail

getPattern

public java.lang.String getPattern()
Returns the search pattern's string representation.

Returns:
the search pattern.

setPattern

public void setPattern(java.lang.String pattern)
Sets the search pattern as a Java regular expression.

Parameters:
pattern - the regular expression pattern.

getPosition

public java.lang.String getPosition()
Returns the starting position for replacements. 0 stands for the first instance from the head of the file. Negative numbers may be used to represent instances from the tail of the file.

Returns:
the starting position.

setPosition

public void setPosition(java.lang.String position)
Sets the starting position for replacements. 0 stands for the first instance from the head of the file. Negative numbers may be used to represent instances from the tail of the file.

Parameters:
position - the starting position.

getRepeat

public java.lang.String getRepeat()
Returns the number of repetitions for the replacement action.

Returns:
the number of repetitions.

setRepeat

public void setRepeat(java.lang.String repeat)
Sets the number of repetitions for the replacement action.

Parameters:
repeat - the number of repetitions.

createReplacement

public ReplacePatternFilter.StringValue createReplacement()

read

public int read()
         throws java.io.IOException
Overrides:
read in class java.io.FilterReader
Throws:
java.io.IOException

chain

public java.io.Reader chain(java.io.Reader rdr)
Specified by:
chain in interface org.apache.tools.ant.filters.ChainableReader

replace

protected void replace(java.io.Reader rdr)

initialize

protected void initialize()
Scans the parameters list for the known parameters.


terp - the ANT Tasks
v1.3.304

Copyright © 2008-2012 by Codemesh, Inc. All Rights Reserved.