source: release-kits/lirk3/bin/ant-installer/src_ext/org/tp23/antinstaller/runtime/exe/ReleaseNotesFilter.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.4 KB
Line 
1/*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14package org.tp23.antinstaller.runtime.exe;
15
16import java.io.BufferedReader;
17import java.io.IOException;
18import java.io.InputStream;
19import java.io.InputStreamReader;
20import java.util.ResourceBundle;
21
22import org.tp23.antinstaller.InstallException;
23import org.tp23.antinstaller.InstallerContext;
24import org.tp23.antinstaller.input.OutputField;
25import org.tp23.antinstaller.renderer.text.Pager;
26import org.tp23.antinstaller.runtime.Runner;
27import org.tp23.antinstaller.runtime.SwingRunner;
28import org.tp23.antinstaller.runtime.TextRunner;
29
30
31/**
32 * A filter that launches a window with release notes if a property has been selected
33 * during the install. The notes are loaded from a resource on the classpath
34 * called /release-notes.txt
35 * @author Paul Hinds
36 * @version $Id: ReleaseNotesFilter.java,v 1.4 2007/01/04 22:57:18 teknopaul Exp $
37 */
38public class ReleaseNotesFilter implements ExecuteFilter {
39
40 private static final ResourceBundle res = ResourceBundle.getBundle("org.tp23.antinstaller.renderer.text.Res");
41 private static final String nextChar = res.getString("nextChar");
42
43 /**
44 * The AntInstaller property that must be "true" for the release notes to show
45 */
46 public static final String RELEASE_NOTES_PROPERTY = "show.release.notes";
47
48 public ReleaseNotesFilter() {
49 }
50
51 public void exec(InstallerContext ctx) throws InstallException {
52 if(ctx.isInstallSucceded() ){
53 String showReleaseNotes = ctx.getInstaller().getResultContainer().getProperty(RELEASE_NOTES_PROPERTY);
54 if(OutputField.isTrue(showReleaseNotes)){
55 try {
56 InputStream is = ReleaseNotesFilter.class.getResourceAsStream("/release-notes.txt");
57 BufferedReader br = new BufferedReader(new InputStreamReader(is));
58 String line = null;
59 StringBuffer file = new StringBuffer();
60 while((line = br.readLine())!=null){
61 file.append(line).append('\n');
62 }
63 br.close();
64 Runner runner = ctx.getRunner();
65 if(runner instanceof TextRunner){
66 renderText(file.toString());
67
68 }
69 else{ // if(runner instanceof SwingRunner){
70 //SwingRunner sRunner = (SwingRunner)runner;
71 ReleaseNotesFrame rFrame = new ReleaseNotesFrame("Readme");
72 rFrame.init(file.toString());
73 }
74 }
75 catch (IOException e) {
76 throw new InstallException("Could not render Release notes",e);
77 }
78 }
79 }
80 }
81
82 private void renderText(String text) throws IOException{
83 BufferedReader commandReader = new BufferedReader(new InputStreamReader(System.in));
84 Pager pager = new Pager(text);
85 String command = null;
86 do {
87 if (!pager.next(System.out)) {
88 break;
89 }
90 System.out.println();
91 System.out.println(getNextInstructions());
92 command = commandReader.readLine();
93 }
94 while (command.toUpperCase().startsWith(nextChar));
95 pager.rest(System.out);
96
97 }
98 private String getNextInstructions() {
99 return res.getString("large_select_next");
100 }
101
102}
Note: See TracBrowser for help on using the repository browser.