01: /*
02: * Copyright 2005 Paul Hinds
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: package org.tp23.antinstaller.renderer.text;
17:
18: import java.io.BufferedReader;
19: import java.io.IOException;
20: import java.io.PrintStream;
21:
22: import org.tp23.antinstaller.InstallerContext;
23: import org.tp23.antinstaller.input.InputField;
24: import org.tp23.antinstaller.input.OutputField;
25: import org.tp23.antinstaller.input.TargetInput;
26: import org.tp23.antinstaller.renderer.AIResourceBundle;
27:
28: public class TargetInputRenderer implements TextOutputFieldRenderer {
29:
30: private static final AIResourceBundle res = new AIResourceBundle();
31:
32: protected InstallerContext ctx;
33:
34: public TargetInputRenderer() {
35: }
36:
37: public void setContext(InstallerContext ctx) {
38: this .ctx = ctx;
39: }
40:
41: public void renderOutput(OutputField field, BufferedReader reader,
42: PrintStream out) throws IOException {
43: TargetInput iField = (TargetInput) field;
44: out.println("Install the following component?");
45: out.print(iField.getDisplayText());
46:
47: out.print(" [");
48: out.print(res.getString("selection.default"));
49: out.print(":");
50: out.print(iField.getDefaultValue());
51: out.print("]");
52:
53: if (InputField.isTrue(iField.getForce())) {
54: out.print(res.getString("selection.required"));
55: ctx.getCurrentPage().addTarget(iField.getIdx(),
56: iField.getTarget());
57: iField.setInputResult("true");
58: out.println();
59: return;
60: }
61:
62: out.println();
63: String input = reader.readLine();
64: out.println();
65: if (input == null || input.trim().equals("")) {
66: input = iField.getDefaultValue();
67: }
68: if (InputField.isTrue(input)) {
69: ctx.getCurrentPage().addTarget(iField.getIdx(),
70: iField.getTarget());
71: iField.setInputResult("true");
72: } else {
73: ctx.getCurrentPage().removeTarget(iField.getIdx());
74: iField.setInputResult("false");
75: }
76:
77: }
78:
79: public boolean isAbort() {
80: return false;
81: }
82:
83: /**
84: * renderError
85: *
86: * @param field InputField
87: * @param out PrintStream
88: */
89: public void renderError(OutputField field, BufferedReader reader,
90: PrintStream out) {
91: }
92: }
|