in src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java [336:462]
public void execute() throws BuildException {
if ("style".equals(getTaskType())) {
log("Warning: the task name <style> is deprecated. Use <xslt> instead.",
Project.MSG_WARN);
}
final File savedBaseDir = baseDir;
final String baseMessage =
"specify the stylesheet either as a filename in style attribute or as a nested resource";
if (xslResource == null && xslFile == null) {
handleError(baseMessage);
return;
}
if (xslResource != null && xslFile != null) {
handleError(baseMessage + " but not as both");
return;
}
if (inFile != null && !inFile.exists()) {
handleError("input file " + inFile + " does not exist");
return;
}
try {
setupLoader();
if (sysProperties.size() > 0) {
sysProperties.setSystem();
}
Resource styleResource;
if (baseDir == null) {
baseDir = getProject().getBaseDir();
}
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);
if (xslFile != null) {
// If we enter here, it means that the stylesheet is supplied
// via style attribute
File stylesheet = getProject().resolveFile(xslFile);
if (!stylesheet.exists()) {
final File alternative = FILE_UTILS.resolveFile(baseDir, xslFile);
/*
* shouldn't throw out deprecation warnings before we know,
* the wrong version has been used.
*/
if (alternative.exists()) {
log("DEPRECATED - the 'style' attribute should be relative to the project's");
log(" basedir, not the tasks's basedir.");
stylesheet = alternative;
}
}
final FileResource fr = new FileResource();
fr.setProject(getProject());
fr.setFile(stylesheet);
styleResource = fr;
} else {
styleResource = xslResource;
}
if (!styleResource.isExists()) {
handleError("stylesheet " + styleResource + " doesn't exist.");
return;
}
// if we have an in file and out then process them
if (inFile != null && outFile != null) {
process(inFile, outFile, styleResource);
return;
}
/*
* if we get here, in and out have not been specified, we are
* in batch processing mode.
*/
//-- make sure destination directory exists...
checkDest();
if (useImplicitFileset) {
DirectoryScanner scanner = getDirectoryScanner(baseDir);
log("Transforming into " + destDir, Project.MSG_INFO);
// Process all the files marked for styling
for (String element : scanner.getIncludedFiles()) {
process(baseDir, element, destDir, styleResource);
}
if (performDirectoryScan) {
// Process all the directories marked for styling
for (String dir : scanner.getIncludedDirectories()) {
String[] elements = new File(baseDir, dir).list();
if (elements != null) {
for (String element : new File(baseDir, dir).list()) {
process(baseDir,
dir + File.separator + element,
destDir, styleResource);
}
}
}
}
} else if (resources.isEmpty()) {
// only resource collections, there better be some
if (failOnNoResources) {
handleError("no resources specified");
}
return;
}
processResources(styleResource);
} finally {
if (loader != null) {
loader.resetThreadContextLoader();
loader.cleanup();
loader = null;
}
if (sysProperties.size() > 0) {
sysProperties.restoreSystem();
}
liaison = null;
stylesheetLoaded = false;
baseDir = savedBaseDir;
}
}