diff --git a/src/main/org/apache/tools/ant/taskdefs/XSLTLogger.java b/src/main/org/apache/tools/ant/taskdefs/XSLTLogger.java index e293b7b1a..aee143ce2 100644 --- a/src/main/org/apache/tools/ant/taskdefs/XSLTLogger.java +++ b/src/main/org/apache/tools/ant/taskdefs/XSLTLogger.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2001 The Apache Software Foundation. All rights + * Copyright (c) 2001-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -54,6 +54,9 @@ package org.apache.tools.ant.taskdefs; +/** + * @since Ant 1.5 + */ public interface XSLTLogger { /** * Log a message. diff --git a/src/main/org/apache/tools/ant/taskdefs/XSLTLoggerAware.java b/src/main/org/apache/tools/ant/taskdefs/XSLTLoggerAware.java index 8ac2ab44f..99b3743c4 100644 --- a/src/main/org/apache/tools/ant/taskdefs/XSLTLoggerAware.java +++ b/src/main/org/apache/tools/ant/taskdefs/XSLTLoggerAware.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2001 The Apache Software Foundation. All rights + * Copyright (c) 2001-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -54,6 +54,9 @@ package org.apache.tools.ant.taskdefs; +/** + * @since Ant 1.5 + */ public interface XSLTLoggerAware { void setLogger(XSLTLogger l); } diff --git a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java index 1ab56536d..231d994f6 100644 --- a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java +++ b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java @@ -71,27 +71,15 @@ import org.xml.sax.EntityResolver; /** * A Task to process via XSLT a set of XML documents. This is * useful for building views of XML based documentation. - * arguments: - * - * Of these arguments, the sourcedir and destdir are required. - *

- * This task will recursively scan the sourcedir and destdir - * looking for XML documents to process via XSLT. Any other files, - * such as images, or html files in the source directory will be - * copied into the destination directory. * * @version $Revision$ * * @author Keith Visco * @author Sam Ruby * @author Russell Gold - * @author Stefan Bodewig + * @author Stefan Bodewig + * + * @since Ant 1.1 * * @ant.task name="style" category="xml" */ @@ -159,13 +147,13 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { /** * Whether to style all files in the included directories as well. * - * @since 1.35, Ant 1.5 + * @since Ant 1.5 */ private boolean performDirectoryScan = true; /** * Creates a new XSLTProcess Task. - **/ + */ public XSLTProcess() { fileUtils = FileUtils.newFileUtils(); } //-- XSLTProcess @@ -174,7 +162,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { * Whether to style all files in the included directories as well. * * @param b true if files in included directories are processed. - * @since 1.35, Ant 1.5 + * @since Ant 1.5 */ public void setScanIncludedDirectories(boolean b) { performDirectoryScan = b; @@ -186,6 +174,8 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { * @exception BuildException if there is an execution problem. */ public void execute() throws BuildException { + File savedBaseDir = baseDir; + DirectoryScanner scanner; String[] list; String[] dirs; @@ -194,74 +184,80 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { throw new BuildException("no stylesheet specified", location); } - if (baseDir == null) { - baseDir = project.resolveFile("."); - } - - liaison = getLiaison(); + try { + if (baseDir == null) { + baseDir = project.resolveFile("."); + } - // check if liaison wants to log errors using us as logger - if (liaison instanceof XSLTLoggerAware) { - ((XSLTLoggerAware)liaison).setLogger(this); - } + liaison = getLiaison(); + + // check if liaison wants to log errors using us as logger + if (liaison instanceof XSLTLoggerAware) { + ((XSLTLoggerAware)liaison).setLogger(this); + } + + log("Using " + liaison.getClass().toString(), Project.MSG_VERBOSE); + + File stylesheet = project.resolveFile(xslFile); + if (!stylesheet.exists()) { + stylesheet = fileUtils.resolveFile(baseDir, xslFile); + /* + * shouldn't throw out deprecation warnings before we know, + * the wrong version has been used. + */ + if (stylesheet.exists()) { + log("DEPRECATED - the style attribute should be relative " + + "to the project\'s"); + log(" basedir, not the tasks\'s basedir."); + } + } - log("Using " + liaison.getClass().toString(), Project.MSG_VERBOSE); + // if we have an in file and out then process them + if (inFile != null && outFile != null) { + process(inFile, outFile, stylesheet); + return; + } - File stylesheet = project.resolveFile(xslFile); - if (!stylesheet.exists()) { - stylesheet = fileUtils.resolveFile(baseDir, xslFile); /* - * shouldn't throw out deprecation warnings before we know, - * the wrong version has been used. + * if we get here, in and out have not been specified, we are + * in batch processing mode. */ - if (stylesheet.exists()) { - log("DEPRECATED - the style attribute should be relative " - + "to the project\'s"); - log(" basedir, not the tasks\'s basedir."); - } - } - - // if we have an in file and out then process them - if (inFile != null && outFile != null) { - process(inFile, outFile, stylesheet); - return; - } - - /* - * if we get here, in and out have not been specified, we are - * in batch processing mode. - */ - //-- make sure Source directory exists... - if (destDir == null ) { - String msg = "destdir attributes must be set!"; - throw new BuildException(msg); - } - scanner = getDirectoryScanner(baseDir); - log("Transforming into " + destDir, Project.MSG_INFO); + //-- make sure Source directory exists... + if (destDir == null ) { + String msg = "destdir attributes must be set!"; + throw new BuildException(msg); + } + scanner = getDirectoryScanner(baseDir); + log("Transforming into " + destDir, Project.MSG_INFO); - // Process all the files marked for styling - list = scanner.getIncludedFiles(); - for (int i = 0; i < list.length; ++i) { - process( baseDir, list[i], destDir, stylesheet ); - } - if (performDirectoryScan) { - // Process all the directories marked for styling - dirs = scanner.getIncludedDirectories(); - for (int j = 0; j < dirs.length; ++j){ - list = new File(baseDir, dirs[j]).list(); - for (int i = 0; i < list.length; ++i) { - process( baseDir, list[i], destDir, stylesheet ); + // Process all the files marked for styling + list = scanner.getIncludedFiles(); + for (int i = 0; i < list.length; ++i) { + process( baseDir, list[i], destDir, stylesheet ); + } + if (performDirectoryScan) { + // Process all the directories marked for styling + dirs = scanner.getIncludedDirectories(); + for (int j = 0; j < dirs.length; ++j){ + list = new File(baseDir, dirs[j]).list(); + for (int i = 0; i < list.length; ++i) { + process( baseDir, list[i], destDir, stylesheet ); + } } } + } finally { + liaison = null; + stylesheetLoaded = false; + baseDir = savedBaseDir; } } //-- execute /** * Set whether to check dependencies, or always generate. * - * @param force true if always generate. - **/ + * @param force true if always generate. + */ public void setForce(boolean force) { this.force = force; } //-- setForce @@ -362,18 +358,15 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { */ private void resolveProcessor(String proc) throws Exception { if (proc.equals("trax")) { - final Class clazz = - loadClass(TRAX_LIAISON_CLASS); + final Class clazz = loadClass(TRAX_LIAISON_CLASS); liaison = (XSLTLiaison)clazz.newInstance(); } else if (proc.equals("xslp")) { log("DEPRECATED - xslp processor is deprecated. Use trax or " + "xalan instead."); - final Class clazz = - loadClass(XSLP_LIASON_CLASS); + final Class clazz = loadClass(XSLP_LIASON_CLASS); liaison = (XSLTLiaison) clazz.newInstance(); } else if (proc.equals("xalan")) { - final Class clazz = - loadClass(XALAN_LIASON_CLASS); + final Class clazz = loadClass(XALAN_LIASON_CLASS); liaison = (XSLTLiaison)clazz.newInstance(); } else { liaison = (XSLTLiaison) loadClass(proc).newInstance(); @@ -519,11 +512,11 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { */ private void ensureDirectoryFor(File targetFile) throws BuildException { - File directory = new File( targetFile.getParent() ); + File directory = fileUtils.getParentFile(targetFile); if (!directory.exists()) { if (!directory.mkdirs()) { throw new BuildException("Unable to create directory: " - + directory.getAbsolutePath() ); + + directory.getAbsolutePath() ); } } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java b/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java index 3a44fcb1e..17cc5d7c7 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java @@ -89,6 +89,7 @@ import javax.xml.transform.sax.SAXSource; * @author Sam Ruby * @author Davanum Srinivas * @author Stephane Bailliez + * @since Ant 1.3 */ public class TraXLiaison implements XSLTLiaison, ErrorListener, XSLTLoggerAware { diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/XalanLiaison.java b/src/main/org/apache/tools/ant/taskdefs/optional/XalanLiaison.java index 4592e60eb..589dafeb4 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/XalanLiaison.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/XalanLiaison.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2001 The Apache Software Foundation. All rights + * Copyright (c) 2000-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -73,6 +73,7 @@ import java.io.IOException; * * @author Sam Ruby * @author Stephane Bailliez + * @since Ant 1.1 */ public class XalanLiaison implements XSLTLiaison { @@ -80,7 +81,7 @@ public class XalanLiaison implements XSLTLiaison { protected File stylesheet; public XalanLiaison() throws Exception { - processor = XSLTProcessorFactory.getProcessor(); + processor = XSLTProcessorFactory.getProcessor(); } public void setStylesheet(File stylesheet) throws Exception { diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/XslpLiaison.java b/src/main/org/apache/tools/ant/taskdefs/optional/XslpLiaison.java index f5d902178..9b2f698b6 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/XslpLiaison.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/XslpLiaison.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2001 The Apache Software Foundation. All rights + * Copyright (c) 2000-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -64,14 +64,12 @@ import java.io.File; import java.io.FileOutputStream; import java.io.OutputStreamWriter; - - - /** * Concrete liaison for XSLP * * @author Sam Ruby * @author Stephane Bailliez + * @since Ant 1.1 */ public class XslpLiaison implements XSLTLiaison { @@ -79,20 +77,21 @@ public class XslpLiaison implements XSLTLiaison { protected XSLStylesheet xslSheet; public XslpLiaison() { - processor = new XSLProcessor(); - // uh ?! I'm forced to do that otherwise a setProperty crashes with NPE ! - // I don't understand why the property map is static though... - // how can we do multithreading w/ multiple identical parameters ? - processor.getProperty("dummy-to-init-properties-map"); + processor = new XSLProcessor(); + // uh ?! I'm forced to do that otherwise a setProperty crashes + // with NPE ! I don't understand why the property map is static + // though... how can we do multithreading w/ multiple identical + // parameters ? + processor.getProperty("dummy-to-init-properties-map"); } public void setStylesheet(File fileName) throws Exception { - XSLReader xslReader = new XSLReader(); - // a file:/// + getAbsolutePath() does not work here - // it is really the pathname - xslSheet = xslReader.read( fileName.getAbsolutePath() ); + XSLReader xslReader = new XSLReader(); + // a file:/// + getAbsolutePath() does not work here + // it is really the pathname + xslSheet = xslReader.read( fileName.getAbsolutePath() ); } - + public void transform(File infile, File outfile) throws Exception { FileOutputStream fos = new FileOutputStream(outfile); // XSLP does not support encoding...we're in hot water. @@ -101,7 +100,7 @@ public class XslpLiaison implements XSLTLiaison { } public void addParam(String name, String expression){ - processor.setProperty(name, expression); + processor.setProperty(name, expression); } public void setOutputtype(String type) throws Exception {