source: release-kits/lirk3/bin/ant-installer/web/manual1.7.0/manual/CoreTypes/filterchain.html@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 46.2 KB
Line 
1<!--
2 Licensed to the Apache Software Foundation (ASF) under one or more
3 contributor license agreements. See the NOTICE file distributed with
4 this work for additional information regarding copyright ownership.
5 The ASF licenses this file to You under the Apache License, Version 2.0
6 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16-->
17<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
18
19<html>
20<head>
21 <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
22<title>FilterChains and FilterReaders</title>
23</head>
24
25<body>
26
27<h2>FilterChains and FilterReaders</h2>
28Consider the flexibility of Unix pipes. If you wanted,
29for example, to copy just those lines that contained the
30string blee from the first 10 lines of a text file 'foo'
31(<em>you wouldn't want to filter a binary file</em>)
32to a file 'bar', you would do something like:<p>
33<code>
34cat foo|head -n10|grep blee &gt; bar
35</code><p>
36Ant was not flexible enough. There was no way for the
37<code>&lt;copy&gt;</code> task to do something similar. If you wanted
38the <code>&lt;copy&gt;</code> task to get the first 10 lines, you would have
39had to create special attributes:<p>
40<code>
41&lt;copy file=&quot;foo&quot; tofile=&quot;bar&quot; head=&quot;10&quot; contains=&quot;blee&quot;/&gt;
42</code><p>
43The obvious problem thus surfaced: Ant tasks would not be able
44to accommodate such data transformation attributes as they would
45be endless. The task would also not know in which order these
46attributes were to be interpreted. That is, must the task execute the
47contains attribute first and then the head attribute or vice-versa?
48What Ant tasks needed was a mechanism to allow pluggable filter (data
49transformer) chains. Ant would provide a few filters for which there
50have been repeated requests. Users with special filtering needs
51would be able to easily write their own and plug them in.<p>
52
53The solution was to refactor data transformation oriented
54tasks to support FilterChains. A FilterChain is a group of
55ordered FilterReaders. Users can define their own FilterReaders
56by just extending the java.io.FilterReader class. Such custom
57FilterReaders can be easily plugged in as nested elements of
58<code>&lt;filterchain&gt;</code> by using <code>&lt;filterreader&gt;</code> elements.
59<p>
60Example:
61<blockquote><pre>
62&lt;copy file=&quot;${src.file}&quot; tofile=&quot;${dest.file}&quot;&gt;
63 &lt;filterchain&gt;
64 &lt;filterreader classname=&quot;your.extension.of.java.io.FilterReader&quot;&gt;
65 &lt;param name=&quot;foo&quot; value=&quot;bar&quot;/&gt;
66 &lt;/filterreader&gt;
67 &lt;filterreader classname=&quot;another.extension.of.java.io.FilterReader&quot;&gt;
68 &lt;classpath&gt;
69 &lt;pathelement path="${classpath}"/&gt;
70 &lt;/classpath&gt;
71 &lt;param name=&quot;blah&quot; value=&quot;blee&quot;/&gt;
72 &lt;param type=&quot;abra&quot; value=&quot;cadabra&quot;/&gt;
73 &lt;/filterreader&gt;
74 &lt;/filterchain&gt;
75&lt;/copy&gt;
76</pre></blockquote>
77
78Ant provides some built-in filter readers. These filter readers
79can also be declared using a syntax similar to the above syntax.
80However, they can be declared using some simpler syntax also.<p>
81Example:
82<blockquote><pre>
83&lt;loadfile srcfile=&quot;${src.file}&quot; property=&quot;src.file.head&quot;&gt;
84 &lt;filterchain&gt;
85 &lt;headfilter lines=&quot;15&quot;/&gt;
86 &lt;/filterchain&gt;
87&lt;/loadfile&gt;
88</pre></blockquote>
89is equivalent to:
90<blockquote><pre>
91&lt;loadfile srcfile=&quot;${src.file}&quot; property=&quot;src.file.head&quot;&gt;
92 &lt;filterchain&gt;
93 &lt;filterreader classname=&quot;org.apache.tools.ant.filters.HeadFilter&quot;&gt;
94 &lt;param name=&quot;lines&quot; value=&quot;15&quot;/&gt;
95 &lt;/filterreader&gt;
96 &lt;/filterchain&gt;
97&lt;/loadfile&gt;
98</pre></blockquote>
99
100The following built-in tasks support nested <code>&lt;filterchain&gt;</code> elements.<br>
101<a href="../CoreTasks/concat.html">Concat</a>,<br>
102<a href="../CoreTasks/copy.html">Copy</a>,<br>
103<a href="../CoreTasks/loadfile.html">LoadFile</a>,<br>
104<a href="../CoreTasks/loadproperties.html">LoadProperties</a>,<br>
105<a href="../CoreTasks/move.html">Move</a><br><br>
106
107A FilterChain is formed by defining zero or more of the following
108nested elements.<br>
109<a href="#filterreader">FilterReader</a><br>
110<a href="#classconstants">ClassConstants</a><br>
111<a href="#escapeunicode">EscapeUnicode</a><br>
112<a href="#expandproperties">ExpandProperties</a><br>
113<a href="#headfilter">HeadFilter</a><br>
114<a href="#linecontains">LineContains</a><br>
115<a href="#linecontainsregexp">LineContainsRegExp</a><br>
116<a href="#prefixlines">PrefixLines</a><br>
117<a href="#replacetokens">ReplaceTokens</a><br>
118<a href="#stripjavacomments">StripJavaComments</a><br>
119<a href="#striplinebreaks">StripLineBreaks</a><br>
120<a href="#striplinecomments">StripLineComments</a><br>
121<a href="#tabstospaces">TabsToSpaces</a><br>
122<a href="#tailfilter">TailFilter</a><br>
123<a href="#deletecharacters">DeleteCharacters</a><br>
124<a href="#concatfilter">ConcatFilter</a><br>
125<a href="#tokenfilter">TokenFilter</a><br>
126<a href="../CoreTasks/fixcrlf.html">FixCRLF</a><br>
127
128<h3><a name="filterreader">FilterReader</a></h3>
129
130The filterreader element is the generic way to
131define a filter. User defined filter elements are
132defined in the build file using this. Please note that
133built in filter readers can also be defined using this
134syntax.
135
136A FilterReader element must be supplied with a class name as
137an attribute value. The class resolved by this name must
138extend java.io.FilterReader. If the custom filter reader
139needs to be parameterized, it must implement
140org.apache.tools.type.Parameterizable.
141
142<table cellSpacing=0 cellPadding=2 border=1>
143 <tr>
144 <td vAlign=top><b>Attribute</b></td>
145 <td vAlign=top><b>Description</b></td>
146 <td vAlign=top align="center"><b>Required</b></td>
147 </tr>
148 <tr>
149 <td vAlign=top>classname</td>
150 <td vAlign=top>The class name of the filter reader.</td>
151 <td vAlign=top align="center">Yes</td>
152 </tr>
153</table>
154
155<p>
156<h4>Nested Elements:</h4>
157<code>&lt;filterreader&gt;</code> supports <code>&lt;classpath&gt;</code> and <code>&lt;param&gt;</code>
158as nested elements. Each <code>&lt;param&gt;</code> element may take in the following
159attributes - name, type and value.
160<p>
161The following FilterReaders are supplied with the default
162distribution.
163
164<h3><a name="classconstants">ClassConstants</a></h3>
165<p>
166 This filters basic constants defined in a Java Class,
167 and outputs them in lines composed of the format <i>name</i>=<i>value</i>.
168 This filter uses the <em>bcel</em> library to understand the Java Class file.
169 See <a href="../install.html#librarydependencies">Library Dependencies</a>.
170<p>
171 <p>
172 <em><b>Important:</b></em>
173 This filter is different from most of the other filters.
174 Most of the filters operate on a sequence of characters.
175 This filter operates on the sequence of bytes that makes up
176 a class. However the bytes arrive to the filter as a sequence
177 of characters. This means that one must be careful on the
178 choice of character encoding to use. Most encoding lose information
179 on conversion from an arbitary sequence of bytes to characters
180 and back again to bytes. In particular the usual default
181 character encodings (CP152 and UTF-8) do.
182 For this reason, <em>since Ant 1.7</em>, the character
183 encoding <b>ISO-8859-1</b> is used to convert from characters back to
184 bytes, so one <b>has</b> to use this encoding for reading the java
185 class file.
186<h4>Example:</h4>
187
188This loads the basic constants defined in a Java class as Ant properties.
189
190<blockquote><pre>
191&lt;loadproperties srcfile="foo.class" encoding="ISO-8859-1"&gt;
192 &lt;filterchain&gt;
193 &lt;classconstants/&gt;
194 &lt;/filterchain&gt;
195&lt;/loadproperties&gt;
196</pre></blockquote>
197
198This loads the constants from a Java class file as Ant properties,
199prepending the names with a prefix.
200
201 <blockquote><pre>
202&lt;loadproperties srcfile="build/classes/org/acme/bar.class"
203 encoding="ISO-8859-1"&gt;
204 &lt;filterchain&gt;
205 &lt;classconstants/&gt;
206 &lt;prefixlines prefix="ini."/&gt;
207 &lt;/filterchain&gt;
208&lt;/loadproperties&gt;
209</pre></blockquote>
210<h3><a name="escapeunicode">EscapeUnicode</a></h3>
211<p>
212This filter converts its input by changing all non US-ASCII characters
213into their equivalent unicode escape backslash u plus 4 digits.</p>
214
215<p><em>since Ant 1.6</em></p>
216
217<h4>Example:</h4>
218
219This loads the basic constants defined in a Java class as Ant properties.
220<blockquote><pre>
221&lt;loadproperties srcfile=&quot;non_ascii_property.properties&quot;&gt;
222 &lt;filterchain&gt;
223 &lt;filterreader classname=&quot;org.apache.tools.ant.filters.EscapeUnicode&quot;/&gt;
224 &lt;/filterchain&gt;
225&lt;/loadproperties&gt;
226</pre></blockquote>
227
228Convenience method:
229<blockquote><pre>
230&lt;loadproperties srcfile=&quot;non_ascii_property.properties&quot;&gt;
231 &lt;filterchain&gt;
232 &lt;escapeunicode/&gt;
233 &lt;/filterchain&gt;
234&lt;/loadproperties&gt;
235</pre></blockquote>
236
237<h3><a name="expandproperties">ExpandProperties</a></h3>
238<p>
239If the data contains data that represents Ant
240properties (of the form ${...}), that is substituted
241with the property's actual value.
242<p>
243<h4>Example:</h4>
244
245This results in the property modifiedmessage holding the value
246&quot;All these moments will be lost in time, like teardrops in the rain&quot;
247<blockquote><pre>
248&lt;echo
249 message=&quot;All these moments will be lost in time, like teardrops in the ${weather}&quot;
250 file=&quot;loadfile1.tmp&quot;
251 /&gt;
252&lt;property name=&quot;weather&quot; value=&quot;rain&quot;/&gt;
253&lt;loadfile property=&quot;modifiedmessage&quot; srcFile=&quot;loadfile1.tmp&quot;&gt;
254 &lt;filterchain&gt;
255 &lt;filterreader classname=&quot;org.apache.tools.ant.filters.ExpandProperties&quot;/&gt;
256 &lt;/filterchain&gt;
257&lt;/loadfile&gt;
258</pre></blockquote>
259
260Convenience method:
261<blockquote><pre>
262&lt;echo
263 message=&quot;All these moments will be lost in time, like teardrops in the ${weather}&quot;
264 file=&quot;loadfile1.tmp&quot;
265 /&gt;
266&lt;property name=&quot;weather&quot; value=&quot;rain&quot;/&gt;
267&lt;loadfile property=&quot;modifiedmessage&quot; srcFile=&quot;loadfile1.tmp&quot;&gt;
268 &lt;filterchain&gt;
269 &lt;expandproperties/&gt;
270 &lt;/filterchain&gt;
271&lt;/loadfile&gt;
272</pre></blockquote>
273
274<h3><a name="headfilter">HeadFilter</a></h3>
275
276This filter reads the first few lines from the data supplied to it.
277
278<table cellSpacing=0 cellPadding=2 border=1>
279 <tr>
280 <td vAlign=top><b>Parameter Name</b></td>
281 <td vAlign=top><b>Parameter Value</b></td>
282 <td vAlign=top align="center"><b>Required</b></td>
283 </tr>
284 <tr>
285 <td vAlign=top>lines</td>
286 <td vAlign=top align="center">Number of lines to be read.
287 Defaults to &quot;10&quot; <br> A negative value means that all lines are
288 passed (useful with <i>skip</i>)</td>
289 <td vAlign=top align="center">No</td>
290 </tr>
291 <tr>
292 <td vAlign=top>skip</td>
293 <td vAlign=top align="center">Number of lines to be skipped (from the beginning).
294 Defaults to &quot;0&quot;</td>
295 <td vAlign=top align="center">No</td>
296 </tr>
297</table>
298<p>
299<h4>Example:</h4>
300
301This stores the first 15 lines of the supplied data in the property src.file.head
302<blockquote><pre>
303&lt;loadfile srcfile=&quot;${src.file}&quot; property=&quot;src.file.head&quot;&gt;
304 &lt;filterchain&gt;
305 &lt;filterreader classname=&quot;org.apache.tools.ant.filters.HeadFilter&quot;&gt;
306 &lt;param name=&quot;lines&quot; value=&quot;15&quot;/&gt;
307 &lt;/filterreader&gt;
308 &lt;/filterchain&gt;
309&lt;/loadfile&gt;
310</pre></blockquote>
311
312Convenience method:
313<blockquote><pre>
314&lt;loadfile srcfile=&quot;${src.file}&quot; property=&quot;src.file.head&quot;&gt;
315 &lt;filterchain&gt;
316 &lt;headfilter lines=&quot;15&quot;/&gt;
317 &lt;/filterchain&gt;
318&lt;/loadfile&gt;
319</pre></blockquote>
320
321This stores the first 15 lines, skipping the first 2 lines, of the supplied data
322in the property src.file.head. (Means: lines 3-17)
323<blockquote><pre>
324&lt;loadfile srcfile=&quot;${src.file}&quot; property=&quot;src.file.head&quot;&gt;
325 &lt;filterchain&gt;
326 &lt;headfilter lines=&quot;15&quot; skip=&quot;2&quot;/&gt;
327 &lt;/filterchain&gt;
328&lt;/loadfile&gt;
329</pre></blockquote>
330
331See the testcases for more examples (<i>src\etc\testcases\filters\head-tail.xml</i> in the
332source distribution).
333
334<h3><a name="linecontains">LineContains</a></h3>
335
336This filter includes only those lines that contain all the user-specified
337strings.
338
339<table cellSpacing=0 cellPadding=2 border=1>
340 <tr>
341 <td vAlign=top><b>Parameter Type</b></td>
342 <td vAlign=top><b>Parameter Value</b></td>
343 <td vAlign=top align="center"><b>Required</b></td>
344 </tr>
345 <tr>
346 <td vAlign=top>contains</td>
347 <td vAlign=top align="center">Substring to be searched for.</td>
348 <td vAlign=top align="center">Yes</td>
349 </tr>
350 <tr>
351 <td vAlign=top>negate</td>
352 <td vAlign=top align="center">Whether to select
353 <i>non-</i>matching lines only. <b>Since Ant 1.7</b></td>
354 <td vAlign=top align="center">No</td>
355 </tr>
356</table>
357<p>
358<h4>Example:</h4>
359
360This will include only those lines that contain <code>foo</code> and
361<code>bar</code>.
362<blockquote><pre>
363&lt;filterreader classname=&quot;org.apache.tools.ant.filters.LineContains&quot;&gt;
364 &lt;param type=&quot;contains&quot; value=&quot;foo&quot;/&gt;
365 &lt;param type=&quot;contains&quot; value=&quot;bar&quot;/&gt;
366&lt;/filterreader&gt;
367</pre></blockquote>
368
369Convenience method:
370<blockquote><pre>
371&lt;linecontains&gt;
372 &lt;contains value=&quot;foo&quot;/&gt;
373 &lt;contains value=&quot;bar&quot;/&gt;
374&lt;/linecontains&gt;
375</pre></blockquote>
376
377Negation:
378<blockquote><pre>
379&lt;filterreader classname=&quot;org.apache.tools.ant.filters.LineContains&quot;&gt;
380 &lt;param type=&quot;negate&quot; value=&quot;true&quot;/&gt;
381 &lt;param type=&quot;contains&quot; value=&quot;foo&quot;/&gt;
382 &lt;param type=&quot;contains&quot; value=&quot;bar&quot;/&gt;
383&lt;/filterreader&gt;
384</pre></blockquote>
385<i>or</i>
386<blockquote><pre>
387&lt;linecontains negate=&quot;true&quot;&gt;
388 &lt;contains value=&quot;foo&quot;/&gt;
389 &lt;contains value=&quot;bar&quot;/&gt;
390&lt;/linecontains&gt;
391</pre></blockquote>
392
393<h3><a name="linecontainsregexp">LineContainsRegExp</a></h3>
394
395Filter which includes only those lines that contain the user-specified
396regular expression matching strings.
397
398<table cellSpacing=0 cellPadding=2 border=1>
399 <tr>
400 <td vAlign=top><b>Parameter Type</b></td>
401 <td vAlign=top><b>Parameter Value</b></td>
402 <td vAlign=top align="center"><b>Required</b></td>
403 </tr>
404 <tr>
405 <td vAlign=top>regexp</td>
406 <td vAlign=top align="center">Regular expression to be searched for.</td>
407 <td vAlign=top align="center">Yes</td>
408 </tr>
409 <tr>
410 <td vAlign=top>negate</td>
411 <td vAlign=top align="center">Whether to select
412 <i>non-</i>matching lines only. <b>Since Ant 1.7</b></td>
413 <td vAlign=top align="center">No</td>
414 </tr>
415</table>
416
417See <a href="regexp.html">Regexp Type</a> for the description of the nested element regexp and of
418the choice of regular expression implementation.
419<h4>Example:</h4>
420
421This will fetch all those lines that contain the pattern <code>foo</code>
422<blockquote><pre>
423&lt;filterreader classname=&quot;org.apache.tools.ant.filters.LineContainsRegExp&quot;&gt;
424 &lt;param type=&quot;regexp&quot; value=&quot;foo*&quot;/&gt;
425&lt;/filterreader&gt;
426</pre></blockquote>
427
428Convenience method:
429<blockquote><pre>
430&lt;linecontainsregexp&gt;
431 &lt;regexp pattern=&quot;foo*&quot;/&gt;
432&lt;/linecontainsregexp&gt;
433</pre></blockquote>
434
435Negation:
436<blockquote><pre>
437&lt;filterreader classname=&quot;org.apache.tools.ant.filters.LineContainsRegExp&quot;&gt;
438 &lt;param type=&quot;negate&quot; value=&quot;true&quot;/&gt;
439 &lt;param type=&quot;regexp&quot; value=&quot;foo*&quot;/&gt;
440&lt;/filterreader&gt;
441</pre></blockquote>
442<i>or</i>
443<blockquote><pre>
444&lt;linecontainsregexp negate=&quot;true&quot;&gt;
445 &lt;regexp pattern=&quot;foo*&quot;/&gt;
446&lt;/linecontainsregexp&gt;
447</pre></blockquote>
448
449<h3><a name="prefixlines">PrefixLines</a></h3>
450
451Attaches a prefix to every line.
452
453<table cellSpacing=0 cellPadding=2 border=1>
454 <tr>
455 <td vAlign=top><b>Parameter Name</b></td>
456 <td vAlign=top><b>Parameter Value</b></td>
457 <td vAlign=top align="center"><b>Required</b></td>
458 </tr>
459 <tr>
460 <td vAlign=top>prefix</td>
461 <td vAlign=top align="center">Prefix to be attached to lines.</td>
462 <td vAlign=top align="center">Yes</td>
463 </tr>
464</table>
465<p>
466<h4>Example:</h4>
467
468This will attach the prefix <code>Foo</code> to all lines.
469<blockquote><pre>
470&lt;filterreader classname=&quot;org.apache.tools.ant.filters.PrefixLines&quot;&gt;
471 &lt;param name=&quot;prefix&quot; value=&quot;Foo&quot;/&gt;
472&lt;/filterreader&gt;
473</pre></blockquote>
474
475Convenience method:
476<blockquote><pre>
477&lt;prefixlines prefix=&quot;Foo&quot;/&gt;
478</pre></blockquote>
479
480<h3><a name="replacetokens">ReplaceTokens</a></h3>
481
482This filter reader replaces all strings that are
483sandwiched between begintoken and endtoken with
484user defined values.
485
486<table cellSpacing=0 cellPadding=2 border=1>
487 <tr>
488 <td vAlign=top><b>Parameter Type</b></td>
489 <td vAlign=top><b>Parameter Name</b></td>
490 <td vAlign=top><b>Parameter Value</b></td>
491 <td vAlign=top align="center"><b>Required</b></td>
492 </tr>
493 <tr>
494 <td vAlign=top>tokenchar</td>
495 <td vAlign=top>begintoken</td>
496 <td vAlign=top>Character marking the
497 beginning of a token. Defaults to @</td>
498 <td vAlign=top align="center">No</td>
499 </tr>
500 <tr>
501 <td vAlign=top>tokenchar</td>
502 <td vAlign=top>endtoken</td>
503 <td vAlign=top>Character marking the
504 end of a token. Defaults to @</td>
505 <td vAlign=top align="center">No</td>
506 </tr>
507 <tr>
508 <td vAlign=top>token</td>
509 <td vAlign=top>User defined String.</td>
510 <td vAlign=top>User defined search String.</td>
511 <td vAlign=top align="center">Yes</td>
512 </tr>
513 <tr>
514 <td vAlign=top>propertiesfile</td>
515 <td vAlign=top>Not applicable.</td>
516 <td vAlign=top>Properties file to take tokens from.</td>
517 <td vAlign=top align="center">No</td>
518 </tr>
519</table>
520<p>
521
522<h4>Example:</h4>
523
524This replaces occurrences of the string &#64;DATE&#64; in the data
525with today's date and stores it in the property ${src.file.replaced}
526<blockquote><pre>
527&lt;tstamp/&gt;
528&lt;loadfile srcfile=&quot;${src.file}&quot; property=&quot;${src.file.replaced}&quot;&gt;
529 &lt;filterchain&gt;
530 &lt;filterreader classname=&quot;org.apache.tools.ant.filters.ReplaceTokens&quot;&gt;
531 &lt;param type=&quot;token&quot; name=&quot;DATE&quot; value=&quot;${TODAY}&quot;/&gt;
532 &lt;/filterreader&gt;
533 &lt;/filterchain&gt;
534&lt;/loadfile&gt;
535</pre></blockquote>
536
537Convenience method:
538<blockquote><pre>
539&lt;tstamp/&gt;
540&lt;loadfile srcfile=&quot;${src.file}&quot; property=&quot;${src.file.replaced}&quot;&gt;
541 &lt;filterchain&gt;
542 &lt;replacetokens&gt;
543 &lt;token key=&quot;DATE&quot; value=&quot;${TODAY}&quot;/&gt;
544 &lt;/replacetokens&gt;
545 &lt;/filterchain&gt;
546&lt;/loadfile&gt;
547</pre></blockquote>
548
549This will treat each properties file entry in sample.properties as a token/key pair :
550<blockquote><pre>
551&lt;loadfile srcfile=&quot;${src.file}&quot; property=&quot;${src.file.replaced}&quot;&gt;
552 &lt;filterchain&gt;
553 &lt;filterreader classname=&quot;org.apache.tools.ant.filters.ReplaceTokens&quot;&gt;
554 &lt;param type=&quot;propertiesfile&quot; value=&quot;sample.properties&quot;/&gt;
555 &lt;/filterreader&gt;
556 &lt;/filterchain&gt;
557&lt;/loadfile&gt;
558&lt;/filterchain&gt;
559</pre></blockquote>
560
561<h3><a name="stripjavacomments">StripJavaComments</a></h3>
562
563This filter reader strips away comments from the data,
564using Java syntax guidelines. This filter does not
565take in any parameters.
566<p>
567<h4>Example:</h4>
568
569<blockquote><pre>
570&lt;loadfile srcfile=&quot;${java.src.file}&quot; property=&quot;${java.src.file.nocomments}&quot;&gt;
571 &lt;filterchain&gt;
572 &lt;filterreader classname=&quot;org.apache.tools.ant.filters.StripJavaComments&quot;/&gt;
573 &lt;/filterchain&gt;
574&lt;/loadfile&gt;
575</pre></blockquote>
576
577Convenience method:
578<blockquote><pre>
579&lt;loadfile srcfile=&quot;${java.src.file}&quot; property=&quot;${java.src.file.nocomments}&quot;&gt;
580 &lt;filterchain&gt;
581 &lt;stripjavacomments/&gt;
582 &lt;/filterchain&gt;
583&lt;/loadfile&gt;
584</pre></blockquote>
585
586<h3><a name="striplinebreaks">StripLineBreaks</a></h3>
587
588This filter reader strips away specific characters
589from the data supplied to it.
590
591<table cellSpacing=0 cellPadding=2 border=1>
592 <tr>
593 <td vAlign=top><b>Parameter Name</b></td>
594 <td vAlign=top><b>Parameter Value</b></td>
595 <td vAlign=top align="center"><b>Required</b></td>
596 </tr>
597 <tr>
598 <td vAlign=top>linebreaks</td>
599 <td vAlign=top align="center">Characters that are to
600 be stripped out. Defaults to &quot;\r\n&quot;</td>
601 <td vAlign=top align="center">No</td>
602 </tr>
603</table>
604<p>
605<h4>Examples:</h4>
606
607This strips the '\r' and '\n' characters.
608<blockquote><pre>
609&lt;loadfile srcfile=&quot;${src.file}&quot; property=&quot;${src.file.contents}&quot;&gt;
610 &lt;filterchain&gt;
611 &lt;filterreader classname=&quot;org.apache.tools.ant.filters.StripLineBreaks&quot;/&gt;
612 &lt;/filterchain&gt;
613&lt;/loadfile&gt;
614</pre></blockquote>
615
616Convenience method:
617<blockquote><pre>
618&lt;loadfile srcfile=&quot;${src.file}&quot; property=&quot;${src.file.contents}&quot;&gt;
619 &lt;filterchain&gt;
620 &lt;striplinebreaks/&gt;
621 &lt;/filterchain&gt;
622&lt;/loadfile&gt;
623</pre></blockquote>
624
625This treats the '(' and ')' characters as line break characters and
626strips them.
627<blockquote><pre>
628&lt;loadfile srcfile=&quot;${src.file}&quot; property=&quot;${src.file.contents}&quot;&gt;
629 &lt;filterchain&gt;
630 &lt;filterreader classname=&quot;org.apache.tools.ant.filters.StripLineBreaks&quot;&gt;
631 &lt;param name=&quot;linebreaks&quot; value=&quot;()&quot;/&gt;
632 &lt;/filterreader&gt;
633 &lt;/filterchain&gt;
634&lt;/loadfile&gt;
635</pre></blockquote>
636
637<h3><a name="striplinecomments">StripLineComments</a></h3>
638
639This filter removes all those lines that begin with strings
640that represent comments as specified by the user.
641
642<table cellSpacing=0 cellPadding=2 border=1>
643 <tr>
644 <td vAlign=top><b>Parameter Type</b></td>
645 <td vAlign=top><b>Parameter Value</b></td>
646 <td vAlign=top align="center"><b>Required</b></td>
647 </tr>
648 <tr>
649 <td vAlign=top>comment</td>
650 <td vAlign=top align="center">Strings that identify a line as a comment
651 when they appear at the start of the line.</td>
652 <td vAlign=top align="center">Yes</td>
653 </tr>
654</table>
655<p>
656<h4>Examples:</h4>
657
658This removes all lines that begin with #, --, REM, rem and //
659<blockquote><pre>
660&lt;filterreader classname=&quot;org.apache.tools.ant.filters.StripLineComments&quot;&gt;
661 &lt;param type=&quot;comment&quot; value=&quot;#&quot;/&gt;
662 &lt;param type=&quot;comment&quot; value=&quot;--&quot;/&gt;
663 &lt;param type=&quot;comment&quot; value=&quot;REM &quot;/&gt;
664 &lt;param type=&quot;comment&quot; value=&quot;rem &quot;/&gt;
665 &lt;param type=&quot;comment&quot; value=&quot;//&quot;/&gt;
666&lt;/filterreader&gt;
667</pre></blockquote>
668
669Convenience method:
670<blockquote><pre>
671&lt;striplinecomments&gt;
672 &lt;comment value=&quot;#&quot;/&gt;
673 &lt;comment value=&quot;--&quot;/&gt;
674 &lt;comment value=&quot;REM &quot;/&gt;
675 &lt;comment value=&quot;rem &quot;/&gt;
676 &lt;comment value=&quot;//&quot;/&gt;
677&lt;/striplinecomments&gt;
678</pre></blockquote>
679
680<h3><a name="tabstospaces">TabsToSpaces</a></h3>
681
682This filter replaces tabs with spaces
683
684<table cellSpacing=0 cellPadding=2 border=1>
685 <tr>
686 <td vAlign=top><b>Parameter Name</b></td>
687 <td vAlign=top><b>Parameter Value</b></td>
688 <td vAlign=top align="center"><b>Required</b></td>
689 </tr>
690 <tr>
691 <td vAlign=top>tablength</td>
692 <td vAlign=top align="center">Defaults to &quot;8&quot;</td>
693 <td vAlign=top align="center">No</td>
694 </tr>
695</table>
696<p>
697<h4>Examples:</h4>
698
699This replaces tabs in ${src.file} with spaces.
700<blockquote><pre>
701&lt;loadfile srcfile=&quot;${src.file}&quot; property=&quot;${src.file.notab}&quot;&gt;
702 &lt;filterchain&gt;
703 &lt;filterreader classname=&quot;org.apache.tools.ant.filters.TabsToSpaces&quot;/&gt;
704 &lt;/filterchain&gt;
705&lt;/loadfile&gt;
706</pre></blockquote>
707
708Convenience method:
709<blockquote><pre>
710&lt;loadfile srcfile=&quot;${src.file}&quot; property=&quot;${src.file.notab}&quot;&gt;
711 &lt;filterchain&gt;
712 &lt;tabstospaces/&gt;
713 &lt;/filterchain&gt;
714&lt;/loadfile&gt;
715</pre></blockquote>
716
717<h3><a name="tailfilter">TailFilter</a></h3>
718
719This filter reads the last few lines from the data supplied to it.
720
721<table cellSpacing=0 cellPadding=2 border=1>
722 <tr>
723 <td vAlign=top><b>Parameter Name</b></td>
724 <td vAlign=top><b>Parameter Value</b></td>
725 <td vAlign=top align="center"><b>Required</b></td>
726 </tr>
727 <tr>
728 <td vAlign=top>lines</td>
729 <td vAlign=top align="center">Number of lines to be read.
730 Defaults to &quot;10&quot; <br> A negative value means that all lines are
731 passed (useful with <i>skip</i>)</td>
732 <td vAlign=top align="center">No</td>
733 </tr>
734 <tr>
735 <td vAlign=top>skip</td>
736 <td vAlign=top align="center">Number of lines to be skipped (from the end).
737 Defaults to &quot;0&quot; </td>
738 <td vAlign=top align="center">No</td>
739 </tr>
740</table>
741<p>
742
743<h4>Background:</h4>
744With HeadFilter and TailFilter you can extract each part of a text file you want.
745This graphic shows the dependencies:
746
747<table cellSpacing=0 cellPadding=2 border=1>
748<tr>
749 <th> Content </th>
750 <th></th>
751 <th></th>
752 <th></th>
753 <th> Filter </th>
754</tr>
755<tr>
756 <td> Line 1 </td>
757 <td rowspan="2" bgcolor="#C0C0C0">&nbsp;</td>
758 <td rowspan="9" bgcolor="#FF00FF">&nbsp;</td>
759 <td rowspan="4">&nbsp;</td>
760 <td rowspan="11">
761 <table>
762 <tr>
763 <td bgcolor="#C0C0C0">&nbsp;</td>
764 <td><pre>&lt;filterchain&gt;
765 &lt;headfilter lines="2"/&gt;
766&lt;/filterchain&gt;</pre></td>
767 </tr>
768 <tr>
769 <td bgcolor="#FF00FF">&nbsp;</td>
770 <td><pre>&lt;filterchain&gt;
771 &lt;tailfilter lines="-1" skip="2"/&gt;
772&lt;/filterchain&gt;</pre></td>
773 </tr>
774 <tr>
775 <td bgcolor="#008000">&nbsp;</td>
776 <td><pre>&lt;filterchain&gt;
777 &lt;headfilter lines="-1" skip="2"/&gt;
778&lt;/filterchain&gt;</pre></td>
779 </tr>
780 <tr>
781 <td bgcolor="#0000FF">&nbsp;</td>
782 <td><pre>&lt;filterchain&gt;
783 &lt;headfilter lines="-1" skip="2"/&gt;
784 &lt;tailfilter lines="-1" skip="2"/&gt;
785&lt;/filterchain&gt;</pre></td>
786 </tr>
787 <tr>
788 <td bgcolor="#00FF00">&nbsp;</td>
789 <td><pre>&lt;filterchain&gt;
790 &lt;tailfilter lines="2"/&gt;
791&lt;/filterchain&gt;</pre></td>
792 </tr>
793 </table>
794 </td>
795</tr>
796<tr>
797 <td> Line 2 </td>
798</tr>
799<tr>
800 <td> Line 3 </td>
801 <td rowspan="9" bgcolor="#008000">&nbsp;</td>
802</tr>
803<tr>
804 <td> Line 4 </td>
805</tr>
806<tr>
807 <td> Line 5 </td>
808 <td rowspan="3" bgcolor="#0000FF">&nbsp;</td>
809</tr>
810<tr>
811 <td> Lines ... </td>
812</tr>
813<tr>
814 <td> Line 95 </td>
815</tr>
816<tr>
817 <td> Line 96 </td>
818 <td rowspan="4">&nbsp;</td>
819</tr>
820<tr>
821 <td> Line 97 </td>
822</tr>
823<tr>
824 <td> Line 98 </td>
825 <td rowspan="2" bgcolor="#00FF00">&nbsp;</td>
826</tr>
827<tr>
828 <td> Line 99 </td>
829</tr>
830</table>
831
832
833
834<h4>Examples:</h4>
835
836This stores the last 15 lines of the supplied data in the property ${src.file.tail}
837<blockquote><pre>
838&lt;loadfile srcfile=&quot;${src.file}&quot; property=&quot;${src.file.tail}&quot;&gt;
839 &lt;filterchain&gt;
840 &lt;filterreader classname=&quot;org.apache.tools.ant.filters.TailFilter&quot;&gt;
841 &lt;param name=&quot;lines&quot; value=&quot;15&quot;/&gt;
842 &lt;/filterreader&gt;
843 &lt;/filterchain&gt;
844&lt;/loadfile&gt;
845</pre></blockquote>
846
847Convenience method:
848<blockquote><pre>
849&lt;loadfile srcfile=&quot;${src.file}&quot; property=&quot;${src.file.tail}&quot;&gt;
850 &lt;filterchain&gt;
851 &lt;tailfilter lines=&quot;15&quot;/&gt;
852 &lt;/filterchain&gt;
853&lt;/loadfile&gt;
854</pre></blockquote>
855
856
857This stores the last 5 lines of the first 15 lines of the supplied
858data in the property ${src.file.mid}
859<blockquote><pre>
860&lt;loadfile srcfile=&quot;${src.file}&quot; property=&quot;${src.file.mid}&quot;&gt;
861 &lt;filterchain&gt;
862 &lt;filterreader classname=&quot;org.apache.tools.ant.filters.HeadFilter&quot;&gt;
863 &lt;param name=&quot;lines&quot; value=&quot;15&quot;/&gt;
864 &lt;/filterreader&gt;
865 &lt;filterreader classname=&quot;org.apache.tools.ant.filters.TailFilter&quot;&gt;
866 &lt;param name=&quot;lines&quot; value=&quot;5&quot;/&gt;
867 &lt;/filterreader&gt;
868 &lt;/filterchain&gt;
869&lt;/loadfile&gt;
870</pre></blockquote>
871
872Convenience method:
873<blockquote><pre>
874&lt;loadfile srcfile=&quot;${src.file}&quot; property=&quot;${src.file.mid}&quot;&gt;
875 &lt;filterchain&gt;
876 &lt;headfilter lines=&quot;15&quot;/&gt;
877 &lt;tailfilter lines=&quot;5&quot;/&gt;
878 &lt;/filterchain&gt;
879&lt;/loadfile&gt;
880</pre></blockquote>
881
882
883This stores the last 10 lines, skipping the last 2 lines, of the supplied data
884in the property src.file.head. (Means: if supplied data contains 60 lines,
885lines 49-58 are extracted)
886<blockquote><pre>
887&lt;loadfile srcfile=&quot;${src.file}&quot; property=&quot;src.file.head&quot;&gt;
888 &lt;filterchain&gt;
889 &lt;tailfilter lines=&quot;10&quot; skip=&quot;2&quot;/&gt;
890 &lt;/filterchain&gt;
891&lt;/loadfile&gt;
892</pre></blockquote>
893
894<h3><a name="deletecharacters">DeleteCharacters</a></h3>
895
896 <p>This filter deletes specified characters.</p>
897 <p><em>since Ant 1.6</em></p>
898 <p>This filter is only available in the convenience form.</p>
899
900<table cellSpacing=0 cellPadding=2 border=1>
901 <tr>
902 <td vAlign=top><b>Parameter Name</b></td>
903 <td vAlign=top><b>Parameter Value</b></td>
904 <td vAlign=top align="center"><b>Required</b></td>
905 </tr>
906 <tr>
907 <td vAlign=top>chars</td>
908 <td vAlign=top>
909 The characters to delete. This attribute is
910 <a href="#backslash">backslash enabled</a>.
911 </td>
912 <td vAlign=top align="center">Yes</td>
913 </tr>
914</table>
915<p>
916<h4>Examples:</h4>
917
918Delete tabs and returns from the data.
919<blockquote><pre>
920&lt;deletecharacters chars="\t\r"/&gt;
921</pre></blockquote>
922
923<h3><a name="concatfilter">ConcatFilter</a></h3>
924 <p>This filter prepends or appends the content file to the filtered files.</p>
925 <p><em>since Ant 1.6</em></p>
926<table cellSpacing=0 cellPadding=2 border=1>
927 <tr>
928 <td vAlign=top><b>Parameter Name</b></td>
929 <td vAlign=top><b>Parameter Value</b></td>
930 <td vAlign=top align="center"><b>Required</b></td>
931 </tr>
932 <tr>
933 <td vAlign=top>prepend</td>
934 <td vAlign=top>
935 The name of the file which content should be prepended to the file.
936 </td>
937 <td vAlign=top align="center">No</td>
938 </tr>
939 <tr>
940 <td vAlign=top>append</td>
941 <td vAlign=top>
942 The name of the file which content should be appended to the file.
943 </td>
944 <td vAlign=top align="center">No</td>
945 </tr>
946</table>
947<p>
948
949<h4>Examples:</h4>
950
951Do nothing:
952<blockquote><pre>
953&lt;filterchain&gt;
954 &lt;concatfilter/&gt;
955&lt;/filterchain&gt;
956</pre></blockquote>
957
958Adds a license text before each java source:
959<blockquote><pre>
960&lt;filterchain&gt;
961 &lt;concatfilter prepend="apache-license-java.txt"/&gt;
962&lt;/filterchain&gt;
963</pre></blockquote>
964
965
966
967<h3><a name="tokenfilter">TokenFilter</a></h3>
968This filter tokenizes the inputstream into strings and passes these
969strings to filters of strings. Unlike the other filterreaders, this does
970not support params, only convenience methods are implemented.
971The tokenizer and the string filters are defined by nested elements.
972<p><em>since Ant 1.6</em></p>
973<p>
974Only one tokenizer element may be used, the LineTokenizer is the
975default if none are specified. A tokenizer
976splits the input into token strings and trailing delimiter strings.
977<p>
978There may be zero or more string filters. A string filter processes
979a token and either returns a string or a null.
980It the string is not null it is passed to the next filter. This
981proceeds until all the filters are called.
982If a string is returned after all the filters, the string is
983outputs with its associated token delimitier
984(if one is present).
985The trailing delimiter may be overridden by the <i>delimOutput</i>
986attribute.
987<p>
988<a name="backslash"><em>blackslash interpretation</em></a>
989A number of attributes (including <i>delimOutput</i>) interpret
990backslash escapes. The following are understood: \n, \r, \f, \t
991and \\.
992
993
994<table cellSpacing=0 cellPadding=2 border=1>
995 <tr>
996 <td vAlign=top><b>Attribute</b></td>
997 <td vAlign=top><b>Description</b></td>
998 <td vAlign=top align="center"><b>Required</b></td>
999 </tr>
1000 <tr>
1001 <td vAlign=top>delimOutput</td>
1002 <td vAlign=top>
1003 This overrides the tokendelimiter
1004 returned by the tokenizer if it is not empty. This
1005 attribute is backslash enabled.
1006</td>
1007 <td vAlign=top align="center">No</td>
1008 </tr>
1009</table>
1010<p>
1011
1012 The following tokenizers are provided by the default distribution.
1013 <p>
1014 <a href="#linetokenizer">LineTokenizer</a><br>
1015 <a href="#filetokenizer">FileTokenizer</a><br>
1016 <a href="#stringtokenizer">StringTokenizer</a><br>
1017 </p>
1018
1019 The following string filters are provided by the default distribution.
1020 <p>
1021 <a href="#replacestring">ReplaceString</a><br>
1022 <a href="#containsstring">ContainsString</a><br>
1023 <a href="#replaceregex">ReplaceRegex</a><br>
1024 <a href="#containsregex">ContainsRegex</a><br>
1025 <a href="#trim">Trim</a><br>
1026 <a href="#ignoreblank">IgnoreBlank</a><br>
1027 <a href="#filterdeletecharacters">DeleteCharacters</a><br>
1028 </p>
1029
1030 The following string filters are provided by the optional distribution.
1031 <p>
1032 <a href="#scriptfilter">ScriptFilter</a><br>
1033 </p>
1034
1035Some of the filters may be used directly within a filter chain. In this
1036case a tokenfilter is created implicitly. An extra attribute "byline"
1037is added to the filter to specify whether to use a linetokenizer
1038(byline="true") or a filetokenizer (byline="false"). The default
1039is "true".
1040<p>
1041
1042<p><b><em><a name="linetokenizer">LineTokenizer</a></em></b></p>
1043This tokenizer splits the input into lines.
1044The tokenizer delimits lines
1045by "\r", "\n" or "\r\n".
1046This is the default tokenizer.
1047<table cellSpacing=0 cellPadding=2 border=1>
1048 <tr>
1049 <td vAlign=top><b>Attribute</b></td>
1050 <td vAlign=top><b>Description</b></td>
1051 <td vAlign=top align="center"><b>Required</b></td>
1052 </tr>
1053 <tr>
1054 <td vAlign=top>includeDelims</td>
1055 <td vAlign=top>
1056 Include the line endings in the token.
1057 Default is false.
1058 </td>
1059 <td vAlign=top align="center">No</td>
1060 </tr>
1061</table>
1062<h4>Examples:</h4>
1063
1064Convert input current line endings to unix style line endings.
1065<blockquote><pre>
1066&lt;tokenfilter delimoutput=&quot;\n&quot;/&gt;
1067</pre></blockquote>
1068
1069
1070Remove blank lines.
1071<blockquote><pre>
1072&lt;tokenfilter&gt;
1073 &lt;ignoreblank/&gt;
1074&lt;/tokenfilter&gt;
1075
1076</pre></blockquote>
1077
1078<p><b><em><a name="filetokenizer">FileTokenizer</a></em></b></p>
1079This tokenizer treats <b>all</b> the input as a token. So be
1080careful not to use this on very large input.
1081<h4>Examples:</h4>
1082
1083Replace the first occurrence of package with //package.
1084<blockquote><pre>
1085&lt;tokenfilter&gt;
1086 &lt;filetokenizer/&gt;
1087 &lt;replaceregex pattern="([\n\r]+[ \t]*|^[ \t]*)package"
1088 flags="s"
1089 replace="\1//package"/&gt;
1090&lt;/tokenfilter&gt;
1091</pre></blockquote>
1092
1093<p><b><em><a name="stringtokenizer">StringTokenizer</a></em></b></p>
1094This tokenizer is based on java.util.StringTokenizer.
1095It splits up the input into strings separated by white space, or
1096by a specified list of delimiting characters.
1097If the stream starts with delimiter characters, the first
1098token will be the empty string (unless the <i>delimsaretokens</i>
1099attribute is used).
1100
1101<table cellSpacing=0 cellPadding=2 border=1>
1102 <tr>
1103 <td vAlign=top><b>Attribute</b></td>
1104 <td vAlign=top><b>Description</b></td>
1105 <td vAlign=top align="center"><b>Required</b></td>
1106 </tr>
1107 <tr>
1108 <td vAlign=top>delims</td>
1109 <td vAlign=top>The delimiter characters. White space
1110 is used if this is not set. (White space is defined
1111 in this case by java.lang.Character.isWhitespace()).
1112 </td>
1113 <td vAlign=top align="center">No</td>
1114 </tr>
1115 <tr>
1116 <td valign="top">delimsaretokens</td>
1117 <td valign="top">If this is true,
1118 each delimiter character is returned as a token.
1119 Default is false.
1120 </td>
1121 <td valign="top" align="center">No</td>
1122 </tr>
1123 <tr>
1124 <td valign="top">suppressdelims</td>
1125 <td valign="top">
1126 If this is true, delimiters are not returned.
1127 Default is false.
1128 </td>
1129 <td valign="top" align="center">No</td>
1130 </tr>
1131 <tr>
1132 <td vAlign=top>includeDelims</td>
1133 <td vAlign=top>
1134 Include the delimiters in the token.
1135 Default is false.
1136 </td>
1137 <td vAlign=top align="center">No</td>
1138 </tr>
1139</table>
1140
1141<h4>Examples:</h4>
1142
1143Surround each non space token with a "[]".
1144
1145<blockquote><pre>
1146&lt;tokenfilter&gt;
1147 &lt;stringtokenizer/&gt;
1148 &lt;replaceregex pattern="(.+)" replace="[\1]"/&gt;
1149&lt;/tokenfilter&gt;
1150
1151</pre></blockquote>
1152
1153<p><b><em><a name="replacestring">ReplaceString</a></em></b></p>
1154This is a simple filter to replace strings.
1155This filter may be used directly within a filterchain.
1156
1157<table cellSpacing=0 cellPadding=2 border=1>
1158 <tr>
1159 <td vAlign=top><b>Attribute</b></td>
1160 <td vAlign=top><b>Description</b></td>
1161 <td vAlign=top align="center"><b>Required</b></td>
1162 </tr>
1163 <tr>
1164 <td vAlign=top>from</td>
1165 <td vAlign=top>The string that must be replaced.</td>
1166 <td vAlign=top align="center">Yes</td>
1167 </tr>
1168 <tr>
1169 <td valign="top">to</td>
1170 <td valign="top">The new value for the replaced string. When omitted
1171 an empty string is used.
1172 </td>
1173 <td valign="top" align="center">No</td>
1174 </tr>
1175</table>
1176
1177<h4>Examples:</h4>
1178
1179Replace "sun" with "moon".
1180
1181<blockquote><pre>
1182&lt;tokenfilter&gt;
1183 &lt;replacestring from="sun" to="moon"/&gt;
1184&lt;/tokenfilter&gt;
1185</pre></blockquote>
1186
1187<p><b><em><a name="containsstring">ContainsString</a></em></b></p>
1188This is a simple filter to filter tokens that contains
1189a specified string.
1190
1191<table cellSpacing=0 cellPadding=2 border=1>
1192 <tr>
1193 <td vAlign=top><b>Attribute</b></td>
1194 <td vAlign=top><b>Description</b></td>
1195 <td vAlign=top align="center"><b>Required</b></td>
1196 </tr>
1197 <tr>
1198 <td vAlign=top>contains</td>
1199 <td vAlign=top>The string that the token must contain.</td>
1200 <td vAlign=top align="center">Yes</td>
1201 </tr>
1202</table>
1203
1204<h4>Examples:</h4>
1205
1206Include only lines that contain "foo";
1207
1208<blockquote><pre>
1209&lt;tokenfilter&gt;
1210 &lt;containsstring contains="foo"/&gt;
1211&lt;/tokenfilter&gt;
1212
1213</pre></blockquote>
1214
1215<p><b><em><a name="replaceregex">ReplaceRegex</a></em></b></p>
1216This string filter replaces regular expressions.
1217This filter may be used directly within a filterchain.
1218<p>
1219 See <a href="regexp.html#implementation">Regexp Type</a>
1220concerning the choice of the implementation.
1221</p>
1222
1223<table cellSpacing=0 cellPadding=2 border=1>
1224 <tr>
1225 <td vAlign=top><b>Attribute</b></td>
1226 <td vAlign=top><b>Description</b></td>
1227 <td vAlign=top align="center"><b>Required</b></td>
1228 </tr>
1229 <tr>
1230 <td vAlign=top>pattern</td>
1231 <td vAlign=top>The regular expression pattern to match in
1232 the token.</td>
1233 <td vAlign=top align="center">Yes</td>
1234 </tr>
1235 <tr>
1236 <td vAlign=top>replace</td>
1237 <td vAlign=top>The substitution pattern to replace the matched
1238 regular expression. When omitted an empty string is used.</td>
1239 <td vAlign=top align="center">No</td>
1240 </tr>
1241 <tr>
1242 <td vAlign=top>flags</td>
1243 <td vAlign=top>See
1244<a href="../OptionalTasks/replaceregexp.html">ReplaceRegexp</a>
1245for an explanation of regex flags.</td>
1246 <td vAlign=top align="center">No</td>
1247 </tr>
1248</table>
1249<h4>Examples:</h4>
1250
1251Replace all occurrences of "hello" with "world", ignoring case.
1252
1253<blockquote><pre>
1254&lt;tokenfilter&gt;
1255 &lt;replaceregex pattern="hello" replace="world" flags="gi"/&gt;
1256&lt;/tokenfilter&gt;
1257
1258</pre></blockquote>
1259
1260<p><b><em><a name="containsregex">ContainsRegex</a></em></b></p>
1261This filters strings that match regular expressions.
1262The filter may optionally replace the matched regular expression.
1263This filter may be used directly within a filterchain.
1264<p>
1265See
1266<a href="regexp.html#implementation">Regexp Type</a>
1267concerning the choice of regular expression implementation.
1268</p>
1269<table cellSpacing=0 cellPadding=2 border=1>
1270 <tr>
1271 <td vAlign=top><b>Attribute</b></td>
1272 <td vAlign=top><b>Description</b></td>
1273 <td vAlign=top align="center"><b>Required</b></td>
1274 </tr>
1275 <tr>
1276 <td vAlign=top>pattern</td>
1277 <td vAlign=top>The regular expression pattern to match in
1278 the token.</td>
1279 <td vAlign=top align="center">Yes</td>
1280 </tr>
1281 <tr>
1282 <td vAlign=top>replace</td>
1283 <td vAlign=top>The substitution pattern to replace the matched
1284 regular expression. When omitted the orignal token is returned.
1285 </td>
1286 <td vAlign=top align="center">No</td>
1287 </tr>
1288 <tr>
1289 <td vAlign=top>flags</td>
1290 <td vAlign=top>See
1291<a href="../OptionalTasks/replaceregexp.html">ReplaceRegexp</a>
1292for an explanation of regex flags.</td>
1293 <td vAlign=top align="center">No</td>
1294 </tr>
1295</table>
1296
1297<h4>Examples:</h4>
1298
1299Filter lines that contain "hello" or "world", ignoring case.
1300
1301<blockquote><pre>
1302&lt;tokenfilter&gt;
1303 &lt;containsregex pattern="(hello|world)" flags="i"/&gt;
1304&lt;/tokenfilter&gt;
1305
1306</pre></blockquote>
1307
1308This example replaces lines like "SUITE(TestSuite, bits);" with
1309"void register_bits();" and removes other lines.
1310
1311<blockquote><pre>
1312&lt;tokenfilter&gt;
1313 &lt;containsregex
1314 pattern="^ *SUITE\(.*,\s*(.*)\s*\).*"
1315 replace="void register_\1();"/&gt;
1316&lt;/tokenfilter&gt;
1317</pre></blockquote>
1318
1319<p><b><em><a name="trim">Trim</a></em></b></p>
1320This filter trims whitespace from the start and end of
1321tokens.
1322This filter may be used directly within a filterchain.
1323<p><b><em><a name="ignoreblank">IgnoreBlank</a></em></b></p>
1324This filter removes empty tokens.
1325This filter may be used directly within a filterchain.
1326<p><b><em><a name="filterdeletecharacters">DeleteCharacters</a></em></b></p>
1327This filter deletes specified characters from tokens.
1328
1329<table cellSpacing=0 cellPadding=2 border=1>
1330 <tr>
1331 <td vAlign=top><b>Attribute</b></td>
1332 <td vAlign=top><b>Description</b></td>
1333 <td vAlign=top align="center"><b>Required</b></td>
1334 </tr>
1335 <tr>
1336 <td vAlign=top>chars</td>
1337 <td vAlign=top>The characters to delete. This attribute
1338 is backslash enabled.</td>
1339 <td vAlign=top align="center">Yes</td>
1340 </tr>
1341</table>
1342
1343<h4>Examples:</h4>
1344
1345Delete tabs from lines, trim the lines and removes empty lines.
1346
1347<blockquote><pre>
1348&lt;tokenfilter&gt;
1349 &lt;deletecharacters chars="\t"/&gt;
1350 &lt;trim/&gt;
1351 &lt;ignoreblank/&gt;
1352&lt;/tokenfilter&gt;
1353
1354</pre></blockquote>
1355
1356<p><b><em><a name="scriptfilter">ScriptFilter</a></em></b></p>
1357This is an optional filter that executes a script in a
1358<a href="http://jakarta.apache.org/bsf" target="_top">Apache BSF</a>
1359 or
1360 <a href="https://scripting.dev.java.net">JSR 223</a>
1361supported language.</p>
1362See the <a href="../OptionalTasks/script.html">Script</a> task for
1363an explanation of scripts and dependencies.
1364</p>
1365<p>
1366The script is provided with an object <i>self</i> that has
1367getToken() and setToken(String) methods.
1368The getToken() method returns the current token. The setToken(String)
1369method replaces the current token.
1370</p>
1371
1372This filter may be used directly within a filterchain.<p>
1373<table cellSpacing=0 cellPadding=2 border=1>
1374 <tr>
1375 <td vAlign=top><b>Attribute</b></td>
1376 <td vAlign=top><b>Description</b></td>
1377 <td vAlign=top align="center"><b>Required</b></td>
1378 </tr>
1379 <tr>
1380 <td vAlign=top>language</td>
1381 <td vAlign=top> The programming language the script is written in.
1382Must be a supported Apache BSF or JSR 223 language</td>
1383 <td vAlign=top align="center">Yes</td>
1384 </tr>
1385 <tr>
1386 <td valign="top">manager</td>
1387 <td valign="top">
1388 The script engine manager to use.
1389 See the <a href="../OptionalTasks/script.html">script</a> task
1390 for using this attribute.
1391 </td>
1392 <td valign="top" align="center">No - default is "auto"</td>
1393 </tr>
1394 <tr>
1395 <td vAlign=top>src</td>
1396 <td vAlign=top>The location of the script as a file, if not inline
1397 </td>
1398 <td vAlign=top align="center">No</td>
1399 </tr>
1400 <tr>
1401 <td valign="top">setbeans</td>
1402 <td valign="top">whether to have all properties, references and targets as
1403 global variables in the script.</td>
1404 <td valign="top" align="center">No, default is "true".</td>
1405 </tr>
1406 <tr>
1407 <td valign="top">classpath</td>
1408 <td valign="top">
1409 The classpath to pass into the script.
1410 </td>
1411 <td align="center" valign="top">No</td>
1412 </tr>
1413 <tr>
1414 <td valign="top">classpathref</td>
1415 <td valign="top">The classpath to use, given as a
1416 <a href="../using.html#references">reference</a> to a path defined elsewhere.
1417 <td align="center" valign="top">No</td>
1418 </tr>
1419</table>
1420 <p>
1421 This filter can take a nested &lt;classpath&gt; element.
1422 See the <a href="../OptionalTasks/script.html">script</a> task
1423 on how to use this element.
1424 </p>
1425<h4>Examples:</h4>
1426
1427Convert to uppercase:
1428<blockquote><pre>
1429&lt;tokenfilter&gt;
1430 &lt;scriptfilter language="javascript"&gt;
1431 self.setToken(self.getToken().toUpperCase());
1432 &lt;/scriptfilter&gt;
1433&lt;/tokenfilter&gt;
1434</pre></blockquote>
1435
1436Remove lines containing the string "bad" while
1437copying text files:
1438 <blockquote>
1439 <pre>
1440&lt;copy todir="dist"&gt;
1441 &lt;fileset dir="src" includes="**/*.txt"/&gt;
1442 &lt;filterchain&gt;
1443 &lt;scriptfilter language="beanshell"&gt;
1444 if (self.getToken().indexOf("bad") != -1) {
1445 self.setToken(null);
1446 }
1447 &lt;/scriptfilter&gt;
1448 &lt;/filterchain&gt;
1449&lt;/copy&gt;
1450 </pre>
1451 </blockquote>
1452
1453<h4>Custom tokenizers and string filters</h4>
1454
1455Custom string filters and tokenizers may be plugged in by
1456extending the interfaces org.apache.tools.ant.filters.TokenFilter.Filter
1457and org.apache.tools.ant.util.Tokenizer respectly.
1458
1459They are defined the build file using <code>&lt;typedef/&gt;</code>. For
1460example a string filter that capitalizes words may be declared as:
1461<blockquote><pre>
1462package my.customant;
1463import org.apache.tools.ant.filters.TokenFilter;
1464
1465public class Capitalize
1466 implements TokenFilter.Filter
1467{
1468 public String filter(String token) {
1469 if (token.length() == 0)
1470 return token;
1471 return token.substring(0, 1).toUpperCase() +
1472 token.substring(1);
1473 }
1474}
1475</pre></blockquote>
1476
1477This may be used as follows:
1478<blockquote><pre>
1479 &lt;typedef type="capitalize" classname="my.customant.Capitalize"
1480 classpath="my.customant.path"/&gt;
1481 &lt;copy file="input" tofile="output"&gt;
1482 &lt;filterchain&gt;
1483 &lt;tokenfilter&gt;
1484 &lt;stringtokenizer/&gt;
1485 &lt;capitalize/&gt;
1486 &lt;/tokenfilter&gt;
1487 &lt;/filterchain&gt;
1488 &lt;/copy&gt;
1489</pre></blockquote>
1490
1491</body></html>
Note: See TracBrowser for help on using the repository browser.