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.InputStreamReader;
21:
22: import org.tp23.antinstaller.InstallerContext;
23: import org.tp23.antinstaller.renderer.MessageRenderer;
24:
25: /**
26: *
27: * <p>Render user messages to the console </p>
28: * <p> </p>
29: * <p>Copyright: Copyright (c) 2004</p>
30: * <p>Company: tp23</p>
31: * @author Paul Hinds
32: * @version $Id: TextMessageRenderer.java,v 1.3 2007/01/09 22:41:40 teknopaul Exp $
33: */
34: public class TextMessageRenderer implements MessageRenderer {
35:
36: private InstallerContext ctx = null;
37:
38: public TextMessageRenderer() {
39: }
40:
41: public void setInstallerContext(InstallerContext ctx) {
42: this .ctx = ctx;
43: }
44:
45: public void printMessage(String message) {
46: System.out.println(message);
47: }
48:
49: public boolean prompt(String message) {
50: try {
51: System.out.println(message);
52: // FIXME need to read directly from InputStreamReader and stop at first \n or \r
53: // test the following
54: // InputStreamReader isr = new InputStreamReader(System.in);
55: // int intChar = -1;
56: // StringBuffer sb = new StringBuffer();
57: // while((intChar = isr.read()) != -1 && intChar != '\n' && intChar != '\r'){
58: // sb.append((char)intChar);
59: // }
60: // String line = sb.toString();
61:
62: BufferedReader reader = new BufferedReader(
63: new InputStreamReader(System.in));
64: String line = reader.readLine();
65: if (line != null && !line.equals("")
66: && line.trim().length() > 0) {
67: return Character.toUpperCase(line.trim().charAt(0)) == 'Y'
68: || Character.toUpperCase(line.trim().charAt(0)) == 'T';
69: }
70: return false;
71: } catch (IOException ex) {
72: throw new RuntimeException("IOException", ex);
73: }
74: }
75: }
|