1 | /*
|
---|
2 | * Copyright 2005 Paul Hinds
|
---|
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 | 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 | import java.util.ResourceBundle;
|
---|
23 |
|
---|
24 | import org.tp23.antinstaller.InstallerContext;
|
---|
25 | import org.tp23.antinstaller.input.FileInput;
|
---|
26 | import org.tp23.antinstaller.input.OutputField;
|
---|
27 | import org.tp23.antinstaller.renderer.MessageRenderer;
|
---|
28 |
|
---|
29 |
|
---|
30 | public class FileInputRenderer
|
---|
31 | implements TextOutputFieldRenderer {
|
---|
32 |
|
---|
33 | private static final ResourceBundle res = ResourceBundle.getBundle("org.tp23.antinstaller.renderer.text.Res");
|
---|
34 |
|
---|
35 | protected InstallerContext ctx;
|
---|
36 | public FileInputRenderer() {
|
---|
37 | }
|
---|
38 |
|
---|
39 | public void setContext(InstallerContext ctx) {
|
---|
40 | this.ctx = ctx;
|
---|
41 | }
|
---|
42 |
|
---|
43 | public void renderOutput(OutputField field, BufferedReader reader, PrintStream out) throws IOException {
|
---|
44 | FileInput iField = (FileInput) field;
|
---|
45 | out.print(iField.getDisplayText());
|
---|
46 |
|
---|
47 | out.print(" [");
|
---|
48 | out.print(res.getString("_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 | public void renderError(OutputField field, BufferedReader reader, PrintStream out) throws IOException{
|
---|
62 | MessageRenderer mr = ctx.getMessageRenderer();
|
---|
63 | mr.printMessage(res.getString("fileDoesNotExist"));
|
---|
64 | renderOutput(field, reader, out);
|
---|
65 | }
|
---|
66 | public boolean isAbort(){
|
---|
67 | return false;
|
---|
68 | }
|
---|
69 |
|
---|
70 | }
|
---|