1 | /*
|
---|
2 | * Copyright 2002-2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 | package org.apache.tools.ant.types;
|
---|
18 |
|
---|
19 | import java.util.Vector;
|
---|
20 |
|
---|
21 | import org.apache.tools.ant.BuildException;
|
---|
22 | import org.apache.tools.ant.filters.ChainableReader;
|
---|
23 | import org.apache.tools.ant.filters.ClassConstants;
|
---|
24 | import org.apache.tools.ant.filters.EscapeUnicode;
|
---|
25 | import org.apache.tools.ant.filters.ExpandProperties;
|
---|
26 | import org.apache.tools.ant.filters.HeadFilter;
|
---|
27 | import org.apache.tools.ant.filters.LineContains;
|
---|
28 | import org.apache.tools.ant.filters.LineContainsRegExp;
|
---|
29 | import org.apache.tools.ant.filters.PrefixLines;
|
---|
30 | import org.apache.tools.ant.filters.ReplaceTokens;
|
---|
31 | import org.apache.tools.ant.filters.StripJavaComments;
|
---|
32 | import org.apache.tools.ant.filters.StripLineBreaks;
|
---|
33 | import org.apache.tools.ant.filters.StripLineComments;
|
---|
34 | import org.apache.tools.ant.filters.TabsToSpaces;
|
---|
35 | import org.apache.tools.ant.filters.TailFilter;
|
---|
36 | import org.apache.tools.ant.filters.TokenFilter;
|
---|
37 |
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * FilterChain may contain a chained set of filter readers.
|
---|
41 | *
|
---|
42 | */
|
---|
43 | public class FilterChain extends DataType
|
---|
44 | implements Cloneable {
|
---|
45 |
|
---|
46 | private Vector filterReaders = new Vector();
|
---|
47 |
|
---|
48 | public final void addFilterReader(final AntFilterReader filterReader) {
|
---|
49 | filterReaders.addElement(filterReader);
|
---|
50 | }
|
---|
51 |
|
---|
52 | public final Vector getFilterReaders() {
|
---|
53 | return filterReaders;
|
---|
54 | }
|
---|
55 |
|
---|
56 | public final void addClassConstants(final ClassConstants classConstants) {
|
---|
57 | filterReaders.addElement(classConstants);
|
---|
58 | }
|
---|
59 |
|
---|
60 | public final void addExpandProperties(final ExpandProperties expandProperties) {
|
---|
61 | filterReaders.addElement(expandProperties);
|
---|
62 | }
|
---|
63 |
|
---|
64 | public final void addHeadFilter(final HeadFilter headFilter) {
|
---|
65 | filterReaders.addElement(headFilter);
|
---|
66 | }
|
---|
67 |
|
---|
68 | public final void addLineContains(final LineContains lineContains) {
|
---|
69 | filterReaders.addElement(lineContains);
|
---|
70 | }
|
---|
71 |
|
---|
72 | public final void addLineContainsRegExp(final LineContainsRegExp
|
---|
73 | lineContainsRegExp) {
|
---|
74 | filterReaders.addElement(lineContainsRegExp);
|
---|
75 | }
|
---|
76 |
|
---|
77 | public final void addPrefixLines(final PrefixLines prefixLines) {
|
---|
78 | filterReaders.addElement(prefixLines);
|
---|
79 | }
|
---|
80 |
|
---|
81 | public final void addReplaceTokens(final ReplaceTokens replaceTokens) {
|
---|
82 | filterReaders.addElement(replaceTokens);
|
---|
83 | }
|
---|
84 |
|
---|
85 | public final void addStripJavaComments(final StripJavaComments
|
---|
86 | stripJavaComments) {
|
---|
87 | filterReaders.addElement(stripJavaComments);
|
---|
88 | }
|
---|
89 |
|
---|
90 | public final void addStripLineBreaks(final StripLineBreaks
|
---|
91 | stripLineBreaks) {
|
---|
92 | filterReaders.addElement(stripLineBreaks);
|
---|
93 | }
|
---|
94 |
|
---|
95 | public final void addStripLineComments(final StripLineComments
|
---|
96 | stripLineComments) {
|
---|
97 | filterReaders.addElement(stripLineComments);
|
---|
98 | }
|
---|
99 |
|
---|
100 | public final void addTabsToSpaces(final TabsToSpaces tabsToSpaces) {
|
---|
101 | filterReaders.addElement(tabsToSpaces);
|
---|
102 | }
|
---|
103 |
|
---|
104 | public final void addTailFilter(final TailFilter tailFilter) {
|
---|
105 | filterReaders.addElement(tailFilter);
|
---|
106 | }
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * @since Ant 1.6
|
---|
110 | */
|
---|
111 | public final void addEscapeUnicode(final EscapeUnicode escapeUnicode) {
|
---|
112 | filterReaders.addElement(escapeUnicode);
|
---|
113 | }
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * @since Ant 1.6
|
---|
117 | */
|
---|
118 | public final void addTokenFilter(final TokenFilter tokenFilter) {
|
---|
119 | filterReaders.addElement(tokenFilter);
|
---|
120 | }
|
---|
121 |
|
---|
122 | /**
|
---|
123 | * delete characters filter
|
---|
124 | * @since Ant 1.6
|
---|
125 | */
|
---|
126 | public void addDeleteCharacters(TokenFilter.DeleteCharacters filter) {
|
---|
127 | filterReaders.addElement(filter);
|
---|
128 | }
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * containsregex
|
---|
132 | * @since Ant 1.6
|
---|
133 | */
|
---|
134 | public void addContainsRegex(TokenFilter.ContainsRegex filter) {
|
---|
135 | filterReaders.addElement(filter);
|
---|
136 | }
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * replaceregex
|
---|
140 | * @since Ant 1.6
|
---|
141 | */
|
---|
142 | public void addReplaceRegex(TokenFilter.ReplaceRegex filter) {
|
---|
143 | filterReaders.addElement(filter);
|
---|
144 | }
|
---|
145 |
|
---|
146 | /**
|
---|
147 | * trim
|
---|
148 | * @since Ant 1.6
|
---|
149 | */
|
---|
150 | public void addTrim(TokenFilter.Trim filter) {
|
---|
151 | filterReaders.addElement(filter);
|
---|
152 | }
|
---|
153 |
|
---|
154 | /**
|
---|
155 | * replacestring
|
---|
156 | * @since Ant 1.6
|
---|
157 | */
|
---|
158 | public void addReplaceString(
|
---|
159 | TokenFilter.ReplaceString filter) {
|
---|
160 | filterReaders.addElement(filter);
|
---|
161 | }
|
---|
162 |
|
---|
163 | /**
|
---|
164 | * ignoreBlank
|
---|
165 | * @since Ant 1.6
|
---|
166 | */
|
---|
167 | public void addIgnoreBlank(
|
---|
168 | TokenFilter.IgnoreBlank filter) {
|
---|
169 | filterReaders.addElement(filter);
|
---|
170 | }
|
---|
171 |
|
---|
172 |
|
---|
173 | /**
|
---|
174 | * Makes this instance in effect a reference to another FilterChain
|
---|
175 | * instance.
|
---|
176 | *
|
---|
177 | * <p>You must not set another attribute or nest elements inside
|
---|
178 | * this element if you make it a reference.</p>
|
---|
179 | *
|
---|
180 | * @param r the reference to which this instance is associated
|
---|
181 | * @exception BuildException if this instance already has been configured.
|
---|
182 | */
|
---|
183 | public void setRefid(Reference r) throws BuildException {
|
---|
184 | if (!filterReaders.isEmpty()) {
|
---|
185 | throw tooManyAttributes();
|
---|
186 | }
|
---|
187 | // change this to get the objects from the other reference
|
---|
188 | Object o = r.getReferencedObject(getProject());
|
---|
189 | if (o instanceof FilterChain) {
|
---|
190 | FilterChain fc = (FilterChain) o;
|
---|
191 | filterReaders = fc.getFilterReaders();
|
---|
192 | } else {
|
---|
193 | String msg = r.getRefId() + " doesn\'t refer to a FilterChain";
|
---|
194 | throw new BuildException(msg);
|
---|
195 | }
|
---|
196 |
|
---|
197 | super.setRefid(r);
|
---|
198 | }
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * add a chainfilter
|
---|
202 | * @since Ant 1.6
|
---|
203 | */
|
---|
204 |
|
---|
205 | public void add(ChainableReader filter) {
|
---|
206 | filterReaders.addElement(filter);
|
---|
207 | }
|
---|
208 |
|
---|
209 | }
|
---|