FileDocCategorySizeDatePackage
TokenFilter.javaAPI DocApache Ant 1.7021285Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.filters

TokenFilter

public class TokenFilter extends BaseFilterReader implements ChainableReader
This splits up input into tokens and passes the tokens to a sequence of filters.
since
Ant 1.6
see
BaseFilterReader
see
ChainableReader
see
org.apache.tools.ant.DynamicConfigurator

Fields Summary
private Vector
filters
string filters
private org.apache.tools.ant.util.Tokenizer
tokenizer
the tokenizer to use on the input stream
private String
delimOutput
the output token termination
private String
line
the current string token from the input stream
private int
linePos
the position in the current string token
Constructors Summary
public TokenFilter()
Constructor for "dummy" instances.

see
BaseFilterReader#BaseFilterReader()


               
      
        super();
    
public TokenFilter(Reader in)
Creates a new filtered reader.

param
in A Reader object providing the underlying stream. Must not be null.

        super(in);
    
Methods Summary
public voidadd(org.apache.tools.ant.filters.TokenFilter$Filter filter)
Add an arbitrary filter

param
filter the filter to add

        filters.addElement(filter);
    
public voidadd(org.apache.tools.ant.util.Tokenizer tokenizer)
add an arbitrary tokenizer

param
tokenizer the tokenizer to all, only one allowed

        if (this.tokenizer != null) {
            throw new BuildException("Only one tokenizer allowed");
        }
        this.tokenizer = tokenizer;
    
public voidaddContainsRegex(org.apache.tools.ant.filters.TokenFilter$ContainsRegex filter)
contains regex filter

param
filter the contains regex filter

        filters.addElement(filter);
    
public voidaddContainsString(org.apache.tools.ant.filters.TokenFilter$ContainsString filter)
contains string filter

param
filter the contains string filter

        filters.addElement(filter);
    
public voidaddDeleteCharacters(org.apache.tools.ant.filters.TokenFilter$DeleteCharacters filter)
delete chars

param
filter the delete characters filter

        filters.addElement(filter);
    
public voidaddFileTokenizer(org.apache.tools.ant.filters.TokenFilter$FileTokenizer tokenizer)
add a file tokenizer

param
tokenizer the file tokenizer

        add(tokenizer);
    
public voidaddIgnoreBlank(org.apache.tools.ant.filters.TokenFilter$IgnoreBlank filter)
ignore blank filter

param
filter the ignore blank filter

        filters.addElement(filter);
    
public voidaddLineTokenizer(org.apache.tools.ant.util.LineTokenizer tokenizer)
add a line tokenizer - this is the default.

param
tokenizer the line tokenizer

        add(tokenizer);
    
public voidaddReplaceRegex(org.apache.tools.ant.filters.TokenFilter$ReplaceRegex filter)
replace regex filter

param
filter the replace regex filter

        filters.addElement(filter);
    
public voidaddReplaceString(org.apache.tools.ant.filters.TokenFilter$ReplaceString filter)
replace string filter

param
filter the replace string filter

        filters.addElement(filter);
    
public voidaddStringTokenizer(org.apache.tools.ant.filters.TokenFilter$StringTokenizer tokenizer)
add a string tokenizer

param
tokenizer the string tokenizer

        add(tokenizer);
    
public voidaddTrim(org.apache.tools.ant.filters.TokenFilter$Trim filter)
trim filter

param
filter the trim filter

        filters.addElement(filter);
    
public final java.io.Readerchain(java.io.Reader reader)
Creates a new TokenFilter using the passed in Reader for instantiation.

param
reader A Reader object providing the underlying stream.
return
a new filter based on this configuration

        TokenFilter newFilter = new TokenFilter(reader);
        newFilter.filters = filters;
        newFilter.tokenizer = tokenizer;
        newFilter.delimOutput = delimOutput;
        newFilter.setProject(getProject());
        return newFilter;
    
public static intconvertRegexOptions(java.lang.String flags)
convert regex option flag characters to regex options
  • g - Regexp.REPLACE_ALL
  • i - Regexp.MATCH_CASE_INSENSITIVE
  • m - Regexp.MATCH_MULTILINE
  • s - Regexp.MATCH_SINGLELINE
  • param
    flags the string containing the flags
    return
    the Regexp option bits

            if (flags == null) {
                return 0;
            }
            int options = 0;
            if (flags.indexOf('g") != -1) {
                options |= Regexp.REPLACE_ALL;
            }
            if (flags.indexOf('i") != -1) {
                options |= Regexp.MATCH_CASE_INSENSITIVE;
            }
            if (flags.indexOf('m") != -1) {
                options |= Regexp.MATCH_MULTILINE;
            }
            if (flags.indexOf('s") != -1) {
                options |= Regexp.MATCH_SINGLELINE;
            }
            return options;
        
    public intread()
    Returns the next character in the filtered stream, only including lines from the original stream which match all of the specified regular expressions.

    return
    the next character in the resulting stream, or -1 if the end of the resulting stream has been reached
    exception
    IOException if the underlying stream throws an IOException during reading

            if (tokenizer == null) {
                tokenizer = new LineTokenizer();
            }
            while (line == null || line.length() == 0) {
                line = tokenizer.getToken(in);
                if (line == null) {
                    return -1;
                }
                for (Enumeration e = filters.elements(); e.hasMoreElements();) {
                    Filter filter = (Filter) e.nextElement();
                    line = filter.filter(line);
                    if (line == null) {
                        break;
                    }
                }
                linePos = 0;
                if (line != null) {
                    if (tokenizer.getPostToken().length() != 0) {
                        if (delimOutput != null) {
                            line = line + delimOutput;
                        } else {
                            line = line + tokenizer.getPostToken();
                        }
                    }
                }
            }
            int ch = line.charAt(linePos);
            linePos++;
            if (linePos == line.length()) {
                line = null;
            }
            return ch;
        
    public static java.lang.StringresolveBackSlash(java.lang.String input)
    xml does not do "c" like interpretation of strings. i.e. \n\r\t etc. this method processes \n, \r, \t, \f, \\ also subs \s -> " \n\r\t\f" a trailing '\' will be ignored

    param
    input raw string with possible embedded '\'s
    return
    converted string

            return StringUtils.resolveBackSlash(input);
        
    public voidsetDelimOutput(java.lang.String delimOutput)
    set the output delimiter.

    param
    delimOutput replaces the delim string returned by the tokenizer, if present.

            this.delimOutput = resolveBackSlash(delimOutput);