/**
* Copyright (c)2010-2011 Enterprise Website Content Management System(EWCMS), All rights reserved.
* EWCMS PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
* http://www.ewcms.com
*/
package com.ewcms.plugin.report.generate.service.text;
import com.ewcms.plugin.BaseRuntimeException;
import java.io.ByteArrayOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.export.JRRtfExporter;
/**
* @author 吴智俊
*/
public class RtfGenerateService extends BaseTextGenerateServiceable {
private static final Logger logger = LoggerFactory.getLogger(RtfGenerateService.class);
protected byte[] generate(JasperPrint jasperPrint,
HttpServletResponse response, HttpServletRequest request) {
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
JRRtfExporter exporter = new JRRtfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,
byteArrayOutputStream);
exporter.exportReport();
byte[] bytes = byteArrayOutputStream.toByteArray();
if (response != null) {
response.setContentLength(bytes.length);
response.setContentType("application/msword");
}
return bytes;
} catch (Exception e) {
logger.error("Rtf Generate Exception", e);
throw new BaseRuntimeException(e.toString());
}
}
}