01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: // java io classes
21:
22: // java util classes
23: import java.util.Enumeration;
24: import java.util.Vector;
25:
26: // ant classes
27:
28: /**
29: * A FilterSetCollection is a collection of filtersets each of which may have
30: * a different start/end token settings.
31: *
32: */
33: public class FilterSetCollection {
34:
35: private Vector filterSets = new Vector();
36:
37: /**
38: * Constructor for a FilterSetCollection.
39: */
40: public FilterSetCollection() {
41: }
42:
43: /**
44: * Constructor for a FilterSetCollection.
45: * @param filterSet a filterset to start the collection with
46: */
47: public FilterSetCollection(FilterSet filterSet) {
48: addFilterSet(filterSet);
49: }
50:
51: /**
52: * Add a filterset to the collection.
53: *
54: * @param filterSet a <code>FilterSet</code> value
55: */
56: public void addFilterSet(FilterSet filterSet) {
57: filterSets.addElement(filterSet);
58: }
59:
60: /**
61: * Does replacement on the given string with token matching.
62: * This uses the defined begintoken and endtoken values which default to @ for both.
63: *
64: * @param line The line to process the tokens in.
65: * @return The string with the tokens replaced.
66: */
67: public String replaceTokens(String line) {
68: String replacedLine = line;
69: for (Enumeration e = filterSets.elements(); e.hasMoreElements();) {
70: FilterSet filterSet = (FilterSet) e.nextElement();
71: replacedLine = filterSet.replaceTokens(replacedLine);
72: }
73: return replacedLine;
74: }
75:
76: /**
77: * Test to see if this filter set it empty.
78: *
79: * @return Return true if there are filter in this set otherwise false.
80: */
81: public boolean hasFilters() {
82: for (Enumeration e = filterSets.elements(); e.hasMoreElements();) {
83: FilterSet filterSet = (FilterSet) e.nextElement();
84: if (filterSet.hasFilters()) {
85: return true;
86: }
87: }
88: return false;
89: }
90: }
|