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.IOException;
|
---|
20 | import java.io.PrintStream;
|
---|
21 | import java.util.ResourceBundle;
|
---|
22 |
|
---|
23 | import org.tp23.antinstaller.InstallerContext;
|
---|
24 | import org.tp23.antinstaller.input.DateInput;
|
---|
25 | import org.tp23.antinstaller.input.OutputField;
|
---|
26 |
|
---|
27 |
|
---|
28 | public class DateInputRenderer
|
---|
29 | implements TextOutputFieldRenderer {
|
---|
30 |
|
---|
31 | private static final ResourceBundle res = ResourceBundle.getBundle("org.tp23.antinstaller.renderer.text.Res");
|
---|
32 |
|
---|
33 | protected InstallerContext ctx;
|
---|
34 | public DateInputRenderer() {
|
---|
35 | }
|
---|
36 |
|
---|
37 | public void setContext(InstallerContext ctx) {
|
---|
38 | this.ctx = ctx;
|
---|
39 | }
|
---|
40 |
|
---|
41 | public void renderOutput(OutputField field, BufferedReader reader, PrintStream out) throws IOException {
|
---|
42 | DateInput iField = (DateInput) field;
|
---|
43 | out.print(field.getDisplayText());
|
---|
44 |
|
---|
45 | out.print(" [");
|
---|
46 | out.print(res.getString("_default_"));
|
---|
47 | out.print(":");
|
---|
48 | out.print(iField.getDefaultValue());
|
---|
49 | out.println("]");
|
---|
50 |
|
---|
51 | // @TODO check this from the patch submitted for bug 1469254
|
---|
52 | String input = reader.readLine();
|
---|
53 |
|
---|
54 | out.println();
|
---|
55 | if(input==null || input.equals(""))input = iField.getDefaultValue();
|
---|
56 | iField.setInputResult(input);
|
---|
57 | }
|
---|
58 | public void renderError(OutputField field, BufferedReader reader, PrintStream out) throws IOException{
|
---|
59 | DateInput iField = (DateInput) field;
|
---|
60 | out.println("The input is not in the correct format:"+iField.getDateFormat());
|
---|
61 | renderOutput(field, reader, out);
|
---|
62 | }
|
---|
63 | public boolean isAbort(){
|
---|
64 | return false;
|
---|
65 | }
|
---|
66 | }
|
---|