KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > plugin > jfreereport > outputs > AbstractGenerateStreamContentComponent


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12  */

13 package org.pentaho.plugin.jfreereport.outputs;
14
15 import java.io.OutputStream JavaDoc;
16
17 import org.jfree.report.JFreeReport;
18 import org.pentaho.core.repository.IContentItem;
19 import org.pentaho.messages.Messages;
20
21 /**
22  * Creation-Date: 07.07.2006, 20:50:22
23  *
24  * @author Thomas Morgner
25  */

26 public abstract class AbstractGenerateStreamContentComponent extends
27     AbstractGenerateContentComponent {
28
29   protected AbstractGenerateStreamContentComponent() {
30   }
31
32   protected boolean validateAction() {
33     if (super.validateAction() == false) {
34       return false;
35     }
36
37     if (isDefinedOutput(REPORTGENERATESTREAM_REPORT_OUTPUT)) {
38       return true;
39     }
40
41     if (getOutputNames().size() == 1) {
42       return true;
43     }
44
45     if (getOutputNames().size() == 0) {
46       warn(Messages.getString("Base.WARN_NO_OUTPUT_STREAM")); //$NON-NLS-1$
47
return true;
48     }
49
50     warn(Messages
51         .getString("AbstractGenerateStreamContentComponent.ERROR_0038_NO_OUTPUT_DEFINED")); //$NON-NLS-1$
52
return false;
53   }
54
55   protected abstract String JavaDoc getMimeType();
56
57   protected abstract String JavaDoc getExtension();
58
59   protected final boolean performExport(final JFreeReport report) {
60     OutputStream JavaDoc outputStream = createOutputStream();
61     if (outputStream == null) {
62       // We could not get an output stream for the content
63
error(Messages
64           .getErrorString("JFreeReport.ERROR_0008_INVALID_OUTPUT_STREAM")); //$NON-NLS-1$
65
return false;
66     }
67
68     return performExport(report, outputStream);
69   }
70
71   protected abstract boolean performExport(final JFreeReport report,
72       final OutputStream JavaDoc outputStream);
73
74   protected OutputStream JavaDoc createOutputStream() {
75     // Try to get the output from the action-sequence document.
76
final String JavaDoc mimeType = getMimeType();
77
78     if (isDefinedOutput(REPORTGENERATESTREAM_REPORT_OUTPUT)) {
79       return getOutputStream(REPORTGENERATESTREAM_REPORT_OUTPUT, mimeType, getExtension());
80     } else if (getOutputNames().size() == 1) {
81       String JavaDoc outputName = (String JavaDoc) getOutputNames().iterator().next();
82       IContentItem contentItem = getOutputContentItem(outputName);
83       contentItem.setMimeType(mimeType);
84       try {
85         return contentItem.getOutputStream(getActionName());
86       } catch (Exception JavaDoc e) {
87         return null;
88       }
89     }
90     if (getOutputNames().size() == 0) {
91       // There was no output in the action-sequence document, so make a
92
// default
93
// outputStream.
94
final OutputStream JavaDoc outputStream = getDefaultOutputStream();
95       if (outputStream != null) {
96         setOutputMimeType(mimeType);
97       }
98       return outputStream;
99     }
100
101     return null;
102   }
103 }
104
Popular Tags