001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: */
013: package org.pentaho.plugin.jfreereport.outputs;
014:
015: import java.awt.GraphicsEnvironment;
016:
017: import org.apache.commons.logging.Log;
018: import org.apache.commons.logging.LogFactory;
019: import org.jfree.report.JFreeReport;
020: import org.pentaho.core.component.IComponent;
021: import org.pentaho.core.runtime.IRuntimeContext;
022: import org.pentaho.messages.Messages;
023: import org.pentaho.plugin.core.StandardSettings;
024: import org.pentaho.plugin.jfreereport.AbstractJFreeReportComponent;
025:
026: /**
027: * Creation-Date: 07.07.2006, 21:01:58
028: *
029: * @author Thomas Morgner
030: */
031: public class JFreeReportAllContentComponent extends
032: AbstractJFreeReportComponent {
033: private static final long serialVersionUID = -8233725514054165666L;
034:
035: private AbstractGenerateContentComponent component;
036:
037: public JFreeReportAllContentComponent() {
038: }
039:
040: public Log getLogger() {
041: return LogFactory.getLog(getClass());
042: }
043:
044: protected boolean executeAction() throws Throwable {
045: if (component != null) {
046: debug(Messages
047: .getString(
048: "JFreeReportAllContentComponent.DEBUG_EXECUTING_COMPONENT", component.toString())); //$NON-NLS-1$
049: return (component.execute() == IRuntimeContext.RUNTIME_STATUS_SUCCESS);
050: }
051:
052: debug(Messages
053: .getString("JFreeReportAllContentComponent.DEBUG_NO_COMPONENT")); //$NON-NLS-1$
054: return false;
055: }
056:
057: public boolean init() {
058: if (component != null) {
059: return component.init();
060: }
061: return true;
062: }
063:
064: public void done() {
065: if (component != null) {
066: component.done();
067: }
068: }
069:
070: protected boolean validateSystemSettings() {
071: return true;
072: }
073:
074: protected boolean initAndValidate(IComponent componentToValidate) {
075: componentToValidate.setInstanceId(getInstanceId());
076: componentToValidate.setActionName(getActionName());
077: componentToValidate.setProcessId(getProcessId());
078: componentToValidate
079: .setComponentDefinition(getComponentDefinition());
080: componentToValidate.setSession(getSession());
081: componentToValidate.setRuntimeContext(getRuntimeContext());
082: componentToValidate.setLoggingLevel(getLoggingLevel());
083: componentToValidate.setMessages(getMessages());
084: return (componentToValidate.validate() == IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_OK);
085: }
086:
087: protected boolean validateAction() {
088:
089: if (isDefinedInput(StandardSettings.PRINTER_NAME)) {
090: component = new JFreeReportPrintComponent();
091: return initAndValidate(component);
092: }
093:
094: if (isDefinedInput(REPORTALLCONTENT_OUTPUTTYPE)) {
095:
096: String reportOutputType = getInputStringValue(REPORTALLCONTENT_OUTPUTTYPE);
097: if (getLogger().isDebugEnabled()) {
098: debug(Messages
099: .getString(
100: "JFreeReport.DEBUG_OUTPUT_TYPE", reportOutputType)); //$NON-NLS-1$
101: }
102: if (REPORTALLCONTENT_OUTPUTTYPE_HTML
103: .equals(reportOutputType)) {
104: component = new JFreeReportHtmlComponent();
105: return initAndValidate(component);
106: } else if (REPORTALLCONTENT_OUTPUTTYPE_PDF
107: .equals(reportOutputType)) {
108: component = new JFreeReportPdfComponent();
109: return initAndValidate(component);
110: } else if (REPORTALLCONTENT_OUTPUTTYPE_XLS
111: .equals(reportOutputType)) {
112: component = new JFreeReportExcelComponent();
113: return initAndValidate(component);
114: } else if (REPORTALLCONTENT_OUTPUTTYPE_CSV
115: .equals(reportOutputType)) {
116: component = new JFreeReportCSVComponent();
117: return initAndValidate(component);
118: } else if (REPORTALLCONTENT_OUTPUTTYPE_RTF
119: .equals(reportOutputType)) {
120: component = new JFreeReportRTFComponent();
121: return initAndValidate(component);
122: } else if (REPORTALLCONTENT_OUTPUTTYPE_XML
123: .equals(reportOutputType)) {
124: component = new JFreeReportXmlComponent();
125: return initAndValidate(component);
126: } else if (REPORTALLCONTENT_OUTPUTTYPE_SWING
127: .equals(reportOutputType)) {
128: if (GraphicsEnvironment.isHeadless()) {
129: component = new JFreeReportPreviewSwingComponent();
130: return initAndValidate(component);
131: }
132: warn(Messages
133: .getString("JFreeReportAllContentComponent.WARN_HEADLESSMODE_ACTIVE")); //$NON-NLS-1$
134: return false;
135: } else {
136: return false;
137: }
138: }
139: warn(Messages
140: .getString("JFreeReportAllContentComponent.WARN_NO_PRINTER_GIVEN")); //$NON-NLS-1$
141: return false;
142: }
143:
144: protected boolean performExport(final JFreeReport report) {
145: return false;
146: }
147: }
|