From 3347fc027018fcbc1b67b25e134e53897f33a911 Mon Sep 17 00:00:00 2001 From: Magesh Umasankar Date: Wed, 27 Feb 2002 21:50:40 +0000 Subject: [PATCH] FilterReaderSet -> FilterChain as this is more representative of the collection. Documentation updates. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271588 13f79535-47bb-0310-9956-ffa450edef68 --- proposal/sandbox/filterreaders/README | 29 ++- .../docs/manual/CoreTasks/loadfile.html | 6 +- .../manual/CoreTypes/filterreaderset.html | 231 ------------------ .../apache/tools/ant/taskdefs/LoadFile.java | 14 +- .../tools/ant/taskdefs/LoadProperties.java | 14 +- .../tools/ant/types/FilterReaderSet.java | 123 ---------- .../tools/ant/util/ChainReaderHelper.java | 18 +- 7 files changed, 49 insertions(+), 386 deletions(-) delete mode 100644 proposal/sandbox/filterreaders/docs/manual/CoreTypes/filterreaderset.html delete mode 100644 proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/types/FilterReaderSet.java diff --git a/proposal/sandbox/filterreaders/README b/proposal/sandbox/filterreaders/README index 409dd2349..90c268b0c 100644 --- a/proposal/sandbox/filterreaders/README +++ b/proposal/sandbox/filterreaders/README @@ -20,13 +20,17 @@ Usecase: Design: ====== -* FilterReaderSet is a collection of 'AntFilterReader's +* FilterChain is an ordered collection of 'AntFilterReader's and + 'java.io.FilterReader's * Each AntFilterReader encloses the custom class representing the actual java.io.FilterReader and contains configuration parameters that may be used by the custom class if it implements the org.apache.tools.ant.types.Parameterizable interface. + +* For ease of use, Ant's core filter readers can + be used with a filter reader specific syntax also. * Custom filter readers can be created easily even without using any of Ant's API - all one needs to @@ -44,14 +48,14 @@ Example: ======= - + - - - + + + - + The above example loads the contents of the file foo, @@ -59,3 +63,16 @@ filters out the lines that begin with //, REM and --, removes line breaks and then stores the result in the property named bar. +Since StripLineComments and StripLineBreaks are built-in +Ant filter readers, the same can also be represented as: + + + + + + + + + + + diff --git a/proposal/sandbox/filterreaders/docs/manual/CoreTasks/loadfile.html b/proposal/sandbox/filterreaders/docs/manual/CoreTasks/loadfile.html index 5d60d4fd5..e909de3cf 100644 --- a/proposal/sandbox/filterreaders/docs/manual/CoreTasks/loadfile.html +++ b/proposal/sandbox/filterreaders/docs/manual/CoreTasks/loadfile.html @@ -74,9 +74,9 @@ Load a file, don't fail if it is missing (a message is printed, though)
    <loadfile
       property="mail.recipients"
       srcFile="recipientlist.txt">
-      <filterreaderset>
-        <filterreader classname="org.apache.tools.ant.filters.StripLineBreaks" />
-      </filterreaderset>
+      <filterchain>
+        <filterreader classname="org.apache.tools.ant.filters.StripLineBreaks" />
+      </filterchaint>
     </loadfile>
 
Load a property which can be used as a parameter for another task (in this case mail), diff --git a/proposal/sandbox/filterreaders/docs/manual/CoreTypes/filterreaderset.html b/proposal/sandbox/filterreaders/docs/manual/CoreTypes/filterreaderset.html deleted file mode 100644 index 67bffd3c7..000000000 --- a/proposal/sandbox/filterreaders/docs/manual/CoreTypes/filterreaderset.html +++ /dev/null @@ -1,231 +0,0 @@ - - - - - FilterReaderSet Type - - - -

FilterReaderSet

- -

FilterReaderSets are groups of FilterReaders. FilterReaderSets can appear -inside tasks that support this feature.
FilterReaderSets are used for -filtering file contents read in by tasks like LoadFile, etc.
- -Each FilterReaderSet is composed of nested FilterReader elements. - -

FilterReader

- -A FilterReader element must be supplied with a class name as -an attribute value. The class resolved by this name must -extend java.io.FilterReader. If the custom filter reader -needs to be parameterized, it must implement -org.apache.tools.type.Parameterizable. - - - - - - - - - - - - -
AttributeDescriptionRequired
classnameThe class name of the filter reader.Yes
- -

-The following FilterReaders are supplied with the default -distribution. - -

org.apache.tools.ant.filters.StripLineBreaks

- -This filter reader strips away specific characters -from the data supplied to it. - - - - - - - - - - - - -
Parameter NameParameter ValueRequired
linebreaksCharacters that are to - be stripped out. Defaults to "\r\n"No
-

-

Examples:

- -This strips the '\r' and '\n' characters. -
-<loadfile srcfile="${src.file}" property="${src.file.contents}">
-  <filterreaderset>
-    <filterreader classname="org.apache.tools.ant.filters.StripLineBreaks"/>
-  </filterreaderset>
-</loadfile>
-
- -This treats the '(' and ')' characters as line break characters and -strips them. -
-<loadfile srcfile="${src.file}" property="${src.file.contents}">
-  <filterreaderset>
-    <filterreader classname="org.apache.tools.ant.filters.StripLineBreaks">
-      <param name="linebreaks" value="()"/>
-    </filterreader>
-  </filterreaderset>
-</loadfile>
-
- -

org.apache.tools.ant.filters.StripJavaComments

- -This filter reader strips away comments from the data, -using Java syntax guidelines. This filter does not -take in any parameters. -

-

Example:

- -
-<loadfile srcfile="${java.src.file}" property="${java.src.file.nocomments}">
-  <filterreaderset>
-    <filterreader classname="org.apache.tools.ant.filters.StripJavaComments"/>
-  </filterreaderset>
-</loadfile>
-
- -

org.apache.tools.ant.filters.ReplaceTokens

- -This filter reader replaces all strings that are -sandwiched between begintoken and endtoken with -user defined values. - - - - - - - - - - - - - - - - - - - - - - - - - - -
Parameter TypeParameter NameParameter ValueRequired
tokencharbegintokenCharacter marking the - beginning of a token. Defaults to @No
tokencharendtokenCharacter marking the - end of a token. Defaults to @No
tokenUser defined String.User defined search StringYes
-

- -

Example:

- -This replaces occurences of the string @DATE@ in the data -with today's date and stores it in the property ${src.file.replaced} -
-<tstamp/>
-<loadfile srcfile="${src.file}" property="${src.file.replaced}">
-  <filterreaderset>
-    <filterreader classname="org.apache.tools.ant.filters.ReplaceTokens">
-      <param type="token" name="DATE" value="${TODAY}"/>
-    <filterreader/>
-  </filterreaderset>
-</loadfile>
-
- -

org.apache.tools.ant.filters.HeadFilter

- -This filter reads the first few lines from the data supplied to it. - - - - - - - - - - - - -
Parameter NameParameter ValueRequired
linesNumber of lines to be read. - Defaults to "10"No
-

-

Example:

- -This stores the first 15 lines of the supplied data in the property ${src.file.head} -
-<loadfile srcfile="${src.file}" property="${src.file.head}">
-  <filterreaderset>
-    <filterreader classname="org.apache.tools.ant.filters.HeadFilter">
-      <param name="lines" value="15"/>
-    </filterreader>
-  </filterreaderset>
-</loadfile>
-
- -

org.apache.tools.ant.filters.TailFilter

- -This filter reads the last few lines from the data supplied to it. - - - - - - - - - - - - -
Parameter NameParameter ValueRequired
linesNumber of lines to be read. - Defaults to "10"No
-

-

Examples:

- -This stores the last 15 lines of the supplied data in the property ${src.file.tail} -
-<loadfile srcfile="${src.file}" property="${src.file.tail}">
-  <filterreaderset>
-    <filterreader classname="org.apache.tools.ant.filters.TailFilter">
-      <param name="lines" value="15"/>
-    </filterreader>
-  </filterreaderset>
-</loadfile>
-
- -This stores the last 5 lines of the first 15 lines of the supplied -data in the property ${src.file.mid} -
-<loadfile srcfile="${src.file}" property="${src.file.mid}">
-  <filterreaderset>
-    <filterreader classname="org.apache.tools.ant.filters.HeadFilter">
-      <param name="lines" value="15"/>
-    </filterreader>
-    <filterreader classname="org.apache.tools.ant.filters.TailFilter">
-      <param name="lines" value="5"/>
-    </filterreader>
-  </filterreaderset>
-</loadfile>
-
- -
- -

Copyright © 2002 Apache Software Foundation. All rights -Reserved.

diff --git a/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadFile.java b/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadFile.java index e8578acfb..ca569c691 100644 --- a/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadFile.java +++ b/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadFile.java @@ -56,7 +56,7 @@ package org.apache.tools.ant.taskdefs; import org.apache.tools.ant.Task; import org.apache.tools.ant.Project; import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.types.FilterReaderSet; +import org.apache.tools.ant.types.FilterChain; import org.apache.tools.ant.util.ChainReaderHelper; import java.io.*; @@ -98,9 +98,9 @@ public final class LoadFile extends Task { private boolean evaluateProperties=false; /** - * Holds filterReaderSets + * Holds FilterChains */ - private final Vector filterReaderSets = new Vector(); + private final Vector filterChains = new Vector(); /** * Encoding to use for filenames, defaults to the platform's default @@ -193,7 +193,7 @@ public final class LoadFile extends Task { ChainReaderHelper crh = new ChainReaderHelper(); crh.setBufferSize(size); crh.setPrimaryReader(instream); - crh.setFilterReaderSets(filterReaderSets); + crh.setFilterChains(filterChains); String text = crh.processStream(); @@ -231,10 +231,10 @@ public final class LoadFile extends Task { } /** - * Add the FilterReaderSet element. + * Add the FilterChain element. */ - public final void addFilterReaderSet(FilterReaderSet filter) { - filterReaderSets.addElement(filter); + public final void addFilterChain(FilterChain filter) { + filterChains.addElement(filter); } //end class diff --git a/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java b/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java index 3946aabd6..b7251fa2d 100644 --- a/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java +++ b/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java @@ -56,7 +56,7 @@ package org.apache.tools.ant.taskdefs; import org.apache.tools.ant.Task; import org.apache.tools.ant.Project; import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.types.FilterReaderSet; +import org.apache.tools.ant.types.FilterChain; import org.apache.tools.ant.util.ChainReaderHelper; import java.io.*; @@ -76,9 +76,9 @@ public final class LoadProperties extends Task { private File srcFile = null; /** - * Holds filterReaderSets + * Holds filterchains */ - private final Vector filterReaderSets = new Vector(); + private final Vector filterChains = new Vector(); /** * Sets the srcfile attribute. @@ -124,7 +124,7 @@ public final class LoadProperties extends Task { ChainReaderHelper crh = new ChainReaderHelper(); crh.setBufferSize(size); crh.setPrimaryReader(instream); - crh.setFilterReaderSets(filterReaderSets); + crh.setFilterChains(filterChains); String text = crh.processStream(); if (!text.endsWith("\n")) { @@ -186,10 +186,10 @@ public final class LoadProperties extends Task { } /** - * Add the FilterReaderSet element. + * Add the FilterChain element. */ - public final void addFilterReaderSet(FilterReaderSet filter) { - filterReaderSets.addElement(filter); + public final void addFilterChain(FilterChain filter) { + filterChains.addElement(filter); } //end class diff --git a/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/types/FilterReaderSet.java b/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/types/FilterReaderSet.java deleted file mode 100644 index 2d3108a01..000000000 --- a/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/types/FilterReaderSet.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2002 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, if - * any, must include the following acknowlegement: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowlegement may appear in the software itself, - * if and wherever such third-party acknowlegements normally appear. - * - * 4. The names "The Jakarta Project", "Ant", and "Apache Software - * Foundation" must not be used to endorse or promote products derived - * from this software without prior written permission. For written - * permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache" - * nor may "Apache" appear in their names without prior written - * permission of the Apache Group. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ -package org.apache.tools.ant.types; - -import java.util.Vector; - -import org.apache.tools.ant.filters.HeadFilter; -import org.apache.tools.ant.filters.LineContains; -import org.apache.tools.ant.filters.PrefixLines; -import org.apache.tools.ant.filters.ReplaceTokens; -import org.apache.tools.ant.filters.StripJavaComments; -import org.apache.tools.ant.filters.StripLineBreaks; -import org.apache.tools.ant.filters.StripLineComments; -import org.apache.tools.ant.filters.TabsToSpaces; -import org.apache.tools.ant.filters.TailFilter; - -/** - * Set of FilterReaders - * - * @author Magesh Umasankar - */ -public final class FilterReaderSet { - - private final Vector filterReaders = new Vector(); - - public final void addFilterReader(final AntFilterReader filterReader) { - filterReaders.addElement(filterReader); - } - - public final Vector getFilterReaders() { - return filterReaders; - } - - public final void addHeadFilter(final HeadFilter headFilter) { - filterReaders.addElement(headFilter); - } - - public final void addLineContains(final LineContains lineContains) { - filterReaders.addElement(lineContains); - } - - public final void addPrefixLines(final PrefixLines prefixLines) { - filterReaders.addElement(prefixLines); - } - - public final void addReplaceTokens(final ReplaceTokens replaceTokens) { - filterReaders.addElement(replaceTokens); - } - - public final void addStripJavaComments(final StripJavaComments - stripJavaComments) { - filterReaders.addElement(stripJavaComments); - } - - public final void addStripLineBreaks(final StripLineBreaks - stripLineBreaks) { - filterReaders.addElement(stripLineBreaks); - } - - public final void addStripLineComments(final StripLineComments - stripLineComments) { - filterReaders.addElement(stripLineComments); - } - - public final void addTabsToSpaces(final TabsToSpaces tabsToSpaces) { - filterReaders.addElement(tabsToSpaces); - } - - public final void addTailFilter(final TailFilter tailFilter) { - filterReaders.addElement(tailFilter); - } -} diff --git a/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/util/ChainReaderHelper.java b/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/util/ChainReaderHelper.java index 256608753..ba423bde2 100644 --- a/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/util/ChainReaderHelper.java +++ b/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/util/ChainReaderHelper.java @@ -58,7 +58,7 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.filters.ChainableReader; import org.apache.tools.ant.types.AntFilterReader; -import org.apache.tools.ant.types.FilterReaderSet; +import org.apache.tools.ant.types.FilterChain; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Parameter; import org.apache.tools.ant.types.Parameterizable; @@ -87,9 +87,9 @@ public final class ChainReaderHelper { public int bufferSize = 4096; /** - * Collection of 'FilterReaderSet's. + * Chain of filters */ - public Vector filterReaderSets = new Vector(); + public Vector filterChains = new Vector(); /** * Sets the primary reader @@ -109,8 +109,8 @@ public final class ChainReaderHelper { /** * Sets the collection of filter reader sets */ - public final void setFilterReaderSets(Vector frsets) { - filterReaderSets = frsets; + public final void setFilterChains(Vector fchain) { + filterChains = fchain; } /** @@ -125,13 +125,13 @@ public final class ChainReaderHelper { Reader instream = primaryReader; final char[] buffer = new char[bufferSize]; - final int filterReadersCount = filterReaderSets.size(); + final int filterReadersCount = filterChains.size(); final Vector finalFilters = new Vector(); for (int i = 0; i < filterReadersCount; i++) { - final FilterReaderSet filterset = - (FilterReaderSet) filterReaderSets.elementAt(i); - final Vector filterReaders = filterset.getFilterReaders(); + final FilterChain filterchain = + (FilterChain) filterChains.elementAt(i); + final Vector filterReaders = filterchain.getFilterReaders(); final int readerCount = filterReaders.size(); for (int j = 0; j < readerCount; j++) { finalFilters.addElement(filterReaders.elementAt(j));