Enclosed is a patch (contributed to jfor by Gianugo Rabellino), that allows 
jfor to be integrated with Cocoon 2 for RTF serialization of XSL-FO documents.

I successfully tested it today with the 20010926101525 CVS snapshot, by 
adding the following to the sitemap after compiling and installing the 
patched version:

   <map:match pattern="hello.rtf">
    <map:generate src="docs/samples/hello-page.xml"/>
    <map:transform src="stylesheets/page/simple-page2fo.xsl"/>
    <map:serialize type="fo2rtf"/>
   </map:match>

The RTFSerializer is only compiled if the jfor converter class is available 
at compile time. See www.jfor.org for how to obtain jfor.

Thanks very much to Gianugo for his contribution - we hope to get this 
integrated in the Cocoon 2 code base to make jfor and Cocoon more useful!

 -- Bertrand Delacrétaz, 
 -- jfor.org project manager

--------- CUT HERE -----------------------------------------------------
Two inline attachments follow:
1) diff for build.xml
2) RTFSerializer source code
--------- CUT HERE -----------------------------------------------------
Index: build.xml
===================================================================
RCS file: /home/cvspublic/xml-cocoon2/build.xml,v
retrieving revision 1.64
diff -u -r1.64 build.xml
--- build.xml   2001/09/19 19:37:55     1.64
+++ build.xml   2001/09/20 09:06:58
@@ -127,7 +127,10 @@
 - fo2pcl serializer : Requires the FOP package (included in the dist)
                     <map:serializer name="fo2pcl" 
src="org.apache.cocoon.serialization.FOPSerializer" 
mime-type="application/vnd.hp-PCL"/>
 
+- fo2rtf serializer : Requires the JFOR package (notincluded in the dist)
+                    <map:serializer name="fo2rtf" 
src="org.apache.cocoon.serialization.RTFSerializer" 
mime-type="application/msword"/>
 
+
                               Happy hacking from the Apache Cocoon 2 Dev 
Team :)
 
 ============================================================================ 
-->
@@ -300,6 +303,9 @@
     <available property="xmldb.present" 
classname="org.xmldb.api.DatabaseManager">
       <classpath refid="classpath"/>
     </available>
+    <available property="jfor.present" 
classname="org.jfor.jfor.converter.Converter">
+      <classpath refid="classpath"/>
+    </available>
   </target>
 
   <!-- =================================================================== 
-->
@@ -323,6 +329,7 @@
         <exclude name="**/LDAPTransformer*.java" unless="naming.present"/>
         <exclude name="**/JSPEngineImplWLS.java" unless="weblogic.present"/>
         <exclude name="**/XMLDB*.java" unless="xmldb.present"/>
+        <exclude name="**/RTFSerializer.java" unless="jfor.present"/>
         <exclude name="**/browser/*.x*"/>
         <exclude name="**/samples/parentcm/*.java" unless="naming.present"/>
       </fileset>
@@ -694,9 +701,22 @@
   </target>
 
   <!-- =================================================================== 
-->
+  <!-- Prepares the webapp sitemap if JFOR is available                  -->
+  <!-- =================================================================== 
-->
+  <target name="prepare-webapp-jfor" depends="copy-webapp"
+  if="jfor.present">
+    <java classname="st">
+        <arg line="-i ${build.war}/sitemap.xmap -o ${build.war}/sitemap.xmap 
-a serializers fo2rtf org.apache.cocoon.serialization.RTFSerializer"/>
+        <classpath>
+          <pathelement location="${bin.dir}"/>
+        </classpath>
+    </java>
+  </target>
+
+  <!-- =================================================================== 
-->
   <!-- Prepares the webapp directories                                     
-->
   <!-- =================================================================== 
-->
-  <target name="prepare-webapp" depends="copy-webapp, prepare-webapp-php, 
prepare-webapp-xt, prepare-webapp-fop, prepare-webapp-tidy, 
prepare-webapp-naming, prepare-webapp-xmldb">
+  <target name="prepare-webapp" depends="copy-webapp, prepare-webapp-php, 
prepare-webapp-xt, prepare-webapp-fop, prepare-webapp-tidy, 
prepare-webapp-naming, prepare-webapp-xmldb, prepare-webapp-jfor">
       <!-- Simply do nothing, just invoke all dependencies -->
   </target>
 
--------- CUT HERE -----------------------------------------------------
Second file: RTFSerializer.java
--------- CUT HERE -----------------------------------------------------

/*****************************************************************************
 * Copyright (C) The Apache Software Foundation. All rights reserved.        *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Apache Software License *
 * version 1.1, a copy of which has been included  with this distribution in *
 * the LICENSE file.                                                         *
 *****************************************************************************
/

package org.apache.cocoon.serialization;

import java.net.URL;
import java.net.MalformedURLException;

import org.apache.avalon.excalibur.pool.Poolable;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.Composable;

import org.apache.cocoon.components.url.URLFactory;

import org.apache.log.Priority;
import org.apache.log.util.OutputStreamLogger;

import org.jfor.jfor.converter.Converter;

import javax.xml.transform.OutputKeys;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.io.BufferedWriter;

import org.xml.sax.SAXException;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.AttributesImpl;

/**
 * This class uses the <a href="http://www.jfor.org";>jfor</a> library
 * to serialize XSL:FO documents to RTF streams.
 *
 * @author <a href="mailto:[EMAIL PROTECTED]";>Gianugo Rabellino</a>
 */

public class RTFSerializer extends AbstractTextSerializer 
  implements Poolable, Composable {

    private Writer rtfWriter = null;
    private Converter handler = null;
    private OutputStreamLogger cocoonLogger = null;
    private ComponentManager manager = null;


    public RTFSerializer() {
    }

    /** 
     * Set the current <code>ComponentManager</code> instance used by this
     * <code>Composable</code>.
     */
    public void compose(ComponentManager manager) {
      this.manager = manager;
    }

    /**
     * Set the OutputStream where the serializer will write to.
     *
     * @param out the OutputStream
     */


    public void setOutputStream(OutputStream out) {
        try {
          cocoonLogger = 
            new OutputStreamLogger(this.getLogger(), Priority.DEBUG);

          rtfWriter = 
            new BufferedWriter(new OutputStreamWriter(out));
          handler = new Converter(rtfWriter, 
            Converter.createConverterOption(cocoonLogger));
          super.setContentHandler(handler);

        } catch (Exception e) {
            getLogger().error("RTFSerializer.setOutputStream()", e);
            throw new RuntimeException(e.toString());
        }
    }

    /**
     * Recycle the serializer. GC instance variables
     */
    public void recycle() {
        super.recycle();
        rtfWriter = null;
        handler = null;
        cocoonLogger = null;
    }
}
--------- CUT HERE -----------------------------------------------------

end of patches.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to