chrisg      2002/11/18 06:37:47

  Modified:    .        Tag: fop-0_20_2-maintain CHANGES build.bat build.sh
                        build.xml
               docs/examples Tag: fop-0_20_2-maintain runtests.bat
                        runtests.sh
               docs/examples/fo Tag: fop-0_20_2-maintain images.fo
               src/org/apache/fop/image Tag: fop-0_20_2-maintain
                        FopImageFactory.java
               src/org/apache/fop/messaging Tag: fop-0_20_2-maintain
                        MessageHandler.java
               src/org/apache/fop/pdf Tag: fop-0_20_2-maintain
                        PDFXObject.java
               src/org/apache/fop/tools/anttasks Tag: fop-0_20_2-maintain
                        Fop.java
               test     Tag: fop-0_20_2-maintain createpdf.sh
  Added:       docs/graphics Tag: fop-0_20_2-maintain xml_fax.tif
               src/org/apache/fop/image Tag: fop-0_20_2-maintain
                        TiffImage.java
               src/org/apache/fop/pdf Tag: fop-0_20_2-maintain
                        CCFFilter.java
  Log:
  Added support for CCITT Group 4 encoded TIFF files
  Made JAI support dynamic (no recompile needed anymore)
  Submitted by: Manuel Mall <[EMAIL PROTECTED]> (see bug #13866)
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.10.2.27 +3 -0      xml-fop/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/xml-fop/CHANGES,v
  retrieving revision 1.10.2.26
  retrieving revision 1.10.2.27
  diff -u -r1.10.2.26 -r1.10.2.27
  --- CHANGES   11 Nov 2002 18:30:15 -0000      1.10.2.26
  +++ CHANGES   18 Nov 2002 14:37:44 -0000      1.10.2.27
  @@ -1,6 +1,9 @@
   ==============================================================================
   Done since 0.20.4 release
   
  +- Added support for CCITT Group 4 encoded TIFF files
  +  Made JAI support dynamic (no recompile needed anymore)
  +  Submitted by: Manuel Mall <[EMAIL PROTECTED]> (see bug #13866)
   - Fixed problem with jpegs with icc profile and acrobat reader 5 (Bug #11301)
     Submitted by: Stephan Neuhaus <[EMAIL PROTECTED]>
   - Fix bug in LinkSet.mergeLinks() (ArrayOutOfBoundsException when number of 
  
  
  
  1.14.2.9  +2 -0      xml-fop/build.bat
  
  Index: build.bat
  ===================================================================
  RCS file: /home/cvs/xml-fop/build.bat,v
  retrieving revision 1.14.2.8
  retrieving revision 1.14.2.9
  diff -u -r1.14.2.8 -r1.14.2.9
  --- build.bat 11 Nov 2002 10:24:39 -0000      1.14.2.8
  +++ build.bat 18 Nov 2002 14:37:45 -0000      1.14.2.9
  @@ -15,6 +15,8 @@
   set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\avalon-framework-cvs-20020806.jar
   set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\bsf.jar
   set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\jimi-1.0.jar
  +set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\jai_core.jar
  +set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\jai_codec.jar
   
   set ANT_HOME=%LIBDIR%
   
  
  
  
  1.15.2.12 +2 -0      xml-fop/build.sh
  
  Index: build.sh
  ===================================================================
  RCS file: /home/cvs/xml-fop/build.sh,v
  retrieving revision 1.15.2.11
  retrieving revision 1.15.2.12
  diff -u -r1.15.2.11 -r1.15.2.12
  --- build.sh  11 Nov 2002 10:24:38 -0000      1.15.2.11
  +++ build.sh  18 Nov 2002 14:37:45 -0000      1.15.2.12
  @@ -37,6 +37,8 @@
   LOCALCLASSPATH=$LOCALCLASSPATH:$LIBDIR/avalon-framework-cvs-20020806.jar
   LOCALCLASSPATH=$LOCALCLASSPATH:$LIBDIR/bsf.jar
   LOCALCLASSPATH=$LOCALCLASSPATH:$LIBDIR/jimi-1.0.jar
  +LOCALCLASSPATH=$LOCALCLASSPATH:$LIBDIR/jai_core.jar
  +LOCALCLASSPATH=$LOCALCLASSPATH:$LIBDIR/jai_codec.jar
   
   # antRun must be executable (can't do this in build.xml because Ant uses antRun
   # to do the chmod)
  
  
  
  1.44.2.27 +5 -3      xml-fop/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/xml-fop/build.xml,v
  retrieving revision 1.44.2.26
  retrieving revision 1.44.2.27
  diff -u -r1.44.2.26 -r1.44.2.27
  --- build.xml 11 Nov 2002 10:24:07 -0000      1.44.2.26
  +++ build.xml 18 Nov 2002 14:37:45 -0000      1.44.2.27
  @@ -212,7 +212,7 @@
   
       <property name="viewer.resources.src.dir" 
value="./src/org/apache/fop/viewer/resources"/>
       <property name="viewer.images.src.dir" 
value="./src/org/apache/fop/viewer/Images"/>
  -     
  +        
       <property name="build.dir" value="./build"/>
       <property name="build.src" value="./build/src"/>
       <property name="build.codegen" value="./build/src/codegen"/>
  @@ -223,7 +223,7 @@
       <property name="viewer.resources.dest.dir" 
value="${build.dest}/org/apache/fop/viewer/resources"/>
       <property name="viewer.images.dest.dir" 
value="${build.dest}/org/apache/fop/viewer/Images"/>
   
  -     <!-- <property name="dist.dir" value="./dist"/> -->
  +        <!-- <property name="dist.dir" value="./dist"/> -->
       <property name="dist.bin.dir" value="./dist-bin"/>
       <property name="dist.src.dir" value="./dist-src"/>
       <property name="dist.bin.result.dir" 
value="${dist.bin.dir}/${name}-${version}"/>
  @@ -236,6 +236,7 @@
       <property name="ignore_this" value="ignore_this.java"/>
       <property name="jimi" value="JimiImage.java"/>
       <property name="jai" value="JAIImage.java"/>
  +    <property name="tiff" value="TiffImage.java"/>
   
       <!--property name="xslt" value="org.apache.xalan.xslt.Process"/-->
       <property name="src.properties.xsl" value="${src.codegen}/properties.xsl"/>
  @@ -356,6 +357,7 @@
       <echo message="JAI library is present. Fop installs JAI support."/>
       <copy todir="${build.src}">
         <fileset dir="${src.dir}" includes="**/${jai}"/>
  +      <fileset dir="${src.dir}" includes="**/${tiff}"/>
       </copy>
     </target>
   
  @@ -374,7 +376,7 @@
       <!-- copy src files -->
       <copy todir="${build.src}" filtering="yes">
         <fileset dir="${src.dir}" 
  -        
excludes="**/${jimi},**/${jai},**/${xsltransform},**/${trax},**/apps/TraxInputHandler.java"/>
  +        
excludes="**/${jimi},**/${jai},**/${tiff},**/${xsltransform},**/${trax},**/apps/TraxInputHandler.java"/>
         <filterset>
           <filter token="XSLFO-STD" value="${xslfo.std}"/>
           <filter token="XSLFO-STDID" value="${xslfo.std.id}"/>
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.11.2.8  +2 -0      xml-fop/docs/examples/runtests.bat
  
  Index: runtests.bat
  ===================================================================
  RCS file: /home/cvs/xml-fop/docs/examples/runtests.bat,v
  retrieving revision 1.11.2.7
  retrieving revision 1.11.2.8
  diff -u -r1.11.2.7 -r1.11.2.8
  --- runtests.bat      11 Nov 2002 10:19:27 -0000      1.11.2.7
  +++ runtests.bat      18 Nov 2002 14:37:45 -0000      1.11.2.8
  @@ -16,6 +16,8 @@
   set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\avalon-framework-cvs-20020806.jar
   set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\bsf.jar
   set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\jimi-1.0.jar
  +set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\jai_core.jar
  +set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\jai_codec.jar
   set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\..\build\fop.jar
   set ANT_HOME=%LIBDIR%
   
  
  
  
  1.8.2.8   +2 -0      xml-fop/docs/examples/runtests.sh
  
  Index: runtests.sh
  ===================================================================
  RCS file: /home/cvs/xml-fop/docs/examples/runtests.sh,v
  retrieving revision 1.8.2.7
  retrieving revision 1.8.2.8
  diff -u -r1.8.2.7 -r1.8.2.8
  --- runtests.sh       11 Nov 2002 10:19:27 -0000      1.8.2.7
  +++ runtests.sh       18 Nov 2002 14:37:45 -0000      1.8.2.8
  @@ -35,6 +35,8 @@
   LOCALCLASSPATH=$LOCALCLASSPATH:$LIBDIR/avalon-framework-cvs-20020806.jar
   LOCALCLASSPATH=$LOCALCLASSPATH:$LIBDIR/bsf.jar
   LOCALCLASSPATH=$LOCALCLASSPATH:$LIBDIR/jimi-1.0.jar
  +LOCALCLASSPATH=$LOCALCLASSPATH:$LIBDIR/jai_core.jar
  +LOCALCLASSPATH=$LOCALCLASSPATH:$LIBDIR/jai_codec.jar
   LOCALCLASSPATH=$LOCALCLASSPATH:$LIBDIR/../build/fop.jar
   
   ANT_HOME=$LIBDIR
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.11.2.2  +26 -20    xml-fop/docs/examples/fo/images.fo
  
  Index: images.fo
  ===================================================================
  RCS file: /home/cvs/xml-fop/docs/examples/fo/images.fo,v
  retrieving revision 1.11.2.1
  retrieving revision 1.11.2.2
  diff -u -r1.11.2.1 -r1.11.2.2
  --- images.fo 6 Dec 2001 21:28:18 -0000       1.11.2.1
  +++ images.fo 18 Nov 2002 14:37:45 -0000      1.11.2.2
  @@ -4,28 +4,28 @@
   
   <fo:layout-master-set>
   <fo:simple-page-master master-name="right"
  -     margin-top="75pt" margin-bottom="25pt" margin-left="100pt" margin-right="50pt">
  -     <fo:region-body margin-bottom="50pt"/>
  -     <fo:region-after extent="25pt"/>
  +        margin-top="75pt" margin-bottom="25pt" margin-left="100pt" 
margin-right="50pt">
  +        <fo:region-body margin-bottom="50pt"/>
  +        <fo:region-after extent="25pt"/>
   </fo:simple-page-master>
   
   <fo:simple-page-master master-name="left"
  -     margin-top="75pt" margin-bottom="25pt" margin-left="50pt" margin-right="100pt">
  -     <fo:region-body margin-bottom="50pt"/>
  -     <fo:region-after extent="25pt"/>
  +        margin-top="75pt" margin-bottom="25pt" margin-left="50pt" 
margin-right="100pt">
  +        <fo:region-body margin-bottom="50pt"/>
  +        <fo:region-after extent="25pt"/>
   </fo:simple-page-master>
   
   <fo:page-sequence-master master-name="psmOddEven" >
  -     <fo:repeatable-page-master-alternatives>
  -             <fo:conditional-page-master-reference master-reference="right"
  -                     page-position="first" />
  -             <fo:conditional-page-master-reference master-reference="left"
  -                     odd-or-even="even" />
  -             <fo:conditional-page-master-reference master-reference="right"
  -                     odd-or-even="odd" />
  -             <!-- recommended fallback procedure -->
  -             <fo:conditional-page-master-reference master-reference="rest" />
  -     </fo:repeatable-page-master-alternatives>
  +        <fo:repeatable-page-master-alternatives>
  +                <fo:conditional-page-master-reference master-reference="right"
  +                        page-position="first" />
  +                <fo:conditional-page-master-reference master-reference="left"
  +                        odd-or-even="even" />
  +                <fo:conditional-page-master-reference master-reference="right"
  +                        odd-or-even="odd" />
  +                <!-- recommended fallback procedure -->
  +                <fo:conditional-page-master-reference master-reference="rest" />
  +        </fo:repeatable-page-master-alternatives>
   </fo:page-sequence-master>
   
   </fo:layout-master-set>
  @@ -33,9 +33,9 @@
   <fo:page-sequence id="N2528" master-reference="psmOddEven">
   
   <fo:static-content flow-name="xsl-region-after">
  -     <fo:block text-align-last="center" font-size="10pt">
  -             <fo:page-number/>
  -     </fo:block>
  +        <fo:block text-align-last="center" font-size="10pt">
  +                <fo:page-number/>
  +        </fo:block>
   </fo:static-content>
   
   <fo:flow flow-name="xsl-region-body">
  @@ -64,6 +64,12 @@
       <fo:external-graphic src="file:../../graphics/linux.bmp"/>
     </fo:block>
   </fo:block>
  +<fo:block id="N2555">
  +  <fo:block font-size="16pt" font-weight="bold" space-before.minimum="1em" 
space-before.optimum="1.5em" space-before.maximum="2em">A TIFF image in FOP (Only 
works with JAI!)</fo:block>
  +    <fo:block>
  +      <fo:external-graphic src="file:../../graphics/xml_fax.tif"/>
  +    </fo:block>
  +</fo:block>
   <fo:block id="N2559">
     <fo:block font-size="16pt" font-weight="bold" space-before.minimum="1em" 
space-before.optimum="1.5em" space-before.maximum="2em"/>
     This section is only required to show that the layout still works.
  @@ -80,4 +86,4 @@
   <fo:block font-size="18pt" font-weight="bold">A. Appendix</fo:block></fo:flow>
   </fo:page-sequence>
   </fo:root>
  -       
  +          
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +7 -0      xml-fop/docs/graphics/Attic/xml_fax.tif
  
        <<Binary file>>
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.25.2.6  +34 -12    xml-fop/src/org/apache/fop/image/Attic/FopImageFactory.java
  
  Index: FopImageFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/Attic/FopImageFactory.java,v
  retrieving revision 1.25.2.5
  retrieving revision 1.25.2.6
  diff -u -r1.25.2.5 -r1.25.2.6
  --- FopImageFactory.java      8 Nov 2002 10:11:06 -0000       1.25.2.5
  +++ FopImageFactory.java      18 Nov 2002 14:37:45 -0000      1.25.2.6
  @@ -30,6 +30,13 @@
       private static Map m_urlMap = new java.util.HashMap();
   
       /**
  +     * The class name of the generic image handler.
  +     * Will be either jimi or jai depending on what
  +     * is available.
  +     */
  +    private static String m_genericImageClassName = null;
  +
  +    /**
        * create an FopImage objects.
        * @param href image URL as a String
        * @return a new FopImage object
  @@ -126,24 +133,18 @@
           String imgClassName = null;
           if ("image/gif".equals(imgMimeType)) {
               imgClassName = "org.apache.fop.image.GifImage";
  -            // imgClassName = "org.apache.fop.image.JAIImage";
           } else if ("image/jpeg".equals(imgMimeType)) {
               imgClassName = "org.apache.fop.image.JpegImage";
  -            // imgClassName = "org.apache.fop.image.JAIImage";
           } else if ("image/bmp".equals(imgMimeType)) {
               imgClassName = "org.apache.fop.image.BmpImage";
  -            // imgClassName = "org.apache.fop.image.JAIImage";
           } else if ("image/png".equals(imgMimeType)) {
  -            imgClassName = "org.apache.fop.image.JimiImage";
  -            // imgClassName = "org.apache.fop.image.JAIImage";
  +            imgClassName = getGenericImageClassName();
           } else if ("image/tga".equals(imgMimeType)) {
  -            imgClassName = "org.apache.fop.image.JimiImage";
  -            // imgClassName = "org.apache.fop.image.JAIImage";
  +            imgClassName = getGenericImageClassName();
           } else if ("image/eps".equals(imgMimeType)) {
               imgClassName = "org.apache.fop.image.EPSImage";
           } else if ("image/tiff".equals(imgMimeType)) {
  -            imgClassName = "org.apache.fop.image.JimiImage";
  -            // imgClassName = "org.apache.fop.image.JAIImage";
  +            imgClassName = getGenericImageClassName();
           } else if ("image/svg+xml".equals(imgMimeType)) {
               imgClassName = "org.apache.fop.image.SVGImage";
           }
  @@ -152,8 +153,8 @@
                                           + absoluteURL.toString() + ") : "
                                           + imgMimeType);
   
  -            // load the right image class
  -            // return new <FopImage implementing class>
  +        // load the right image class
  +        // return new <FopImage implementing class>
           Object imageInstance = null;
           Class imageClass = null;
           try {
  @@ -194,6 +195,27 @@
           m_urlMap.put(href, imageInstance);
           return (FopImage)imageInstance;
       }
  +
  +
  +    /**
  +     * Determines the class name of the generic image handler
  +     * This should really come from a config file but we leave this
  +     * to some future time.
  +     */
  +    private static String getGenericImageClassName() {
  +
  +        if (m_genericImageClassName == null) {
  +            try {
  +                Class.forName("org.apache.fop.image.JAIImage");
  +                m_genericImageClassName = "org.apache.fop.image.JAIImage";
  +            } catch (Exception ex) {
  +                /* on any exception assume Jai is not present and use Jimi instead 
*/
  +                m_genericImageClassName = "org.apache.fop.image.JimiImage";
  +            }
  +        }
  +        return m_genericImageClassName;
  +    }
  +
   
       /**
        * Clear the image cache.
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +170 -0    xml-fop/src/org/apache/fop/image/Attic/TiffImage.java
  
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.6.2.4   +302 -301  xml-fop/src/org/apache/fop/messaging/Attic/MessageHandler.java
  
  Index: MessageHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/messaging/Attic/MessageHandler.java,v
  retrieving revision 1.6.2.3
  retrieving revision 1.6.2.4
  diff -u -r1.6.2.3 -r1.6.2.4
  --- MessageHandler.java       2 Aug 2002 20:28:53 -0000       1.6.2.3
  +++ MessageHandler.java       18 Nov 2002 14:37:46 -0000      1.6.2.4
  @@ -1,301 +1,302 @@
  -/*
  - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  - * For details on use and redistribution please refer to the
  - * LICENSE file included with these sources."
  - */
  -
  -
  -package org.apache.fop.messaging;
  -
  -import org.apache.avalon.framework.logger.ConsoleLogger;
  -import org.apache.avalon.framework.logger.Logger;
  -
  -import java.io.*;
  -import java.util.*;
  -
  -/**
  - * The class MessageHandler contains the static methods log and error which
  - * should be used for any end user information instead of System.out.print() or
  - * System.err.print(). The class defines several output methods:
  - * writing to the screen (default), logging to a file, creating message events and 
repressing all
  - * output. If you don't want to change the default behaviour, you should be
  - * happy with MessageHandler.log(message) and MessageHandler.error(message)<br>
  - * The class MessageHandler also supports the setting of an id. If set every 
message
  - * has as a prefix an identifying string. That way Fop probably can also be used in
  - * environments, where more than one Fop instance are running in same  JVM.<br>
  - * If Fop is embedded in a gui application or for any reasons the existing
  - * messaging system doesn't meet the programmer's requirements, one can add
  - * a MessageEvent listener to MessageHandler and handle the incoming messages
  - * in an appropriate way. See the class DefaultMessageListener, which is a trivial
  - * implementation of the MessageListener.
  - * Here is an example how to configure MessageHandler for the 
DefaultMessageListener (anybody
  - * can provide his own listener by extending MessageListener<br>
  - * <code>
  - * MessageHandler.setOutputMethod(MessageHandler.EVENT);
  - * MessageHandler.addListener(new DefaultMessageListener());
  - * </code><br>
  - * This examples shows, how to redirect the messages to a log file called fop.log.
  - * All messages are appended to this file.
  - * <code>
  - * MessageHandler.setOutputMethod(MessageHandler.FILE);
  - * MessageHandler.setLogfileName("\\fop.log",true);
  - * </code>
  - */
  -
  -public class MessageHandler {
  -    public static final int SCREEN = 0;
  -    public static final int FILE = 1;
  -    public static final int EVENT = 2;
  -    public static final int NONE = 3;    // this should always be the last method
  -
  -    private static Logger logger = null;
  -    private static String logfileName = "fop.log";
  -    private static PrintWriter writer;
  -    private static int outputMethod = SCREEN;
  -    private static boolean fileOpened = false;
  -    private static boolean appendToFile = true;
  -    private static String message = "";
  -    private static String prefix = "";
  -    private static Vector listeners = new Vector();
  -    private static boolean IDisSet = false;
  -    private static boolean quiet = false;
  -
  -    /**
  -     * helper class to access the message
  -     * @return a string containing the message
  -     */
  -
  -    private static String getMessage() {
  -        return message;
  -    }
  -
  -    /**
  -     * helper class which sets the message
  -     * and adds a prefix which can contain
  -     * the id of the thread which uses this messagehandler
  -     */
  -    private static void setMessage(String m) {
  -        if (IDisSet) {
  -            message = getID() + ":" + m;
  -        } else {
  -            message = m;
  -        }
  -    }
  -
  -    /**
  -     * informs the user of the message
  -     * @param message the message for the user
  -     */
  -    public static void log(String message) {
  -        if (quiet)
  -         return;
  -
  -     if (logger == null) {
  -         logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
  -         logger.warn("Screen logger not set.");
  -     }
  -     
  -     setMessage(message);
  -     switch (outputMethod) {
  -     case SCREEN:
  -         logger.debug(getMessage());
  -         break;
  -     case FILE:
  -         if (fileOpened) {
  -             writer.print(getMessage());
  -             writer.flush();
  -         } else {
  -             openFile();
  -             writer.print(getMessage());
  -             writer.flush();
  -         }
  -         break;
  -     case EVENT:
  -         setMessage(message);
  -         Enumeration enum = listeners.elements();
  -         while (enum.hasMoreElements()) {
  -             ((MessageListener)enum.nextElement()).processMessage(new 
MessageEvent(getMessage()));
  -         }
  -         break;
  -     case NONE:
  -         // do nothing
  -         break;
  -     default:
  -         logger.debug(message);
  -     }
  -    }
  -
  -    /**
  -     * convenience method which adds a return to the message
  -     * @param message the message for the user
  -     */
  -    public static void logln(String message) {
  -        log(message);
  -    }
  -
  -    /**
  -     * error warning for the user
  -     * @param errorMessage contains the warning string
  -     */
  -
  -    public static void error(String errorMessage) {
  -     if (logger == null) {
  -         logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
  -         logger.warn("Screen logger not set.");
  -     }
  -
  -        setMessage(errorMessage);
  -        switch (outputMethod) {
  -        case SCREEN:
  -            logger.error(getMessage());
  -            break;
  -        case FILE:
  -            if (fileOpened) {
  -                writer.print(getMessage());
  -                writer.flush();
  -            } else {
  -                openFile();
  -                writer.print(getMessage());
  -                writer.flush();
  -            }
  -            break;
  -        case EVENT:
  -            setMessage(message);
  -            Enumeration enum = listeners.elements();
  -            while (enum.hasMoreElements()) {
  -                MessageEvent messEv = new MessageEvent(getMessage());
  -                messEv.setMessageType(MessageEvent.ERROR);
  -                ((MessageListener)enum.nextElement()).processMessage(messEv);
  -            }
  -            break;
  -        case NONE:
  -            // do nothing
  -            break;
  -        default:
  -            logger.error(errorMessage);
  -        }
  -    }
  -
  -    /**
  -     * convenience method which adds a return to the error message
  -     * @param errorMessage the message for the user
  -     */
  -    public static void errorln(String errorMessage) {
  -        error(errorMessage);
  -    }
  -
  -    /**
  -     * adds a MessageListener which listens for MessageEvents
  -     * @param MessageListener the listener to add
  -     */
  -    public static void addListener(MessageListener listener) {
  -        listeners.add(listener);
  -    }
  -
  -    /**
  -     * removes a MessageListener
  -     * @param MessageListener the listener to remove
  -     */
  -    public static void removeListener(MessageListener listener) {
  -        listeners.removeElement(listener);
  -    }
  -
  -    /**
  -     * Sets the Logger used for the screen output method.
  -     * @param newLogger a logger for screen output. This may not be null.
  -     */
  -    public static void setScreenLogger(Logger newLogger) {
  -     if (newLogger == null)
  -         throw new NullPointerException();
  -     logger = newLogger;
  -    }
  -
  -    /**
  -     * sets the output method
  -     * @param method the output method to use, allowed values are<br>
  -     * MessageHandler.SCREEN, MessageHandler.FILE, MessageHandler.EVENT
  -     * MessageHandler.NONE
  -     */
  -    public static void setOutputMethod(int method) {
  -        if (method > NONE) {
  -            MessageHandler.error("Error: Unknown output method");
  -        } else {
  -            outputMethod = method;
  -        }
  -    }
  -
  -    /**
  -     * informs what output method is set
  -     * @return the output method
  -     */
  -    public static int getOutputMethod() {
  -        return outputMethod;
  -    }
  -
  -    /**
  -     * sets the logfile name
  -     * @param filename name of the logfile
  -     * @param append if true, the logfile is appended
  -     */
  -    public static void setLogfileName(String filename, boolean append) {
  -        logfileName = filename;
  -        appendToFile = append;
  -    }
  -
  -    /**
  -     * returns the logfile name
  -     * @return String containing the logfile name
  -     */
  -    public static String getLogfileName() {
  -        return logfileName;
  -    }
  -
  -    /**
  -     * helper file which opens the file for output method FILE
  -     */
  -    private static void openFile() {
  -        try {
  -            writer =
  -                new PrintWriter(new FileWriter(logfileName, appendToFile),
  -                                true);
  -            writer.println("\n==============================================");
  -            fileOpened = true;
  -        } catch (IOException ioe) {
  -            System.err.println("Error: " + ioe);
  -        }
  -    }
  -
  -    /**
  -     * if set to true an id string is prefixed to every message
  -     * uses the thread info as an id for the message producer. Should be used if
  -     * more than one instance of Fop is running in the same JVM
  -     * this id becomes a prefix to every message
  -     */
  -    private static String getID() {
  -        return Thread.currentThread().toString();
  -    }
  -
  -    /**
  -     * if set to true an id string is prefixed to every message
  -     * uses the thread info as an id for the message producer. Should be used if
  -     * more than one instance of Fop is running in the same JVM
  -     * this id becomes a prefix to every message
  -     *
  -     * @param id boolean (default is false)
  -     */
  -
  -    public static void setID(boolean id) {
  -        IDisSet = id;
  -    }
  -
  -    /**
  -     * if set to true all normal messages are suppressed.
  -     * error messages are displayed allthesame
  -     *
  -     * @param quietMode boolean (default is false)
  -     */
  -    public static void setQuiet(boolean quietMode) {
  -        quiet = quietMode;
  -    }
  -
  -}
  +/*
  + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  + * For details on use and redistribution please refer to the
  + * LICENSE file included with these sources."
  + */
  +
  +
  +package org.apache.fop.messaging;
  +
  +import org.apache.avalon.framework.logger.ConsoleLogger;
  +import org.apache.avalon.framework.logger.Logger;
  +
  +import java.io.*;
  +import java.util.*;
  +
  +/**
  + * The class MessageHandler contains the static methods log and error which
  + * should be used for any end user information instead of System.out.print() or
  + * System.err.print(). The class defines several output methods:
  + * writing to the screen (default), logging to a file, creating message events and 
repressing all
  + * output. If you don't want to change the default behaviour, you should be
  + * happy with MessageHandler.log(message) and MessageHandler.error(message)<br>
  + * The class MessageHandler also supports the setting of an id. If set every message
  + * has as a prefix an identifying string. That way Fop probably can also be used in
  + * environments, where more than one Fop instance are running in same  JVM.<br>
  + * If Fop is embedded in a gui application or for any reasons the existing
  + * messaging system doesn't meet the programmer's requirements, one can add
  + * a MessageEvent listener to MessageHandler and handle the incoming messages
  + * in an appropriate way. See the class DefaultMessageListener, which is a trivial
  + * implementation of the MessageListener.
  + * Here is an example how to configure MessageHandler for the 
DefaultMessageListener (anybody
  + * can provide his own listener by extending MessageListener<br>
  + * <code>
  + * MessageHandler.setOutputMethod(MessageHandler.EVENT);
  + * MessageHandler.addListener(new DefaultMessageListener());
  + * </code><br>
  + * This examples shows, how to redirect the messages to a log file called fop.log.
  + * All messages are appended to this file.
  + * <code>
  + * MessageHandler.setOutputMethod(MessageHandler.FILE);
  + * MessageHandler.setLogfileName("\\fop.log",true);
  + * </code>
  + */
  +
  +public class MessageHandler {
  +    public static final int SCREEN = 0;
  +    public static final int FILE = 1;
  +    public static final int EVENT = 2;
  +    public static final int NONE = 3;    // this should always be the last method
  +
  +    private static Logger logger = null;
  +    private static String logfileName = "fop.log";
  +    private static PrintWriter writer;
  +    private static int outputMethod = SCREEN;
  +    private static boolean fileOpened = false;
  +    private static boolean appendToFile = true;
  +    private static String message = "";
  +    private static String prefix = "";
  +    private static Vector listeners = new Vector();
  +    private static boolean IDisSet = false;
  +    private static boolean quiet = false;
  +
  +    /**
  +     * helper class to access the message
  +     * @return a string containing the message
  +     */
  +
  +    private static String getMessage() {
  +        return message;
  +    }
  +
  +    /**
  +     * helper class which sets the message
  +     * and adds a prefix which can contain
  +     * the id of the thread which uses this messagehandler
  +     */
  +    private static void setMessage(String m) {
  +        if (IDisSet) {
  +            message = getID() + ":" + m;
  +        } else {
  +            message = m;
  +        }
  +    }
  +
  +    /**
  +     * informs the user of the message
  +     * @param message the message for the user
  +     */
  +    public static void log(String message) {
  +        if (quiet) {
  +            return;
  +        }
  +
  +        if (logger == null) {
  +            logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
  +            logger.warn("Screen logger not set.");
  +        }
  +
  +        setMessage(message);
  +        switch (outputMethod) {
  +        case SCREEN:
  +            logger.info(getMessage());
  +            break;
  +        case FILE:
  +            if (fileOpened) {
  +                writer.print(getMessage());
  +                writer.flush();
  +            } else {
  +                openFile();
  +                writer.print(getMessage());
  +                writer.flush();
  +            }
  +            break;
  +        case EVENT:
  +            setMessage(message);
  +            Enumeration enum = listeners.elements();
  +            while (enum.hasMoreElements()) {
  +                ((MessageListener)enum.nextElement()).processMessage(new 
MessageEvent(getMessage()));
  +            }
  +            break;
  +        case NONE:
  +            // do nothing
  +            break;
  +        default:
  +            logger.info(message);
  +        }
  +    }
  +
  +    /**
  +     * convenience method which adds a return to the message
  +     * @param message the message for the user
  +     */
  +    public static void logln(String message) {
  +        log(message);
  +    }
  +
  +    /**
  +     * error warning for the user
  +     * @param errorMessage contains the warning string
  +     */
  +
  +    public static void error(String errorMessage) {
  +        if (logger == null) {
  +            logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
  +            logger.warn("Screen logger not set.");
  +        }
  +
  +        setMessage(errorMessage);
  +        switch (outputMethod) {
  +        case SCREEN:
  +            logger.error(getMessage());
  +            break;
  +        case FILE:
  +            if (fileOpened) {
  +                writer.print(getMessage());
  +                writer.flush();
  +            } else {
  +                openFile();
  +                writer.print(getMessage());
  +                writer.flush();
  +            }
  +            break;
  +        case EVENT:
  +            setMessage(message);
  +            Enumeration enum = listeners.elements();
  +            while (enum.hasMoreElements()) {
  +                MessageEvent messEv = new MessageEvent(getMessage());
  +                messEv.setMessageType(MessageEvent.ERROR);
  +                ((MessageListener)enum.nextElement()).processMessage(messEv);
  +            }
  +            break;
  +        case NONE:
  +            // do nothing
  +            break;
  +        default:
  +            logger.error(errorMessage);
  +        }
  +    }
  +
  +    /**
  +     * convenience method which adds a return to the error message
  +     * @param errorMessage the message for the user
  +     */
  +    public static void errorln(String errorMessage) {
  +        error(errorMessage);
  +    }
  +
  +    /**
  +     * adds a MessageListener which listens for MessageEvents
  +     * @param MessageListener the listener to add
  +     */
  +    public static void addListener(MessageListener listener) {
  +        listeners.add(listener);
  +    }
  +
  +    /**
  +     * removes a MessageListener
  +     * @param MessageListener the listener to remove
  +     */
  +    public static void removeListener(MessageListener listener) {
  +        listeners.removeElement(listener);
  +    }
  +
  +    /**
  +     * Sets the Logger used for the screen output method.
  +     * @param newLogger a logger for screen output. This may not be null.
  +     */
  +    public static void setScreenLogger(Logger newLogger) {
  +        if (newLogger == null)
  +            throw new NullPointerException();
  +        logger = newLogger;
  +    }
  +
  +    /**
  +     * sets the output method
  +     * @param method the output method to use, allowed values are<br>
  +     * MessageHandler.SCREEN, MessageHandler.FILE, MessageHandler.EVENT
  +     * MessageHandler.NONE
  +     */
  +    public static void setOutputMethod(int method) {
  +        if (method > NONE) {
  +            MessageHandler.error("Error: Unknown output method");
  +        } else {
  +            outputMethod = method;
  +        }
  +    }
  +
  +    /**
  +     * informs what output method is set
  +     * @return the output method
  +     */
  +    public static int getOutputMethod() {
  +        return outputMethod;
  +    }
  +
  +    /**
  +     * sets the logfile name
  +     * @param filename name of the logfile
  +     * @param append if true, the logfile is appended
  +     */
  +    public static void setLogfileName(String filename, boolean append) {
  +        logfileName = filename;
  +        appendToFile = append;
  +    }
  +
  +    /**
  +     * returns the logfile name
  +     * @return String containing the logfile name
  +     */
  +    public static String getLogfileName() {
  +        return logfileName;
  +    }
  +
  +    /**
  +     * helper file which opens the file for output method FILE
  +     */
  +    private static void openFile() {
  +        try {
  +            writer =
  +                new PrintWriter(new FileWriter(logfileName, appendToFile),
  +                                true);
  +            writer.println("\n==============================================");
  +            fileOpened = true;
  +        } catch (IOException ioe) {
  +            System.err.println("Error: " + ioe);
  +        }
  +    }
  +
  +    /**
  +     * if set to true an id string is prefixed to every message
  +     * uses the thread info as an id for the message producer. Should be used if
  +     * more than one instance of Fop is running in the same JVM
  +     * this id becomes a prefix to every message
  +     */
  +    private static String getID() {
  +        return Thread.currentThread().toString();
  +    }
  +
  +    /**
  +     * if set to true an id string is prefixed to every message
  +     * uses the thread info as an id for the message producer. Should be used if
  +     * more than one instance of Fop is running in the same JVM
  +     * this id becomes a prefix to every message
  +     *
  +     * @param id boolean (default is false)
  +     */
  +
  +    public static void setID(boolean id) {
  +        IDisSet = id;
  +    }
  +
  +    /**
  +     * if set to true all normal messages are suppressed.
  +     * error messages are displayed allthesame
  +     *
  +     * @param quietMode boolean (default is false)
  +     */
  +    public static void setQuiet(boolean quietMode) {
  +        quiet = quietMode;
  +    }
  +
  +}
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.14.2.4  +10 -3     xml-fop/src/org/apache/fop/pdf/PDFXObject.java
  
  Index: PDFXObject.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFXObject.java,v
  retrieving revision 1.14.2.3
  retrieving revision 1.14.2.4
  diff -u -r1.14.2.3 -r1.14.2.4
  --- PDFXObject.java   8 Nov 2002 10:25:27 -0000       1.14.2.3
  +++ PDFXObject.java   18 Nov 2002 14:37:46 -0000      1.14.2.4
  @@ -187,12 +187,19 @@
                    * Added by Eric Dalquist
                    * If the DCT filter hasn't been added to the object we add it here
                    */
  +                /*
  +                 * Added by Manuel Mall
  +                 * Only add the default filters if we don't have an image filter to
  +                 * avoid double encoding of images
  +                 */
  +                 
                   if (fopimage.getPDFFilter() != null) {
                       imgStream.addFilter(fopimage.getPDFFilter());
  +                } else {
  +                    imgStream.addDefaultFilters();
                   }
   
  -                imgStream.addDefaultFilters();
  -
  +                
                   String dictEntries = imgStream.applyFilters();
   
                   String p = this.number + " " + this.generation + " obj\n";
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +42 -0     xml-fop/src/org/apache/fop/pdf/Attic/CCFFilter.java
  
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.14.2.6  +377 -366  xml-fop/src/org/apache/fop/tools/anttasks/Fop.java
  
  Index: Fop.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/tools/anttasks/Fop.java,v
  retrieving revision 1.14.2.5
  retrieving revision 1.14.2.6
  diff -u -r1.14.2.5 -r1.14.2.6
  --- Fop.java  2 Aug 2002 20:28:58 -0000       1.14.2.5
  +++ Fop.java  18 Nov 2002 14:37:46 -0000      1.14.2.6
  @@ -1,366 +1,377 @@
  -/*
  - * $Id$
  - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  - * For details on use and redistribution please refer to the
  - * LICENSE file included with these sources.
  - */
  -
  -package org.apache.fop.tools.anttasks;
  -
  -// Ant
  -import org.apache.tools.ant.*;
  -import org.apache.tools.ant.types.FileSet;
  -
  -// SAX
  -import org.xml.sax.XMLReader;
  -import org.xml.sax.InputSource;
  -import org.xml.sax.SAXException;
  -import org.xml.sax.SAXParseException;
  -
  -// Java
  -import java.io.*;
  -import java.util.*;
  -
  -// FOP
  -import org.apache.fop.messaging.*;
  -import org.apache.fop.apps.Options;
  -import org.apache.fop.apps.Starter;
  -import org.apache.fop.apps.InputHandler;
  -import org.apache.fop.apps.FOInputHandler;
  -import org.apache.fop.apps.Driver;
  -import org.apache.fop.apps.FOPException;
  -import org.apache.fop.configuration.Configuration;
  -
  -// Avalon
  -import org.apache.avalon.framework.logger.ConsoleLogger;
  -import org.apache.avalon.framework.logger.Logger;
  -
  -/**
  - * Wrapper for Fop which allows it to be accessed from within an Ant task.
  - * Accepts the inputs:
  - * <ul>
  - * <li>fofile -> formatting objects file to be transformed</li>
  - * <li>format -> MIME type of the format to generate ex. "application/pdf"</li>
  - * <li>outfile -> output filename</li>
  - * <li>baseDir -> directory to work from</li>
  - * <li>userconfig -> file with user configuration (same as the "-c" command line 
option)</li>
  - * <li>messagelevel -> (info | verbose | debug) level to output non-error 
messages</li>
  - * </ul>
  - */
  -public class Fop extends Task {
  -    File foFile;
  -    ArrayList filesets = new ArrayList();
  -    File outFile;
  -    File outDir;
  -    String format; //MIME type
  -    File baseDir;
  -    File userConfig;
  -    int messageType = Project.MSG_VERBOSE;
  -
  -    /**
  -     * Sets the input file
  -     * @param File to input from
  -     */
  -    public void setUserconfig (File userConfig) {
  -        this.userConfig = userConfig;
  -    }
  -
  -    /**
  -     * Sets the input file
  -     * @param File to input from
  -     */
  -    public void setFofile(File foFile) {
  -        this.foFile = foFile;
  -    }
  -
  -    /**
  -     * Gets the input file
  -     */
  -    public File getFofile() {
  -        return foFile;
  -    }
  -
  -    /**
  -     * Adds a set of fo files (nested fileset attribute).
  -     */
  -    public void addFileset(FileSet set) {
  -        filesets.add(set);
  -    }
  -
  -    /**
  -     * Sets the output file
  -     * @param File to output to
  -     */
  -    public void setOutfile(File outFile) {
  -        this.outFile = outFile;
  -    }
  -
  -    /**
  -     * Gets the output file
  -     */
  -    public File getOutfile() {
  -        return this.outFile;
  -    }
  -
  -    /**
  -     * Sets the output directory
  -     * @param Directory to output to
  -     */
  -    public void setOutdir(File outDir) {
  -        this.outDir = outDir;
  -    }
  -
  -    /**
  -     * Gets the output directory
  -     */
  -    public File getOutdir() {
  -        return this.outDir;
  -    }
  -
  -    /**
  -     * Sets output format (MIME type)
  -     */
  -    public void setFormat(String format) {
  -        this.format = format;
  -    }
  -
  -    /**
  -     * Gets the output format (MIME type)
  -     */
  -    public String getFormat() {
  -        return this.format;
  -    }
  -
  -    /**
  -     * Sets the message level to be used while processing.
  -     * @param String (info | verbose | debug)
  -     */
  -    public void setMessagelevel(String messageLevel) {
  -        if (messageLevel.equalsIgnoreCase("info")) {
  -            messageType = Project.MSG_INFO;
  -        } else if (messageLevel.equalsIgnoreCase("verbose")) {
  -            messageType = Project.MSG_VERBOSE;
  -        } else if (messageLevel.equalsIgnoreCase("debug")) {
  -            messageType = Project.MSG_DEBUG;
  -        } else {
  -            log("messagelevel set to unknown value \"" + messageLevel +
  -                "\"", Project.MSG_ERR);
  -            throw new BuildException("unknown messagelevel");
  -        }
  -    }
  -
  -    /**
  -     * Returns the message type corresponding to Property.MSG_(INFO | VERBOSE | 
DEBUG)
  -     * representing the current message level.
  -     */
  -    public int getMessageType() {
  -        return messageType;
  -    }
  -
  -    /**
  -     * Sets the base directory; currently ignored
  -     * @param File to use as a working directory
  -     */
  -    public void setBasedir(File baseDir) {
  -        this.baseDir = baseDir;
  -    }
  -
  -    /**
  -     * Gets the base directory
  -     */
  -    public File getBasedir() {
  -        return (baseDir != null) ? baseDir : project.resolveFile(".");
  -    }
  -
  -    /**
  -     * Starts execution of this task
  -     */
  -    public void execute() throws BuildException {
  -        try {
  -            Starter starter = new FOPTaskStarter(this);
  -            starter.run();
  -        } catch (FOPException ex) {
  -            throw new BuildException(ex);
  -        }
  -
  -    }
  -
  -}
  -
  -class FOPTaskStarter extends Starter {
  -    Fop task;
  -    Logger log;
  -
  -    FOPTaskStarter(Fop task) throws FOPException {
  -        this.task = task;
  -
  -     log = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
  -     MessageHandler.setScreenLogger(log);
  -    }
  -
  -    private int determineRenderer(String format) {
  -        if ((format == null) ||
  -                format.equalsIgnoreCase("application/pdf") ||
  -                format.equalsIgnoreCase("pdf")) {
  -            return Driver.RENDER_PDF;
  -        } else if (format.equalsIgnoreCase("application/postscript") ||
  -            format.equalsIgnoreCase("ps")) {
  -            return Driver.RENDER_PS;
  -        } else if (format.equalsIgnoreCase("application/vnd.mif") ||
  -            format.equalsIgnoreCase("mif")) {
  -            return Driver.RENDER_MIF;
  -        } else if (format.equalsIgnoreCase("application/vnd.gp-PCL") ||
  -            format.equalsIgnoreCase("pcl")) {
  -            return Driver.RENDER_PCL;
  -        } else if (format.equalsIgnoreCase("text/plain") ||
  -            format.equalsIgnoreCase("txt")) {
  -            return Driver.RENDER_TXT;
  -        } else if (format.equalsIgnoreCase("text/xml") ||
  -            format.equalsIgnoreCase("at") ||
  -            format.equalsIgnoreCase("xml")) {
  -            return Driver.RENDER_XML;
  -        } else {
  -            String err = "Couldn't determine renderer to use: "+format;
  -            log.error(err);
  -            throw new BuildException(err);
  -        }
  -    }
  -
  -    private String determineExtension(int renderer) {
  -        switch (renderer) {
  -            case Driver.RENDER_PDF:
  -                return ".pdf";
  -            case Driver.RENDER_PS:
  -                return ".ps";
  -            case Driver.RENDER_MIF:
  -                return ".mif";
  -            case Driver.RENDER_PCL:
  -                return ".pcl";
  -            case Driver.RENDER_TXT:
  -                return ".txt";
  -            case Driver.RENDER_XML:
  -                return ".xml";
  -            default:
  -                String err = "Unknown renderer: "+renderer;
  -                log.error(err);
  -                throw new BuildException(err);
  -        }
  -    }
  -
  -    private File replaceExtension(File file, String expectedExt,
  -                                  String newExt) {
  -        String name = file.getName();
  -        if (name.toLowerCase().endsWith(expectedExt)) {
  -            name = name.substring(0, name.length() - expectedExt.length());
  -        }
  -        name = name.concat(newExt);
  -        return new File(file.getParentFile(), name);
  -    }
  -
  -    public void run() throws FOPException {
  -        if (task.userConfig != null) {
  -            new Options (task.userConfig);
  -        }
  -
  -        try {
  -            if (task.getFofile() != null) {
  -                Configuration.put("baseDir",
  -                                  task.getFofile().getParentFile().toURL().
  -                                  toExternalForm());
  -            }
  -        } catch (Exception e) {
  -            log.error("Error setting base directory",e);
  -        }
  -
  -        task.log("Using base directory: " +
  -                 Configuration.getValue("baseDir"), Project.MSG_DEBUG);
  -
  -        int rint = determineRenderer(task.getFormat());
  -        String newExtension = determineExtension(rint);
  -
  -        int actioncount = 0;
  -
  -        // deal with single source file
  -        if (task.getFofile() != null) {
  -            if (task.getFofile().exists()) {
  -                File outf = task.getOutfile();
  -                if (outf == null) {
  -                    throw new BuildException("outfile is required when fofile is 
used");
  -                }
  -                if (task.getOutdir() != null) {
  -                    outf = new File(task.getOutdir(), outf.getName());
  -                }
  -                render(task.getFofile(), outf, rint);
  -                actioncount++;
  -            }
  -        }
  -
  -        // deal with the filesets
  -        for (int i = 0; i < task.filesets.size(); i++) {
  -            FileSet fs = (FileSet) task.filesets.get(i);
  -            DirectoryScanner ds = fs.getDirectoryScanner(task.getProject());
  -            String[] files = ds.getIncludedFiles();
  -
  -            for (int j = 0; j < files.length; j++) {
  -                File f = new File(fs.getDir(task.getProject()), files[j]);
  -                File outf = replaceExtension(f, ".fo", newExtension);
  -                if (task.getOutdir() != null) {
  -                    outf = new File(task.getOutdir(), outf.getName());
  -                }
  -                try {
  -                    Configuration.put("baseDir",
  -                                      fs.getDir(task.getProject()).toURL().
  -                                      toExternalForm());
  -
  -                } catch (Exception e) {
  -                    task.log("Error setting base directory",
  -                             Project.MSG_DEBUG);
  -                }
  -
  -                render(f, outf, rint);
  -                actioncount++;
  -            }
  -        }
  -
  -        if (actioncount == 0) {
  -            task.log(
  -              "No files processed. No files were selected by the filesets and no 
fofile was set." ,
  -              Project.MSG_WARN);
  -        }
  -    }
  -
  -    private void render(File foFile, File outFile,
  -                        int renderer) throws FOPException {
  -        InputHandler inputHandler = new FOInputHandler(foFile);
  -        XMLReader parser = inputHandler.getParser();
  -
  -        FileOutputStream out = null;
  -        try {
  -            out = new FileOutputStream(outFile);
  -        } catch (Exception ex) {
  -            log.error("Failed to open " + outFile);
  -            throw new BuildException(ex);
  -        }
  -
  -        task.log(foFile + " -> " + outFile, Project.MSG_INFO);
  -
  -        try {
  -            Driver driver = new Driver(inputHandler.getInputSource(), out);
  -            driver.setLogger(log);
  -            driver.setRenderer(renderer);
  -         if (renderer == Driver.RENDER_XML) {
  -             HashMap rendererOptions = new HashMap();
  -             rendererOptions.put("fineDetail", new Boolean(true));
  -             driver.getRenderer().setOptions(rendererOptions);
  -         }
  -            driver.setXMLReader(parser);
  -            driver.run();
  -            out.close();
  -        } catch (Exception ex) {
  -            log.error("Couldn't render file: " + ex.getMessage());
  -            throw new BuildException(ex);
  -        }
  -    }
  -
  -}
  -
  +/*
  + * $Id$
  + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  + * For details on use and redistribution please refer to the
  + * LICENSE file included with these sources.
  + */
  +
  +package org.apache.fop.tools.anttasks;
  +
  +// Ant
  +import org.apache.tools.ant.*;
  +import org.apache.tools.ant.types.FileSet;
  +
  +// SAX
  +import org.xml.sax.XMLReader;
  +import org.xml.sax.InputSource;
  +import org.xml.sax.SAXException;
  +import org.xml.sax.SAXParseException;
  +
  +// Java
  +import java.io.*;
  +import java.util.*;
  +
  +// FOP
  +import org.apache.fop.messaging.*;
  +import org.apache.fop.apps.Options;
  +import org.apache.fop.apps.Starter;
  +import org.apache.fop.apps.InputHandler;
  +import org.apache.fop.apps.FOInputHandler;
  +import org.apache.fop.apps.Driver;
  +import org.apache.fop.apps.FOPException;
  +import org.apache.fop.configuration.Configuration;
  +
  +// Avalon
  +import org.apache.avalon.framework.logger.ConsoleLogger;
  +import org.apache.avalon.framework.logger.Logger;
  +
  +/**
  + * Wrapper for Fop which allows it to be accessed from within an Ant task.
  + * Accepts the inputs:
  + * <ul>
  + * <li>fofile -> formatting objects file to be transformed</li>
  + * <li>format -> MIME type of the format to generate ex. "application/pdf"</li>
  + * <li>outfile -> output filename</li>
  + * <li>baseDir -> directory to work from</li>
  + * <li>userconfig -> file with user configuration (same as the "-c" command line 
option)</li>
  + * <li>messagelevel -> (info | verbose | debug) level to output non-error 
messages</li>
  + * </ul>
  + */
  +public class Fop extends Task {
  +    File foFile;
  +    ArrayList filesets = new ArrayList();
  +    File outFile;
  +    File outDir;
  +    String format; //MIME type
  +    File baseDir;
  +    File userConfig;
  +    int messageType = Project.MSG_VERBOSE;
  +
  +    /**
  +     * Sets the input file
  +     * @param File to input from
  +     */
  +    public void setUserconfig (File userConfig) {
  +        this.userConfig = userConfig;
  +    }
  +
  +    /**
  +     * Sets the input file
  +     * @param File to input from
  +     */
  +    public void setFofile(File foFile) {
  +        this.foFile = foFile;
  +    }
  +
  +    /**
  +     * Gets the input file
  +     */
  +    public File getFofile() {
  +        return foFile;
  +    }
  +
  +    /**
  +     * Adds a set of fo files (nested fileset attribute).
  +     */
  +    public void addFileset(FileSet set) {
  +        filesets.add(set);
  +    }
  +
  +    /**
  +     * Sets the output file
  +     * @param File to output to
  +     */
  +    public void setOutfile(File outFile) {
  +        this.outFile = outFile;
  +    }
  +
  +    /**
  +     * Gets the output file
  +     */
  +    public File getOutfile() {
  +        return this.outFile;
  +    }
  +
  +    /**
  +     * Sets the output directory
  +     * @param Directory to output to
  +     */
  +    public void setOutdir(File outDir) {
  +        this.outDir = outDir;
  +    }
  +
  +    /**
  +     * Gets the output directory
  +     */
  +    public File getOutdir() {
  +        return this.outDir;
  +    }
  +
  +    /**
  +     * Sets output format (MIME type)
  +     */
  +    public void setFormat(String format) {
  +        this.format = format;
  +    }
  +
  +    /**
  +     * Gets the output format (MIME type)
  +     */
  +    public String getFormat() {
  +        return this.format;
  +    }
  +
  +    /**
  +     * Sets the message level to be used while processing.
  +     * @param String (info | verbose | debug)
  +     */
  +    public void setMessagelevel(String messageLevel) {
  +        if (messageLevel.equalsIgnoreCase("info")) {
  +            messageType = Project.MSG_INFO;
  +        } else if (messageLevel.equalsIgnoreCase("verbose")) {
  +            messageType = Project.MSG_VERBOSE;
  +        } else if (messageLevel.equalsIgnoreCase("debug")) {
  +            messageType = Project.MSG_DEBUG;
  +        } else {
  +            log("messagelevel set to unknown value \"" + messageLevel +
  +                "\"", Project.MSG_ERR);
  +            throw new BuildException("unknown messagelevel");
  +        }
  +    }
  +
  +    /**
  +     * Returns the message type corresponding to Property.MSG_(INFO | VERBOSE | 
DEBUG)
  +     * representing the current message level.
  +     */
  +    public int getMessageType() {
  +        return messageType;
  +    }
  +
  +    /**
  +     * Sets the base directory; currently ignored
  +     * @param File to use as a working directory
  +     */
  +    public void setBasedir(File baseDir) {
  +        this.baseDir = baseDir;
  +    }
  +
  +    /**
  +     * Gets the base directory
  +     */
  +    public File getBasedir() {
  +        return (baseDir != null) ? baseDir : project.resolveFile(".");
  +    }
  +
  +    /**
  +     * Starts execution of this task
  +     */
  +    public void execute() throws BuildException {
  +        try {
  +            Starter starter = new FOPTaskStarter(this);
  +            starter.run();
  +        } catch (FOPException ex) {
  +            throw new BuildException(ex);
  +        }
  +
  +    }
  +
  +}
  +
  +class FOPTaskStarter extends Starter {
  +    Fop task;
  +    Logger log;
  +
  +    FOPTaskStarter(Fop task) throws FOPException {
  +        this.task = task;
  +
  +    log = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
  +    MessageHandler.setScreenLogger(log);
  +    }
  +
  +    private int determineRenderer(String format) {
  +        if ((format == null) ||
  +                format.equalsIgnoreCase("application/pdf") ||
  +                format.equalsIgnoreCase("pdf")) {
  +            return Driver.RENDER_PDF;
  +        } else if (format.equalsIgnoreCase("application/postscript") ||
  +            format.equalsIgnoreCase("ps")) {
  +            return Driver.RENDER_PS;
  +        } else if (format.equalsIgnoreCase("application/vnd.mif") ||
  +            format.equalsIgnoreCase("mif")) {
  +            return Driver.RENDER_MIF;
  +        } else if (format.equalsIgnoreCase("application/vnd.gp-PCL") ||
  +            format.equalsIgnoreCase("pcl")) {
  +            return Driver.RENDER_PCL;
  +        } else if (format.equalsIgnoreCase("text/plain") ||
  +            format.equalsIgnoreCase("txt")) {
  +            return Driver.RENDER_TXT;
  +        } else if (format.equalsIgnoreCase("text/xml") ||
  +            format.equalsIgnoreCase("at") ||
  +            format.equalsIgnoreCase("xml")) {
  +            return Driver.RENDER_XML;
  +        } else {
  +            String err = "Couldn't determine renderer to use: "+format;
  +            log.error(err);
  +            throw new BuildException(err);
  +        }
  +    }
  +
  +    private String determineExtension(int renderer) {
  +        switch (renderer) {
  +            case Driver.RENDER_PDF:
  +                return ".pdf";
  +            case Driver.RENDER_PS:
  +                return ".ps";
  +            case Driver.RENDER_MIF:
  +                return ".mif";
  +            case Driver.RENDER_PCL:
  +                return ".pcl";
  +            case Driver.RENDER_TXT:
  +                return ".txt";
  +            case Driver.RENDER_XML:
  +                return ".xml";
  +            default:
  +                String err = "Unknown renderer: "+renderer;
  +                log.error(err);
  +                throw new BuildException(err);
  +        }
  +    }
  +
  +    private File replaceExtension(File file, String expectedExt,
  +                                  String newExt) {
  +        String name = file.getName();
  +        if (name.toLowerCase().endsWith(expectedExt)) {
  +            name = name.substring(0, name.length() - expectedExt.length());
  +        }
  +        name = name.concat(newExt);
  +        return new File(file.getParentFile(), name);
  +    }
  +
  +    public void run() throws FOPException {
  +        if (task.userConfig != null) {
  +            new Options (task.userConfig);
  +        }
  +
  +        try {
  +            if (task.getFofile() != null) {
  +                if (task.getBasedir() != null) {
  +                    Configuration.put("baseDir",
  +                                      task.getBasedir().toURL().
  +                                      toExternalForm());
  +                } else {
  +                    Configuration.put("baseDir",
  +                                      task.getFofile().getParentFile().toURL().
  +                                      toExternalForm());
  +                }
  +            }
  +            task.log("Using base directory: " +
  +                     Configuration.getValue("baseDir"), Project.MSG_DEBUG);
  +        } catch (Exception e) {
  +            log.error("Error setting base directory",e);
  +        }
  +
  +        int rint = determineRenderer(task.getFormat());
  +        String newExtension = determineExtension(rint);
  +
  +        int actioncount = 0;
  +
  +        // deal with single source file
  +        if (task.getFofile() != null) {
  +            if (task.getFofile().exists()) {
  +                File outf = task.getOutfile();
  +                if (outf == null) {
  +                    throw new BuildException("outfile is required when fofile is 
used");
  +                }
  +                if (task.getOutdir() != null) {
  +                    outf = new File(task.getOutdir(), outf.getName());
  +                }
  +                render(task.getFofile(), outf, rint);
  +                actioncount++;
  +            }
  +        }
  +
  +        // deal with the filesets
  +        for (int i = 0; i < task.filesets.size(); i++) {
  +            FileSet fs = (FileSet) task.filesets.get(i);
  +            DirectoryScanner ds = fs.getDirectoryScanner(task.getProject());
  +            String[] files = ds.getIncludedFiles();
  +
  +            for (int j = 0; j < files.length; j++) {
  +                File f = new File(fs.getDir(task.getProject()), files[j]);
  +                File outf = replaceExtension(f, ".fo", newExtension);
  +                if (task.getOutdir() != null) {
  +                    outf = new File(task.getOutdir(), outf.getName());
  +                }
  +                try {
  +                    if (task.getBasedir() != null) {
  +                        Configuration.put("baseDir",
  +                                          task.getBasedir().toURL().
  +                                          toExternalForm());
  +                    } else {
  +                        Configuration.put("baseDir",
  +                                          fs.getDir(task.getProject()).toURL().
  +                                          toExternalForm());
  +                    }
  +                    task.log("Using base directory: " +
  +                             Configuration.getValue("baseDir"), Project.MSG_DEBUG);
  +                } catch (Exception e) {
  +                    log.error("Error setting base directory", e);
  +                }
  +
  +                render(f, outf, rint);
  +                actioncount++;
  +            }
  +        }
  +
  +        if (actioncount == 0) {
  +            task.log(
  +              "No files processed. No files were selected by the filesets and no 
fofile was set." ,
  +              Project.MSG_WARN);
  +        }
  +    }
  +
  +    private void render(File foFile, File outFile,
  +                        int renderer) throws FOPException {
  +        InputHandler inputHandler = new FOInputHandler(foFile);
  +        XMLReader parser = inputHandler.getParser();
  +
  +        FileOutputStream out = null;
  +        try {
  +            out = new FileOutputStream(outFile);
  +        } catch (Exception ex) {
  +            log.error("Failed to open " + outFile);
  +            throw new BuildException(ex);
  +        }
  +
  +        task.log(foFile + " -> " + outFile, Project.MSG_INFO);
  +
  +        try {
  +            Driver driver = new Driver(inputHandler.getInputSource(), out);
  +            driver.setLogger(log);
  +            driver.setRenderer(renderer);
  +            if (renderer == Driver.RENDER_XML) {
  +                HashMap rendererOptions = new HashMap();
  +                rendererOptions.put("fineDetail", new Boolean(true));
  +                driver.getRenderer().setOptions(rendererOptions);
  +            }
  +            driver.setXMLReader(parser);
  +            driver.run();
  +            out.close();
  +        } catch (Exception ex) {
  +            log.error("Couldn't render file: " + ex.getMessage());
  +            throw new BuildException(ex);
  +        }
  +    }
  +
  +}
  +
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.4.2.3   +6 -2      xml-fop/test/createpdf.sh
  
  Index: createpdf.sh
  ===================================================================
  RCS file: /home/cvs/xml-fop/test/createpdf.sh,v
  retrieving revision 1.4.2.2
  retrieving revision 1.4.2.3
  diff -u -r1.4.2.2 -r1.4.2.3
  --- createpdf.sh      2 Jun 2002 00:13:26 -0000       1.4.2.2
  +++ createpdf.sh      18 Nov 2002 14:37:47 -0000      1.4.2.3
  @@ -1,8 +1,12 @@
   # this can be used to create pdf output of the testsuite files
   
   
  -$JAVA_HOME/bin/java -cp 
../build/fop.jar:../lib/batik.jar:../lib/xalan-2.3.1.jar:../lib/xercesImpl-2.0.1.jar:../lib/xml-apis.jar:../lib/avalon-framework-4.0.jar:../lib/logkit-1.0.jar:../lib/jimi-1.0.jar
 org.apache.fop.tools.TestConverter -pdf -b ./ basictests.xml
  +LIBDIR=../lib
  
+LOCALCLASSPATH=$LIBDIR/batik.jar:$LIBDIR/xercesImpl-2.0.1.jar:$LIBDIR/xalan-2.3.1.jar:$LIBDIR/xml-apis.jar:$LIBDIR/bsf.jar
  
+LOCALCLASSPATH=$LOCALCLASSPATH:$LIBDIR/jimi-1.0.jar:$LIBDIR/jai_core.jar:$LIBDIR/jai_codec.jar:$LIBDIR/avalon-framework-cvs-20020806.jar:$LIBDIR/logkit-1.0.jar
   
  -$JAVA_HOME/bin/java -cp 
../build/fop.jar:../lib/batik.jar:../lib/xalan-2.3.1.jar:../lib/xercesImpl-2.0.1.jar:../lib/xml-apis.jar:../lib/avalon-framework-4.0.jar:../lib/logkit-1.0.jar:../lib/jimi-1.0.jar
 org.apache.fop.tools.TestConverter -pdf -b ./ bugtests.xml
  +$JAVA_HOME/bin/java -cp ../build/fop.jar:$LOCALCLASSPATH 
org.apache.fop.tools.TestConverter -pdf -b ./ basictests.xml
  +
  +$JAVA_HOME/bin/java -cp ../build/fop.jar:$LOCALCLASSPATH 
org.apache.fop.tools.TestConverter -pdf -b ./ bugtests.xml
   
   
  
  
  

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

Reply via email to