source: release-kits/lirk3/resources/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/filters/ExpandProperties.java@ 14982

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

initial import of LiRK3

File size: 3.4 KB
Line 
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 */
17package org.apache.tools.ant.filters;
18
19import java.io.IOException;
20import java.io.Reader;
21import org.apache.tools.ant.Project;
22
23/**
24 * Expands Ant properties, if any, in the data.
25 * <p>
26 * Example:<br>
27 * <pre>&lt;expandproperties/&gt;</pre>
28 * Or:
29 * <pre>&lt;filterreader
30 * classname=&quot;org.apache.tools.ant.filters.ExpandProperties&quot;/&gt;</pre>
31 *
32 */
33public final class ExpandProperties
34 extends BaseFilterReader
35 implements ChainableReader {
36 /** Data that must be read from, if not null. */
37 private String queuedData = null;
38
39 /**
40 * Constructor for "dummy" instances.
41 *
42 * @see BaseFilterReader#BaseFilterReader()
43 */
44 public ExpandProperties() {
45 super();
46 }
47
48 /**
49 * Creates a new filtered reader.
50 *
51 * @param in A Reader object providing the underlying stream.
52 * Must not be <code>null</code>.
53 */
54 public ExpandProperties(final Reader in) {
55 super(in);
56 }
57
58 /**
59 * Returns the next character in the filtered stream. The original
60 * stream is first read in fully, and the Ant properties are expanded.
61 * The results of this expansion are then queued so they can be read
62 * character-by-character.
63 *
64 * @return the next character in the resulting stream, or -1
65 * if the end of the resulting stream has been reached
66 *
67 * @exception IOException if the underlying stream throws an IOException
68 * during reading
69 */
70 public final int read() throws IOException {
71
72 int ch = -1;
73
74 if (queuedData != null && queuedData.length() == 0) {
75 queuedData = null;
76 }
77
78 if (queuedData != null) {
79 ch = queuedData.charAt(0);
80 queuedData = queuedData.substring(1);
81 if (queuedData.length() == 0) {
82 queuedData = null;
83 }
84 } else {
85 queuedData = readFully();
86 if (queuedData == null) {
87 ch = -1;
88 } else {
89 Project project = getProject();
90 queuedData = project.replaceProperties(queuedData);
91 return read();
92 }
93 }
94 return ch;
95 }
96
97 /**
98 * Creates a new ExpandProperties filter using the passed in
99 * Reader for instantiation.
100 *
101 * @param rdr A Reader object providing the underlying stream.
102 * Must not be <code>null</code>.
103 *
104 * @return a new filter based on this configuration, but filtering
105 * the specified reader
106 */
107 public final Reader chain(final Reader rdr) {
108 ExpandProperties newFilter = new ExpandProperties(rdr);
109 newFilter.setProject(getProject());
110 return newFilter;
111 }
112}
Note: See TracBrowser for help on using the repository browser.