diff options
30 files changed, 1285 insertions, 63 deletions
@@ -6,7 +6,7 @@ echo ---------------- if "%JAVA_HOME%" == "" goto error -set LOCALCLASSPATH=%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\classes.zip;lib\ant.jar;lib\w3c.jar;lib +set LOCALCLASSPATH=%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\classes.zip;lib\ant.jar;lib\w3c.jar;lib\buildtools.jar set ANT_HOME=.\lib echo Building with classpath %LOCALCLASSPATH% @@ -13,7 +13,7 @@ if [ "$JAVA_HOME" = "" ] ; then exit 1 fi -LOCALCLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/classes.zip:./lib/ant.jar:./lib/w3c.jar:./lib +LOCALCLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/classes.zip:./lib/ant.jar:./lib/w3c.jar:./lib/buildtools.jar ANT_HOME=./lib echo Building with classpath $CLASSPATH:$LOCALCLASSPATH @@ -121,8 +121,8 @@ Sometimes ant gives out this warnings, but the build is finished without any pro <tstamp/> <property name="Name" value="Fop"/> <property name="name" value="fop"/> - <property name="version" value="0.15cvs"/> - <property name="year" value="1999-2000"/> + <property name="version" value="0.17cvs"/> + <property name="year" value="1999-2001"/> <echo message="------------------- ${Name} ${version} [${year}] ----------------"/> @@ -192,17 +192,28 @@ Sometimes ant gives out this warnings, but the build is finished without any pro <property name="ZapfDingbats.xml" value="${build.codegen}/ZapfDingbats.xml"/> <property name="Symbol.xml" value="${build.codegen}/Symbol.xml"/> + <property name="xalan1" value="Xalan1Transform.java"/> + <property name="trax" value="TraxTransform.java"/> + <property name="xsltransform" value="XSLTransform.java"/> + <property name="pfmreader" value="PFMReader.java"/> + + <property name="tools.pkg" value="org/apache/fop/tools"/> + + <!-- insert custom font information here (step 1 of 2) --> <!-- use this as a template <property name="myfont.xml" value="${build.codegen}/myfont.xml"/> --> - <taskdef name="serHyph" classname="SerializeHyphPattern"/> - <taskdef name="xslt" classname="Xslt"/> + <taskdef name="serHyph" classname="org.apache.fop.tools.anttasks.SerializeHyphPattern"/> + <taskdef name="xslt" classname="org.apache.fop.tools.anttasks.Xslt"/> <available property="xt.present" classname="com.jclark.xsl.sax.XSLProcessor"/> <available property="jimi.present" classname="com.sun.jimi.core.Jimi"/> <available property="jai.present" classname="javax.media.jai.JAI"/> + <available property="trax.present" classname="javax.xml.transform.Transformer"/> + <available property="xalan1.present" classname="org.apache.xalan.xslt.XSLTProcessor"/> + <filter token="${replacestring}" value="${build.src}/${replacestring}"/> </target> @@ -290,14 +301,29 @@ Sometimes ant gives out this warnings, but the build is finished without any pro </target> + <target name="prepare-xalan1" if="xalan1.present"> + <echo message="Xalan1 is present. Installing Xalan1 support"/> + <copydir src="${src.dir}" + dest="${build.src}" + includes="**/${xsltransform},**/${xalan1},**/${pfmreader}"/> + </target> + + <target name="prepare-trax" if="trax.present"> + <echo message="JAXP1.1 transforms is present. Installing TRaX support"/> + <copydir src="${src.dir}" + dest="${build.src}" + includes="**/${xsltransform},**/${trax}"/> + </target> + + <!-- =================================================================== --> <!-- Prepares the source code --> <!-- =================================================================== --> - <target name="prepare-src" depends="prepare, prepare-xt, prepare-jimi, prepare-jai"> + <target name="prepare-src" depends="prepare, prepare-xt, prepare-jimi, prepare-jai, prepare-xalan1, prepare-trax"> <!-- copy src files --> <copydir src="${src.dir}" dest="${build.src}" - excludes="**/Makefile*, **/package.html, **/XT*,**/PDFOutputHandler.java,**/${jimi},**/${jai}"/> + excludes="**/Makefile*, **/package.html, **/XT*,**/PDFOutputHandler.java,**/${jimi},**/${jai},**/${pfmreader}"/> </target> <!-- =================================================================== --> @@ -422,7 +448,7 @@ Sometimes ant gives out this warnings, but the build is finished without any pro <target name="prepare-docs" depends="init"> <mkdir dir="${build.docs}"/> <!-- sets exec permission for antRun on Unix systems. necessary for javadoc--> - <chmod src="${lib.dir}/bin/antRun" perm="ugo+rx" /> + <chmod file="${lib.dir}/bin/antRun" perm="ugo+rx" /> </target> <!-- =================================================================== --> @@ -463,7 +489,7 @@ Sometimes ant gives out this warnings, but the build is finished without any pro <echo message="Building the distribution files (zip,tar)"/> <mkdir dir="${dist.dir}"/> <copyfile src="${basedir}/build.sh" dest="${dist.dir}/build.sh" /> - <chmod src="${dist.dir}/build.sh" perm="ugo+rx" /> + <chmod file="${dist.dir}/build.sh" perm="ugo+rx" /> <copyfile src="${basedir}/build.bat" dest="${dist.dir}/build.bat" /> <copydir src="${build.dir}" dest="${dist.dir}" excludes="**/classes/**, **/${ignore_this}"/> diff --git a/buildtools.xml b/buildtools.xml new file mode 100644 index 000000000..aa1c96d3c --- /dev/null +++ b/buildtools.xml @@ -0,0 +1,75 @@ +<?xml version="1.0"?> + +<!-- ======================================================================= + + Instructions for building the buildtools.jar: + + Classpath should contain the following: + Xerces 1.2.x + Xalan 1.2.x + Xalan 2.x + xml-fop/lib/ant.jar + + Run "ant -f buildtools.xml" to build a new version of the buildtools jar + +======================================================================= --> + + +<project default="buildtools" basedir="."> + <target name="init"> + <property name="src.dir" value="./src"/> + <property name="build.src" value="./lib/src"/> + <property name="build.dest" value="./lib/classes"/> + + <property name="tools" value="org/apache/fop/tools"/> + <property name="hyph" value="org/apache/fop/layout/hyphenation"/> + <property name="buildtools.jar" value="./lib/buildtools.jar"/> + + <property name="xalan1" value="Xalan1Transform.java"/> + <property name="trax" value="TraxTransform.java"/> + + <available property="trax.present" classname="javax.xml.transform.Transformer"/> + <available property="xalan1.present" classname="org.apache.xalan.xslt.XSLTProcessor"/> + </target> + + <target name="compile" depends="init,prepare.src"> + <mkdir dir="${build.dest}"/> + <javac srcdir="${build.src}" + destdir="${build.dest}"/> + + </target> + + <target name="buildtools" depends="clean,init,compile"> + <echo message="Creating the jar file ${buildtools.jar}"/> + <jar jarfile="${buildtools.jar}" + basedir="${build.dest}" + includes="${tools}/**,${hyph}/**"/> + </target> + + <target name="prepare.src" depends="prepare.xalan1,prepare.trax"> + <copydir src="${src.dir}" + dest="${build.src}" + includes="${tools}/**,${hyph}/**" + excludes="${tools}/anttasks/Fop.java,${hyph}/Hyphenator.java,**/${xalan1},**/${trax}"/> + </target> + + <target name="prepare.xalan1" if="xalan1.present"> + <echo message="Xalan1 is present. Installing Xalan1 support"/> + <copydir src="${src.dir}" + dest="${build.src}" + includes="**/${xalan1}"/> + </target> + + <target name="prepare.trax" if="trax.present"> + <echo message="JAXP1.1 transforms is present. Installing TRaX support"/> + <copydir src="${src.dir}" + dest="${build.src}" + includes="**/${trax}"/> + </target> + + <target name="clean" depends="init"> + <deltree dir="${build.src}"/> + <deltree dir="${build.dest}"/> + </target> + +</project> diff --git a/docs/bugtests/build.xml b/docs/bugtests/build.xml index 806569520..7980daa92 100644 --- a/docs/bugtests/build.xml +++ b/docs/bugtests/build.xml @@ -13,8 +13,8 @@ <property name="referenceDir" value="reference"/> <property name="testDir" value="tests"/> <property name="foDir" value="fo"/> - <taskdef name="fop" classname="Fop"/> - <taskdef name="compare" classname="Compare"/> + <taskdef name="fop" classname="org.apache.fop.tools.anttasks.Fop"/> + <taskdef name="compare" classname="org.apache.fop.tools.anttasks.Compare"/> </target> diff --git a/docs/bugtests/runtests.bat b/docs/bugtests/runtests.bat index ecd04d8dc..8fe5ea89d 100755 --- a/docs/bugtests/runtests.bat +++ b/docs/bugtests/runtests.bat @@ -6,7 +6,7 @@ echo ---------------- if "%JAVA_HOME%" == "" goto error -set LOCALCLASSPATH=%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\classes.zip;..\..\lib\ant.jar;..\..\lib;..\..\lib\w3c.jar;..\..\build\fop.jar +set LOCALCLASSPATH=%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\classes.zip;..\..\lib\ant.jar;..\..\lib\buildtools.jar;..\..\lib\w3c.jar;..\..\build\fop.jar set ANT_HOME=..\..\lib echo Starting Tests ... diff --git a/docs/bugtests/runtests.sh b/docs/bugtests/runtests.sh index 34a2e403c..9e72861f2 100755 --- a/docs/bugtests/runtests.sh +++ b/docs/bugtests/runtests.sh @@ -13,7 +13,7 @@ if [ "$JAVA_HOME" = "" ] ; then exit 1 fi -LOCALCLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/classes.zip:../../lib/ant.jar:../../lib:../../build/fop.jar:../../lib/w3c.jar +LOCALCLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/classes.zip:../../lib/ant.jar:../../lib/buildtools.jar:../../build/fop.jar:../../lib/w3c.jar ANT_HOME=../../lib echo Building with classpath $CLASSPATH:$LOCALCLASSPATH diff --git a/docs/examples/build.xml b/docs/examples/build.xml index 42bd51d87..016227214 100644 --- a/docs/examples/build.xml +++ b/docs/examples/build.xml @@ -13,8 +13,8 @@ <property name="referenceDir" value="reference"/> <property name="testDir" value="tests"/> <property name="foDir" value="fo"/> - <taskdef name="fop" classname="Fop"/> - <taskdef name="compare" classname="Compare"/> + <taskdef name="fop" classname="org.apache.fop.tools.anttasks.Fop"/> + <taskdef name="compare" classname="org.apache.fop.tools.anttasks.Compare"/> </target> diff --git a/docs/examples/results.html b/docs/examples/results.html index b518c3d38..3fefc0e72 100644 --- a/docs/examples/results.html +++ b/docs/examples/results.html @@ -1,6 +1,6 @@ <html><head><title>Test Results</title></head><body> <h2>Compare Results<br> -<font size='1'>created 02.08.2000 23:33:08</font></h2> +<font size='1'>created Jan 16, 2001 1:40:19 AM</font></h2> <table cellpadding='10' border='2'><thead><th align='center'>reference file</th><th align='center'>test file</th><th align='center'>identical?</th></thead> </table></html> diff --git a/docs/examples/runtests.bat b/docs/examples/runtests.bat index ecd04d8dc..8fe5ea89d 100755 --- a/docs/examples/runtests.bat +++ b/docs/examples/runtests.bat @@ -6,7 +6,7 @@ echo ---------------- if "%JAVA_HOME%" == "" goto error -set LOCALCLASSPATH=%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\classes.zip;..\..\lib\ant.jar;..\..\lib;..\..\lib\w3c.jar;..\..\build\fop.jar +set LOCALCLASSPATH=%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\classes.zip;..\..\lib\ant.jar;..\..\lib\buildtools.jar;..\..\lib\w3c.jar;..\..\build\fop.jar set ANT_HOME=..\..\lib echo Starting Tests ... diff --git a/docs/examples/runtests.sh b/docs/examples/runtests.sh index 34a2e403c..9e72861f2 100755 --- a/docs/examples/runtests.sh +++ b/docs/examples/runtests.sh @@ -13,7 +13,7 @@ if [ "$JAVA_HOME" = "" ] ; then exit 1 fi -LOCALCLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/classes.zip:../../lib/ant.jar:../../lib:../../build/fop.jar:../../lib/w3c.jar +LOCALCLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/classes.zip:../../lib/ant.jar:../../lib/buildtools.jar:../../build/fop.jar:../../lib/w3c.jar ANT_HOME=../../lib echo Building with classpath $CLASSPATH:$LOCALCLASSPATH diff --git a/docs/examples/svg/build.xml b/docs/examples/svg/build.xml index 8aa448e78..9578538be 100644 --- a/docs/examples/svg/build.xml +++ b/docs/examples/svg/build.xml @@ -73,8 +73,8 @@ These are the meaningful targets for this build file: <property name="xslt" value="org.apache.xalan.xslt.Process"/> - <taskdef name="fop" classname="Fop"/> - <taskdef name="xslt" classname="Xslt"/> + <taskdef name="fop" classname="org.apache.fop.tools.anttasks.Fop"/> + <taskdef name="xslt" classname="org.apache.fop.tools.anttasks.Xslt"/> </target> diff --git a/docs/examples/svg/makedoc.bat b/docs/examples/svg/makedoc.bat index ce6d65d34..c699a5ed2 100755 --- a/docs/examples/svg/makedoc.bat +++ b/docs/examples/svg/makedoc.bat @@ -5,7 +5,7 @@ echo ---------------- if "%JAVA_HOME%" == "" goto error -set LOCALCLASSPATH=%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\classes.zip;..\..\..\lib\ant.jar;..\..\..\lib\xml.jar;..\..\..\lib;..\..\..\build\fop.jar;..\..\..\lib\w3c.jar +set LOCALCLASSPATH=%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\classes.zip;..\..\..\lib\ant.jar;..\..\..\lib\xml.jar;..\..\..\lib\buildtools.jar;..\..\..\build\fop.jar;..\..\..\lib\w3c.jar set ANT_HOME=..\..\..\lib diff --git a/docs/examples/svg/makedoc.sh b/docs/examples/svg/makedoc.sh index 619733d31..dcf1fd303 100755 --- a/docs/examples/svg/makedoc.sh +++ b/docs/examples/svg/makedoc.sh @@ -13,7 +13,7 @@ if [ "$JAVA_HOME" = "" ] ; then exit 1 fi -LOCALCLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/classes.zip:../../../lib/ant.jar:../../../lib/w3c.jar:../../../lib:../../../build/fop.jar +LOCALCLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/classes.zip:../../../lib/ant.jar:../../../lib/w3c.jar:../../../lib/buildtools.jar:../../../build/fop.jar ANT_HOME=../../../lib echo Building with classpath $CLASSPATH:$LOCALCLASSPATH diff --git a/docs/xml-docs/build.xml b/docs/xml-docs/build.xml index 8be735c05..b66a9310f 100644 --- a/docs/xml-docs/build.xml +++ b/docs/xml-docs/build.xml @@ -27,8 +27,8 @@ These are the meaningful targets for this build file: <property name="outfile.fo" value="fop.fo"/> <property name="outfile.pdf" value="fop.pdf"/> - <taskdef name="fop" classname="Fop"/> - <taskdef name="xslt" classname="Xslt"/> + <taskdef name="fop" classname="org.apache.fop.tools.anttasks.Fop"/> + <taskdef name="xslt" classname="org.apache.fop.tools.anttasks.Xslt"/> </target> diff --git a/docs/xml-docs/makedoc.bat b/docs/xml-docs/makedoc.bat index eac7a1ac3..45b36ba72 100755 --- a/docs/xml-docs/makedoc.bat +++ b/docs/xml-docs/makedoc.bat @@ -6,7 +6,7 @@ echo ---------------- if "%JAVA_HOME%" == "" goto error -set LOCALCLASSPATH=%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\classes.zip;..\..\lib\ant.jar;..\..\lib\xml.jar;..\..\lib\w3c.jar;..\..\lib;..\..\build\fop.jar;..\..\lib\stylebook.jar +set LOCALCLASSPATH=%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\classes.zip;..\..\lib\ant.jar;..\..\lib\xml.jar;..\..\lib\w3c.jar;..\..\lib\buildtools.jar;..\..\build\fop.jar;..\..\lib\stylebook.jar set ANT_HOME=.\lib diff --git a/docs/xml-docs/makedoc.sh b/docs/xml-docs/makedoc.sh index 92b813171..e3859e399 100755 --- a/docs/xml-docs/makedoc.sh +++ b/docs/xml-docs/makedoc.sh @@ -13,7 +13,7 @@ if [ "$JAVA_HOME" = "" ] ; then exit 1 fi -LOCALCLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/classes.zip:../../lib/ant.jar:../../lib/xml.jar:../../lib/w3c.jar:../../lib:../../build/fop.jar:../../lib\stylebook.jar +LOCALCLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/classes.zip:../../lib/ant.jar:../../lib/xml.jar:../../lib/w3c.jar:../../lib/buildtools.jar:../../build/fop.jar:../../lib\stylebook.jar ANT_HOME=../../lib echo Building with classpath $CLASSPATH:$LOCALCLASSPATH diff --git a/lib/buildtools.jar b/lib/buildtools.jar Binary files differnew file mode 100644 index 000000000..5169b943a --- /dev/null +++ b/lib/buildtools.jar diff --git a/lib/org/apache/fop/tools/anttasks/TraxTransform.class b/lib/org/apache/fop/tools/anttasks/TraxTransform.class Binary files differdeleted file mode 100644 index 0f5278c78..000000000 --- a/lib/org/apache/fop/tools/anttasks/TraxTransform.class +++ /dev/null diff --git a/lib/org/apache/fop/tools/anttasks/Xalan1Transform.class b/lib/org/apache/fop/tools/anttasks/Xalan1Transform.class Binary files differdeleted file mode 100644 index d7e693e8b..000000000 --- a/lib/org/apache/fop/tools/anttasks/Xalan1Transform.class +++ /dev/null diff --git a/lib/org/apache/fop/tools/anttasks/Xslt.class b/lib/org/apache/fop/tools/anttasks/Xslt.class Binary files differdeleted file mode 100644 index 2c223a664..000000000 --- a/lib/org/apache/fop/tools/anttasks/Xslt.class +++ /dev/null diff --git a/src/org/apache/fop/apps/XalanCommandLine.java b/src/org/apache/fop/apps/XalanCommandLine.java index a126e305c..e413a9229 100644 --- a/src/org/apache/fop/apps/XalanCommandLine.java +++ b/src/org/apache/fop/apps/XalanCommandLine.java @@ -63,17 +63,20 @@ import org.xml.sax.SAXParseException; import java.io.*; import java.net.URL; +/* // Xalan import org.apache.xalan.xpath.xml.XMLParserLiaison; import org.apache.xalan.xslt.XSLTInputSource; import org.apache.xalan.xslt.XSLTProcessor; import org.apache.xalan.xslt.XSLTProcessorFactory; import org.apache.xalan.xslt.XSLTResultTarget; +*/ // FOP import org.apache.fop.messaging.MessageHandler; import org.apache.fop.configuration.ConfigurationReader; import org.apache.fop.configuration.Configuration; +import org.apache.fop.tools.xslt.XSLTransform; /** * mainline class. @@ -261,24 +264,27 @@ public class XalanCommandLine { } // Use XSLTProcessorFactory to instantiate an XSLTProcessor. - XSLTProcessor processor = XSLTProcessorFactory.getProcessor(); + // XSLTProcessor processor = XSLTProcessorFactory.getProcessor(); // Create the 3 objects the XSLTProcessor needs to perform the transformation. // Fix up the args... - XMLParserLiaison xmlPL = processor.getXMLProcessorLiaison(); - URL urlTmp = xmlPL.getURLFromString(foFile, null); - MessageHandler.errorln("xml: " + urlTmp); - XSLTInputSource xmlSource = + // XMLParserLiaison xmlPL = processor.getXMLProcessorLiaison(); + // URL urlTmp = xmlPL.getURLFromString(foFile, null); + // MessageHandler.errorln("xml: " + urlTmp); + /* XSLTInputSource xmlSource = new XSLTInputSource (urlTmp.toString()); - urlTmp = xmlPL.getURLFromString(xsltFile, null); - MessageHandler.errorln("xslt: " + urlTmp); - XSLTInputSource xslSheet = + */ + // urlTmp = xmlPL.getURLFromString(xsltFile, null); + // MessageHandler.errorln("xslt: " + urlTmp); + /* XSLTInputSource xslSheet = new XSLTInputSource (urlTmp.toString()); XSLTResultTarget xmlResult = new XSLTResultTarget (writer); - + */ // Perform the transformation. - processor.process(xmlSource, xslSheet, xmlResult); + // processor.process(xmlSource, xslSheet, xmlResult); + + XSLTransform.transform(foFile, xsltFile, writer); if (usefile) { reader = new FileReader(pdfFile + ".tmp"); diff --git a/src/org/apache/fop/tools/anttasks/Compare.java b/src/org/apache/fop/tools/anttasks/Compare.java new file mode 100644 index 000000000..effc7fb88 --- /dev/null +++ b/src/org/apache/fop/tools/anttasks/Compare.java @@ -0,0 +1,200 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + */ +package org.apache.fop.tools.anttasks; + + +import java.util.*; +import java.io.*; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.BuildException; +import java.text.DateFormat; + + /** This class is an extension of Ant, a script utility from + * jakarta.apache.org. + * It provides methods to compare two files + */ + +public class Compare { + private String referenceDirectory, testDirectory; + private String [] filenameList; + private String filenames; + private static boolean IDENTICAL_FILES = true; + private static boolean NOTIDENTICAL_FILES = false; + private BufferedInputStream oldfileInput; + private BufferedInputStream newfileInput; + + //sets directory for test files + public void setTestDirectory(String testDirectory) { + if (!(testDirectory.endsWith("/") | testDirectory.endsWith("\\"))) { + testDirectory += File.separator; + } + this.testDirectory = testDirectory; + } + + //sets directory for reference files + public void setReferenceDirectory(String referenceDirectory) { + if (!(referenceDirectory.endsWith("/") | referenceDirectory.endsWith("\\"))) { + referenceDirectory += File.separator; + } + this.referenceDirectory = referenceDirectory; + } + + public void setFilenames (String filenames) { + StringTokenizer tokens = new StringTokenizer(filenames,","); + Vector filenameListTmp = new Vector(20); + while (tokens.hasMoreTokens()) { + filenameListTmp.addElement(tokens.nextToken()); + } + filenameList = new String [filenameListTmp.size()] ; + filenameListTmp.copyInto((String[]) filenameList); + } + + private boolean compareBytes (File oldFile, File newFile) { + try { + oldfileInput = new BufferedInputStream(new FileInputStream(oldFile)); + newfileInput = new BufferedInputStream(new FileInputStream(newFile)); + int charactO = 0; + int charactN = 0; + boolean identical = true; + + while (identical & (charactO != -1)) { + if (charactO == charactN) { + charactO = oldfileInput.read(); + charactN = newfileInput.read(); + } else { + return NOTIDENTICAL_FILES; + } + } + return IDENTICAL_FILES; + } catch (IOException io) { + System.err.println("Task Compare - Error: \n" + io.toString()); + } + return NOTIDENTICAL_FILES; + } + + private boolean compareFileSize(File oldFile, File newFile) { + if (oldFile.length() != newFile.length()) { + return NOTIDENTICAL_FILES; + } else { + return IDENTICAL_FILES; + } + } //end: compareBytes + + private boolean filesExist (File oldFile, File newFile) { + if (!oldFile.exists()) { + System.err.println("Task Compare - ERROR: File " + + referenceDirectory + oldFile.getName() + + " doesn't exist!"); + return false; + } else if (!newFile.exists()) { + System.err.println("Task Compare - ERROR: File " + + testDirectory + newFile.getName() + " doesn't exist!"); + return false; + } else { + return true; + } + } + + public void writeHeader (PrintWriter results) { + String dateTime = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM).format(new Date()); + results.println("<html><head><title>Test Results</title></head><body>\n"); + results.println("<h2>Compare Results<br>"); + results.println("<font size='1'>created " + dateTime + "</font></h2>"); + results.println("<table cellpadding='10' border='2'><thead><th align='center'>reference file</th><th align='center'>test file</th>" + + "<th align='center'>identical?</th></thead>"); + + + } + + //main method of task compare + public void execute () throws BuildException { + boolean identical = false; + File oldFile; + File newFile; + try { + PrintWriter results = new PrintWriter (new FileWriter("results.html"),true); + this.writeHeader(results); + for (int i = 0; i < filenameList.length; i++) { + oldFile = new File (referenceDirectory + filenameList[i]); + newFile = new File (testDirectory + filenameList[i]); + if (filesExist(oldFile, newFile)) { + identical = compareFileSize(oldFile, newFile); + if (identical) { + identical = compareBytes(oldFile,newFile); + } + if (!identical) { + System.out.println("Task Compare: \nFiles " + referenceDirectory + + oldFile.getName()+ " - " + testDirectory + + newFile.getName() + " are *not* identical."); + results.println("<tr><td><a href='" + referenceDirectory + oldFile.getName() + "'>" + + oldFile.getName() + "</a> </td><td> <a href='" + + testDirectory + newFile.getName() +"'>" + + newFile.getName() +"</a>" + + " </td><td><font color='red'>No</font></td></tr>"); + } else { + results.println("<tr><td><a href='" + referenceDirectory + oldFile.getName() + "'>" + + oldFile.getName() + "</a> </td><td> <a href='" + + testDirectory + newFile.getName() + "'>" + + newFile.getName() + "</a>" + + " </td><td>Yes</td></tr>"); + } + } + } + results.println("</table></html>"); + } catch (IOException ioe) { + System.err.println("ERROR: " + ioe); + } + } //end: execute() +} + diff --git a/src/org/apache/fop/tools/anttasks/CompileXMLFiles.java b/src/org/apache/fop/tools/anttasks/CompileXMLFiles.java new file mode 100644 index 000000000..0a9ab2af5 --- /dev/null +++ b/src/org/apache/fop/tools/anttasks/CompileXMLFiles.java @@ -0,0 +1,296 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + * + */ + +package org.apache.fop.tools.anttasks; + + /** This class is an extension of Ant, a script utility from + jakarta.apache.org. + It takes a couple of xml files conforming to the xml-site dtd and + writes them all into one xml file, deleting any reference to + the proprietary protocol sbk. The configFile determines what files + are read in what sequence. + */ +// Ant +import org.apache.tools.ant.Task; +import org.apache.tools.ant.BuildException; + + +// SAX +import org.xml.sax.Parser; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.Locator; +import org.xml.sax.AttributeList; + +// Java +import java.io.*; +import java.util.*; +import java.net.URL; + +public class CompileXMLFiles extends Task + implements org.xml.sax.EntityResolver, + org.xml.sax.DTDHandler, + org.xml.sax.DocumentHandler, + org.xml.sax.ErrorHandler { + private String configFile, outFile; + private String [] filenameList; + private String filenames; + private Vector files = new Vector(); + + //sets name of configuration file, which must + //be an xml file conforming to the book.dtd used by xml-site + public void setConfigFile(String configFile) { + this.configFile = configFile; + } + + public void setOutFile(String outFile) { + this.outFile = outFile; + } + + + //main method of this task + public void execute () throws BuildException { + boolean errors = false; + + if (!(new File(configFile).exists())) { + errors = true; + System.err.println("Task CompileXMLFiles - ERROR: config file " + configFile + " is missing."); + } + + Parser parser = createParser(); + + if (parser == null) { + System.err.println("Task CompileXMLFiles - ERROR: Unable to create SAX parser"); + errors = true; + } + parser.setDocumentHandler(this); + try { + parser.parse(CompileXMLFiles.fileInputSource(configFile)); + } catch (SAXException e) { + System.out.println(e); + } catch (IOException ioe) { + System.out.println(ioe); + } + } //end: execute() + + + /*the following methods belong to the sax parser and implement the Document Handler*/ + public InputSource resolveEntity (String publicId, String systemId) + throws SAXException + { + return null; + } + + public void notationDecl (String name, String publicId, String systemId) + { + // no op + } + + public void unparsedEntityDecl (String name, String publicId, + String systemId, String notationName) + { + // no op + } + + public void setDocumentLocator (Locator locator) + { + // no op + } + + public void startDocument () + throws SAXException + { + // no op + } + + /* After the cnfiguration file has been parsed all files which + have been collected in the ArrayList files are concatinated + and written to a new (temporary) file */ + public void endDocument () + throws SAXException + { + String line, filename; + BufferedReader in; + Enumeration iterator = files.elements(); + try { + BufferedWriter out = + new BufferedWriter (new FileWriter("compileXMLFiles-tmp.xml")); + out.write("<?xml version=\"1.0\"?>\n" + + "<!DOCTYPE documentation [\n" + + "<!ENTITY nbsp \" \">\n" + + "]>\n<documentation>"); + while (iterator.hasMoreElements()) { + filename = (String) iterator.nextElement(); + in = new BufferedReader(new FileReader(filename)); + while ((line = in.readLine()) != null) { + //kill the lines pointing to the sbk protocol and the xml declaration + if (line.indexOf("<!DOCTYPE ")!= -1 || line.indexOf("<?xml ")!= -1 ) { + line = ""; + } + out.write(line+"\n"); + } + out.flush(); + } + out.write("\n</documentation>"); + out.close(); + } catch (Exception e) { + System.out.println(e); + } + + } + + public void startElement (String name, AttributeList atts) + throws SAXException { + String id, label, source; + if (name.equals("document") || name.equals("entry")) { + source = atts.getValue("source"); + files.addElement(source); + } + } + public void endElement (String name) + throws SAXException + { + // no op + } + + public void characters (char ch[], int start, int length) + throws SAXException + { + // no op + } + + public void ignorableWhitespace (char ch[], int start, int length) + throws SAXException + { + // no op + } + public void processingInstruction (String target, String data) + throws SAXException + { + // no op + } + + public void warning (SAXParseException e) + throws SAXException + { + // no op + } + public void error (SAXParseException e) + throws SAXException + { + // no op + } + + public void fatalError (SAXParseException e) + throws SAXException + { + throw e; + } + + /* ------------------------*/ + /** + * creates a SAX parser, using the value of org.xml.sax.parser + * defaulting to org.apache.xerces.parsers.SAXParser + * + * @return the created SAX parser + */ + static Parser createParser() { + String parserClassName = System.getProperty("org.xml.sax.parser"); + if (parserClassName == null) { + parserClassName = "org.apache.xerces.parsers.SAXParser"; + } + System.err.println("using SAX parser " + parserClassName); + + try { + return (Parser) Class.forName(parserClassName).newInstance(); + } catch (ClassNotFoundException e) { + System.err.println("Could not find " + parserClassName); + } catch (InstantiationException e) { + System.err.println("Could not instantiate " + parserClassName); + } catch (IllegalAccessException e) { + System.err.println("Could not access " + parserClassName); + } catch (ClassCastException e) { + System.err.println(parserClassName + " is not a SAX driver"); + } + return null; + } + + /** + * create an InputSource from a file name + * + * @param filename the name of the file + * @return the InputSource created + */ + protected static InputSource fileInputSource(String filename) { + + /* this code adapted from James Clark's in XT */ + File file = new File(filename); + String path = file.getAbsolutePath(); + String fSep = System.getProperty("file.separator"); + if (fSep != null && fSep.length() == 1) + path = path.replace(fSep.charAt(0), '/'); + if (path.length() > 0 && path.charAt(0) != '/') + path = '/' + path; + try { + return new InputSource(new URL("file", null, path).toString()); + } catch (java.net.MalformedURLException e) { + throw new Error("unexpected MalformedURLException"); + } + } + +} + diff --git a/src/org/apache/fop/tools/anttasks/Fop.java b/src/org/apache/fop/tools/anttasks/Fop.java new file mode 100644 index 000000000..25c3946a7 --- /dev/null +++ b/src/org/apache/fop/tools/anttasks/Fop.java @@ -0,0 +1,212 @@ +/* + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "Fop" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ +package org.apache.fop.tools.anttasks; + +// Ant +import org.apache.tools.ant.Task; +import org.apache.tools.ant.BuildException; + + +// 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.net.URL; + +// FOP +import org.apache.fop.messaging.MessageHandler; +import org.apache.fop.apps.*; + +/** + * extension to Ant which allows usage of Fop in the + * same way as org.apache.fop.apps.CommandLine (the code is adapted from this class) + * Gets input and output filenames from the script file <br/> + * needed libraries: Sax 2 parser (defaults to Xerces-J), Jimi for images, w3c.jar + * containing org.w3c.dom.svg etc. for svg support + */ + +public class Fop { + String fofile, pdffile; + + /** + * sets the name of the input file + * @param String name of the input fo file + */ + public void setFofile(String fofile) { + this.fofile = fofile; + } + + /** + * sets the name of the output file + * @param String name of the output pdf file + */ + public void setPdffile(String pdffile) { + this.pdffile = pdffile; + } + + + /** + * creates a SAX parser, using the value of org.xml.sax.parser + * defaulting to org.apache.xerces.parsers.SAXParser + * + * @return the created SAX parser + */ + static XMLReader createParser() { + String parserClassName = System.getProperty("org.xml.sax.parser"); + if (parserClassName == null) { + parserClassName = "org.apache.xerces.parsers.SAXParser"; + } + MessageHandler.logln("using SAX parser " + parserClassName); + + try { + return (XMLReader) Class.forName( + parserClassName).newInstance(); + } catch (ClassNotFoundException e) { + MessageHandler.errorln("Could not find " + parserClassName); + } + catch (InstantiationException e) { + MessageHandler.errorln("Could not instantiate " + + parserClassName); + } + catch (IllegalAccessException e) { + MessageHandler.errorln("Could not access " + parserClassName); + } + catch (ClassCastException e) { + MessageHandler.errorln(parserClassName + " is not a SAX driver"); + } + return null; + } // end: createParser + + /** + * create an InputSource from a file name + * + * @param filename the name of the file + * @return the InputSource created + */ + protected static InputSource fileInputSource(String filename) { + + /* this code adapted from James Clark's in XT */ + File file = new File(filename); + String path = file.getAbsolutePath(); + String fSep = System.getProperty("file.separator"); + if (fSep != null && fSep.length() == 1) + path = path.replace(fSep.charAt(0), '/'); + if (path.length() > 0 && path.charAt(0) != '/') + path = '/' + path; + try { + return new InputSource(new URL("file", null, path).toString()); + } catch (java.net.MalformedURLException e) { + throw new Error("unexpected MalformedURLException"); + } + } // end: fileInputSource + + /** + * main method, starts execution of this task + * + */ + public void execute () throws BuildException { + Driver driver = new Driver(); + driver.setBaseDir(fofile); + boolean errors = false; + String version = Version.getVersion(); + MessageHandler.logln("=======================\nTask " + + version + "\nconverting file " + fofile + " to " + pdffile); + + if (!(new File(fofile).exists())) { + errors = true; + MessageHandler.errorln( + "Task Fop - ERROR: Formatting objects file " + + fofile + " missing."); + } + + XMLReader parser = createParser(); + + if (parser == null) { + MessageHandler.errorln("Task Fop - ERROR: Unable to create SAX parser"); + errors = true; + } + + // setting the parser features + try { + parser.setFeature("http://xml.org/sax/features/namespace-prefixes", + true); + } catch (SAXException e) { + MessageHandler.errorln("Error in setting up parser feature namespace-prefixes"); + MessageHandler.errorln("You need a parser which supports SAX version 2"); + System.exit(1); + } + + if (!errors) { + try { + driver.setRenderer("org.apache.fop.render.pdf.PDFRenderer", + version); + driver.addElementMapping("org.apache.fop.fo.StandardElementMapping"); + driver.addElementMapping("org.apache.fop.svg.SVGElementMapping"); + driver.addPropertyList("org.apache.fop.fo.StandardPropertyListMapping"); + driver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping"); + driver.setOutputStream(new FileOutputStream(pdffile)); + driver.buildFOTree(parser, fileInputSource(fofile)); + driver.format(); + driver.render(); + } catch (Exception e) { + MessageHandler.errorln("Task Fop - FATAL ERROR: " + + e.getMessage()); + System.exit(1); + } + } + MessageHandler.logln("=======================\n"); + } // end: execute +} + diff --git a/src/org/apache/fop/tools/anttasks/SerializeHyphPattern.java b/src/org/apache/fop/tools/anttasks/SerializeHyphPattern.java new file mode 100644 index 000000000..e3477d325 --- /dev/null +++ b/src/org/apache/fop/tools/anttasks/SerializeHyphPattern.java @@ -0,0 +1,199 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + */ +package org.apache.fop.tools.anttasks; + +//package org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.taskdefs.MatchingTask; +import org.apache.tools.ant.DirectoryScanner; +import java.net.*; +import java.io.*; +import java.util.*; +import org.xml.sax.SAXException; + +//fop +import org.apache.fop.layout.hyphenation.HyphenationTree; +import org.apache.fop.layout.hyphenation.HyphenationException; + +/** + * SerializeHyphPattern + */ + + +public class SerializeHyphPattern extends MatchingTask { + private File sourceDir, targetDir; + private boolean errorDump = false; + + /** + * Main method, which is called by ant. + */ + public void execute () throws org.apache.tools.ant.BuildException { + DirectoryScanner ds = this.getDirectoryScanner(sourceDir); + String[] files = ds.getIncludedFiles(); + for (int i = 0; i < files.length ; i++) { + processFile(files[i].substring(0, files[i].length() - 4)); + } + } //end execute + + + /** + * Sets the source directory + * + */ + public void setSourceDir (String sourceDir) { + File dir = new File(sourceDir); + if (!dir.exists()) { + System.err.println("Fatal Error: source directory " + + sourceDir + " for hyphenation files doesn't exist."); + System.exit(1); + } + this.sourceDir = dir; + } + + /** + * Sets the target directory + * + */ + public void setTargetDir (String targetDir) { + File dir = new File(targetDir); + this.targetDir = dir; + } + + /** + * more error information + * + */ + public void setErrorDump (boolean errorDump) { + this.errorDump = errorDump; + } + + + /* + * checks whether input or output files exists or the latter is older than input file + * and start build if necessary + */ + private void processFile (String filename) { + File infile = new File (sourceDir , filename + ".xml"); + File outfile = new File(targetDir , filename + ".hyp"); + long outfileLastModified = outfile.lastModified(); + boolean startProcess = true; + + startProcess = rebuild(infile, outfile); + if (startProcess) { + buildPatternFile(infile, outfile); + } + } + + /* + * serializes pattern files + */ + private void buildPatternFile (File infile, File outfile) { + System.out.println("Processing " + infile); + HyphenationTree hTree = new HyphenationTree(); + try { + hTree.loadPatterns(infile.toString()); + if (errorDump) { + System.out.println("Stats: "); + hTree.printStats(); + } + } catch (HyphenationException ex) { + System.err.println("Can't load patterns from xml file " + + infile + " - Maybe hyphenation.dtd is missing?"); + if (errorDump) { + System.err.println(ex.toString()); + } + } + //serialize class + try { + ObjectOutputStream out = new ObjectOutputStream ( + new FileOutputStream(outfile)); + out.writeObject(hTree); + out.close(); + } catch (IOException ioe) { + System.err.println("Can't write compiled pattern file: " + + outfile); + System.err.println(ioe); + } + } + + /** + * Checks for existence of output file and compares + * dates with input and stylesheet file + */ + private boolean rebuild (File infile, File outfile) { + if (outfile.exists()) { + //checks whether output file is older than input file + if (outfile.lastModified() < infile.lastModified()) { + return true; + } + } else { + //if output file does not exist, start process + return true; + } + return false; + } //end rebuild + +/* + //quick access for debugging + public static void main (String args[]) { + SerializeHyphPattern ser = new SerializeHyphPattern(); + ser.setIncludes("*.xml"); + ser.setSourceDir("\\xml-fop\\hyph\\"); + ser.setTargetDir("\\xml-fop\\hyph\\"); + ser.execute(); + } +*/ + + +} diff --git a/lib/org/apache/fop/tools/anttasks/Xslt.java b/src/org/apache/fop/tools/anttasks/Xslt.java index d7444dd6e..1b42d9d97 100644 --- a/lib/org/apache/fop/tools/anttasks/Xslt.java +++ b/src/org/apache/fop/tools/anttasks/Xslt.java @@ -209,13 +209,18 @@ public class Xslt extends Task { xsltfile + "\nout: " + outfile); System.out.println("============================"); + /* if (isTraxAvailable()) { TraxTransform.transform(source, xsltfile, outfile); } else { Xalan1Transform.transform(source, xsltfile, outfile); } - } catch (org.xml.sax.SAXException saxerror) { + */ + org.apache.fop.tools.xslt.XSLTransform.transform(source,xsltfile,outfile); + + + } catch (org.xml.sax.SAXException saxerror) { System.out.println("Task xslt - SAX ERROR:\n " + saxerror); } catch (MalformedURLException urlerror) { @@ -224,11 +229,17 @@ public class Xslt extends Task { catch (IOException ioerror) { System.out.println("Task xslt - IO ERROR:\n " + ioerror); } - + + catch (Exception ex) { + ex.printStackTrace(); + } + } //end transform + /* private boolean isTraxAvailable() { + try { // check for trax Class transformer = Class.forName("javax.xml.transform.Transformer"); @@ -241,6 +252,7 @@ public class Xslt extends Task { } return false; } + */ /** * Checks for existence of output file and compares diff --git a/lib/org/apache/fop/tools/anttasks/TraxTransform.java b/src/org/apache/fop/tools/xslt/TraxTransform.java index dc9710796..d93a611be 100644 --- a/lib/org/apache/fop/tools/anttasks/TraxTransform.java +++ b/src/org/apache/fop/tools/xslt/TraxTransform.java @@ -52,11 +52,13 @@ * <http://www.apache.org/>. */ -package org.apache.fop.tools.anttasks; +package org.apache.fop.tools.xslt; import javax.xml.transform.*; import java.io.FileInputStream; +import java.io.Writer; + import java.util.Hashtable; import org.w3c.dom.Document; @@ -69,10 +71,11 @@ public class TraxTransform /** Cache of compiled stylesheets (filename, StylesheetRoot) */ private static Hashtable _stylesheetCache = new Hashtable(); - public static Transformer getTransformer(String xsltFilename) + public static Transformer getTransformer(String xsltFilename, + boolean cache) { try { - if (_stylesheetCache.containsKey(xsltFilename)) { + if (cache && _stylesheetCache.containsKey(xsltFilename)) { Templates cachedStylesheet = (Templates)_stylesheetCache.get(xsltFilename); return cachedStylesheet.newTransformer(); } @@ -81,16 +84,17 @@ public class TraxTransform new javax.xml.transform.stream.StreamSource (xsltFilename); - System.out.println("****************************"); + /* System.out.println("****************************"); System.out.println("trax compile \nin: " + xsltFilename); System.out.println("****************************"); - + */ TransformerFactory factory = TransformerFactory.newInstance(); Templates compiledSheet = factory.newTemplates(xslSheet); - - _stylesheetCache.put(xsltFilename, compiledSheet); + if (cache) { + _stylesheetCache.put(xsltFilename, compiledSheet); + } return compiledSheet.newTransformer(); } catch (TransformerConfigurationException ex) { @@ -100,16 +104,18 @@ public class TraxTransform } - public static void transform(String xmlSource, String xslURL, - String outputFile) + public static void transform(String xmlSource, + String xslURL, + String outputFile) { transform(new javax.xml.transform.stream.StreamSource(xmlSource), new javax.xml.transform.stream.StreamSource(xslURL), new javax.xml.transform.stream.StreamResult(outputFile)); } - public static void transform(Document xmlSource, String xslURL, - String outputFile) + public static void transform(Document xmlSource, + String xslURL, + String outputFile) { transform(new javax.xml.transform.dom.DOMSource(xmlSource), @@ -118,16 +124,27 @@ public class TraxTransform } - public static void transform(Source xmlSource, Source xslSource, Result result) + public static void transform(String xmlSource, + String xslURL, + Writer output) { - try { + transform(new javax.xml.transform.stream.StreamSource(xmlSource), + new javax.xml.transform.stream.StreamSource(xslURL), + new javax.xml.transform.stream.StreamResult(output)); + } + + public static void transform(Source xmlSource, + Source xslSource, + Result result) + { + try { Transformer transformer; if (xslSource.getSystemId() == null) { TransformerFactory factory = TransformerFactory.newInstance(); transformer = factory.newTransformer(xslSource); } else { - transformer = getTransformer(xslSource.getSystemId()); + transformer = getTransformer(xslSource.getSystemId(),true); } transformer.transform(xmlSource, result); } diff --git a/src/org/apache/fop/tools/xslt/XSLTransform.java b/src/org/apache/fop/tools/xslt/XSLTransform.java new file mode 100644 index 000000000..0d876158d --- /dev/null +++ b/src/org/apache/fop/tools/xslt/XSLTransform.java @@ -0,0 +1,173 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + */ + +package org.apache.fop.tools.xslt; + +import java.io.Writer; +import java.lang.reflect.*; + + +public class XSLTransform +{ + + public static void transform(String xmlSource, + String xslURL, + String outputFile) + throws Exception + { + Class[] argTypes = {String.class, String.class, String.class}; + Object[] params = {xmlSource, xslURL, outputFile}; + transform(params, argTypes); + } + + public static void transform(org.w3c.dom.Document xmlSource, + String xslURL, + String outputFile) + throws Exception + { + Class[] argTypes = {org.w3c.dom.Document.class, + String.class, String.class}; + + Object[] params = {xmlSource, xslURL, outputFile}; + transform(params, argTypes); + + } + + public static void transform(String xmlSource, + String xslURL, + Writer outputWriter) + throws Exception + { + Class[] argTypes = {String.class, String.class, Writer.class}; + Object[] params = {xmlSource, xslURL, outputWriter}; + transform(params, argTypes); + + } + + + private static void transform(Object[] args, Class[] argTypes) + throws Exception + { + Class transformer = getTransformClass(); + if (transformer != null) { + Method transformMethod = getTransformMethod(transformer,argTypes); + if (transformMethod != null) { + try { + transformMethod.invoke(null, args); + } + catch (InvocationTargetException ex) { + ex.printStackTrace(); + } + } + else { + throw new Exception("transform method not found"); + } + } + else { + throw new Exception("no transformer class found"); + } + + } + + + private static Class getTransformClass() + { + try { + // try trax first + Class transformer = Class.forName("javax.xml.transform.Transformer"); + // ok, make sure we have a liaison to trax + transformer = Class.forName("org.apache.fop.tools.xslt.TraxTransform"); + return transformer; + + } + catch (ClassNotFoundException ex){ + } + // otherwise, try regular xalan1 + try { + Class transformer = Class.forName("org.apache.xalan.xslt.XSLTProcessor"); + // get the liaison + transformer = Class.forName("org.apache.fop.tools.xslt.Xalan1Transform"); + return transformer; + } + catch (ClassNotFoundException ex){ + } + return null; + + } + + + private static Method getTransformMethod(Class c, Class[] argTypes) + { + // System.out.println("transformer class = "+c); + + try { + // Class[] argTypes = new Class[args.length]; + for (int i=0; i<argTypes.length; i++) { + // argTypes[i] = args[i].getClass(); + //System.out.println("arg["+i+"] type = "+argTypes[i]); + + } + + Method transformer = c.getMethod("transform",argTypes); + return transformer; + + } + catch (NoSuchMethodException ex) { + ex.printStackTrace(); + + } + return null; + } + +} diff --git a/lib/org/apache/fop/tools/anttasks/Xalan1Transform.java b/src/org/apache/fop/tools/xslt/Xalan1Transform.java index c2a6cef18..413eb5617 100644 --- a/lib/org/apache/fop/tools/anttasks/Xalan1Transform.java +++ b/src/org/apache/fop/tools/xslt/Xalan1Transform.java @@ -52,7 +52,7 @@ * <http://www.apache.org/>. */ -package org.apache.fop.tools.anttasks; +package org.apache.fop.tools.xslt; import org.apache.xalan.xslt.*; @@ -69,10 +69,11 @@ public class Xalan1Transform /** Cache of compiled stylesheets (filename, StylesheetRoot) */ private static Hashtable _stylesheetCache = new Hashtable(); - public static StylesheetRoot getStylesheet(String xsltFilename) + public static StylesheetRoot getStylesheet(String xsltFilename, + boolean cache) throws org.xml.sax.SAXException { - if (_stylesheetCache.containsKey(xsltFilename)) { + if (cache && _stylesheetCache.containsKey(xsltFilename)) { return (StylesheetRoot)_stylesheetCache.get(xsltFilename); } @@ -86,14 +87,16 @@ public class Xalan1Transform new org.apache.xalan.xslt.XSLTInputSource (xsltFilename); // Perform the transformation. + /* System.out.println("****************************"); System.out.println("new xslt compile \nin: " + xsltFilename); System.out.println("****************************"); - + */ StylesheetRoot compiledSheet = processor.processStylesheet(xslSheet); - - _stylesheetCache.put(xsltFilename, compiledSheet); + if (cache) { + _stylesheetCache.put(xsltFilename, compiledSheet); + } return compiledSheet; } @@ -116,9 +119,12 @@ public class Xalan1Transform } - public static void transform(Document xmlSource, String xslURL, - String outputFile) throws java.io.IOException, - java.net.MalformedURLException, org.xml.sax.SAXException + public static void transform(Document xmlSource, + String xslURL, + String outputFile) + throws java.io.IOException, + java.net.MalformedURLException, + org.xml.sax.SAXException { // Create the 3 objects the XSLTProcessor needs to perform the transformation. org.apache.xalan.xslt.XSLTInputSource source = @@ -126,7 +132,7 @@ public class Xalan1Transform org.apache.xalan.xslt.XSLTResultTarget xmlResult = new org.apache.xalan.xslt.XSLTResultTarget (outputFile); - StylesheetRoot stylesheet = getStylesheet(xslURL); + StylesheetRoot stylesheet = getStylesheet(xslURL,true); // Perform the transformation. stylesheet.process(XSLTProcessorFactory.getProcessor |