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.File;
20: import java.io.IOException;
21: import java.io.PrintStream;
22:
23: import org.tp23.antinstaller.InstallerContext;
24: import org.tp23.antinstaller.input.FileInput;
25: import org.tp23.antinstaller.input.OutputField;
26: import org.tp23.antinstaller.renderer.AIResourceBundle;
27: import org.tp23.antinstaller.renderer.MessageRenderer;
28:
29: public class FileInputRenderer implements TextOutputFieldRenderer {
30:
31: private static final AIResourceBundle res = new AIResourceBundle();
32:
33: protected InstallerContext ctx;
34:
35: public FileInputRenderer() {
36: }
37:
38: public void setContext(InstallerContext ctx) {
39: this .ctx = ctx;
40: }
41:
42: public void renderOutput(OutputField field, BufferedReader reader,
43: PrintStream out) throws IOException {
44: FileInput iField = (FileInput) field;
45: out.print(iField.getDisplayText());
46:
47: out.print(" [");
48: out.print(res.getString("selection.default"));
49: out.print(":");
50: out.print(iField.getDefaultValue(true));
51: out.print("]");
52:
53: out.println();
54: String input = reader.readLine();
55: out.println();
56: if (input == null || input.equals("")) {
57: input = iField.getDefaultValue(true);
58: }
59: iField.setInputResult(new File(input).getAbsolutePath());
60: }
61:
62: public void renderError(OutputField field, BufferedReader reader,
63: PrintStream out) throws IOException {
64: MessageRenderer mr = ctx.getMessageRenderer();
65: mr.printMessage(res.getString("file.does.not.exist"));
66: renderOutput(field, reader, out);
67: }
68:
69: public boolean isAbort() {
70: return false;
71: }
72:
73: }
|