001: /*
002: * Licensed under the Apache License, Version 2.0 (the "License");
003: * you may not use this file except in compliance with the License.
004: * You may obtain a copy of the License at
005: *
006: * http://www.apache.org/licenses/LICENSE-2.0
007: *
008: * Unless required by applicable law or agreed to in writing, software
009: * distributed under the License is distributed on an "AS IS" BASIS,
010: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011: * See the License for the specific language governing permissions and
012: * limitations under the License.
013: */
014: package org.tp23.antinstaller.runtime.exe;
015:
016: import java.io.BufferedReader;
017: import java.io.IOException;
018: import java.io.InputStream;
019: import java.io.InputStreamReader;
020:
021: import org.tp23.antinstaller.InstallException;
022: import org.tp23.antinstaller.InstallerContext;
023: import org.tp23.antinstaller.input.OutputField;
024: import org.tp23.antinstaller.renderer.AIResourceBundle;
025: import org.tp23.antinstaller.renderer.text.Pager;
026: import org.tp23.antinstaller.runtime.Runner;
027: import org.tp23.antinstaller.runtime.TextRunner;
028:
029: /**
030: * A filter that launches a window with release notes if a property has been selected
031: * during the install. The notes are loaded from a resource on the classpath
032: * called /release-notes.txt
033: * @author Paul Hinds
034: * @version $Id: ReleaseNotesFilter.java,v 1.4 2007/01/04 22:57:18 teknopaul Exp $
035: */
036: public class ReleaseNotesFilter implements ExecuteFilter {
037:
038: private static final AIResourceBundle res = new AIResourceBundle();
039: private static final String nextChar = res.getString("next.char");
040:
041: /**
042: * The AntInstaller property that must be "true" for the release notes to show
043: */
044: public static final String RELEASE_NOTES_PROPERTY = "show.release.notes";
045:
046: public ReleaseNotesFilter() {
047: }
048:
049: public void exec(InstallerContext ctx) throws InstallException {
050: if (ctx.isInstallSucceded()) {
051: String showReleaseNotes = ctx.getInstaller()
052: .getResultContainer().getProperty(
053: RELEASE_NOTES_PROPERTY);
054: if (OutputField.isTrue(showReleaseNotes)) {
055: try {
056: InputStream is = ReleaseNotesFilter.class
057: .getResourceAsStream("/release-notes.txt");
058: BufferedReader br = new BufferedReader(
059: new InputStreamReader(is));
060: String line = null;
061: StringBuffer file = new StringBuffer();
062: while ((line = br.readLine()) != null) {
063: file.append(line).append('\n');
064: }
065: br.close();
066: Runner runner = ctx.getRunner();
067: if (runner instanceof TextRunner) {
068: renderText(file.toString());
069:
070: } else { // if(runner instanceof SwingRunner){
071: //SwingRunner sRunner = (SwingRunner)runner;
072: ReleaseNotesFrame rFrame = new ReleaseNotesFrame(
073: "Readme");
074: rFrame.init(file.toString());
075: }
076: } catch (IOException e) {
077: throw new InstallException(
078: "Could not render Release notes", e);
079: }
080: }
081: }
082: }
083:
084: private void renderText(String text) throws IOException {
085: BufferedReader commandReader = new BufferedReader(
086: new InputStreamReader(System.in));
087: Pager pager = new Pager(text);
088: String command = null;
089: do {
090: if (!pager.next(System.out)) {
091: break;
092: }
093: System.out.println();
094: System.out.println(getNextInstructions());
095: command = commandReader.readLine();
096: } while (command.toUpperCase().startsWith(nextChar));
097: pager.rest(System.out);
098:
099: }
100:
101: private String getNextInstructions() {
102: return res.getString("large.select.next");
103: }
104:
105: }
|