Index: src/documentation/content/xdocs/trunk/anttask.xml
===================================================================
--- src/documentation/content/xdocs/trunk/anttask.xml	(revision 937333)
+++ src/documentation/content/xdocs/trunk/anttask.xml	(working copy)
@@ -77,14 +77,29 @@
        <td>xsltfile</td> 
        <td>XSLT input file</td> 
        <td>Yes, if no fofile is specified</td> 
-      </tr> 
+      </tr>
+      <tr>
+       <td>iffile</td>
+       <td>Intermediate format input file</td>
+       <td>Yes, if no fofile is specified</td>
+      </tr>
       <tr> 
        <td>outfile</td> 
        <td>Output filename</td> 
-       <td>Yes, when fofile is used.  (This attribute is not valid for filesets.)</td> 
-      </tr> 
+       <td>Yes, when fofile/iffile is used.  (This attribute is not valid for filesets.)</td>
+      </tr>
+      <tr>
+       <td>inputformat</td>
+       <td>Possible input file formats:<br/>
+         <code>fo (xsl:fo file)</code><br/>
+         <code>if (intermediate format file)</code><br/>
+         <code>at (area tree input file)</code><br/>
+         <code>xml</code><br/>
+       </td>
+       <td>No, defaults to <code>fo (xsl:fo file)</code></td>
+      </tr>
       <tr> 
-       <td>format</td> 
+       <td>outputformat</td>
        <td>Possible output formats:<br/>
          <code>application/X-fop-awt-preview</code><br/>
          <code>application/X-fop-print</code><br/>
@@ -187,7 +202,7 @@
 
     <source><![CDATA[
 <target name="generate-pdf" description="Generates a single PDF file">
-   <fop format="application/pdf" 
+   <fop outputformat="application/pdf"
         fofile="c:\working\foDirectory\foDocument.fo"
         outfile="c:\working\pdfDirectory\pdfDocument.pdf" />
 </target>
@@ -198,7 +213,7 @@
     <source><![CDATA[
 <target name="generate-multiple-ps" 
         description="Generates multiple PostScript files">
-   <fop format="application/postscript" 
+   <fop outputformat="application/postscript"
         outdir="${build.dir}" messagelevel="debug">
         <fileset dir="${fo.examples.dir}">
            <include name="*.fo"/>
@@ -211,7 +226,7 @@
     </p>
     <source><![CDATA[
 <target name="generate-afp-from-transform" description="Generates a single AFP file from an XSLT stylesheet">
-   <fop format="application/x-afp" 
+   <fop outputformat="application/x-afp"
         xmlfile="c:\working\foDirectory\Document.xml"
         xsltfile="c:\working\foDirectory\Document.xslt"
         outfile="c:\working\afpDirectory\Document.afp" />
@@ -222,7 +237,7 @@
     </p>
     <source><![CDATA[
 <target name="generate-multiple-ps-from-transform" description="Generates multiple PostScript files using an XSLT stylesheet">
-   <fop format="application/postscript" 
+   <fop outputformat="application/postscript"
         xsltfile="c:\working\foDirectory\Document.xslt"
         outdir="${build.dir}" messagelevel="debug">
         <fileset dir="${test.dir}">
@@ -231,6 +246,30 @@
    </fop>
 </target>
     ]]></source>
+    <p>
+    This example transforms and converts the intermediate format file to PostScript output file:
+    </p>
+    <source><![CDATA[
+<target name="generate-ps-from-intermediate-format" description="Generates PostScript file using an intermediate format file">
+   <fop outputformat="application/postscript"
+        iffile="c:\working\ifDirectory\ifDocument.if"
+        outfile="c:\working\psDirectory\psDocument.ps" />
+</target>
+    ]]></source>
+    <p>
+    This example transforms and converts all intermediate format files within an entire directory to PostScript:
+    </p>
+    <source><![CDATA[
+<target name="generate-multiple-ps-from-intermediate-format" description="Generates multiple PostScript files using an intermediate format files">
+   <fop outputformat="application/postscript"
+        inputformat="if"
+        outdir="${build.dir}" messagelevel="debug">
+        <fileset dir="${test.dir}">
+           <include name="*.if.xml"/>
+        </fileset>
+   </fop>
+</target>
+    ]]></source>
     </section>
     </body>
 </document>
Index: src/java/org/apache/fop/tools/anttasks/Fop.java
===================================================================
--- src/java/org/apache/fop/tools/anttasks/Fop.java	(revision 937333)
+++ src/java/org/apache/fop/tools/anttasks/Fop.java	(working copy)
@@ -42,6 +42,7 @@
 import org.apache.fop.apps.FopFactory;
 import org.apache.fop.apps.MimeConstants;
 import org.apache.fop.cli.InputHandler;
+import org.apache.fop.cli.IFInputHandler;
 
 import org.apache.commons.logging.impl.SimpleLog;
 import org.apache.commons.logging.Log;
@@ -52,7 +53,9 @@
  * 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>iffile -> intermediate format input file to be transformed</li>
+ * <li>outputFormat -> MIME type of the format to generate ex. "application/pdf"</li>
+ * <li>inputFormat -> Input file format (like "fo","xml","if")</li>
  * <li>outfile -> output filename</li>
  * <li>baseDir -> directory to work from</li>
  * <li>relativebase -> (true | false) control whether to use each FO's
@@ -68,13 +71,15 @@
 public class Fop extends Task {
 
     private File foFile;
+    private File ifFile;
     private File xmlFile;
     private File xsltFile;
     private String xsltParams;
     private List/*<FileSet>*/ filesets = new java.util.ArrayList/*<FileSet>*/();
     private File outFile;
     private File outDir;
-    private String format; //MIME type
+    private String outputFormat; //output file type
+    private String inputFormat; //input file type
     private File baseDir;
     private File userConfig;
     private int messageType = Project.MSG_VERBOSE;
@@ -116,6 +121,22 @@
     }
 
     /**
+     * Sets the input intermediate format file alternative to XSL-FO file.
+     * @param ifFile input Intermeidate format file
+     */
+    public void setIffile(File ifFile) {
+        this.ifFile = ifFile;
+    }
+
+    /**
+     * Gets the input intermediate format file.
+     * @return input intermediate format file
+     */
+    public File getIffile() {
+        return ifFile;
+    }
+
+    /**
      * Gets the input XML file.
      * @return the input XML file.
      */
@@ -252,23 +273,39 @@
      * Sets output format (MIME type).
      * @param format the output format
      */
-    public void setFormat(String format) {
-        this.format = format;
+    public void setOutputFormat(String format) {
+        this.outputFormat = format;
     }
 
     /**
      * Gets the output format (MIME type).
      * @return the output format
      */
-    public String getFormat() {
-        return this.format;
+    public String getOutputFormat() {
+        return this.outputFormat;
     }
 
     /**
+     * Sets input file type (fo,if, and xml).
+     * @param filetype the output format
+     */
+    public void setInputFormat(String filetype) {
+        this.inputFormat = filetype;
+    }
+
+    /**
+     * Gets the input file type (fo,if, and xml).
+     * @return the input file type
+     */
+    public String getInputFormat() {
+        return this.inputFormat;
+    }
+
+    /**
      * Set whether exceptions are thrown.
      * default is false.
      *
-     * @param force true if always generate.
+     * @param throwExceptions true if always generate.
      */
     public void setThrowexceptions(boolean throwExceptions) {
         this.throwExceptions = throwExceptions;
@@ -309,6 +346,7 @@
      * Returns the message type corresponding to Project.MSG_*
      * representing the current message level.
      * @see org.apache.tools.ant.Project
+     * @return int integer
      */
     public int getMessageType() {
         return messageType;
@@ -351,7 +389,7 @@
      * {@inheritDoc}
      */
     public void execute() throws BuildException {
-        int logLevel = SimpleLog.LOG_LEVEL_INFO;
+        int logLevel;
         switch (getMessageType()) {
             case Project.MSG_DEBUG  : logLevel = SimpleLog.LOG_LEVEL_DEBUG; break;
             case Project.MSG_INFO   : logLevel = SimpleLog.LOG_LEVEL_INFO; break;
@@ -422,6 +460,7 @@
         {"rtf",  MimeConstants.MIME_RTF},
         {"pcl",  MimeConstants.MIME_PCL},
         {"txt",  MimeConstants.MIME_PLAIN_TEXT},
+        {"if",   MimeConstants.MIME_FOP_IF},
         {"at",   MimeConstants.MIME_FOP_AREA_TREE},
         {"xml",  MimeConstants.MIME_FOP_AREA_TREE},
         {"tiff", MimeConstants.MIME_TIFF},
@@ -444,6 +483,7 @@
 
     private static final String[][] EXTENSIONS = {
         {MimeConstants.MIME_FOP_AREA_TREE,   ".at.xml"},
+        {MimeConstants.MIME_FOP_IF,   ".if.xml"},
         {MimeConstants.MIME_FOP_AWT_PREVIEW, null},
         {MimeConstants.MIME_FOP_PRINT,       null},
         {MimeConstants.MIME_PDF,             ".pdf"},
@@ -464,6 +504,13 @@
         {MimeConstants.MIME_XSL_FO,          ".fo"}
     };
 
+    private static final String[][] FILE_EXTENSIONS = {
+        {"at",  ".at.xml"},
+        {"if",  ".if.xml"},
+        {"fo",  ".fo"},
+        {"xml",  ".xml"}
+    };
+
     private String determineExtension(String outputFormat) {
         for (int i = 0; i < EXTENSIONS.length; i++) {
             if (EXTENSIONS[i][0].equals(outputFormat)) {
@@ -479,6 +526,25 @@
         return ".unk"; //unknown
     }
 
+    private String determineInputFileExtension(String inputType) {
+        if (inputType == null){
+            task.log("inputFormat attribute not specified, using 'fo' as default.", Project.MSG_INFO);
+            inputType = "fo"; //defaults to xsl:fo document
+        }
+        for (int i = 0; i < FILE_EXTENSIONS.length; i++) {
+            if (FILE_EXTENSIONS[i][0].equals(inputType)) {
+                String ext = FILE_EXTENSIONS[i][1];
+                if (ext == null) {
+                    throw new RuntimeException("Input file type '"
+                            + inputType + "' not allowed.");
+                } else {
+                    return ext;
+                }
+            }
+        }
+        return inputType;
+    }
+
     private File replaceExtension(File file, String expectedExt,
                                   String newExt) {
         String name = file.getName();
@@ -500,20 +566,24 @@
             } catch (MalformedURLException mfue) {
                 logger.error("Error creating base URL from base directory", mfue);
             }
-        } else {
+        } else if (task.getFofile() != null) {
             try {
-                if (task.getFofile() != null) {
                     this.baseURL =  task.getFofile().getParentFile().toURI().toURL().
                                       toExternalForm();
-                }
             } catch (MalformedURLException mfue) {
                 logger.error("Error creating base URL from XSL-FO input file", mfue);
             }
+        } else if (task.getIffile() != null) {
+            try {
+                    this.baseURL =  task.getIffile().getParentFile().toURI().toURL().
+                                      toExternalForm();
+            } catch (MalformedURLException mfue) {
+                logger.error("Error creating base URL from intermediate format input file", mfue);
+            }
         }
 
         task.log("Using base URL: " + baseURL, Project.MSG_DEBUG);
-
-        String outputFormat = normalizeOutputFormat(task.getFormat());
+        String outputFormat = normalizeOutputFormat(task.getOutputFormat());
         String newExtension = determineExtension(outputFormat);
 
         // actioncount = # of fofiles actually processed through FOP
@@ -547,7 +617,7 @@
             if (task.getXmlFile().exists() && task.getXsltFile().exists()) {
                 File outf = task.getOutfile();
                 if (outf == null) {
-                    throw new BuildException("outfile is required when fofile is used");
+                    throw new BuildException("outfile is required when xmlFile and xsltFile are used");
                 }
                 if (task.getOutdir() != null) {
                     outf = new File(task.getOutdir(), outf.getName());
@@ -566,15 +636,40 @@
                     skippedcount++;
                 }
             }
+        } else if (task.getIffile() != null) {
+            if (task.getIffile().exists()) {
+                File outf = task.getOutfile();
+                if (outf == null) {
+                    throw new BuildException("outfile is required when iffile is used");
+                }
+                if (task.getOutdir() != null) {
+                    outf = new File(task.getOutdir(), outf.getName());
+                }
+                // Render if "force" flag is set OR
+                // OR output file doesn't exist OR
+                // output file is older than input file
+                if (task.getForce() || !outf.exists()
+                    || (task.getIffile().lastModified() > outf.lastModified())) {
+                    render(task.getIffile(), outf, outputFormat);
+                    actioncount++;
+                } else if (outf.exists()
+                        && (task.getIffile().lastModified() <= outf.lastModified())) {
+                    skippedcount++;
+                }
+            }
         }
 
         GlobPatternMapper mapper = new GlobPatternMapper();
 
-        String inputExtension = ".fo";
+        String inputExtension = determineInputFileExtension(task.getInputFormat());
         File xsltFile = task.getXsltFile();
         if (xsltFile != null) {
             inputExtension = ".xml";
         }
+//        File ifFile = task.getIffile();
+//        if (ifFile != null) {
+//            inputExtension = ".if.xml";
+//        }
         mapper.setFrom("*" + inputExtension);
         mapper.setTo("*" + newExtension);
 
@@ -587,7 +682,7 @@
             for (int j = 0; j < files.length; j++) {
                 File f = new File(fs.getDir(task.getProject()), files[j]);
 
-                File outf = null;
+                File outf;
                 if (task.getOutdir() != null && files[j].endsWith(inputExtension)) {
                   String[] sa = mapper.mapFileName(files[j]);
                   outf = new File(task.getOutdir(), sa[0]);
@@ -634,7 +729,7 @@
 
         if (actioncount + skippedcount == 0) {
             task.log("No files processed. No files were selected by the filesets "
-                + "and no fofile was set." , Project.MSG_WARN);
+                + "and no fofile/iffile was set." , Project.MSG_WARN);
         } else if (skippedcount > 0) {
             task.log(skippedcount + " xslfo file(s) skipped (no change found"
                 + " since last generation; set force=\"true\" to override)."
@@ -643,7 +738,7 @@
     }
 
     private void renderInputHandler(InputHandler inputHandler, File outFile, String outputFormat) throws Exception {
-        OutputStream out = null;
+        OutputStream out;
         try {
             out = new java.io.FileOutputStream(outFile);
             out = new BufferedOutputStream(out);
@@ -673,16 +768,21 @@
         }
     }
 
-    private void render(File foFile, File outFile,
+    private void render(File inputFile, File outFile,
                         String outputFormat) throws FOPException {
-        InputHandler inputHandler = new InputHandler(foFile);
+        InputHandler inputHandler;
+        if (task.getIffile() == null) {
+            inputHandler = new InputHandler(inputFile);
+        } else {
+            inputHandler = new IFInputHandler(inputFile);
+        }
         try {
             renderInputHandler(inputHandler, outFile, outputFormat);
         } catch (Exception ex) {
-            logger.error("Error rendering fo file: " + foFile, ex);
+            logger.error("Error rendering input file: " + inputFile, ex);
         }
         if (task.getLogFiles()) {
-            task.log(foFile + " -> " + outFile, Project.MSG_INFO);
+            task.log(inputFile + " -> " + outFile, Project.MSG_INFO);
         }
     }
 
