Concrete liaison for XSLT processor implementing TraX. (ie JAXP 1.1)
| Method from org.apache.tools.ant.taskdefs.optional.TraXLiaison Detail: |
public void addParam(String name,
String value) {
params.put(name, value);
}
|
public void configure(XSLTProcess xsltTask) {
project = xsltTask.getProject();
XSLTProcess.Factory factory = xsltTask.getFactory();
if (factory != null) {
setFactory(factory.getName());
// configure factory attributes
for (Enumeration attrs = factory.getAttributes();
attrs.hasMoreElements();) {
XSLTProcess.Factory.Attribute attr =
(XSLTProcess.Factory.Attribute) attrs.nextElement();
setAttribute(attr.getName(), attr.getValue());
}
}
XMLCatalog xmlCatalog = xsltTask.getXMLCatalog();
// use XMLCatalog as the entity resolver and URI resolver
if (xmlCatalog != null) {
setEntityResolver(xmlCatalog);
setURIResolver(xmlCatalog);
}
// configure output properties
for (Enumeration props = xsltTask.getOutputProperties();
props.hasMoreElements();) {
XSLTProcess.OutputProperty prop
= (XSLTProcess.OutputProperty) props.nextElement();
setOutputProperty(prop.getName(), prop.getValue());
}
}
Specific configuration for the TRaX liaison. |
public void error(TransformerException e) {
logError(e, "Error");
}
|
public void fatalError(TransformerException e) {
logError(e, "Fatal Error");
throw new BuildException("Fatal error during transformation", e);
}
|
protected String getSystemId(File file) {
return JAXPUtils.getSystemId(file);
} Deprecated! since - 1.5.x.
Use org.apache.tools.ant.util.JAXPUtils#getSystemId instead.
|
public void setAttribute(String name,
Object value) {
final Object[] pair = new Object[]{name, value};
attributes.addElement(pair);
}
Set a custom attribute for the JAXP factory implementation. |
public void setEntityResolver(EntityResolver aResolver) {
entityResolver = aResolver;
}
Set the class to resolve entities during the transformation. |
public void setFactory(String name) {
factoryName = name;
}
Set the factory name to use instead of JAXP default lookup. |
public void setLogger(XSLTLogger l) {
logger = l;
}
|
public void setOutputProperty(String name,
String value) {
final String[] pair = new String[]{name, value};
outputProperties.addElement(pair);
}
Set the output property for the current transformer.
Note that the stylesheet must be set prior to calling
this method. |
public void setStylesheet(File stylesheet) throws Exception {
FileResource fr = new FileResource();
fr.setProject(project);
fr.setFile(stylesheet);
setStylesheet(fr);
}
|
public void setStylesheet(Resource stylesheet) throws Exception {
if (this.stylesheet != null) {
// resetting the stylesheet - reset transformer
transformer = null;
// do we need to reset templates as well
if (!this.stylesheet.equals(stylesheet)
|| (stylesheet.getLastModified() != templatesModTime)) {
templates = null;
}
}
this.stylesheet = stylesheet;
}
|
public void setURIResolver(URIResolver aResolver) {
uriResolver = aResolver;
}
Set the class to resolve URIs during the transformation |
public void transform(File infile,
File outfile) throws Exception {
if (transformer == null) {
createTransformer();
}
InputStream fis = null;
OutputStream fos = null;
try {
fis = new BufferedInputStream(new FileInputStream(infile));
fos = new BufferedOutputStream(new FileOutputStream(outfile));
StreamResult res = new StreamResult(fos);
// not sure what could be the need of this...
res.setSystemId(JAXPUtils.getSystemId(outfile));
Source src = getSource(fis, infile);
// set parameters on each transformation, maybe something has changed
//(e.g. value of file name parameter)
setTransformationParameters();
transformer.transform(src, res);
} finally {
// make sure to close all handles, otherwise the garbage
// collector will close them...whenever possible and
// Windows may complain about not being able to delete files.
try {
if (fis != null) {
fis.close();
}
} catch (IOException ignored) {
// ignore
}
try {
if (fos != null) {
fos.close();
}
} catch (IOException ignored) {
// ignore
}
}
}
|
public void warning(TransformerException e) {
logError(e, "Warning");
}
|