package org.xins.common.ant;
import java.io.File;
import java.util.StringTokenizer;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.XSLTProcess;
import org.apache.tools.ant.types.Mapper;
import org.apache.tools.ant.util.FileNameMapper;
public class XsltPlusTask extends XSLTProcess {
private boolean neverOverwrite = false;
private String implicitIncludes;
private Mapper mapper;
private File destDir;
public void setNeverOverwrite(boolean neverOverwrite) {
this.neverOverwrite = neverOverwrite;
}
public void setIncludes(String includes) {
this.implicitIncludes = includes;
}
public void addMapper(Mapper mapper) {
super.addMapper(mapper);
this.mapper = mapper;
}
public void setDestdir(File destDir) {
super.setDestdir(destDir);
this.destDir = destDir;
}
public void execute() throws BuildException {
if (neverOverwrite) {
if (mapper == null) {
throw new BuildException("Please specify a mapper");
}
FileNameMapper mapperImpl = mapper.getImplementation();
String newIncludes = "";
StringTokenizer stIncludes = new StringTokenizer(implicitIncludes, " ,");
while (stIncludes.hasMoreTokens()) {
String nextInclude = stIncludes.nextToken();
String includeDest = mapperImpl.mapFileName(nextInclude)[0];
File destination = new File(destDir, includeDest);
if (!destination.exists()) {
if (newIncludes.equals("")) {
newIncludes = nextInclude;
} else {
newIncludes += "," + nextInclude;
}
}
}
super.setIncludes(newIncludes);
if (newIncludes.equals("")) {
return;
}
} else {
super.setIncludes(implicitIncludes);
}
super.execute();
}
}