dims        01/05/03 17:51:38

  Modified:    src/org/apache/cocoon/serialization Tag: xml-cocoon2
                        FOPSerializer.java
  Log:
  Checked-in Colin's Patch for FOPSerializer.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.20  +64 -9     
xml-cocoon/src/org/apache/cocoon/serialization/Attic/FOPSerializer.java
  
  Index: FOPSerializer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon/src/org/apache/cocoon/serialization/Attic/FOPSerializer.java,v
  retrieving revision 1.1.2.19
  retrieving revision 1.1.2.20
  diff -u -r1.1.2.19 -r1.1.2.20
  --- FOPSerializer.java        2001/04/30 20:55:35     1.1.2.19
  +++ FOPSerializer.java        2001/05/04 00:51:37     1.1.2.20
  @@ -8,6 +8,8 @@
   
   package org.apache.cocoon.serialization;
   
  +import java.io.File;
  +import java.io.FileNotFoundException;
   import java.io.IOException;
   import java.io.OutputStream;
   import java.io.PrintWriter;
  @@ -15,8 +17,12 @@
   import org.apache.cocoon.caching.Cacheable;
   import org.apache.cocoon.caching.NOPCacheValidity;
   import org.apache.avalon.excalibur.pool.Recyclable;
  +import org.apache.avalon.framework.configuration.Configurable;
  +import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.fop.apps.Driver;
   import org.apache.fop.apps.FOPException;
  +import org.apache.fop.apps.Options;
   import org.apache.fop.apps.Version;
   import org.apache.fop.messaging.MessageEvent;
   import org.apache.fop.messaging.MessageHandler;
  @@ -31,22 +37,70 @@
    *         (PWR Organisation & Entwicklung)
    * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.1.2.19 $ $Date: 2001/04/30 20:55:35 $
  + * @version CVS $Revision: 1.1.2.20 $ $Date: 2001/05/04 00:51:37 $
    *
  + * The use of a config file for FOP is enabled by adding a configuration
  + * element to the serializer in the sitemap.
  + * <user-config src="../webapps/cocoon/WEB-INF/fop_config.xml"/> 
  + * note the path to the config file has to be relative to where the 
application
  + * started the JVM, or absolute. If any one wants to fix this, go ahead!
  + * (colin britton)
    */
   public class FOPSerializer extends AbstractSerializer
  -implements MessageListener, Recyclable, Cacheable {
  +implements MessageListener, Recyclable, Configurable, Cacheable {
   
  -    /**
  -     * The FOP driver
  -     */
  +    //Declare options for FOP 
  +    private Options options;
  +    
  +    //Declare the FOP driver
       private Driver driver;
  +    
  +   /**
  +    * Set the configurations for this serializer.
  +    */
  +    public void configure(Configuration conf) 
  +    throws ConfigurationException {
  +        String userConfig = null;
  +        File userConfigFile = null;
  +
  +        if (conf != null) {
  +            Configuration child = conf.getChild("user-config");
  +            if (child != null) {
  +                try{
  +                    userConfig = child.getAttribute("src");
  +                } catch(Exception ex) {              
  +                    // getLogger().debug("FOPSerializer: No config file 
specified ");
  +                }
  +            }
  +        }
  +             
  +        // Check for null, use external or inbuilt config.
  +        if(userConfig != null){
  +            try {
  +                userConfigFile = new File(userConfig);
  +                options = new Options(userConfigFile);
  +                getLogger().debug("FOPSerializer: Using config file " + 
userConfig);
  +                 } catch (Exception ex) {
  +                     getLogger().error("FOPSerializer: Cannot load  config " 
+ userConfig, ex);
  +                     throw new ConfigurationException("FOPSerializer: Cannot 
load config " + userConfig, ex);
  +            }
  +        } else {
  +                 try {
  +                 options = new Options();
  +                 getLogger().debug("FOPSerializer: Using default config 
file");
  +                 } catch (Exception e) {
  +                 getLogger().error("FOPSerializer: Cannot load default 
config ", e);
  +            }
  +        }
  +    }
  +    
   
       /**
        * Create the FOP driver
        * Set the <code>OutputStream</code> where the XML should be serialized.
        */
       public void setOutputStream(OutputStream out) {
  +        // load the fop driver
           this.driver = new Driver();
   
           // the use of static resources sucks for servlet enviornments
  @@ -88,10 +142,10 @@
        * Receive FOP events.
        */
       public void processMessage (MessageEvent event) {
  -        // XXX (SM)
  -        // we should consume the events in some meaningful way
  -        // for example formatting them on the metapipeline
  -     getLogger().debug("FOP Message: "+event.getMessage());
  +        // Output FOP messgaes to Cocoon logging system
  +        // Rather verbose,  so wrote all as debug (including errors)
  +        // Could be cleaned up to handle different messages as required (CB)
  +        getLogger().debug("FOP Message: "+event.getMessage());
       }
   
       /**
  @@ -124,6 +178,7 @@
       public void recycle() {
           super.recycle();
           MessageHandler.removeListener(this);
  +        this.options = null;
           this.driver = null;
       }
   
  
  
  

----------------------------------------------------------------------
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