formats are supported output type can be specified by mime type and also handles file sets Submitted by: Jeremias Maerki <jeremias.maerki@outline.ch> git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194479 13f79535-47bb-0310-9956-ffa450edef68tags/fop-0_20_3
@@ -1,73 +1,58 @@ | |||
<?xml version="1.0"?> | |||
<!-- ======================================================================= --> | |||
<!-- JBoss documentation build file --> | |||
<!-- ======================================================================= --> | |||
<project name="FOPDocs" default="docs" basedir="./"> | |||
<target name="init"> | |||
<target name="init"> | |||
<property name="Name" value="FOPDocs"/> | |||
<property name="name" value="fopdocs"/> | |||
<property name="version" value="0.1"/> | |||
<property name="lib.dir" value="${basedir}/lib"/> | |||
<taskdef name="xslt" classname="org.apache.fop.tools.anttasks.Xslt"/> | |||
<taskdef name="fop" classname="org.apache.fop.tools.anttasks.Fop"/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Generate a help screen --> | |||
<!-- =================================================================== --> | |||
<target name="help" depends="init"> | |||
<echo message="${name}-${version} build file, available targets:" /> | |||
<echo message="------------------------------------------------------------" /> | |||
<echo message="main : Compile and prepare deployment directory. " /> | |||
<echo message="pdf : Compile and prepare pdf user docs. "/> | |||
<echo message="clean : Clean deployment and distribution. " /> | |||
<echo message="------------------------------------------------------------" /> | |||
<echo message=" USAGE: build <target> " /> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Prepares the build directory --> | |||
<!-- =================================================================== --> | |||
<target name="prepare" depends="init"> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Generates the pdf documentation --> | |||
<!-- =================================================================== --> | |||
<target name="pdf" depends="prepare"> | |||
<echo message="Building pdf documentation. Please wait ..."/> | |||
<delete file="fop.fo"/> | |||
<xslt infile="fop.xml" xsltfile="docbook/fo/docbook.xsl" | |||
dependent="fop.xml" | |||
outfile="fop.fo" smart="yes"/> | |||
<!-- | |||
<taskdef name="xslt" classname="org.apache.fop.tools.anttasks.Xslt"/> | |||
<taskdef name="fop" classname="org.apache.fop.tools.anttasks.Fop"/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Generate a help screen --> | |||
<!-- =================================================================== --> | |||
<target name="help" depends="init"> | |||
<echo message="${name}-${version} build file, available targets:"/> | |||
<echo message="------------------------------------------------------------"/> | |||
<echo message="main : Compile and prepare deployment directory. "/> | |||
<echo message="pdf : Compile and prepare pdf user docs. "/> | |||
<echo message="clean : Clean deployment and distribution. "/> | |||
<echo message="------------------------------------------------------------"/> | |||
<echo message=" USAGE: build <target> "/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Prepares the build directory --> | |||
<!-- =================================================================== --> | |||
<target name="prepare" depends="init"/> | |||
<!-- =================================================================== --> | |||
<!-- Generates the pdf documentation --> | |||
<!-- =================================================================== --> | |||
<target name="pdf" depends="prepare"> | |||
<echo message="Building pdf documentation. Please wait ..."/> | |||
<delete file="fop.fo"/> | |||
<xslt infile="fop.xml" xsltfile="docbook/fo/docbook.xsl" dependent="fop.xml" outfile="fop.fo" smart="yes"/> | |||
<!-- | |||
<style basedir="./" | |||
destdir="./" | |||
style="docbook/fo/docbook.xsl" | |||
extension=".fo" | |||
includes="fop.xml"/> | |||
--> | |||
<fop fofile="fop.fo" pdffile="fop.pdf"/> | |||
<!-- <delete file="fop.fo"/>--> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Generates pdf and html documentation --> | |||
<!-- =================================================================== --> | |||
<target name="docs" depends="pdf"/> | |||
<!-- =================================================================== --> | |||
<!-- Cleans up generated stuff --> | |||
<!-- =================================================================== --> | |||
<target name="clean" depends="init"> | |||
<delete file="fop.fo"/> | |||
<delete file="fop.pdf"/> | |||
</target> | |||
<fop fofile="fop.fo" outfile="fop.pdf"/> | |||
<!-- <delete file="fop.fo"/>--> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Generates pdf and html documentation --> | |||
<!-- =================================================================== --> | |||
<target name="docs" depends="pdf"/> | |||
<!-- =================================================================== --> | |||
<!-- Cleans up generated stuff --> | |||
<!-- =================================================================== --> | |||
<target name="clean" depends="init"> | |||
<delete file="fop.fo"/> | |||
<delete file="fop.pdf"/> | |||
</target> | |||
</project> | |||
@@ -1,126 +1,126 @@ | |||
<?xml version="1.0"?> | |||
<!-- =========================================================================== --> | |||
<project default="creating new test pdf files" basedir="."> | |||
<!-- =================================================================== --> | |||
<!-- Initialization target --> | |||
<!-- =================================================================== --> | |||
<target name="init"> | |||
<tstamp/> | |||
<mkdir dir="tests"/> | |||
<property name="referenceDir" value="reference"/> | |||
<property name="testDir" value="tests"/> | |||
<property name="foDir" value="fo"/> | |||
<taskdef name="fop" classname="org.apache.fop.tools.anttasks.Fop"/> | |||
<taskdef name="compare" classname="org.apache.fop.tools.anttasks.Compare"/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Help on usage --> | |||
<!-- =================================================================== --> | |||
<target name="usage"> | |||
<echo message=""/> | |||
<echo message=""/> | |||
<echo message="USAGE of runtests"/> | |||
<echo message="-------------------------------------------------------------"/> | |||
<echo message=""/> | |||
<echo message=" available targets are:"/> | |||
<echo message=""/> | |||
<echo message=" compare --> generates new pdf test files and compares them to reference files (default)"/> | |||
<echo message=" reference --> generates new reference pdf files"/> | |||
<echo message=" See the comments inside the build.xml file for more details."/> | |||
<echo message="-------------------------------------------------------------"/> | |||
<echo message=""/> | |||
<echo message=""/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Produces new test pdf files --> | |||
<!-- =================================================================== --> | |||
<target name="creating new test pdf files" depends="init"> | |||
<fop fofile="${foDir}/normal.fo" pdffile="${testDir}/normal.pdf"/> | |||
<fop fofile="${foDir}/table.fo" pdffile="${testDir}/table.pdf"/> | |||
<fop fofile="${foDir}/list.fo" pdffile="${testDir}/list.pdf"/> | |||
<fop fofile="${foDir}/link.fo" pdffile="${testDir}/link.pdf"/> | |||
<fop fofile="${foDir}/newlinktest.fo" pdffile="${testDir}/newlinktest.pdf"/> | |||
<fop fofile="${foDir}/border.fo" pdffile="${testDir}/border.pdf"/> | |||
<fop fofile="${foDir}/extensive.fo" pdffile="${testDir}/extensive.pdf"/> | |||
<fop fofile="${foDir}/images.fo" pdffile="${testDir}/images.pdf"/> | |||
<fop fofile="${foDir}/readme.fo" pdffile="${testDir}/readme.pdf"/> | |||
<fop fofile="${foDir}/fonts.fo" pdffile="${testDir}/fonts.pdf"/> | |||
<fop fofile="${foDir}/leader.fo" pdffile="${testDir}/leader.pdf"/> | |||
<fop fofile="${foDir}/textdeko.fo" pdffile="${testDir}/textdeko.pdf"/> | |||
<fop fofile="${foDir}/inhprop.fo" pdffile="${testDir}/inhprop.pdf"/> | |||
<fop fofile="${foDir}/normalex.fo" pdffile="${testDir}/normalex.pdf"/> | |||
<fop fofile="${foDir}/simple.fo" pdffile="${testDir}/simple.pdf"/> | |||
<!-- <fop fofile="${foDir}/hyphen.fo" pdffile="${testDir}/hyphen.pdf"/> --> | |||
<fop fofile="${foDir}/character.fo" pdffile="${testDir}/character.pdf"/> | |||
<fop fofile="${foDir}/pdfoutline.fo" pdffile="${testDir}/pdfoutline.pdf"/> | |||
<fop fofile="${foDir}/corresprop.fo" pdffile="${testDir}/corresprop.pdf"/> | |||
<fop fofile="${foDir}/bordershorthand.fo" pdffile="${testDir}/bordershorthand.pdf"/> | |||
</target> | |||
<target name="image" depends="init"> | |||
<fop fofile="${foDir}/images.fo" pdffile="${testDir}/images.pdf"/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Compares new test pdf files to reference pdf files --> | |||
<!-- =================================================================== --> | |||
<target name="compare" depends ="creating new test pdf files"> | |||
<compare referenceDirectory = "${referenceDir}" | |||
testDirectory = "${testDir}" | |||
filenames = "normal.pdf,table.pdf,list.pdf,link.pdf,border.pdf,images.pdf,extensive.pdf,readme.pdf,fonts.pdf,list2.pdf"/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Produces new reference pdf files --> | |||
<!-- =================================================================== --> | |||
<target name="reference"> | |||
<fop fofile="${foDir}/normal.fo" pdffile="${referenceDir}/normal.pdf"/> | |||
<fop fofile="${foDir}/table.fo" pdffile="${referenceDir}/table.pdf"/> | |||
<fop fofile="${foDir}/list.fo" pdffile="${referenceDir}/list.pdf"/> | |||
<fop fofile="${foDir}/link.fo" pdffile="${referenceDir}/link.pdf"/> | |||
<fop fofile="${foDir}/newlinktest.fo" pdffile="${referenceDir}/newlinktest.pdf"/> | |||
<fop fofile="${foDir}/border.fo" pdffile="${referenceDir}/border.pdf"/> | |||
<fop fofile="${foDir}/extensive.fo" pdffile="${referenceDir}/extensive.pdf"/> | |||
<fop fofile="${foDir}/images.fo" pdffile="${referenceDir}/images.pdf"/> | |||
<fop fofile="${foDir}/readme.fo" pdffile="${referenceDir}/readme.pdf"/> | |||
<fop fofile="${foDir}/fonts.fo" pdffile="${referenceDir}/fonts.pdf"/> | |||
<fop fofile="${foDir}/leader.fo" pdffile="${referenceDir}/leader.pdf"/> | |||
<fop fofile="${foDir}/textdeko.fo" pdffile="${referenceDir}/textdeko.pdf"/> | |||
<fop fofile="${foDir}/inhprop.fo" pdffile="${referenceDir}/inhprop.pdf"/> | |||
<fop fofile="${foDir}/normalex.fo" pdffile="${referenceDir}/normalex.pdf"/> | |||
<fop fofile="${foDir}/simple.fo" pdffile="${referenceDir}/simple.pdf"/> | |||
<!-- <fop fofile="${foDir}/hyphen.fo" pdffile="${referenceDir}/hyphen.pdf"/> --> | |||
<fop fofile="${foDir}/character.fo" pdffile="${referenceDir}/character.pdf"/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Starts the test --> | |||
<!-- =================================================================== --> | |||
<target name="runtest" depends="compare"> | |||
<echo message="Running Fop tests"/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Clean targets --> | |||
<!-- =================================================================== --> | |||
<target name="clean" depends="init"> | |||
<delete dir="${testDir}"/> | |||
</target> | |||
<project default="newPDF" basedir="."> | |||
<!-- =================================================================== --> | |||
<!-- Initialization target --> | |||
<!-- =================================================================== --> | |||
<target name="init"> | |||
<tstamp/> | |||
<mkdir dir="tests"/> | |||
<property name="referenceDir" value="reference"/> | |||
<property name="testDir" value="tests"/> | |||
<property name="foDir" value="fo"/> | |||
<taskdef name="fop" classname="org.apache.fop.tools.anttasks.Fop"/> | |||
<taskdef name="compare" classname="org.apache.fop.tools.anttasks.Compare"/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Help on usage --> | |||
<!-- =================================================================== --> | |||
<target name="usage"> | |||
<echo message=""/> | |||
<echo message=""/> | |||
<echo message="USAGE of runtests"/> | |||
<echo message="-------------------------------------------------------------"/> | |||
<echo message=""/> | |||
<echo message=" available targets are:"/> | |||
<echo message=""/> | |||
<echo message=" newPDF --> generates new PDF test files (default)"/> | |||
<echo message=" newPS --> generates new PostScript test files"/> | |||
<echo message=" newAT --> generates new AreaTree (XML) test files"/> | |||
<echo message=" comparePDF --> generates new PDF test files and compares them to reference files"/> | |||
<echo message=" referencePDF --> generates new reference PDF files"/> | |||
<echo message=" See the comments inside the build.xml file for more details."/> | |||
<echo message="-------------------------------------------------------------"/> | |||
<echo message=""/> | |||
<echo message=""/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Produces new test pdf files --> | |||
<!-- =================================================================== --> | |||
<target name="newPDF" depends="init"> | |||
<fop fofile="${foDir}/normal.fo" outfile="${testDir}/normal.pdf"/> | |||
<fop fofile="${foDir}/table.fo" outfile="${testDir}/table.pdf"/> | |||
<fop fofile="${foDir}/list.fo" outfile="${testDir}/list.pdf"/> | |||
<fop fofile="${foDir}/link.fo" outfile="${testDir}/link.pdf"/> | |||
<fop fofile="${foDir}/newlinktest.fo" outfile="${testDir}/newlinktest.pdf"/> | |||
<fop fofile="${foDir}/border.fo" outfile="${testDir}/border.pdf"/> | |||
<fop fofile="${foDir}/extensive.fo" outfile="${testDir}/extensive.pdf"/> | |||
<fop fofile="${foDir}/images.fo" outfile="${testDir}/images.pdf"/> | |||
<fop fofile="${foDir}/readme.fo" outfile="${testDir}/readme.pdf"/> | |||
<fop fofile="${foDir}/fonts.fo" outfile="${testDir}/fonts.pdf"/> | |||
<fop fofile="${foDir}/leader.fo" outfile="${testDir}/leader.pdf"/> | |||
<fop fofile="${foDir}/textdeko.fo" outfile="${testDir}/textdeko.pdf"/> | |||
<fop fofile="${foDir}/inhprop.fo" outfile="${testDir}/inhprop.pdf"/> | |||
<fop fofile="${foDir}/normalex.fo" outfile="${testDir}/normalex.pdf"/> | |||
<fop fofile="${foDir}/simple.fo" outfile="${testDir}/simple.pdf"/> | |||
<!-- <fop fofile="${foDir}/hyphen.fo" outfile="${testDir}/hyphen.pdf"/> --> | |||
<fop fofile="${foDir}/character.fo" outfile="${testDir}/character.pdf"/> | |||
<fop fofile="${foDir}/pdfoutline.fo" outfile="${testDir}/pdfoutline.pdf"/> | |||
<fop fofile="${foDir}/corresprop.fo" outfile="${testDir}/corresprop.pdf"/> | |||
<fop fofile="${foDir}/bordershorthand.fo" outfile="${testDir}/bordershorthand.pdf"/> | |||
</target> | |||
<target name="image" depends="init"> | |||
<fop fofile="${foDir}/images.fo" outfile="${testDir}/images.pdf"/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Produces new test ps files --> | |||
<!-- =================================================================== --> | |||
<target name="newPS" depends="init"> | |||
<fop format="application/postscript" outdir="${testDir}"> | |||
<fileset dir="${foDir}"> | |||
<include name="**/*.fo"/> | |||
</fileset> | |||
</fop> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Produces new test areatree files --> | |||
<!-- =================================================================== --> | |||
<target name="newAT" depends="init"> | |||
<fop format="text/xml" outdir="${testDir}"> | |||
<fileset dir="${foDir}"> | |||
<include name="**/*.fo"/> | |||
</fileset> | |||
</fop> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Compares new test pdf files to reference pdf files --> | |||
<!-- =================================================================== --> | |||
<target name="comparePDF" depends="newPDF"> | |||
<compare referenceDirectory="${referenceDir}" testDirectory="${testDir}" filenames="normal.pdf,table.pdf,list.pdf,link.pdf,border.pdf,images.pdf,extensive.pdf,readme.pdf,fonts.pdf,list2.pdf"/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Produces new reference pdf files --> | |||
<!-- =================================================================== --> | |||
<target name="referencePDF"> | |||
<fop fofile="${foDir}/normal.fo" outfile="${referenceDir}/normal.pdf"/> | |||
<fop fofile="${foDir}/table.fo" outfile="${referenceDir}/table.pdf"/> | |||
<fop fofile="${foDir}/list.fo" outfile="${referenceDir}/list.pdf"/> | |||
<fop fofile="${foDir}/link.fo" outfile="${referenceDir}/link.pdf"/> | |||
<fop fofile="${foDir}/newlinktest.fo" outfile="${referenceDir}/newlinktest.pdf"/> | |||
<fop fofile="${foDir}/border.fo" outfile="${referenceDir}/border.pdf"/> | |||
<fop fofile="${foDir}/extensive.fo" outfile="${referenceDir}/extensive.pdf"/> | |||
<fop fofile="${foDir}/images.fo" outfile="${referenceDir}/images.pdf"/> | |||
<fop fofile="${foDir}/readme.fo" outfile="${referenceDir}/readme.pdf"/> | |||
<fop fofile="${foDir}/fonts.fo" outfile="${referenceDir}/fonts.pdf"/> | |||
<fop fofile="${foDir}/leader.fo" outfile="${referenceDir}/leader.pdf"/> | |||
<fop fofile="${foDir}/textdeko.fo" outfile="${referenceDir}/textdeko.pdf"/> | |||
<fop fofile="${foDir}/inhprop.fo" outfile="${referenceDir}/inhprop.pdf"/> | |||
<fop fofile="${foDir}/normalex.fo" outfile="${referenceDir}/normalex.pdf"/> | |||
<fop fofile="${foDir}/simple.fo" outfile="${referenceDir}/simple.pdf"/> | |||
<!-- <fop fofile="${foDir}/hyphen.fo" outfile="${referenceDir}/hyphen.pdf"/> --> | |||
<fop fofile="${foDir}/character.fo" outfile="${referenceDir}/character.pdf"/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Starts the test --> | |||
<!-- =================================================================== --> | |||
<target name="runtest" depends="comparePDF"> | |||
<echo message="Running Fop tests"/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Clean targets --> | |||
<!-- =================================================================== --> | |||
<target name="clean" depends="init"> | |||
<delete dir="${testDir}"/> | |||
</target> | |||
</project> | |||
<!-- End of file --> |
@@ -1,5 +1,4 @@ | |||
<?xml version="1.0"?> | |||
<!-- =========================================================================== | |||
@@ -12,62 +11,45 @@ These are the meaningful targets for this build file: | |||
- clean -> deletes all files produced by this script | |||
--> | |||
<project default="pdf" basedir="."> | |||
<!-- =================================================================== --> | |||
<!-- Initialization target --> | |||
<!-- =================================================================== --> | |||
<target name="init"> | |||
<tstamp/> | |||
<property name="src.dir" value="./fop"/> | |||
<property name="allfiles.xml" value="fop-doc.xml"/> | |||
<property name="outfile.fo" value="fop.fo"/> | |||
<property name="outfile.pdf" value="fop.pdf"/> | |||
<taskdef name="fop" classname="org.apache.fop.tools.anttasks.Fop"/> | |||
<taskdef name="xslt" classname="org.apache.fop.tools.anttasks.Xslt"/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- copies all xml files into one. the infile is a dummy, because the --> | |||
<!-- source files are defined in the stylesheet --> | |||
<!-- =================================================================== --> | |||
<target name="prepare-files" depends="init"> | |||
<xslt infile="fop.xml" xsltfile="xml2xml.xsl" | |||
outfile="${allfiles.xml}" smart="yes"/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Generates the fo file --> | |||
<!-- =================================================================== --> | |||
<target name="fo" depends="prepare-files"> | |||
<xslt infile="${allfiles.xml}" xsltfile="xml2pdf.xsl" | |||
outfile="${outfile.fo}" smart="yes"/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Generates the pdf file --> | |||
<!-- =================================================================== --> | |||
<target name="pdf" depends="fo"> | |||
<fop fofile="${outfile.fo}" pdffile="${outfile.pdf}"/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Clean targets --> | |||
<!-- =================================================================== --> | |||
<target name="clean"> | |||
<delete file="${allfiles.xml}"/> | |||
<delete file="${outfile.fo}"/> | |||
<delete file="${outfile.pdf}"/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Initialization target --> | |||
<!-- =================================================================== --> | |||
<target name="init"> | |||
<tstamp/> | |||
<property name="src.dir" value="./fop"/> | |||
<property name="allfiles.xml" value="fop-doc.xml"/> | |||
<property name="outfile.fo" value="fop.fo"/> | |||
<property name="outfile.pdf" value="fop.pdf"/> | |||
<taskdef name="fop" classname="org.apache.fop.tools.anttasks.Fop"/> | |||
<taskdef name="xslt" classname="org.apache.fop.tools.anttasks.Xslt"/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- copies all xml files into one. the infile is a dummy, because the --> | |||
<!-- source files are defined in the stylesheet --> | |||
<!-- =================================================================== --> | |||
<target name="prepare-files" depends="init"> | |||
<xslt infile="fop.xml" xsltfile="xml2xml.xsl" outfile="${allfiles.xml}" smart="yes"/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Generates the fo file --> | |||
<!-- =================================================================== --> | |||
<target name="fo" depends="prepare-files"> | |||
<xslt infile="${allfiles.xml}" xsltfile="xml2pdf.xsl" outfile="${outfile.fo}" smart="yes"/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Generates the pdf file --> | |||
<!-- =================================================================== --> | |||
<target name="pdf" depends="fo"> | |||
<fop fofile="${outfile.fo}" outfile="${outfile.pdf}"/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Clean targets --> | |||
<!-- =================================================================== --> | |||
<target name="clean"> | |||
<delete file="${allfiles.xml}"/> | |||
<delete file="${outfile.fo}"/> | |||
<delete file="${outfile.pdf}"/> | |||
</target> | |||
</project> | |||
<!-- End of file --> |
@@ -1150,7 +1150,7 @@ public class PDFDocument { | |||
String goToRef = getGoToReference(destination); | |||
PDFOutline obj = new PDFOutline(++this.objectcount, label, goToRef); | |||
System.out.println("created new outline object"); | |||
//log.debug("created new outline object"); | |||
if (parent != null) { | |||
parent.addOutline(obj); |
@@ -9,6 +9,7 @@ package org.apache.fop.tools.anttasks; | |||
// Ant | |||
import org.apache.tools.ant.*; | |||
import org.apache.tools.ant.types.FileSet; | |||
import org.apache.log.*; | |||
import org.apache.log.format.*; | |||
@@ -34,20 +35,23 @@ import org.apache.fop.apps.Driver; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.configuration.Configuration; | |||
/** | |||
* 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>pdffile -> output filename</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>messagelevel -> (info | verbose | debug) level to output non-error messages</li> | |||
* </ul> | |||
*/ | |||
public class Fop extends Task { | |||
File foFile; | |||
File pdfFile; | |||
Vector filesets = new Vector(); | |||
File outFile; | |||
File outDir; | |||
String format; //MIME type | |||
File baseDir; | |||
int messageType = Project.MSG_VERBOSE; | |||
@@ -63,30 +67,58 @@ public class Fop extends Task { | |||
* Gets the input file | |||
*/ | |||
public File getFofile() { | |||
if (foFile == null) { | |||
log("fofile attribute is not set", Project.MSG_ERR); | |||
throw new BuildException("fofile attribute is not set"); | |||
} | |||
return foFile; | |||
} | |||
/** | |||
* Adds a set of fo files (nested fileset attribute). | |||
*/ | |||
public void addFileset(FileSet set) { | |||
filesets.addElement(set); | |||
} | |||
/** | |||
* Sets the output file | |||
* @param File to output to | |||
*/ | |||
public void setPdffile(File pdfFile) { | |||
this.pdfFile = pdfFile; | |||
public void setOutfile(File outFile) { | |||
this.outFile = outFile; | |||
} | |||
/** | |||
* Sets the output file | |||
* Gets the output file | |||
*/ | |||
public File getPdffile() { | |||
if (pdfFile == null) { | |||
log("pdffile attribute is not set", Project.MSG_ERR); | |||
throw new BuildException("pdffile attribute is not set"); | |||
} | |||
return pdfFile; | |||
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; | |||
} | |||
/** | |||
@@ -173,6 +205,58 @@ class FOPTaskStarter extends Starter { | |||
log.setPriority(Priority.INFO); | |||
} | |||
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 { | |||
try { | |||
// Configuration.put("baseDir", task.getBasedir().toURL().toExternalForm()); | |||
@@ -182,31 +266,76 @@ class FOPTaskStarter extends Starter { | |||
task.log("Error setting base directory", Project.MSG_DEBUG); | |||
} | |||
InputHandler inputHandler = new FOInputHandler(task.getFofile()); | |||
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.elementAt(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()); | |||
} | |||
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(); | |||
setParserFeatures(parser); | |||
FileOutputStream pdfOut = null; | |||
FileOutputStream out = null; | |||
try { | |||
pdfOut = new FileOutputStream(task.getPdffile()); | |||
out = new FileOutputStream(outFile); | |||
} catch (Exception ex) { | |||
log.error("Failed to open " + task.getPdffile()); | |||
log.error("Failed to open " + outFile); | |||
throw new BuildException(ex); | |||
} | |||
task.log("Using base directory: " | |||
+ Configuration.getValue("baseDir"), Project.MSG_DEBUG); | |||
task.log(task.getFofile().getName() + " -> " | |||
+ task.getPdffile().getName(), Project.MSG_INFO); | |||
task.log(foFile + " -> " + outFile, Project.MSG_INFO); | |||
try { | |||
Driver driver = new Driver(inputHandler.getInputSource(), pdfOut); | |||
Driver driver = new Driver(inputHandler.getInputSource(), out); | |||
driver.setLogger(log); | |||
driver.setRenderer(Driver.RENDER_PDF); | |||
driver.setRenderer(renderer); | |||
driver.setXMLReader(parser); | |||
driver.run(); | |||
out.close(); | |||
} catch (Exception ex) { | |||
log.error("Couldn't render pdf: " + ex.getMessage()); | |||
log.error("Couldn't render file: " + ex.getMessage()); | |||
throw new BuildException(ex); | |||
} | |||
} |