X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=source%2Fmir%2Fmisc%2FPDFUtil.java;h=48966e72c172b579b16d5909ef6afe8f537eebca;hb=97c5a1ec21aec86ea4a7c97c8552de5b049658a1;hp=2ef9fe641d92bd465d9ce09f26dccbe29d792523;hpb=e368bbb50c99177c97d0f3c7de877accc014a4b3;p=mir.git diff --git a/source/mir/misc/PDFUtil.java b/source/mir/misc/PDFUtil.java index 2ef9fe64..48966e72 100755 --- a/source/mir/misc/PDFUtil.java +++ b/source/mir/misc/PDFUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2001, 2002 The Mir-coders group + * Copyright (C) 2001, 2002 The Mir-coders group * * This file is part of Mir. * @@ -18,17 +18,15 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * In addition, as a special exception, The Mir-coders gives permission to link - * the code of this program with the com.oreilly.servlet library, any library - * licensed under the Apache Software License, The Sun (tm) Java Advanced - * Imaging library (JAI), The Sun JIMI library (or with modified versions of - * the above that use the same license as the above), and distribute linked - * combinations including the two. You must obey the GNU General Public - * License in all respects for all of the code used other than the above - * mentioned libraries. If you modify this file, you may extend this exception - * to your version of the file, but you are not obligated to do so. If you do - * not wish to do so, delete this exception statement from your version. + * the code of this program with any library licensed under the Apache Software License, + * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library + * (or with modified versions of the above that use the same license as the above), + * and distribute linked combinations including the two. You must obey the + * GNU General Public License in all respects for all of the code used other than + * the above mentioned libraries. If you modify this file, you may extend this + * exception to your version of the file, but you are not obligated to do so. + * If you do not wish to do so, delete this exception statement from your version. */ - package mir.misc; import java.io.ByteArrayOutputStream; @@ -37,8 +35,6 @@ import java.io.FileOutputStream; import javax.servlet.http.HttpServletResponse; -import mircoders.global.MirGlobal; - import org.apache.fop.apps.Driver; import org.apache.fop.apps.InputHandler; import org.apache.fop.apps.XSLTInputHandler; @@ -48,63 +44,56 @@ import org.apache.log.Priority; import org.xml.sax.XMLReader; public class PDFUtil { - + public static void makePDF(String foFilePath,Object pdfDestination,String stylesheetPath) throws Exception { try{ Driver driver = new Driver(); - + //stupid logging that fop wants to use, needs to be changed Hierarchy hierarchy = Hierarchy.getDefaultHierarchy(); Logger fopLog=null; fopLog = hierarchy.getLoggerFor("fop"); fopLog.setPriority(Priority.WARN); driver.setLogger(fopLog); - + driver.setRenderer(Driver.RENDER_PDF); - + File foFile=new File(foFilePath); - + String html2foStyleSheetPath; - if (stylesheetPath == "FROMCONFIG"){ - html2foStyleSheetPath=MirGlobal.getConfigProperty("Home") - + MirGlobal.getConfigProperty("HTMLTemplateProcessor.Dir") - + "/" - + MirGlobal.getConfigProperty("Producer.PrintableContent.html2foStyleSheetName"); - } - else { - html2foStyleSheetPath=stylesheetPath; - } + html2foStyleSheetPath=stylesheetPath; + File html2foStyleSheet=new File(html2foStyleSheetPath); InputHandler inputHandler = - new XSLTInputHandler(foFile, html2foStyleSheet); + new XSLTInputHandler(foFile, html2foStyleSheet); XMLReader parser = inputHandler.getParser(); - + if (pdfDestination instanceof String) { - String filePath = (String) pdfDestination; - driver.setOutputStream(new FileOutputStream(filePath)); - driver.render(parser, inputHandler.getInputSource()); + String filePath = (String) pdfDestination; + driver.setOutputStream(new FileOutputStream(filePath)); + driver.render(parser, inputHandler.getInputSource()); } else if (pdfDestination instanceof HttpServletResponse){ - HttpServletResponse res = (HttpServletResponse) pdfDestination; - ByteArrayOutputStream out = new ByteArrayOutputStream(); - driver.setOutputStream(out); - res.setContentType("application/pdf"); - - driver.render(parser, inputHandler.getInputSource()); - - byte[] content = out.toByteArray(); - res.setContentLength(content.length); - res.getOutputStream().write(content); - res.getOutputStream().flush(); + HttpServletResponse res = (HttpServletResponse) pdfDestination; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + driver.setOutputStream(out); + res.setContentType("application/pdf"); + + driver.render(parser, inputHandler.getInputSource()); + + byte[] content = out.toByteArray(); + res.setContentLength(content.length); + res.getOutputStream().write(content); + res.getOutputStream().flush(); } else { - throw new Exception("I'm sorry but I don't know how to output a pdf to an object of type" + pdfDestination.getClass().getName()); + throw new Exception("I'm sorry but I don't know how to output a pdf to an object of type" + pdfDestination.getClass().getName()); } } - + catch (Exception ex){ - throw(ex); + throw(ex); } } }