From 8aa012856f348eb5138de60634712b7460420ad6 Mon Sep 17 00:00:00 2001 From: Kelly Campbell Date: Tue, 16 Jan 2001 08:00:50 +0000 Subject: Packaged build tasks into lib/buildtools.jar Added buildtools.xml for building the build tools jar file. Moved source for ant tasks into src/org/apache/fop/tools/anttasks Set up dual support for Xalan 1 native and Xalan 2 JAXP1.1 transform interfaces. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193970 13f79535-47bb-0310-9956-ffa450edef68 --- build.bat | 2 +- build.sh | 2 +- build.xml | 42 ++- buildtools.xml | 75 +++++ docs/bugtests/build.xml | 4 +- docs/bugtests/runtests.bat | 2 +- docs/bugtests/runtests.sh | 2 +- docs/examples/build.xml | 4 +- docs/examples/results.html | 2 +- docs/examples/runtests.bat | 2 +- docs/examples/runtests.sh | 2 +- docs/examples/svg/build.xml | 4 +- docs/examples/svg/makedoc.bat | 2 +- docs/examples/svg/makedoc.sh | 2 +- docs/xml-docs/build.xml | 4 +- docs/xml-docs/makedoc.bat | 2 +- docs/xml-docs/makedoc.sh | 2 +- lib/buildtools.jar | Bin 0 -> 32598 bytes .../apache/fop/tools/anttasks/TraxTransform.class | Bin 2552 -> 0 bytes .../apache/fop/tools/anttasks/TraxTransform.java | 143 -------- .../fop/tools/anttasks/Xalan1Transform.class | Bin 2733 -> 0 bytes .../apache/fop/tools/anttasks/Xalan1Transform.java | 138 -------- lib/org/apache/fop/tools/anttasks/Xslt.class | Bin 4692 -> 0 bytes lib/org/apache/fop/tools/anttasks/Xslt.java | 356 -------------------- src/org/apache/fop/apps/XalanCommandLine.java | 26 +- src/org/apache/fop/tools/anttasks/Compare.java | 200 +++++++++++ .../apache/fop/tools/anttasks/CompileXMLFiles.java | 296 +++++++++++++++++ src/org/apache/fop/tools/anttasks/Fop.java | 212 ++++++++++++ .../fop/tools/anttasks/SerializeHyphPattern.java | 199 +++++++++++ src/org/apache/fop/tools/anttasks/Xslt.java | 368 +++++++++++++++++++++ src/org/apache/fop/tools/xslt/TraxTransform.java | 160 +++++++++ src/org/apache/fop/tools/xslt/XSLTransform.java | 173 ++++++++++ src/org/apache/fop/tools/xslt/Xalan1Transform.java | 144 ++++++++ 33 files changed, 1896 insertions(+), 674 deletions(-) create mode 100644 buildtools.xml create mode 100644 lib/buildtools.jar delete mode 100644 lib/org/apache/fop/tools/anttasks/TraxTransform.class delete mode 100644 lib/org/apache/fop/tools/anttasks/TraxTransform.java delete mode 100644 lib/org/apache/fop/tools/anttasks/Xalan1Transform.class delete mode 100644 lib/org/apache/fop/tools/anttasks/Xalan1Transform.java delete mode 100644 lib/org/apache/fop/tools/anttasks/Xslt.class delete mode 100644 lib/org/apache/fop/tools/anttasks/Xslt.java create mode 100644 src/org/apache/fop/tools/anttasks/Compare.java create mode 100644 src/org/apache/fop/tools/anttasks/CompileXMLFiles.java create mode 100644 src/org/apache/fop/tools/anttasks/Fop.java create mode 100644 src/org/apache/fop/tools/anttasks/SerializeHyphPattern.java create mode 100644 src/org/apache/fop/tools/anttasks/Xslt.java create mode 100644 src/org/apache/fop/tools/xslt/TraxTransform.java create mode 100644 src/org/apache/fop/tools/xslt/XSLTransform.java create mode 100644 src/org/apache/fop/tools/xslt/Xalan1Transform.java diff --git a/build.bat b/build.bat index 24c5ff862..dc3c46a8e 100755 --- a/build.bat +++ b/build.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\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% diff --git a/build.sh b/build.sh index 56901fbb5..5b6dc2f80 100755 --- a/build.sh +++ b/build.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 +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 diff --git a/build.xml b/build.xml index 6141cf4b0..a345fb5ea 100644 --- a/build.xml +++ b/build.xml @@ -121,8 +121,8 @@ Sometimes ant gives out this warnings, but the build is finished without any pro - - + + @@ -192,17 +192,28 @@ Sometimes ant gives out this warnings, but the build is finished without any pro + + + + + + + + - - + + + + + @@ -290,14 +301,29 @@ Sometimes ant gives out this warnings, but the build is finished without any pro + + + + + + + + + + + - + + excludes="**/Makefile*, **/package.html, **/XT*,**/PDFOutputHandler.java,**/${jimi},**/${jai},**/${pfmreader}"/> @@ -422,7 +448,7 @@ Sometimes ant gives out this warnings, but the build is finished without any pro - + @@ -463,7 +489,7 @@ Sometimes ant gives out this warnings, but the build is finished without any pro - + diff --git a/buildtools.xml b/buildtools.xml new file mode 100644 index 000000000..aa1c96d3c --- /dev/null +++ b/buildtools.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 @@ - - + + 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 @@ - - + + 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 @@ Test Results

Compare Results
-created 02.08.2000 23:33:08

+created Jan 16, 2001 1:40:19 AM
reference filetest fileidentical?
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: - - + + 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: - - + + 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 new file mode 100644 index 000000000..5169b943a Binary files /dev/null and b/lib/buildtools.jar differ diff --git a/lib/org/apache/fop/tools/anttasks/TraxTransform.class b/lib/org/apache/fop/tools/anttasks/TraxTransform.class deleted file mode 100644 index 0f5278c78..000000000 Binary files a/lib/org/apache/fop/tools/anttasks/TraxTransform.class and /dev/null differ diff --git a/lib/org/apache/fop/tools/anttasks/TraxTransform.java b/lib/org/apache/fop/tools/anttasks/TraxTransform.java deleted file mode 100644 index dc9710796..000000000 --- a/lib/org/apache/fop/tools/anttasks/TraxTransform.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * 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 - * . - */ - -package org.apache.fop.tools.anttasks; - -import javax.xml.transform.*; - -import java.io.FileInputStream; -import java.util.Hashtable; -import org.w3c.dom.Document; - -/** - * Handles xslt tranformations via Trax (xalan2) - */ - -public class TraxTransform -{ - /** Cache of compiled stylesheets (filename, StylesheetRoot) */ - private static Hashtable _stylesheetCache = new Hashtable(); - - public static Transformer getTransformer(String xsltFilename) - { - try { - if (_stylesheetCache.containsKey(xsltFilename)) { - Templates cachedStylesheet = (Templates)_stylesheetCache.get(xsltFilename); - return cachedStylesheet.newTransformer(); - } - - Source xslSheet = - new javax.xml.transform.stream.StreamSource (xsltFilename); - - - 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); - return compiledSheet.newTransformer(); - } - catch (TransformerConfigurationException ex) { - ex.printStackTrace(); - } - return null; - - } - - 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) - { - - transform(new javax.xml.transform.dom.DOMSource(xmlSource), - new javax.xml.transform.stream.StreamSource(xslURL), - new javax.xml.transform.stream.StreamResult(outputFile)); - - } - - 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.transform(xmlSource, result); - } - catch (TransformerConfigurationException ex) { - ex.printStackTrace(); - } - catch (TransformerException ex) { - ex.printStackTrace(); - } - - } - -} diff --git a/lib/org/apache/fop/tools/anttasks/Xalan1Transform.class b/lib/org/apache/fop/tools/anttasks/Xalan1Transform.class deleted file mode 100644 index d7e693e8b..000000000 Binary files a/lib/org/apache/fop/tools/anttasks/Xalan1Transform.class and /dev/null differ diff --git a/lib/org/apache/fop/tools/anttasks/Xalan1Transform.java b/lib/org/apache/fop/tools/anttasks/Xalan1Transform.java deleted file mode 100644 index c2a6cef18..000000000 --- a/lib/org/apache/fop/tools/anttasks/Xalan1Transform.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * 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 - * . - */ - -package org.apache.fop.tools.anttasks; - -import org.apache.xalan.xslt.*; - -import java.io.FileInputStream; -import java.util.Hashtable; -import org.w3c.dom.Document; - -/** - * Handles xslt tranformations via Xalan1 (non-trax) - */ - -public class Xalan1Transform -{ - /** Cache of compiled stylesheets (filename, StylesheetRoot) */ - private static Hashtable _stylesheetCache = new Hashtable(); - - public static StylesheetRoot getStylesheet(String xsltFilename) - throws org.xml.sax.SAXException - { - if (_stylesheetCache.containsKey(xsltFilename)) { - return (StylesheetRoot)_stylesheetCache.get(xsltFilename); - } - - // Use XSLTProcessor to instantiate an XSLTProcessor. - org.apache.xalan.xslt.XSLTProcessor processor = - org.apache.xalan.xslt.XSLTProcessorFactory.getProcessor - (new org.apache.xalan.xpath.xdom.XercesLiaison()); - - - org.apache.xalan.xslt.XSLTInputSource xslSheet = - 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); - return compiledSheet; - } - - public static void transform(String xmlSource, String xslURL, - String outputFile) - throws java.io.IOException, - java.net.MalformedURLException, - org.xml.sax.SAXException - { - try { - javax.xml.parsers.DocumentBuilder docBuilder = - javax.xml.parsers.DocumentBuilderFactory.newInstance(). - newDocumentBuilder(); - Document doc = docBuilder.parse(new FileInputStream(xmlSource)); - transform(doc,xslURL,outputFile); - } - catch (javax.xml.parsers.ParserConfigurationException ex){ - throw new org.xml.sax.SAXException(ex); - } - - } - - 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 = - new org.apache.xalan.xslt.XSLTInputSource (xmlSource); - org.apache.xalan.xslt.XSLTResultTarget xmlResult = - new org.apache.xalan.xslt.XSLTResultTarget (outputFile); - - StylesheetRoot stylesheet = getStylesheet(xslURL); - - // Perform the transformation. - stylesheet.process(XSLTProcessorFactory.getProcessor - (new org.apache.xalan.xpath.xdom.XercesLiaison()), - xmlSource, xmlResult); - } - - -} diff --git a/lib/org/apache/fop/tools/anttasks/Xslt.class b/lib/org/apache/fop/tools/anttasks/Xslt.class deleted file mode 100644 index 2c223a664..000000000 Binary files a/lib/org/apache/fop/tools/anttasks/Xslt.class and /dev/null differ diff --git a/lib/org/apache/fop/tools/anttasks/Xslt.java b/lib/org/apache/fop/tools/anttasks/Xslt.java deleted file mode 100644 index d7444dd6e..000000000 --- a/lib/org/apache/fop/tools/anttasks/Xslt.java +++ /dev/null @@ -1,356 +0,0 @@ -/* - * 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 - * . - */ - -package org.apache.fop.tools.anttasks; - -import org.apache.tools.ant.Task; -import java.net.*; -import java.io.*; -import java.util.*; -//import org.apache.xalan.xslt.*; -import org.w3c.dom.*; -import org.xml.sax.SAXException; - - - -/** - * Task to call the XSLT processor Xalan (part of xml.apache.org), which converts xml files - * from a source to an output using a stylesheet file - * - *

- * This task can take the following arguments: - *

    - *
  • infile - *
  • xsltfile - *
  • outfile - *
  • mergefile - *
  • smart - *
  • dependent - *
- *

- * Of these arguments, infile, outfile and xsltfile are required. - *

smart defaults to 'no'. The other allowed value is 'yes'. If smart is set to 'yes' - *

- * xalan is only called if either the outfile is older than the infile or the stylesheet - * or the outfile doesn't exist. - *

- *

dependent defaults to 'none'. Other possible values: a comma delimited list of file names - * which date is checked against the output file. This way you can name files which, if - * they have been modified, initiate a restart of the xslt process, like external entities etc. - *

- * The mergefile parameter causes this task to merge the contents of the specified file into the infile at the end. This is used for the font character mapping generation because the keys() xslt function doesn't work on an external document. - * - * @author Fotis Jannidis fotis@jannidis.de - * @author Kelly A. Campbell camk@camk.net - */ - - -public class Xslt extends Task { - private String infile, outfile, xsltfile, mergefile; - private String smart = "no"; //defaults to do conversion everytime task is called - private String dependent = "none"; //defaults to no dependencies - private boolean startXslt = false; - - /** When true, we use the trax api's from xalan2, otherwise - * just the xalan1 native interfaces - */ - private boolean useTrax = false; - - - /** - * Sets the input file - * - */ - public void setInfile (String infile) { - this.infile = infile; - } - - public void setMergefile (String mergefile) { - this.mergefile = mergefile; - } - - /** - * Sets the stylesheet file - * - */ - public void setXsltfile (String xsltfile) { - this.xsltfile = xsltfile; - } - - /** - * Sets the output file - * - */ - public void setOutfile (String outfile) { - this.outfile = outfile; - } - - /** - * Sets the value for smart - * - * @param option valid values: - *

    - *
  • yes: check whether output file is older than input or stylesheet - *
  • no: (default) do conversion everytime task is called - *
- */ - public void setSmart (String smart) { - this.smart = smart; - } - - /** - * Sets the value for dependent - * - * @param option valid values: - *
    - *
  • none: (default) - *
  • comma delimited list of files whose existence and date is checked - * against the output file - *
- */ - public void setDependent (String dependent) { - this.dependent = dependent; - } - - - /** - * Builds a document from the given file, merging the mergefile onto the end of the root node - */ - private org.w3c.dom.Document buildDocument(String xmlFile) - throws IOException, SAXException { - try { - - javax.xml.parsers.DocumentBuilder docBuilder = - javax.xml.parsers.DocumentBuilderFactory.newInstance(). - newDocumentBuilder(); - Document doc = docBuilder.parse(new FileInputStream(xmlFile)); - - if (mergefile != null && !mergefile.equals("")) { - - File mergefileF = new File(mergefile); - - Document mergedoc = - docBuilder.parse(new FileInputStream(mergefileF)); - Node mergenode = - doc.importNode(mergedoc.getDocumentElement(), true); - doc.getDocumentElement().appendChild(mergenode); - } - - return doc; - } catch (javax.xml.parsers.ParserConfigurationException e) { - System.out.println("Task xslt - SAX ERROR:\n " + - e.getMessage()); - } - return null; - } - - - /** - * Calls Xalan and does the transformation - * - */ - private void transform() { - try { - org.w3c.dom.Document source = buildDocument(infile); - // Perform the transformation. - System.out.println("============================"); - System.out.println("new xslt \nin: " + infile + "\nstyle: " + - 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) { - System.out.println("Task xslt - SAX ERROR:\n " + saxerror); - } - catch (MalformedURLException urlerror) { - System.out.println("Task xslt - URL ERROR:\n " + urlerror); - } - catch (IOException ioerror) { - System.out.println("Task xslt - IO ERROR:\n " + ioerror); - } - - } //end transform - - private boolean isTraxAvailable() - { - try { - // check for trax - Class transformer = Class.forName("javax.xml.transform.Transformer"); - if (transformer != null) { - return true; - } - } - catch (ClassNotFoundException ex){ - return false; - } - return false; - } - - /** - * Checks for existence of output file and compares - * dates with input and stylesheet file - */ - private boolean smartCheck (File outfileF, - long outfileLastModified, File infileF, File xsltfileF) { - - if (outfileF.exists()) { - //checks whether output file is older than input file or xslt stylesheet file - if ((outfileLastModified < infileF.lastModified()) | - (outfileLastModified < xsltfileF.lastModified())) { - return true; - } - } else { - //if output file does not exist, start xslt process - return true; - } - return false; - } //end smartCheck - - /** - * Checks for existence and date of dependent files - * This could be folded together with smartCheck by using - * a general routine but it wouldn't be as fast as now - */ - private boolean dependenciesCheck(File outfileF, - long outfileLastModified) { - String dependentFileName; - File dependentFile; - StringTokenizer tokens = new StringTokenizer(dependent, ","); - while (tokens.hasMoreTokens()) { - dependentFileName = (String) tokens.nextToken(); - dependentFile = new File (dependentFileName); - //check: does dependent file exist - if (dependentFile.exists()) { - //check dates - if ((outfileLastModified < dependentFile.lastModified())) { - return true; - } - } else { - System.err.println( - "Task xslt - ERROR in attribute 'dependent':\n file " + - dependentFileName + " does not exist."); - } - } - return false; - } //end dependenciesCheck - - /** - * Main method, which is called by ant. - * Checks for the value of smart and calls startTransform accordingly - */ - public void execute () throws org.apache.tools.ant.BuildException { - - File outfileF = new File (outfile); - File infileF = new File(infile); - File xsltfileF = new File (xsltfile); - long outfileLastModified = outfileF.lastModified(); - boolean startFileExist = true; - - //checks whether input and stylesheet exist. - //this could be left to the parser, but this solution does make problems if smart is set to yes - if (!infileF.exists()) { - System.err.println( - "Task xslt - ERROR:\n Input file " + infile + - " does not exist!"); - startFileExist = false; - } else if (!xsltfileF.exists()) { - System.err.println( - "Task xslt - ERROR:\n Stylesheet file " + - xsltfile + " does not exist!"); - startFileExist = false; - } - - //checks attribute 'smart' - if (smart.equals("no")) { - startXslt = true; - //if attribute smart = 'yes' - } else if (smart.equals("yes")) { - startXslt = smartCheck (outfileF, outfileLastModified, - infileF, xsltfileF); - //checks dependent files against output file, makes only sense if smartCheck returns false - if (!dependent.equals("none") & (startXslt == false)) { - startXslt = - dependenciesCheck(outfileF, outfileLastModified); - } - //returns error message, if smart has another value as 'yes' or 'no' - } else { - System.err.println("Task xslt - ERROR: Allowed values for the attribute smart are 'yes' or 'no'"); - } - if (startFileExist & startXslt) { - transform(); - } - } //end execute - - //quick access for debugging - //usage XSLT infile xsltfile outfile (smart is 'yes') - /* - public static void main (String args[]) { - Xslt xslt = new Xslt(); - xslt.setInfile(args[0]); - xslt.setXsltfile(args[1]); - xslt.setOutfile(args[2]); - xslt.setSmart("yes"); - xslt.setDependent("test1,test2"); - xslt.execute(); -} */ - - - - -} 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 + * . + */ +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("Test Results\n"); + results.println("

Compare Results
"); + results.println("created " + dateTime + "

"); + results.println("" + + ""); + + + } + + //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(""); + } else { + results.println(""); + } + } + } + results.println("
reference filetest fileidentical?
" + + oldFile.getName() + " " + + newFile.getName() +"" + + " No
" + + oldFile.getName() + " " + + newFile.getName() + "" + + " Yes
"); + } 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 + * . + * + * + */ + +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("\n" + + "\n" + + "]>\n"); + 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(""); + 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 . For more information on the Apache + Software Foundation, please see . + + */ +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
+ * 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 + * . + */ +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/src/org/apache/fop/tools/anttasks/Xslt.java b/src/org/apache/fop/tools/anttasks/Xslt.java new file mode 100644 index 000000000..1b42d9d97 --- /dev/null +++ b/src/org/apache/fop/tools/anttasks/Xslt.java @@ -0,0 +1,368 @@ +/* + * 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 + * . + */ + +package org.apache.fop.tools.anttasks; + +import org.apache.tools.ant.Task; +import java.net.*; +import java.io.*; +import java.util.*; +//import org.apache.xalan.xslt.*; +import org.w3c.dom.*; +import org.xml.sax.SAXException; + + + +/** + * Task to call the XSLT processor Xalan (part of xml.apache.org), which converts xml files + * from a source to an output using a stylesheet file + * + *

+ * This task can take the following arguments: + *

    + *
  • infile + *
  • xsltfile + *
  • outfile + *
  • mergefile + *
  • smart + *
  • dependent + *
+ *

+ * Of these arguments, infile, outfile and xsltfile are required. + *

smart defaults to 'no'. The other allowed value is 'yes'. If smart is set to 'yes' + *

+ * xalan is only called if either the outfile is older than the infile or the stylesheet + * or the outfile doesn't exist. + *

+ *

dependent defaults to 'none'. Other possible values: a comma delimited list of file names + * which date is checked against the output file. This way you can name files which, if + * they have been modified, initiate a restart of the xslt process, like external entities etc. + *

+ * The mergefile parameter causes this task to merge the contents of the specified file into the infile at the end. This is used for the font character mapping generation because the keys() xslt function doesn't work on an external document. + * + * @author Fotis Jannidis fotis@jannidis.de + * @author Kelly A. Campbell camk@camk.net + */ + + +public class Xslt extends Task { + private String infile, outfile, xsltfile, mergefile; + private String smart = "no"; //defaults to do conversion everytime task is called + private String dependent = "none"; //defaults to no dependencies + private boolean startXslt = false; + + /** When true, we use the trax api's from xalan2, otherwise + * just the xalan1 native interfaces + */ + private boolean useTrax = false; + + + /** + * Sets the input file + * + */ + public void setInfile (String infile) { + this.infile = infile; + } + + public void setMergefile (String mergefile) { + this.mergefile = mergefile; + } + + /** + * Sets the stylesheet file + * + */ + public void setXsltfile (String xsltfile) { + this.xsltfile = xsltfile; + } + + /** + * Sets the output file + * + */ + public void setOutfile (String outfile) { + this.outfile = outfile; + } + + /** + * Sets the value for smart + * + * @param option valid values: + *

    + *
  • yes: check whether output file is older than input or stylesheet + *
  • no: (default) do conversion everytime task is called + *
+ */ + public void setSmart (String smart) { + this.smart = smart; + } + + /** + * Sets the value for dependent + * + * @param option valid values: + *
    + *
  • none: (default) + *
  • comma delimited list of files whose existence and date is checked + * against the output file + *
+ */ + public void setDependent (String dependent) { + this.dependent = dependent; + } + + + /** + * Builds a document from the given file, merging the mergefile onto the end of the root node + */ + private org.w3c.dom.Document buildDocument(String xmlFile) + throws IOException, SAXException { + try { + + javax.xml.parsers.DocumentBuilder docBuilder = + javax.xml.parsers.DocumentBuilderFactory.newInstance(). + newDocumentBuilder(); + Document doc = docBuilder.parse(new FileInputStream(xmlFile)); + + if (mergefile != null && !mergefile.equals("")) { + + File mergefileF = new File(mergefile); + + Document mergedoc = + docBuilder.parse(new FileInputStream(mergefileF)); + Node mergenode = + doc.importNode(mergedoc.getDocumentElement(), true); + doc.getDocumentElement().appendChild(mergenode); + } + + return doc; + } catch (javax.xml.parsers.ParserConfigurationException e) { + System.out.println("Task xslt - SAX ERROR:\n " + + e.getMessage()); + } + return null; + } + + + /** + * Calls Xalan and does the transformation + * + */ + private void transform() { + try { + org.w3c.dom.Document source = buildDocument(infile); + // Perform the transformation. + System.out.println("============================"); + System.out.println("new xslt \nin: " + infile + "\nstyle: " + + xsltfile + "\nout: " + outfile); + System.out.println("============================"); + + /* + if (isTraxAvailable()) { + TraxTransform.transform(source, xsltfile, outfile); + } + else { + Xalan1Transform.transform(source, xsltfile, outfile); + } + */ + 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) { + System.out.println("Task xslt - URL ERROR:\n " + urlerror); + } + 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"); + if (transformer != null) { + return true; + } + } + catch (ClassNotFoundException ex){ + return false; + } + return false; + } + */ + + /** + * Checks for existence of output file and compares + * dates with input and stylesheet file + */ + private boolean smartCheck (File outfileF, + long outfileLastModified, File infileF, File xsltfileF) { + + if (outfileF.exists()) { + //checks whether output file is older than input file or xslt stylesheet file + if ((outfileLastModified < infileF.lastModified()) | + (outfileLastModified < xsltfileF.lastModified())) { + return true; + } + } else { + //if output file does not exist, start xslt process + return true; + } + return false; + } //end smartCheck + + /** + * Checks for existence and date of dependent files + * This could be folded together with smartCheck by using + * a general routine but it wouldn't be as fast as now + */ + private boolean dependenciesCheck(File outfileF, + long outfileLastModified) { + String dependentFileName; + File dependentFile; + StringTokenizer tokens = new StringTokenizer(dependent, ","); + while (tokens.hasMoreTokens()) { + dependentFileName = (String) tokens.nextToken(); + dependentFile = new File (dependentFileName); + //check: does dependent file exist + if (dependentFile.exists()) { + //check dates + if ((outfileLastModified < dependentFile.lastModified())) { + return true; + } + } else { + System.err.println( + "Task xslt - ERROR in attribute 'dependent':\n file " + + dependentFileName + " does not exist."); + } + } + return false; + } //end dependenciesCheck + + /** + * Main method, which is called by ant. + * Checks for the value of smart and calls startTransform accordingly + */ + public void execute () throws org.apache.tools.ant.BuildException { + + File outfileF = new File (outfile); + File infileF = new File(infile); + File xsltfileF = new File (xsltfile); + long outfileLastModified = outfileF.lastModified(); + boolean startFileExist = true; + + //checks whether input and stylesheet exist. + //this could be left to the parser, but this solution does make problems if smart is set to yes + if (!infileF.exists()) { + System.err.println( + "Task xslt - ERROR:\n Input file " + infile + + " does not exist!"); + startFileExist = false; + } else if (!xsltfileF.exists()) { + System.err.println( + "Task xslt - ERROR:\n Stylesheet file " + + xsltfile + " does not exist!"); + startFileExist = false; + } + + //checks attribute 'smart' + if (smart.equals("no")) { + startXslt = true; + //if attribute smart = 'yes' + } else if (smart.equals("yes")) { + startXslt = smartCheck (outfileF, outfileLastModified, + infileF, xsltfileF); + //checks dependent files against output file, makes only sense if smartCheck returns false + if (!dependent.equals("none") & (startXslt == false)) { + startXslt = + dependenciesCheck(outfileF, outfileLastModified); + } + //returns error message, if smart has another value as 'yes' or 'no' + } else { + System.err.println("Task xslt - ERROR: Allowed values for the attribute smart are 'yes' or 'no'"); + } + if (startFileExist & startXslt) { + transform(); + } + } //end execute + + //quick access for debugging + //usage XSLT infile xsltfile outfile (smart is 'yes') + /* + public static void main (String args[]) { + Xslt xslt = new Xslt(); + xslt.setInfile(args[0]); + xslt.setXsltfile(args[1]); + xslt.setOutfile(args[2]); + xslt.setSmart("yes"); + xslt.setDependent("test1,test2"); + xslt.execute(); +} */ + + + + +} diff --git a/src/org/apache/fop/tools/xslt/TraxTransform.java b/src/org/apache/fop/tools/xslt/TraxTransform.java new file mode 100644 index 000000000..d93a611be --- /dev/null +++ b/src/org/apache/fop/tools/xslt/TraxTransform.java @@ -0,0 +1,160 @@ +/* + * 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 + * . + */ + +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; + +/** + * Handles xslt tranformations via Trax (xalan2) + */ + +public class TraxTransform +{ + /** Cache of compiled stylesheets (filename, StylesheetRoot) */ + private static Hashtable _stylesheetCache = new Hashtable(); + + public static Transformer getTransformer(String xsltFilename, + boolean cache) + { + try { + if (cache && _stylesheetCache.containsKey(xsltFilename)) { + Templates cachedStylesheet = (Templates)_stylesheetCache.get(xsltFilename); + return cachedStylesheet.newTransformer(); + } + + Source xslSheet = + new javax.xml.transform.stream.StreamSource (xsltFilename); + + + /* System.out.println("****************************"); + System.out.println("trax compile \nin: " + xsltFilename); + System.out.println("****************************"); + */ + TransformerFactory factory = TransformerFactory.newInstance(); + + Templates compiledSheet = + factory.newTemplates(xslSheet); + if (cache) { + _stylesheetCache.put(xsltFilename, compiledSheet); + } + return compiledSheet.newTransformer(); + } + catch (TransformerConfigurationException ex) { + ex.printStackTrace(); + } + return null; + + } + + 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) + { + + transform(new javax.xml.transform.dom.DOMSource(xmlSource), + new javax.xml.transform.stream.StreamSource(xslURL), + new javax.xml.transform.stream.StreamResult(outputFile)); + + } + + public static void transform(String xmlSource, + String xslURL, + Writer output) + { + 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(),true); + } + transformer.transform(xmlSource, result); + } + catch (TransformerConfigurationException ex) { + ex.printStackTrace(); + } + catch (TransformerException ex) { + ex.printStackTrace(); + } + + } + +} 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 + * . + */ + +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. + */ + +package org.apache.fop.tools.xslt; + +import org.apache.xalan.xslt.*; + +import java.io.FileInputStream; +import java.util.Hashtable; +import org.w3c.dom.Document; + +/** + * Handles xslt tranformations via Xalan1 (non-trax) + */ + +public class Xalan1Transform +{ + /** Cache of compiled stylesheets (filename, StylesheetRoot) */ + private static Hashtable _stylesheetCache = new Hashtable(); + + public static StylesheetRoot getStylesheet(String xsltFilename, + boolean cache) + throws org.xml.sax.SAXException + { + if (cache && _stylesheetCache.containsKey(xsltFilename)) { + return (StylesheetRoot)_stylesheetCache.get(xsltFilename); + } + + // Use XSLTProcessor to instantiate an XSLTProcessor. + org.apache.xalan.xslt.XSLTProcessor processor = + org.apache.xalan.xslt.XSLTProcessorFactory.getProcessor + (new org.apache.xalan.xpath.xdom.XercesLiaison()); + + + org.apache.xalan.xslt.XSLTInputSource xslSheet = + 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); + if (cache) { + _stylesheetCache.put(xsltFilename, compiledSheet); + } + return compiledSheet; + } + + public static void transform(String xmlSource, String xslURL, + String outputFile) + throws java.io.IOException, + java.net.MalformedURLException, + org.xml.sax.SAXException + { + try { + javax.xml.parsers.DocumentBuilder docBuilder = + javax.xml.parsers.DocumentBuilderFactory.newInstance(). + newDocumentBuilder(); + Document doc = docBuilder.parse(new FileInputStream(xmlSource)); + transform(doc,xslURL,outputFile); + } + catch (javax.xml.parsers.ParserConfigurationException ex){ + throw new org.xml.sax.SAXException(ex); + } + + } + + 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 = + new org.apache.xalan.xslt.XSLTInputSource (xmlSource); + org.apache.xalan.xslt.XSLTResultTarget xmlResult = + new org.apache.xalan.xslt.XSLTResultTarget (outputFile); + + StylesheetRoot stylesheet = getStylesheet(xslURL,true); + + // Perform the transformation. + stylesheet.process(XSLTProcessorFactory.getProcessor + (new org.apache.xalan.xpath.xdom.XercesLiaison()), + xmlSource, xmlResult); + } + + +} -- cgit v1.2.3