/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright 2006 - 2009 Pentaho Corporation. All rights reserved. * */ package org.pentaho.platform.plugin.action.jfreereport.outputs; import java.io.IOException; import java.io.OutputStream; import org.pentaho.reporting.engine.classic.core.MasterReport; import org.pentaho.reporting.engine.classic.core.ReportProcessingException; import org.pentaho.reporting.engine.classic.core.layout.output.YieldReportListener; import org.pentaho.reporting.engine.classic.core.modules.output.table.base.StreamReportProcessor; import org.pentaho.reporting.engine.classic.core.modules.output.table.csv.StreamCSVOutputProcessor; /** * Creation-Date: 07.07.2006, 20:42:17 * * @author Thomas Morgner */ public class JFreeReportCSVComponent extends AbstractGenerateStreamContentComponent { private static final long serialVersionUID = -6277594193744555596L; public JFreeReportCSVComponent() { } @Override protected String getMimeType() { return "text/csv"; //$NON-NLS-1$ } @Override protected String getExtension() { return ".csv"; //$NON-NLS-1$ } @Override protected boolean performExport(final MasterReport report, final OutputStream outputStream) { try { final StreamCSVOutputProcessor target = new StreamCSVOutputProcessor(report.getConfiguration(), outputStream); final StreamReportProcessor reportProcessor = new StreamReportProcessor(report, target); final int yieldRate = getYieldRate(); if (yieldRate > 0) { reportProcessor.addReportProgressListener(new YieldReportListener(yieldRate)); } reportProcessor.processReport(); reportProcessor.close(); outputStream.flush(); close(); return true; } catch (ReportProcessingException e) { return false; } catch (IOException e) { return false; } } }