| Method from org.apache.tools.ant.taskdefs.XSLTProcess Detail: |
public void add(ResourceCollection rc) {
resources.add(rc);
}
Adds a collection of resources to style in addition to the
given file or the implicit fileset. |
public void add(FileNameMapper fileNameMapper) throws BuildException {
Mapper mapper = new Mapper(getProject());
mapper.add(fileNameMapper);
addMapper(mapper);
}
Adds a nested filenamemapper. |
public void addConfiguredStyle(Resources rc) {
if (rc.size() != 1) {
throw new BuildException("The style element must be specified"
+ " with exactly one nested resource.");
}
setXslResource((Resource) rc.iterator().next());
}
Add a nested <style> element. |
public void addConfiguredXMLCatalog(XMLCatalog xmlCatalog) {
this.xmlCatalog.addConfiguredXMLCatalog(xmlCatalog);
}
Add the catalog to our internal catalog |
public void addMapper(Mapper mapper) {
if (mapperElement != null) {
throw new BuildException("Cannot define more than one mapper",
getLocation());
}
mapperElement = mapper;
}
Defines the mapper to map source to destination files. |
protected void configureLiaison(File stylesheet) throws BuildException {
FileResource fr = new FileResource();
fr.setProject(getProject());
fr.setFile(stylesheet);
configureLiaison(fr);
} Deprecated! since - Ant 1.7
Loads the stylesheet and set xsl:param parameters. |
protected void configureLiaison(Resource stylesheet) throws BuildException {
if (stylesheetLoaded && reuseLoadedStylesheet) {
return;
}
stylesheetLoaded = true;
try {
log("Loading stylesheet " + stylesheet, Project.MSG_INFO);
// We call liason.configure() and then liaison.setStylesheet()
// so that the internal variables of liaison can be set up
if (liaison instanceof XSLTLiaison2) {
((XSLTLiaison2) liaison).configure(this);
}
if (liaison instanceof XSLTLiaison3) {
// If we are here we can set the stylesheet as a
// resource
((XSLTLiaison3) liaison).setStylesheet(stylesheet);
} else {
// If we are here we cannot set the stylesheet as
// a resource, but we can set it as a file. So,
// we make an attempt to get it as a file
if (stylesheet instanceof FileResource) {
liaison.setStylesheet(
((FileResource) stylesheet).getFile());
} else {
throw new BuildException(liaison.getClass().toString()
+ " accepts the stylesheet only as a file",
getLocation());
}
}
for (Enumeration e = params.elements(); e.hasMoreElements();) {
Param p = (Param) e.nextElement();
if (p.shouldUse()) {
liaison.addParam(p.getName(), p.getExpression());
}
}
} catch (Exception ex) {
log("Failed to transform using stylesheet " + stylesheet,
Project.MSG_INFO);
throw new BuildException(ex);
}
}
Loads the stylesheet and set xsl:param parameters. |
public Path createClasspath() {
if (classpath == null) {
classpath = new Path(getProject());
}
return classpath.createPath();
}
Set the optional classpath to the XSL processor |
public XSLTProcess.Factory createFactory() throws BuildException {
if (factory != null) {
throw new BuildException("'factory' element must be unique");
}
factory = new Factory();
return factory;
}
Create the factory element to configure a trax liaison. |
public XSLTProcess.OutputProperty createOutputProperty() {
OutputProperty p = new OutputProperty();
outputProperties.addElement(p);
return p;
}
Create an instance of an output property to be configured. |
public XSLTProcess.Param createParam() {
Param p = new Param();
params.addElement(p);
return p;
}
Create an instance of an XSL parameter for configuration by Ant. |
public void execute() throws BuildException {
if ("style".equals(getTaskType())) {
log("Warning: the task name < style > is deprecated. Use < xslt > instead.",
Project.MSG_WARN);
}
File savedBaseDir = baseDir;
DirectoryScanner scanner;
String[] list;
String[] dirs;
if (xslResource == null && xslFile == null) {
throw new BuildException("specify the "
+ "stylesheet either as a filename in style "
+ "attribute or as a nested resource", getLocation());
}
if (xslResource != null && xslFile != null) {
throw new BuildException("specify the "
+ "stylesheet either as a filename in style "
+ "attribute or as a nested resource but not "
+ "as both", getLocation());
}
if (inFile != null && !inFile.exists()) {
throw new BuildException(
"input file " + inFile.toString() + " does not exist", getLocation());
}
try {
if (baseDir == null) {
baseDir = getProject().resolveFile(".");
}
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()) {
stylesheet = FILE_UTILS.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.");
}
}
FileResource fr = new FileResource();
fr.setProject(getProject());
fr.setFile(stylesheet);
xslResource = fr;
}
// if we have an in file and out then process them
if (inFile != null && outFile != null) {
process(inFile, outFile, xslResource);
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) {
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, xslResource);
}
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, dirs[j] + File.separator + list[i],
destDir, xslResource);
}
}
}
} else { // only resource collections, there better be some
if (resources.size() == 0) {
throw new BuildException("no resources specified");
}
}
processResources(xslResource);
} finally {
if (loader != null) {
loader.resetThreadContextLoader();
loader.cleanup();
loader = null;
}
liaison = null;
stylesheetLoaded = false;
baseDir = savedBaseDir;
}
}
|
public XSLTProcess.Factory getFactory() {
return factory;
}
Get the factory instance configured for this processor |
protected XSLTLiaison getLiaison() {
// if processor wasn't specified, see if TraX is available. If not,
// default it to xalan, depending on which is in the classpath
if (liaison == null) {
if (processor != null) {
try {
resolveProcessor(processor);
} catch (Exception e) {
throw new BuildException(e);
}
} else {
try {
resolveProcessor(PROCESSOR_TRAX);
} catch (Throwable e1) {
e1.printStackTrace();
throw new BuildException(e1);
}
}
}
return liaison;
}
Get the Liason implementation to use in processing. |
public Enumeration getOutputProperties() {
return outputProperties.elements();
}
Get an enumeration on the outputproperties. |
public XMLCatalog getXMLCatalog() {
xmlCatalog.setProject(getProject());
return xmlCatalog;
}
Get the XML catalog containing entity definitions |
public void init() throws BuildException {
super.init();
xmlCatalog.setProject(getProject());
}
Initialize internal instance of XMLCatalog |
public void setBasedir(File dir) {
baseDir = dir;
}
Set the base directory;
optional, default is the project's basedir. |
public void setClasspath(Path classpath) {
createClasspath().append(classpath);
}
Set the optional classpath to the XSL processor |
public void setClasspathRef(Reference r) {
createClasspath().setRefid(r);
}
Set the reference to an optional classpath to the XSL processor |
public void setDestdir(File dir) {
destDir = dir;
}
Set the destination directory into which the XSL result
files should be copied to;
required, unless in and out are
specified. |
public void setExtension(String name) {
targetExtension = name;
}
Set the desired file extension to be used for the target;
optional, default is html. |
public void setFileDirParameter(String fileDirParameter) {
this.fileDirParameter = fileDirParameter;
}
Pass the directory name of the current processed file as a xsl parameter
to the transformation. This value sets the name of that xsl parameter. |
public void setFileNameParameter(String fileNameParameter) {
this.fileNameParameter = fileNameParameter;
}
Pass the filename of the current processed file as a xsl parameter
to the transformation. This value sets the name of that xsl parameter. |
public void setForce(boolean force) {
this.force = force;
}
Set whether to check dependencies, or always generate;
optional, default is false. |
public void setIn(File inFile) {
this.inFile = inFile;
}
specifies a single XML document to be styled. Should be used
with the out attribute; ; required if out is set |
public void setOut(File outFile) {
this.outFile = outFile;
}
Specifies the output name for the styled result from the
in attribute; required if in is set |
public void setProcessor(String processor) {
this.processor = processor;
}
Set the name of the XSL processor to use; optional, default trax.
Other values are "xalan" for Xalan1 |
public void setReloadStylesheet(boolean b) {
reuseLoadedStylesheet = !b;
}
Controls whether the stylesheet is reloaded for every transform.
Setting this to true may get around a bug in certain
Xalan-J versions, default is false. |
public void setScanIncludedDirectories(boolean b) {
performDirectoryScan = b;
}
Whether to style all files in the included directories as well;
optional, default is true. |
public void setStyle(String xslFile) {
this.xslFile = xslFile;
}
Name of the stylesheet to use - given either relative
to the project's basedir or as an absolute path; required. |
public void setUseImplicitFileset(boolean useimplicitfileset) {
useImplicitFileset = useimplicitfileset;
}
|
public void setXslResource(Resource xslResource) {
this.xslResource = xslResource;
}
API method to set the XSL Resource. |