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 */
16package org.tp23.antinstaller.renderer.text;
17
18import java.io.BufferedReader;
19import java.io.IOException;
20import java.io.InputStream;
21import java.io.InputStreamReader;
22import java.util.ResourceBundle;
23
24import org.tp23.antinstaller.InstallException;
25import org.tp23.antinstaller.page.Page;
26import org.tp23.antinstaller.page.TextPage;
27
28
29public class TextPageRenderer
30    extends AbstractTextPageRenderer {
31
32    private static final ResourceBundle res = ResourceBundle.getBundle("org.tp23.antinstaller.renderer.text.Res");
33    private static final String nextChar = res.getString("nextChar");
34
35    public TextPageRenderer() {
36    }
37
38    public boolean renderPage(Page page) throws InstallException {
39        if (page instanceof TextPage) {
40            TextPage lPage = (TextPage) page;
41            return renderTextPage(lPage);
42        }
43        else {
44            throw new InstallException("Wrong Renderer in TextPageRenderer.renderPage");
45        }
46    }
47
48    private boolean renderTextPage(TextPage page) throws InstallException {
49        try {
50            BufferedReader commandReader = reader;//new BufferedReader(new InputStreamReader(in));
51
52            String resource = page.getTextResource();
53            InputStream textin = this.getClass().getResourceAsStream(resource);
54            BufferedReader reader = new BufferedReader(new InputStreamReader(textin));
55            printHeader(page);
56            String lineread = null;
57            StringBuffer sb = new StringBuffer();
58
59            while ( (lineread = reader.readLine()) != null) {
60                sb.append(lineread);
61                sb.append('\n');
62            }
63            // as per FindBugs
64            reader.close();
65
66            // parse property references
67            String parsedText = getContext().getInstaller().getResultContainer().getDefaultValue(sb.toString());
68
69            String command = null;
70            Pager pager = new Pager(parsedText);
71            do {
72                if (!pager.next(out)) {
73                    break;
74                }
75                out.println();
76                out.println(getNextInstructions());
77                command = commandReader.readLine();
78            }
79            while (command.toUpperCase().startsWith(nextChar));
80            pager.rest(out);
81
82            for (int i = 0; i < PAGE_DECO_WIDTH; i++) {
83                out.print('~');
84            }
85            
86            out.println();
87            out.println(res.getString("clickViewText"));
88            commandReader.readLine();
89            
90            return true;
91        }
92        catch (IOException ex) {
93            throw new InstallException("Not able to read text file", ex);
94        }
95    }
96
97    private String getNextInstructions() {
98        return res.getString("license_next");
99    }
00}
01
02