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 @@
   
   <!--
     History of Cocoon changes   
  -  $Id: changes.xml,v 1.222 2001/03/22 19:58:26 greenrd Exp $ 
  +  $Id: changes.xml,v 1.223 2001/03/25 16:23:22 greenrd Exp $ 
   -->
   
   <changes title="History of Changes">
  @@ -18,6 +18,9 @@
     </devs>
   
    <release version="@version@" date="@date@">
  +  <action dev="RDG" type="fix">
  +   Workaround for encoding in FOP > 0.15
  +  </action>
     <action dev="RDG" type="fix" due-to="Krzysztof Zielinski" 
      due-to-email="[EMAIL PROTECTED]">
      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 <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Robin Green</a>
  - * @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:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to