package com.kiasoft.modules.screens.pdf; /* ------------------------------------------------------------------ * Kiasoft, Inc. * http://kiasoft.com * * Copyright (c) 2004-2006 Kiasoft, Inc. All Rights Reserved. * * ------------------------------------------------------------------ */ import java.io.ByteArrayOutputStream; import org.apache.turbine.modules.screens.RawScreen; import org.apache.turbine.util.RunData; /** * RawScreen for displaying generated PDF files */ public abstract class PdfScreen extends RawScreen { /** * Set the content type to Pdf. (see RawScreen) * * @param data Turbine information. * @return content type. */ public String getContentType(RunData data) { return "application/pdf"; }; /** * Classes that implement this ADT must override this to build the pdf * file. * @param data RunData * @return ByteArrayOutputStream * @exception Exception, any old exception. */ protected abstract ByteArrayOutputStream buildPdf (RunData data) throws Exception; /** * Overrides & finalizes doOutput in RawScreen to serve the output stream * created in buildPDF. * * @param data RunData * @exception Exception, any old generic exception. */ protected final void doOutput(RunData data) throws Exception { ByteArrayOutputStream baos = buildPdf(data); if (baos != null) { javax.servlet.http.HttpServletResponse response = data.getResponse(); //We have to set the size to workaround a bug in IE (see com.lowagie iText FAQ) data.getResponse().setContentLength(baos.size()); javax.servlet.ServletOutputStream out = response.getOutputStream(); baos.writeTo(out); } else { throw new Exception("output stream from buildPDF is null"); } } }