Documentation updates. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271588 13f79535-47bb-0310-9956-ffa450edef68master
@@ -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: | |||
======= | |||
<loadfile srcFile="foo" property="bar"> | |||
<filterreaderset> | |||
<filterchain> | |||
<filterreader classname="org.apache.tools.ant.filters.StripLineComments"> | |||
<param name="cpp.comment" value="//"/> | |||
<param name="oracle.comment" value="REM"/> | |||
<param name="dbms.comment" value="--"/> | |||
<param type="comment" value="//"/> | |||
<param type="comment" value="REM "/> | |||
<param type="comment" value="--"/> | |||
</filterreader> | |||
<filterreader classname="org.apache.tools.ant.filters.StripLineBreaks"/> | |||
</filterreaderset> | |||
</filterchain> | |||
</loadfile> | |||
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: | |||
<loadfile srcFile="foo" property="bar"> | |||
<filterchain> | |||
<striplinecomments> | |||
<comment value="//"/> | |||
<comment value="REM "/> | |||
<comment value="--"/> | |||
</striplinecomments> | |||
<striplinebreaks/> | |||
</filterchain> | |||
</loadfile> |
@@ -74,9 +74,9 @@ Load a file, don't fail if it is missing (a message is printed, though) | |||
<pre> <loadfile | |||
property="mail.recipients" | |||
srcFile="recipientlist.txt"> | |||
<filterreaderset> | |||
<filterreader classname="org.apache.tools.ant.filters.<a href="../CoreTypes/filterreaderset.html#StripLineBreaks">StripLineBreaks</a>" /> | |||
</filterreaderset> | |||
<filterchain> | |||
<filterreader classname="org.apache.tools.ant.filters.<a href="../CoreTypes/filterchain.html#StripLineBreaks">StripLineBreaks</a>" /> | |||
</filterchaint> | |||
</loadfile> | |||
</pre> | |||
Load a property which can be used as a parameter for another task (in this case mail), | |||
@@ -1,231 +0,0 @@ | |||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> | |||
<HTML> | |||
<HEAD> | |||
<TITLE>FilterReaderSet Type</TITLE> | |||
</HEAD> | |||
<BODY> | |||
<H2><A name="filterreaderset">FilterReaderSet</A></H2> | |||
<P>FilterReaderSets are groups of FilterReaders. FilterReaderSets can appear | |||
inside tasks that support this feature. <BR>FilterReaderSets are used for | |||
filtering file contents read in by tasks like LoadFile, etc.<BR> | |||
Each FilterReaderSet is composed of nested <a name="filterreader">FilterReader</a> elements. | |||
<H2>FilterReader</H2> | |||
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. | |||
<TABLE cellSpacing=0 cellPadding=2 border=1> | |||
<TR> | |||
<TD vAlign=top><B>Attribute</B></TD> | |||
<TD vAlign=top><B>Description</B></TD> | |||
<TD vAlign=top align="center"><B>Required</B></TD> | |||
</TR> | |||
<TR> | |||
<TD vAlign=top>classname</TD> | |||
<TD vAlign=top>The class name of the filter reader.</TD> | |||
<TD vAlign=top align="center">Yes</TD> | |||
</TR> | |||
</TABLE> | |||
<p> | |||
The following FilterReaders are supplied with the default | |||
distribution. | |||
<H3>org.apache.tools.ant.filters.<a name="striplinebreaks">StripLineBreaks</a></H3> | |||
This filter reader strips away specific characters | |||
from the data supplied to it. | |||
<TABLE cellSpacing=0 cellPadding=2 border=1> | |||
<TR> | |||
<TD vAlign=top><B>Parameter Name</B></TD> | |||
<TD vAlign=top><B>Parameter Value</B></TD> | |||
<TD vAlign=top align="center"><B>Required</B></TD> | |||
</TR> | |||
<TR> | |||
<TD vAlign=top>linebreaks</TD> | |||
<TD vAlign=top align="center">Characters that are to | |||
be stripped out. Defaults to "\r\n"</TD> | |||
<TD vAlign=top align="center">No</TD> | |||
</TR> | |||
</TABLE> | |||
<P> | |||
<H4>Examples:</H4> | |||
This strips the '\r' and '\n' characters. | |||
<BLOCKQUOTE><PRE> | |||
<loadfile srcfile="${src.file}" property="${src.file.contents}"> | |||
<filterreaderset> | |||
<filterreader classname="org.apache.tools.ant.filters.StripLineBreaks"/> | |||
</filterreaderset> | |||
</loadfile> | |||
</PRE></BLOCKQUOTE> | |||
This treats the '(' and ')' characters as line break characters and | |||
strips them. | |||
<BLOCKQUOTE><PRE> | |||
<loadfile srcfile="${src.file}" property="${src.file.contents}"> | |||
<filterreaderset> | |||
<filterreader classname="org.apache.tools.ant.filters.StripLineBreaks"> | |||
<param name="linebreaks" value="()"/> | |||
</filterreader> | |||
</filterreaderset> | |||
</loadfile> | |||
</PRE></BLOCKQUOTE> | |||
<H3>org.apache.tools.ant.filters.<a name="stripjavacomments">StripJavaComments</a></H3> | |||
This filter reader strips away comments from the data, | |||
using Java syntax guidelines. This filter does not | |||
take in any parameters. | |||
<P> | |||
<H4>Example:</H4> | |||
<BLOCKQUOTE><PRE> | |||
<loadfile srcfile="${java.src.file}" property="${java.src.file.nocomments}"> | |||
<filterreaderset> | |||
<filterreader classname="org.apache.tools.ant.filters.StripJavaComments"/> | |||
</filterreaderset> | |||
</loadfile> | |||
</PRE></BLOCKQUOTE> | |||
<H3>org.apache.tools.ant.filters.<a name="replacetokens">ReplaceTokens</a></H3> | |||
This filter reader replaces all strings that are | |||
sandwiched between begintoken and endtoken with | |||
user defined values. | |||
<TABLE cellSpacing=0 cellPadding=2 border=1> | |||
<TR> | |||
<TD vAlign=top><B>Parameter Type</B></TD> | |||
<TD vAlign=top><B>Parameter Name</B></TD> | |||
<TD vAlign=top><B>Parameter Value</B></TD> | |||
<TD vAlign=top align="center"><B>Required</B></TD> | |||
</TR> | |||
<TR> | |||
<TD vAlign=top>tokenchar</TD> | |||
<TD vAlign=top>begintoken</TD> | |||
<TD vAlign=top>Character marking the | |||
beginning of a token. Defaults to @</TD> | |||
<TD vAlign=top align="center">No</TD> | |||
</TR> | |||
<TR> | |||
<TD vAlign=top>tokenchar</TD> | |||
<TD vAlign=top>endtoken</TD> | |||
<TD vAlign=top>Character marking the | |||
end of a token. Defaults to @</TD> | |||
<TD vAlign=top align="center">No</TD> | |||
</TR> | |||
<TR> | |||
<TD vAlign=top>token</TD> | |||
<TD vAlign=top>User defined String.</TD> | |||
<TD vAlign=top>User defined search String</TD> | |||
<TD vAlign=top align="center">Yes</TD> | |||
</TR> | |||
</TABLE> | |||
<P> | |||
<H4>Example:</H4> | |||
This replaces occurences of the string @DATE@ in the data | |||
with today's date and stores it in the property ${src.file.replaced} | |||
<BLOCKQUOTE><PRE> | |||
<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> | |||
</PRE></BLOCKQUOTE> | |||
<H3>org.apache.tools.ant.filters.<a name="headfilter">HeadFilter</a></H3> | |||
This filter reads the first few lines from the data supplied to it. | |||
<TABLE cellSpacing=0 cellPadding=2 border=1> | |||
<TR> | |||
<TD vAlign=top><B>Parameter Name</B></TD> | |||
<TD vAlign=top><B>Parameter Value</B></TD> | |||
<TD vAlign=top align="center"><B>Required</B></TD> | |||
</TR> | |||
<TR> | |||
<TD vAlign=top>lines</TD> | |||
<TD vAlign=top align="center">Number of lines to be read. | |||
Defaults to "10"</TD> | |||
<TD vAlign=top align="center">No</TD> | |||
</TR> | |||
</TABLE> | |||
<P> | |||
<H4>Example:</H4> | |||
This stores the first 15 lines of the supplied data in the property ${src.file.head} | |||
<BLOCKQUOTE><PRE> | |||
<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> | |||
</PRE></BLOCKQUOTE> | |||
<H3>org.apache.tools.ant.filters.<a name="tailfilter">TailFilter</a></H3> | |||
This filter reads the last few lines from the data supplied to it. | |||
<TABLE cellSpacing=0 cellPadding=2 border=1> | |||
<TR> | |||
<TD vAlign=top><B>Parameter Name</B></TD> | |||
<TD vAlign=top><B>Parameter Value</B></TD> | |||
<TD vAlign=top align="center"><B>Required</B></TD> | |||
</TR> | |||
<TR> | |||
<TD vAlign=top>lines</TD> | |||
<TD vAlign=top align="center">Number of lines to be read. | |||
Defaults to "10"</TD> | |||
<TD vAlign=top align="center">No</TD> | |||
</TR> | |||
</TABLE> | |||
<P> | |||
<H4>Examples:</H4> | |||
This stores the last 15 lines of the supplied data in the property ${src.file.tail} | |||
<BLOCKQUOTE><PRE> | |||
<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> | |||
</PRE></BLOCKQUOTE> | |||
This stores the last 5 lines of the first 15 lines of the supplied | |||
data in the property ${src.file.mid} | |||
<BLOCKQUOTE><PRE> | |||
<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> | |||
</PRE></BLOCKQUOTE> | |||
<HR> | |||
<P align=center>Copyright © 2002 Apache Software Foundation. All rights | |||
Reserved.</P></BODY></HTML> |
@@ -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 | |||
@@ -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 | |||
@@ -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 | |||
* <http://www.apache.org/>. | |||
*/ | |||
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 <a href="mailto:umagesh@apache.org">Magesh Umasankar</a> | |||
*/ | |||
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); | |||
} | |||
} |
@@ -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)); | |||