source: release-kits/shared/ant-installer/src/org/tp23/antinstaller/renderer/text/TextPageRenderer.java@ 17514

Last change on this file since 17514 was 17514, checked in by oranfry, 16 years ago

changes to the way ant-installer loads and reloads the language packs, and a new attribute to the select input which triggers it to change the language to the input value

File size: 2.8 KB
Line 
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 String nextChar = org.tp23.antinstaller.Installer.langPack.getString("nextChar");
33
34 public TextPageRenderer() {
35 }
36
37 public boolean renderPage(Page page) throws InstallException {
38 if (page instanceof TextPage) {
39 TextPage lPage = (TextPage) page;
40 return renderTextPage(lPage);
41 }
42 else {
43 throw new InstallException("Wrong Renderer in TextPageRenderer.renderPage");
44 }
45 }
46
47 private boolean renderTextPage(TextPage page) throws InstallException {
48 try {
49 BufferedReader commandReader = reader;//new BufferedReader(new InputStreamReader(in));
50
51 String resource = page.getTextResource();
52 InputStream textin = this.getClass().getResourceAsStream(resource);
53 BufferedReader reader = new BufferedReader(new InputStreamReader(textin));
54 printHeader(page);
55 String lineread = null;
56 StringBuffer sb = new StringBuffer();
57
58 while ( (lineread = reader.readLine()) != null) {
59 sb.append(lineread);
60 sb.append('\n');
61 }
62 // as per FindBugs
63 reader.close();
64
65 // parse property references
66 String parsedText = getContext().getInstaller().getResultContainer().getDefaultValue(sb.toString());
67
68 String command = null;
69 Pager pager = new Pager(parsedText);
70 do {
71 if (!pager.next(out)) {
72 break;
73 }
74 out.println();
75 out.println(getNextInstructions());
76 command = commandReader.readLine();
77 }
78 while (command.toUpperCase().startsWith(nextChar));
79 pager.rest(out);
80
81 for (int i = 0; i < PAGE_DECO_WIDTH; i++) {
82 out.print('~');
83 }
84
85 out.println();
86 out.println(org.tp23.antinstaller.Installer.langPack.getString("clickViewText"));
87 commandReader.readLine();
88
89 return true;
90 }
91 catch (IOException ex) {
92 throw new InstallException("Not able to read text file", ex);
93 }
94 }
95
96 private String getNextInstructions() {
97 return org.tp23.antinstaller.Installer.langPack.getString("license_next");
98 }
99}
100
Note: See TracBrowser for help on using the repository browser.