KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > types > FilterChain


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  */

18 package org.apache.tools.ant.types;
19
20 import java.util.Vector JavaDoc;
21
22 import org.apache.tools.ant.BuildException;
23 import org.apache.tools.ant.filters.ChainableReader;
24 import org.apache.tools.ant.filters.ClassConstants;
25 import org.apache.tools.ant.filters.EscapeUnicode;
26 import org.apache.tools.ant.filters.ExpandProperties;
27 import org.apache.tools.ant.filters.HeadFilter;
28 import org.apache.tools.ant.filters.LineContains;
29 import org.apache.tools.ant.filters.LineContainsRegExp;
30 import org.apache.tools.ant.filters.PrefixLines;
31 import org.apache.tools.ant.filters.ReplaceTokens;
32 import org.apache.tools.ant.filters.StripJavaComments;
33 import org.apache.tools.ant.filters.StripLineBreaks;
34 import org.apache.tools.ant.filters.StripLineComments;
35 import org.apache.tools.ant.filters.TabsToSpaces;
36 import org.apache.tools.ant.filters.TailFilter;
37 import org.apache.tools.ant.filters.TokenFilter;
38
39
40 /**
41  * FilterChain may contain a chained set of filter readers.
42  *
43  */

44 public class FilterChain extends DataType
45     implements Cloneable JavaDoc {
46
47     private Vector JavaDoc filterReaders = new Vector JavaDoc();
48
49     /**
50      * Add an AntFilterReader filter.
51      *
52      * @param filterReader an <code>AntFilterReader</code> value
53      */

54     public void addFilterReader(final AntFilterReader filterReader) {
55         filterReaders.addElement(filterReader);
56     }
57
58     /**
59      * Return the filters.
60      *
61      * @return a <code>Vector</code> value containing the filters
62      */

63     public Vector JavaDoc getFilterReaders() {
64         return filterReaders;
65     }
66
67     /**
68      * Add a ClassConstants filter.
69      *
70      * @param classConstants a <code>ClassConstants</code> value
71      */

72     public void addClassConstants(final ClassConstants classConstants) {
73         filterReaders.addElement(classConstants);
74     }
75
76     /**
77      * Add an ExpandProperties filter.
78      *
79      * @param expandProperties an <code>ExpandProperties</code> value
80      */

81     public void addExpandProperties(final ExpandProperties expandProperties) {
82         filterReaders.addElement(expandProperties);
83     }
84
85     /**
86      * Add a HeadFilter filter.
87      *
88      * @param headFilter a <code>HeadFilter</code> value
89      */

90     public void addHeadFilter(final HeadFilter headFilter) {
91         filterReaders.addElement(headFilter);
92     }
93
94     /**
95      * Add a LineContains filter.
96      *
97      * @param lineContains a <code>LineContains</code> value
98      */

99     public void addLineContains(final LineContains lineContains) {
100         filterReaders.addElement(lineContains);
101     }
102
103     /**
104      * Add a LineContainsRegExp filter.
105      *
106      * @param lineContainsRegExp a <code>LineContainsRegExp</code> value
107      */

108     public void addLineContainsRegExp(final LineContainsRegExp
109                                                 lineContainsRegExp) {
110         filterReaders.addElement(lineContainsRegExp);
111     }
112
113     /**
114      * Add a PrefixLines filter.
115      *
116      * @param prefixLines a <code>PrefixLines</code> value
117      */

118     public void addPrefixLines(final PrefixLines prefixLines) {
119         filterReaders.addElement(prefixLines);
120     }
121
122     /**
123      * Add a ReplaceTokens filter.
124      *
125      * @param replaceTokens a <code>ReplaceTokens</code> value
126      */

127     public void addReplaceTokens(final ReplaceTokens replaceTokens) {
128         filterReaders.addElement(replaceTokens);
129     }
130
131     /**
132      * Add a StripJavaCommands filter.
133      *
134      * @param stripJavaComments a <code>StripJavaComments</code> value
135      */

136     public void addStripJavaComments(final StripJavaComments
137                                                 stripJavaComments) {
138         filterReaders.addElement(stripJavaComments);
139     }
140
141     /**
142      * Add a StripLineBreaks filter.
143      *
144      * @param stripLineBreaks a <code>StripLineBreaks</code> value
145      */

146     public void addStripLineBreaks(final StripLineBreaks
147                                                 stripLineBreaks) {
148         filterReaders.addElement(stripLineBreaks);
149     }
150
151     /**
152      * Add a StripLineComments filter.
153      *
154      * @param stripLineComments a <code>StripLineComments</code> value
155      */

156     public void addStripLineComments(final StripLineComments
157                                                 stripLineComments) {
158         filterReaders.addElement(stripLineComments);
159     }
160
161     /**
162      * Add a TabsToSpaces filter.
163      *
164      * @param tabsToSpaces a <code>TabsToSpaces</code> value
165      */

166     public void addTabsToSpaces(final TabsToSpaces tabsToSpaces) {
167         filterReaders.addElement(tabsToSpaces);
168     }
169
170     /**
171      * Add a TailFilter filter.
172      *
173      * @param tailFilter a <code>TailFilter</code> value
174      */

175     public void addTailFilter(final TailFilter tailFilter) {
176         filterReaders.addElement(tailFilter);
177     }
178
179     /**
180      * Add an EscapeUnicode filter.
181      *
182      * @param escapeUnicode an <code>EscapeUnicode</code> value
183      * @since Ant 1.6
184      */

185     public void addEscapeUnicode(final EscapeUnicode escapeUnicode) {
186         filterReaders.addElement(escapeUnicode);
187     }
188
189     /**
190      * Add a TokenFilter filter.
191      *
192      * @param tokenFilter a <code>TokenFilter</code> value
193      * @since Ant 1.6
194      */

195     public void addTokenFilter(final TokenFilter tokenFilter) {
196         filterReaders.addElement(tokenFilter);
197     }
198
199     /**
200      * Add a delete characters filter.
201      *
202      * @param filter a <code>TokenFilter.DeleteCharacters</code> value
203      * @since Ant 1.6
204      */

205     public void addDeleteCharacters(TokenFilter.DeleteCharacters filter) {
206         filterReaders.addElement(filter);
207     }
208
209     /**
210      * Add a containsregex filter.
211      *
212      * @param filter a <code>TokenFilter.ContainsRegex</code> value
213      * @since Ant 1.6
214      */

215     public void addContainsRegex(TokenFilter.ContainsRegex filter) {
216         filterReaders.addElement(filter);
217     }
218
219     /**
220      * Add a replaceregex filter.
221      *
222      * @param filter a <code>TokenFilter.ReplaceRegex</code> value
223      */

224     public void addReplaceRegex(TokenFilter.ReplaceRegex filter) {
225         filterReaders.addElement(filter);
226     }
227
228     /**
229      * Add a trim filter.
230      *
231      * @param filter a <code>TokenFilter.Trim</code> value
232      * @since Ant 1.6
233      */

234     public void addTrim(TokenFilter.Trim filter) {
235         filterReaders.addElement(filter);
236     }
237
238     /**
239      * Add a replacestring filter.
240      *
241      * @param filter a <code>TokenFilter.ReplaceString</code> value
242      * @since Ant 1.6
243      */

244     public void addReplaceString(
245         TokenFilter.ReplaceString filter) {
246         filterReaders.addElement(filter);
247     }
248
249     /**
250      * Add an ignoreBlank filter.
251      *
252      * @param filter a <code>TokenFilter.IgnoreBlank</code> value
253      * @since Ant 1.6
254      */

255     public void addIgnoreBlank(
256         TokenFilter.IgnoreBlank filter) {
257         filterReaders.addElement(filter);
258     }
259
260
261     /**
262      * Makes this instance in effect a reference to another FilterChain
263      * instance.
264      *
265      * <p>You must not set another attribute or nest elements inside
266      * this element if you make it a reference.</p>
267      *
268      * @param r the reference to which this instance is associated
269      * @exception BuildException if this instance already has been configured.
270      */

271     public void setRefid(Reference r) throws BuildException {
272         if (!filterReaders.isEmpty()) {
273             throw tooManyAttributes();
274         }
275         // change this to get the objects from the other reference
276
Object JavaDoc o = r.getReferencedObject(getProject());
277         if (o instanceof FilterChain) {
278             FilterChain fc = (FilterChain) o;
279             filterReaders = fc.getFilterReaders();
280         } else {
281             String JavaDoc msg = r.getRefId() + " doesn\'t refer to a FilterChain";
282             throw new BuildException(msg);
283         }
284
285         super.setRefid(r);
286     }
287
288     /**
289      * Add a chainfilter filter.
290      *
291      * @param filter a <code>ChainableReader</code> value
292      * @since Ant 1.6
293      */

294
295     public void add(ChainableReader filter) {
296         filterReaders.addElement(filter);
297     }
298
299 }
300
Popular Tags