001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.tools.ant.types;
019:
020: import java.util.Vector;
021:
022: import org.apache.tools.ant.BuildException;
023: import org.apache.tools.ant.filters.ChainableReader;
024: import org.apache.tools.ant.filters.ClassConstants;
025: import org.apache.tools.ant.filters.EscapeUnicode;
026: import org.apache.tools.ant.filters.ExpandProperties;
027: import org.apache.tools.ant.filters.HeadFilter;
028: import org.apache.tools.ant.filters.LineContains;
029: import org.apache.tools.ant.filters.LineContainsRegExp;
030: import org.apache.tools.ant.filters.PrefixLines;
031: import org.apache.tools.ant.filters.ReplaceTokens;
032: import org.apache.tools.ant.filters.StripJavaComments;
033: import org.apache.tools.ant.filters.StripLineBreaks;
034: import org.apache.tools.ant.filters.StripLineComments;
035: import org.apache.tools.ant.filters.TabsToSpaces;
036: import org.apache.tools.ant.filters.TailFilter;
037: import org.apache.tools.ant.filters.TokenFilter;
038:
039: /**
040: * FilterChain may contain a chained set of filter readers.
041: *
042: */
043: public class FilterChain extends DataType implements Cloneable {
044:
045: private Vector filterReaders = new Vector();
046:
047: /**
048: * Add an AntFilterReader filter.
049: *
050: * @param filterReader an <code>AntFilterReader</code> value
051: */
052: public void addFilterReader(final AntFilterReader filterReader) {
053: filterReaders.addElement(filterReader);
054: }
055:
056: /**
057: * Return the filters.
058: *
059: * @return a <code>Vector</code> value containing the filters
060: */
061: public Vector getFilterReaders() {
062: return filterReaders;
063: }
064:
065: /**
066: * Add a ClassConstants filter.
067: *
068: * @param classConstants a <code>ClassConstants</code> value
069: */
070: public void addClassConstants(final ClassConstants classConstants) {
071: filterReaders.addElement(classConstants);
072: }
073:
074: /**
075: * Add an ExpandProperties filter.
076: *
077: * @param expandProperties an <code>ExpandProperties</code> value
078: */
079: public void addExpandProperties(
080: final ExpandProperties expandProperties) {
081: filterReaders.addElement(expandProperties);
082: }
083:
084: /**
085: * Add a HeadFilter filter.
086: *
087: * @param headFilter a <code>HeadFilter</code> value
088: */
089: public void addHeadFilter(final HeadFilter headFilter) {
090: filterReaders.addElement(headFilter);
091: }
092:
093: /**
094: * Add a LineContains filter.
095: *
096: * @param lineContains a <code>LineContains</code> value
097: */
098: public void addLineContains(final LineContains lineContains) {
099: filterReaders.addElement(lineContains);
100: }
101:
102: /**
103: * Add a LineContainsRegExp filter.
104: *
105: * @param lineContainsRegExp a <code>LineContainsRegExp</code> value
106: */
107: public void addLineContainsRegExp(
108: final LineContainsRegExp lineContainsRegExp) {
109: filterReaders.addElement(lineContainsRegExp);
110: }
111:
112: /**
113: * Add a PrefixLines filter.
114: *
115: * @param prefixLines a <code>PrefixLines</code> value
116: */
117: public void addPrefixLines(final PrefixLines prefixLines) {
118: filterReaders.addElement(prefixLines);
119: }
120:
121: /**
122: * Add a ReplaceTokens filter.
123: *
124: * @param replaceTokens a <code>ReplaceTokens</code> value
125: */
126: public void addReplaceTokens(final ReplaceTokens replaceTokens) {
127: filterReaders.addElement(replaceTokens);
128: }
129:
130: /**
131: * Add a StripJavaCommands filter.
132: *
133: * @param stripJavaComments a <code>StripJavaComments</code> value
134: */
135: public void addStripJavaComments(
136: final StripJavaComments stripJavaComments) {
137: filterReaders.addElement(stripJavaComments);
138: }
139:
140: /**
141: * Add a StripLineBreaks filter.
142: *
143: * @param stripLineBreaks a <code>StripLineBreaks</code> value
144: */
145: public void addStripLineBreaks(final StripLineBreaks stripLineBreaks) {
146: filterReaders.addElement(stripLineBreaks);
147: }
148:
149: /**
150: * Add a StripLineComments filter.
151: *
152: * @param stripLineComments a <code>StripLineComments</code> value
153: */
154: public void addStripLineComments(
155: final StripLineComments stripLineComments) {
156: filterReaders.addElement(stripLineComments);
157: }
158:
159: /**
160: * Add a TabsToSpaces filter.
161: *
162: * @param tabsToSpaces a <code>TabsToSpaces</code> value
163: */
164: public void addTabsToSpaces(final TabsToSpaces tabsToSpaces) {
165: filterReaders.addElement(tabsToSpaces);
166: }
167:
168: /**
169: * Add a TailFilter filter.
170: *
171: * @param tailFilter a <code>TailFilter</code> value
172: */
173: public void addTailFilter(final TailFilter tailFilter) {
174: filterReaders.addElement(tailFilter);
175: }
176:
177: /**
178: * Add an EscapeUnicode filter.
179: *
180: * @param escapeUnicode an <code>EscapeUnicode</code> value
181: * @since Ant 1.6
182: */
183: public void addEscapeUnicode(final EscapeUnicode escapeUnicode) {
184: filterReaders.addElement(escapeUnicode);
185: }
186:
187: /**
188: * Add a TokenFilter filter.
189: *
190: * @param tokenFilter a <code>TokenFilter</code> value
191: * @since Ant 1.6
192: */
193: public void addTokenFilter(final TokenFilter tokenFilter) {
194: filterReaders.addElement(tokenFilter);
195: }
196:
197: /**
198: * Add a delete characters filter.
199: *
200: * @param filter a <code>TokenFilter.DeleteCharacters</code> value
201: * @since Ant 1.6
202: */
203: public void addDeleteCharacters(TokenFilter.DeleteCharacters filter) {
204: filterReaders.addElement(filter);
205: }
206:
207: /**
208: * Add a containsregex filter.
209: *
210: * @param filter a <code>TokenFilter.ContainsRegex</code> value
211: * @since Ant 1.6
212: */
213: public void addContainsRegex(TokenFilter.ContainsRegex filter) {
214: filterReaders.addElement(filter);
215: }
216:
217: /**
218: * Add a replaceregex filter.
219: *
220: * @param filter a <code>TokenFilter.ReplaceRegex</code> value
221: */
222: public void addReplaceRegex(TokenFilter.ReplaceRegex filter) {
223: filterReaders.addElement(filter);
224: }
225:
226: /**
227: * Add a trim filter.
228: *
229: * @param filter a <code>TokenFilter.Trim</code> value
230: * @since Ant 1.6
231: */
232: public void addTrim(TokenFilter.Trim filter) {
233: filterReaders.addElement(filter);
234: }
235:
236: /**
237: * Add a replacestring filter.
238: *
239: * @param filter a <code>TokenFilter.ReplaceString</code> value
240: * @since Ant 1.6
241: */
242: public void addReplaceString(TokenFilter.ReplaceString filter) {
243: filterReaders.addElement(filter);
244: }
245:
246: /**
247: * Add an ignoreBlank filter.
248: *
249: * @param filter a <code>TokenFilter.IgnoreBlank</code> value
250: * @since Ant 1.6
251: */
252: public void addIgnoreBlank(TokenFilter.IgnoreBlank filter) {
253: filterReaders.addElement(filter);
254: }
255:
256: /**
257: * Makes this instance in effect a reference to another FilterChain
258: * instance.
259: *
260: * <p>You must not set another attribute or nest elements inside
261: * this element if you make it a reference.</p>
262: *
263: * @param r the reference to which this instance is associated
264: * @exception BuildException if this instance already has been configured.
265: */
266: public void setRefid(Reference r) throws BuildException {
267: if (!filterReaders.isEmpty()) {
268: throw tooManyAttributes();
269: }
270: // change this to get the objects from the other reference
271: Object o = r.getReferencedObject(getProject());
272: if (o instanceof FilterChain) {
273: FilterChain fc = (FilterChain) o;
274: filterReaders = fc.getFilterReaders();
275: } else {
276: String msg = r.getRefId()
277: + " doesn\'t refer to a FilterChain";
278: throw new BuildException(msg);
279: }
280:
281: super .setRefid(r);
282: }
283:
284: /**
285: * Add a chainfilter filter.
286: *
287: * @param filter a <code>ChainableReader</code> value
288: * @since Ant 1.6
289: */
290:
291: public void add(ChainableReader filter) {
292: filterReaders.addElement(filter);
293: }
294:
295: }
|