01: /*
02: * Licensed under the Apache License, Version 2.0 (the "License");
03: * you may not use this file except in compliance with the License.
04: * You may obtain a copy of the License at
05: *
06: * http://www.apache.org/licenses/LICENSE-2.0
07: *
08: * Unless required by applicable law or agreed to in writing, software
09: * distributed under the License is distributed on an "AS IS" BASIS,
10: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11: * See the License for the specific language governing permissions and
12: * limitations under the License.
13: */
14:
15: package org.tp23.antinstaller.renderer.text;
16:
17: import java.io.BufferedReader;
18: import java.io.IOException;
19: import java.io.PrintStream;
20:
21: import org.tp23.antinstaller.InstallException;
22: import org.tp23.antinstaller.InstallerContext;
23: import org.tp23.antinstaller.AIResourceBundleHelper;
24: import org.tp23.antinstaller.ValidationException;
25: import org.tp23.antinstaller.input.ConditionalField;
26: import org.tp23.antinstaller.input.OutputField;
27: import org.tp23.antinstaller.runtime.ConfigurationException;
28:
29: /**
30: * Conditionally render a collection of fields
31: *
32: * @author mwilson
33: * @version $Id
34: * @since 0.7.4.patch 7
35: */
36: public class ConditionalFieldRenderer implements
37: TextOutputFieldRenderer {
38: private static final AIResourceBundleHelper res = new AIResourceBundleHelper();
39:
40: private InstallerContext context;
41:
42: public void setContext(InstallerContext context) {
43: this .context = context;
44: }
45:
46: public void renderOutput(OutputField field, BufferedReader reader,
47: PrintStream out) throws ValidationException,
48: InstallException, IOException {
49: ConditionalField conditional = (ConditionalField) field;
50:
51: try {
52:
53: OutputField[] fields = null;
54:
55: if (conditional.getExpression().evaluate()) {
56: fields = conditional.getFields();
57:
58: SimpleInputPageRenderer.renderFields(context, fields,
59: reader, out);
60: }
61: } catch (ConfigurationException configExc) {
62: throw new InstallException(res.getMessage(
63: "invalid.conditional.expression", conditional
64: .getIfProperty()), configExc);
65: } catch (ClassNotFoundException clsNotFoundExc) {
66: throw new InstallException(res
67: .getMessage("text.render.not.found"),
68: clsNotFoundExc);
69: }
70: }
71:
72: public void renderError(OutputField field, BufferedReader reader,
73: PrintStream out) throws IOException {
74: //renderOutput will have already rendered any errors
75: }
76:
77: public boolean isAbort() {
78: return false;
79: }
80: }
|