source: release-kits/lirk3/bin/ant-installer/src/org/tp23/antinstaller/renderer/text/LicensePageRenderer.java@ 14982

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

initial import of LiRK3

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