Browse Source

Make sure <style> resets its state - may even help the garbage collector.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272403 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
ca5695fa0b
6 changed files with 98 additions and 98 deletions
  1. +4
    -1
      src/main/org/apache/tools/ant/taskdefs/XSLTLogger.java
  2. +4
    -1
      src/main/org/apache/tools/ant/taskdefs/XSLTLoggerAware.java
  3. +72
    -79
      src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
  4. +1
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
  5. +3
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/XalanLiaison.java
  6. +14
    -15
      src/main/org/apache/tools/ant/taskdefs/optional/XslpLiaison.java

+ 4
- 1
src/main/org/apache/tools/ant/taskdefs/XSLTLogger.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * 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. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -54,6 +54,9 @@


package org.apache.tools.ant.taskdefs; package org.apache.tools.ant.taskdefs;


/**
* @since Ant 1.5
*/
public interface XSLTLogger { public interface XSLTLogger {
/** /**
* Log a message. * Log a message.


+ 4
- 1
src/main/org/apache/tools/ant/taskdefs/XSLTLoggerAware.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * 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. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -54,6 +54,9 @@


package org.apache.tools.ant.taskdefs; package org.apache.tools.ant.taskdefs;


/**
* @since Ant 1.5
*/
public interface XSLTLoggerAware { public interface XSLTLoggerAware {
void setLogger(XSLTLogger l); void setLogger(XSLTLogger l);
} }

+ 72
- 79
src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java View File

@@ -71,27 +71,15 @@ import org.xml.sax.EntityResolver;
/** /**
* A Task to process via XSLT a set of XML documents. This is * A Task to process via XSLT a set of XML documents. This is
* useful for building views of XML based documentation. * useful for building views of XML based documentation.
* arguments:
* <ul>
* <li>basedir
* <li>destdir
* <li>style
* <li>includes
* <li>excludes
* </ul>
* Of these arguments, the <b>sourcedir</b> and <b>destdir</b> are required.
* <p>
* 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$ * @version $Revision$
* *
* @author <a href="mailto:kvisco@exoffice.com">Keith Visco</a> * @author <a href="mailto:kvisco@exoffice.com">Keith Visco</a>
* @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a> * @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a>
* @author <a href="mailto:russgold@acm.org">Russell Gold</a> * @author <a href="mailto:russgold@acm.org">Russell Gold</a>
* @author <a href="stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*
* @since Ant 1.1
* *
* @ant.task name="style" category="xml" * @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. * 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; private boolean performDirectoryScan = true;


/** /**
* Creates a new XSLTProcess Task. * Creates a new XSLTProcess Task.
**/
*/
public XSLTProcess() { public XSLTProcess() {
fileUtils = FileUtils.newFileUtils(); fileUtils = FileUtils.newFileUtils();
} //-- XSLTProcess } //-- XSLTProcess
@@ -174,7 +162,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* Whether to style all files in the included directories as well. * Whether to style all files in the included directories as well.
* *
* @param b true if files in included directories are processed. * @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) { public void setScanIncludedDirectories(boolean b) {
performDirectoryScan = b; performDirectoryScan = b;
@@ -186,6 +174,8 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @exception BuildException if there is an execution problem. * @exception BuildException if there is an execution problem.
*/ */
public void execute() throws BuildException { public void execute() throws BuildException {
File savedBaseDir = baseDir;

DirectoryScanner scanner; DirectoryScanner scanner;
String[] list; String[] list;
String[] dirs; String[] dirs;
@@ -194,74 +184,80 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
throw new BuildException("no stylesheet specified", location); 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 } //-- execute
/** /**
* Set whether to check dependencies, or always generate. * 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) { public void setForce(boolean force) {
this.force = force; this.force = force;
} //-- setForce } //-- setForce
@@ -362,18 +358,15 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*/ */
private void resolveProcessor(String proc) throws Exception { private void resolveProcessor(String proc) throws Exception {
if (proc.equals("trax")) { if (proc.equals("trax")) {
final Class clazz =
loadClass(TRAX_LIAISON_CLASS);
final Class clazz = loadClass(TRAX_LIAISON_CLASS);
liaison = (XSLTLiaison)clazz.newInstance(); liaison = (XSLTLiaison)clazz.newInstance();
} else if (proc.equals("xslp")) { } else if (proc.equals("xslp")) {
log("DEPRECATED - xslp processor is deprecated. Use trax or " log("DEPRECATED - xslp processor is deprecated. Use trax or "
+ "xalan instead."); + "xalan instead.");
final Class clazz =
loadClass(XSLP_LIASON_CLASS);
final Class clazz = loadClass(XSLP_LIASON_CLASS);
liaison = (XSLTLiaison) clazz.newInstance(); liaison = (XSLTLiaison) clazz.newInstance();
} else if (proc.equals("xalan")) { } else if (proc.equals("xalan")) {
final Class clazz =
loadClass(XALAN_LIASON_CLASS);
final Class clazz = loadClass(XALAN_LIASON_CLASS);
liaison = (XSLTLiaison)clazz.newInstance(); liaison = (XSLTLiaison)clazz.newInstance();
} else { } else {
liaison = (XSLTLiaison) loadClass(proc).newInstance(); liaison = (XSLTLiaison) loadClass(proc).newInstance();
@@ -519,11 +512,11 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*/ */
private void ensureDirectoryFor(File targetFile) private void ensureDirectoryFor(File targetFile)
throws BuildException { throws BuildException {
File directory = new File( targetFile.getParent() );
File directory = fileUtils.getParentFile(targetFile);
if (!directory.exists()) { if (!directory.exists()) {
if (!directory.mkdirs()) { if (!directory.mkdirs()) {
throw new BuildException("Unable to create directory: " throw new BuildException("Unable to create directory: "
+ directory.getAbsolutePath() );
+ directory.getAbsolutePath() );
} }
} }
} }


+ 1
- 0
src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java View File

@@ -89,6 +89,7 @@ import javax.xml.transform.sax.SAXSource;
* @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a> * @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a>
* @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a> * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
* @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a> * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a>
* @since Ant 1.3
*/ */
public class TraXLiaison implements XSLTLiaison, ErrorListener, XSLTLoggerAware { public class TraXLiaison implements XSLTLiaison, ErrorListener, XSLTLoggerAware {




+ 3
- 2
src/main/org/apache/tools/ant/taskdefs/optional/XalanLiaison.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * 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. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -73,6 +73,7 @@ import java.io.IOException;
* *
* @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a> * @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a>
* @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a> * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a>
* @since Ant 1.1
*/ */
public class XalanLiaison implements XSLTLiaison { public class XalanLiaison implements XSLTLiaison {


@@ -80,7 +81,7 @@ public class XalanLiaison implements XSLTLiaison {
protected File stylesheet; protected File stylesheet;


public XalanLiaison() throws Exception { public XalanLiaison() throws Exception {
processor = XSLTProcessorFactory.getProcessor();
processor = XSLTProcessorFactory.getProcessor();
} }


public void setStylesheet(File stylesheet) throws Exception { public void setStylesheet(File stylesheet) throws Exception {


+ 14
- 15
src/main/org/apache/tools/ant/taskdefs/optional/XslpLiaison.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * 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. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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.FileOutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;





/** /**
* Concrete liaison for XSLP * Concrete liaison for XSLP
* *
* @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a> * @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a>
* @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a> * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a>
* @since Ant 1.1
*/ */
public class XslpLiaison implements XSLTLiaison { public class XslpLiaison implements XSLTLiaison {


@@ -79,20 +77,21 @@ public class XslpLiaison implements XSLTLiaison {
protected XSLStylesheet xslSheet; protected XSLStylesheet xslSheet;


public XslpLiaison() { 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 { 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 { public void transform(File infile, File outfile) throws Exception {
FileOutputStream fos = new FileOutputStream(outfile); FileOutputStream fos = new FileOutputStream(outfile);
// XSLP does not support encoding...we're in hot water. // 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){ public void addParam(String name, String expression){
processor.setProperty(name, expression);
processor.setProperty(name, expression);
} }


public void setOutputtype(String type) throws Exception { public void setOutputtype(String type) throws Exception {


Loading…
Cancel
Save