source: release-kits/shared/ant-installer/src/org/tp23/antinstaller/renderer/text/LicensePageRenderer.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: 3.4 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.runtime.ConfigurationException;
26import org.tp23.antinstaller.page.LicensePage;
27import org.tp23.antinstaller.page.Page;
28
29
30public class LicensePageRenderer
31 extends AbstractTextPageRenderer {
32
33 private static final String nextChar = org.tp23.antinstaller.Installer.langPack.getString("nextChar");
34
35 private boolean usePaging = false;
36
37 public LicensePageRenderer() {
38 }
39
40 public boolean renderPage(Page page) throws InstallException {
41 if (page instanceof LicensePage) {
42 LicensePage lPage = (LicensePage) page;
43 String strUsePaging = lPage.getUsePaging();
44 usePaging = strUsePaging!=null && isTrue(strUsePaging);
45 return renderLicensePage(lPage);
46 }
47 else {
48 throw new InstallException("Wrong Renderer in LicensePageRenderer.renderPage");
49 }
50 }
51
52 private boolean renderLicensePage(LicensePage page) throws InstallException {
53 try {
54 BufferedReader commandReader = reader;
55 out.println();
56 out.println(org.tp23.antinstaller.Installer.langPack.getString("clickViewLicense"));
57 commandReader.readLine();
58
59 String resource = page.getResource();
60 InputStream licensein = this.getClass().getResourceAsStream(resource);
61 if (licensein == null) {
62 throw new ConfigurationException("License resource '" + resource + "' is missing from installer");
63 }
64 BufferedReader reader = new BufferedReader(new InputStreamReader(licensein));
65 printHeader(page);
66 String lineread = null;
67 StringBuffer sb = new StringBuffer();
68
69 while ( (lineread = reader.readLine()) != null) {
70 sb.append(lineread);
71 sb.append('\n');
72 }
73 // as per FindBugs
74 reader.close();
75
76 String command = null;
77 Pager pager = new Pager(sb.toString());
78 if (usePaging) {
79 do {
80 if (!pager.next(out)) {
81 break;
82 }
83 out.println();
84 out.println(getNextInstructions());
85 command = commandReader.readLine();
86 }
87 while (command.toUpperCase().startsWith(nextChar));
88 pager.rest(out);
89 }
90 else {
91 out.println(pager.getText());
92 }
93
94 for (int i = 0; i < PAGE_DECO_WIDTH; i++) {
95 out.print('~');
96 }
97 out.println();
98 out.println(org.tp23.antinstaller.Installer.langPack.getString("licenseAccept"));
99 command = commandReader.readLine();
100 command = command.trim();
101 if (isTrue(command)) {
102 return true;
103 }
104 else {
105 page.setAbort(true);
106 return false;
107 }
108 }
109 catch (IOException ex) {
110 throw new InstallException("Not able to read license file", ex);
111 }
112 }
113
114 private String getNextInstructions() {
115 return org.tp23.antinstaller.Installer.langPack.getString("license_next");
116 }
117}
118
Note: See TracBrowser for help on using the repository browser.