1
14
15package org.tp23.antinstaller.renderer.text;
16
17import java.io.BufferedReader;
18import java.io.IOException;
19import java.io.PrintStream;
20
21import org.tp23.antinstaller.InstallException;
22import org.tp23.antinstaller.InstallerContext;
23import org.tp23.antinstaller.ResourceBundleHelper;
24import org.tp23.antinstaller.ValidationException;
25import org.tp23.antinstaller.input.ConditionalField;
26import org.tp23.antinstaller.input.OutputField;
27import org.tp23.antinstaller.runtime.ConfigurationException;
28
29
36public class ConditionalFieldRenderer implements TextOutputFieldRenderer
37{
38 private static final ResourceBundleHelper res = new ResourceBundleHelper("org.tp23.antinstaller.renderer.text.Res");
39
40 private InstallerContext context;
41
42 public void setContext( InstallerContext context )
43 {
44 this.context = context;
45 }
46
47 public void renderOutput( OutputField field, BufferedReader reader, PrintStream out )
48 throws ValidationException, InstallException, IOException
49 {
50 ConditionalField conditional = (ConditionalField) field;
51
52 try
53 {
54
55 OutputField[] fields = null;
56
57 if( conditional.getExpression().evaluate() )
58 {
59 fields = conditional.getFields();
60
61 SimpleInputPageRenderer.renderFields( context, fields, reader, out);
62 }
63 }
64 catch( ConfigurationException configExc )
65 {
66 throw new InstallException( res.getMessage( "invalid.conditional.expression", conditional.getIfProperty()),
67 configExc );
68 }
69 catch( ClassNotFoundException clsNotFoundExc )
70 {
71 throw new InstallException( res.getMessage( "text.render.not.found" ),
72 clsNotFoundExc );
73 }
74 }
75
76 public void renderError( OutputField field, BufferedReader reader, PrintStream out ) throws IOException
77 {
78 }
80
81 public boolean isAbort()
82 {
83 return false;
84 }
85}
86