1
16package org.tp23.antinstaller.renderer.text;
17
18import java.io.BufferedReader;
19import java.io.IOException;
20import java.io.PrintStream;
21import java.util.ResourceBundle;
22
23import org.tp23.antinstaller.InstallException;
24import org.tp23.antinstaller.InstallerContext;
25import org.tp23.antinstaller.page.Page;
26import org.tp23.antinstaller.renderer.PageRenderer;
27
34public abstract class AbstractTextPageRenderer
35 implements PageRenderer {
36
37 public static final int PAGE_BLANK_LINES = 20;
38 public static final int PAGE_DECO_WIDTH = 80;
39
40 protected BufferedReader reader;
41 protected PrintStream out;
42 private InstallerContext ctx;
43
44
45 public AbstractTextPageRenderer() {
46 }
47
48 public void setContext(InstallerContext ctx){
49 this.ctx = ctx;
50 }
51 public InstallerContext getContext(){
52 return ctx;
53 }
54
55 public void init( BufferedReader reader, PrintStream out){
56 this.out = out;
57 this.reader = reader;
58 }
59
65 public abstract boolean renderPage(Page page) throws InstallException;
66
67 protected void printHeader(Page page) throws IOException{
68 for (int i = 0; i < PAGE_BLANK_LINES; i++) {
69 out.println();
70 }
71
72
73 for (int i = 0; i < PAGE_DECO_WIDTH; i++) {
74 out.print('~');
75 }
76 out.println();
77 out.println(" " + page.getDisplayText());
78 for (int i = 0; i < PAGE_DECO_WIDTH; i++) {
79 out.print('~');
80 }
81 out.println();
82 out.println();
83 out.println();
84 }
85
86 private static final ResourceBundle res = ResourceBundle.getBundle("org.tp23.antinstaller.renderer.text.Res");
87 private static final char[] affimativeChars = parseChars(res.getString("affirmativeChars"));
88
89 private static char[] parseChars(String commaSeparated){
90 char[] input = commaSeparated.toCharArray();
91 char[] theChars = new char[input.length];
92 int j = 0;
93 for (int i = 0; i < input.length; i++) {
94 if(Character.isWhitespace(input[i]))continue;
95 if(',' == input[i]) {
96 continue;
97 }
98 else theChars[j++] = input[i];
99 }
00 char[] toReturn = new char[j];
01 System.arraycopy(theChars,0,toReturn,0,j);
02 return toReturn;
03 }
04
05
10 protected boolean isTrue(String entered){
11 if(entered.length() == 0) {
12 return true;
13 }
14 char first = entered.charAt(0);
15 boolean isTrue= false;
16 for (int i = 0; i < affimativeChars.length; i++) {
17 isTrue |= Character.toUpperCase(first) == affimativeChars[i];
18 }
19 return isTrue;
20 }
21}
22