01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: */
16: package org.outerj.daisy.tools.importexport.export.cli;
17:
18: import org.outerj.daisy.tools.importexport.export.ExportListener;
19: import org.outerj.daisy.tools.importexport.export.BaseExportListener;
20: import org.outerj.daisy.tools.importexport.export.config.ExportOptions;
21: import org.outerj.daisy.tools.importexport.ImportExportException;
22: import org.outerj.daisy.tools.importexport.model.ImpExpVariantKey;
23: import org.outerj.daisy.tools.importexport.util.ProgressIndicator;
24:
25: import java.io.PrintStream;
26:
27: class CliExportListener extends BaseExportListener implements
28: ExportListener {
29: private PrintStream out;
30: private ExportOptions exportOptions;
31: private ProgressIndicator documentProgess;
32: private boolean interrupted = false;
33:
34: public CliExportListener(PrintStream out,
35: ExportOptions exportOptions) {
36: this .out = out;
37: this .exportOptions = exportOptions;
38: this .documentProgess = new ProgressIndicator(out);
39: }
40:
41: public void info(String message) {
42: out.println(message);
43: }
44:
45: public void failed(ImpExpVariantKey variantKey, Throwable e)
46: throws Exception {
47: documentProgess.failureOccured();
48: super .failed(variantKey, e);
49:
50: if (exportOptions.getFailOnError()) {
51: throw new ImportExportException(
52: "Got an error exporting the document " + variantKey,
53: e);
54: }
55: }
56:
57: protected boolean includeFullStackTracesOfFailures() {
58: return exportOptions.getStackTracesOfFailures();
59: }
60:
61: protected String getStackTraceDisabledMessage() {
62: return "(stacktraces disabled, enable them via export options)";
63: }
64:
65: public void startDocumentProgress(int total) {
66: documentProgess.startProgress(total);
67: }
68:
69: public void updateDocumentProgress(int current) {
70: documentProgess.updateProgress(current);
71: }
72:
73: public void endDocumentProgress() {
74: if (interrupted) {
75: out.println("interrupted!");
76: } else {
77: documentProgess.endProgress();
78: }
79: }
80:
81: public synchronized boolean isInterrupted() {
82: return interrupted;
83: }
84:
85: public synchronized void interrupt() {
86: interrupted = true;
87: }
88: }
|