001: /*
002: * Copyright 2005 Paul Hinds
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.tp23.antinstaller.renderer.text;
017:
018: import java.io.BufferedReader;
019: import java.io.IOException;
020: import java.io.InputStream;
021: import java.io.InputStreamReader;
022:
023: import org.tp23.antinstaller.InstallException;
024: import org.tp23.antinstaller.page.Page;
025: import org.tp23.antinstaller.page.TextPage;
026: import org.tp23.antinstaller.renderer.AIResourceBundle;
027:
028: public class TextPageRenderer extends AbstractTextPageRenderer {
029:
030: private static final AIResourceBundle res = new AIResourceBundle();
031: private static final String nextChar = res.getString("next.char");
032:
033: public TextPageRenderer() {
034: }
035:
036: public boolean renderPage(Page page) throws InstallException {
037: if (page instanceof TextPage) {
038: TextPage lPage = (TextPage) page;
039: return renderTextPage(lPage);
040: } else {
041: throw new InstallException(
042: "Wrong Renderer in TextPageRenderer.renderPage");
043: }
044: }
045:
046: private boolean renderTextPage(TextPage page)
047: throws InstallException {
048: try {
049: BufferedReader commandReader = reader;//new BufferedReader(new InputStreamReader(in));
050:
051: String resource = page.getTextResource();
052: InputStream textin = this .getClass().getResourceAsStream(
053: resource);
054: BufferedReader reader = new BufferedReader(
055: new InputStreamReader(textin));
056: printHeader(page);
057: String lineread = null;
058: StringBuffer sb = new StringBuffer();
059:
060: while ((lineread = reader.readLine()) != null) {
061: sb.append(lineread);
062: sb.append('\n');
063: }
064: // as per FindBugs
065: reader.close();
066:
067: // parse property references
068: String parsedText = getContext().getInstaller()
069: .getResultContainer()
070: .getDefaultValue(sb.toString());
071:
072: String command = null;
073: Pager pager = new Pager(parsedText);
074: do {
075: if (!pager.next(out)) {
076: break;
077: }
078: out.println();
079: out.println(getNextInstructions());
080: command = commandReader.readLine();
081: } while (command.toUpperCase().startsWith(nextChar));
082: pager.rest(out);
083:
084: for (int i = 0; i < PAGE_DECO_WIDTH; i++) {
085: out.print('~');
086: }
087:
088: out.println();
089: out.println(res.getString("click.view.text"));
090: commandReader.readLine();
091:
092: return true;
093: } catch (IOException ex) {
094: throw new InstallException("Not able to read text file", ex);
095: }
096: }
097:
098: private String getNextInstructions() {
099: return res.getString("license.next");
100: }
101: }
|