Return-Path: Delivered-To: apmail-xml-cocoon-cvs-archive@xml.apache.org Received: (qmail 96848 invoked by uid 500); 25 Mar 2001 16:23:25 -0000 Mailing-List: contact cocoon-cvs-help@xml.apache.org; run by ezmlm Precedence: bulk Reply-To: cocoon-dev@xml.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cocoon-cvs@xml.apache.org Received: (qmail 96839 invoked by uid 1172); 25 Mar 2001 16:23:24 -0000 Date: 25 Mar 2001 16:23:24 -0000 Message-ID: <20010325162324.96838.qmail@apache.org> From: greenrd@apache.org To: xml-cocoon-cvs@apache.org Subject: cvs commit: xml-cocoon/src/org/apache/cocoon/formatter FO2PDFFormatter.java greenrd 01/03/25 08:23:24 Modified: . changes.xml src/org/apache/cocoon/formatter FO2PDFFormatter.java Log: workaround for encoding in FOP > 0.15 Revision Changes Path 1.223 +4 -1 xml-cocoon/changes.xml Index: changes.xml =================================================================== RCS file: /home/cvs/xml-cocoon/changes.xml,v retrieving revision 1.222 retrieving revision 1.223 diff -u -r1.222 -r1.223 --- changes.xml 2001/03/22 19:58:26 1.222 +++ changes.xml 2001/03/25 16:23:22 1.223 @@ -4,7 +4,7 @@ @@ -18,6 +18,9 @@ + + Workaround for encoding in FOP > 0.15 + Non-default encodings in logicsheets should now work. 1.12 +26 -5 xml-cocoon/src/org/apache/cocoon/formatter/FO2PDFFormatter.java Index: FO2PDFFormatter.java =================================================================== RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/formatter/FO2PDFFormatter.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- FO2PDFFormatter.java 2001/03/01 17:19:06 1.11 +++ FO2PDFFormatter.java 2001/03/25 16:23:23 1.12 @@ -1,4 +1,4 @@ -/*-- $Id: FO2PDFFormatter.java,v 1.11 2001/03/01 17:19:06 greenrd Exp $ -- +/*-- $Id: FO2PDFFormatter.java,v 1.12 2001/03/25 16:23:23 greenrd Exp $ -- ============================================================================ The Apache Software License, Version 1.1 @@ -65,7 +65,7 @@ * * @author Stefano Mazzocchi * @author Robin Green - * @version $Revision: 1.11 $ $Date: 2001/03/01 17:19:06 $ + * @version $Revision: 1.12 $ $Date: 2001/03/25 16:23:23 $ */ public class FO2PDFFormatter extends AbstractFormatter implements Actor { @@ -81,6 +81,7 @@ private static final Hashtable NO_PARAMETERS = new Hashtable (); private static final double UNKNOWN_VERSION = -1.0; private static double FOP_VERSION_NO; + private static boolean STREAM_MODE; static { try { // This is a real mess! Why couldn't they just do a getVersionNumber() method!? @@ -96,6 +97,7 @@ catch (Exception ex) { FOP_VERSION_NO = UNKNOWN_VERSION; } + STREAM_MODE = FOP_VERSION_NO > 0.15 || FOP_VERSION_NO == UNKNOWN_VERSION; System.err.println ("FOP_VERSION = " + FOP_VERSION); System.err.println ("FOP_VERSION_NO = " + FOP_VERSION_NO); } @@ -103,6 +105,9 @@ protected Director director; protected Formatter xmlFormatter; protected Parser parser; + + protected boolean encodingHackEnabled; + protected String encoding; public FO2PDFFormatter() { super.MIMEtype = "application/pdf"; @@ -111,6 +116,7 @@ public void init(Configurations conf) { super.init(conf); + encodingHackEnabled = "true".equals (conf.get ("encoding.hack")); } public void init(Director director) { @@ -132,16 +138,26 @@ driver.setRenderer("org.apache.fop.render.pdf.PDFRenderer", FOP_VERSION); driver.addElementMapping("org.apache.fop.fo.StandardElementMapping"); driver.addElementMapping("org.apache.fop.svg.SVGElementMapping"); + + OutputStream outStream; + if (STREAM_MODE) { + + if (encodingHackEnabled) { + outStream = new ByteArrayOutputStream (); + } + else { + outStream = stream; + } - if (FOP_VERSION_NO > 0.15 || FOP_VERSION_NO == UNKNOWN_VERSION) { // We use reflection here to avoid compile-time errors // This translates at runtime to - //driver.setOutputStream (stream); + //driver.setOutputStream (outStream); Driver.class.getMethod ("setOutputStream", new Class [] {OutputStream.class}) - .invoke (driver, new Object [] {stream}); + .invoke (driver, new Object [] {outStream}); } else { PrintWriter pw = new PrintWriter (new OutputStreamWriter (stream)); + // We use reflection here to avoid compile-time errors // This translates at runtime to //driver.setWriter (pw); @@ -172,5 +188,10 @@ } driver.format(); driver.render(); + + if (STREAM_MODE && encodingHackEnabled) { + if (encoding == null) encoding = "UTF-8"; + stream.write (new String (outputStream.toByteArray (), encoding).getBytes ()); + } } } ---------------------------------------------------------------------- In case of troubles, e-mail: webmaster@xml.apache.org To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org For additional commands, e-mail: cocoon-cvs-help@xml.apache.org