Browse Source

Allow to specify a given factory implementation for the transformer

(xsltc, xalan, saxon...) and to specify processor specific settings.

TraxLiaison has been completely refactored because the factory
needed to be created once everything was set up.

I don't think it is final state since it might be better to specify factory attributes
and element in a <factory> element rather than how it is now.

XSLTProcess starts to bevery difficult to read with all the inner classes as well...


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273089 13f79535-47bb-0310-9956-ffa450edef68
master
Stephane Bailliez 23 years ago
parent
commit
1e8307708d
5 changed files with 411 additions and 117 deletions
  1. +52
    -0
      docs/manual/CoreTasks/style.html
  2. +18
    -1
      src/etc/testcases/taskdefs/optional/xslt.xml
  3. +112
    -9
      src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
  4. +220
    -103
      src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
  5. +9
    -4
      src/testcases/org/apache/tools/ant/taskdefs/optional/XsltTest.java

+ 52
- 0
docs/manual/CoreTasks/style.html View File

@@ -102,6 +102,18 @@ element which is used to perform Entity and URI resolution</p>
</td> </td>
<td align="center" valign="top">No</td> <td align="center" valign="top">No</td>
</tr> </tr>
<tr>
<td valign="top">factory</td>

<td valign="top">fully qualified class name of the transformer
factory to use. For example
<tt>org.apache.xalan.processor.TransformerFactoryImpl</tt>
or <tt>org.apache.xalan.xsltc.trax.TransformerFactoryImpl</tt>
or <tt>net.sf.saxon.TransformerFactoryImpl</tt>...
</td>
<td align="center" valign="top">No. Works only with 'trax'/default processor
and defaults to JAXP lookup mechanism.</td>
</tr>
<tr> <tr>
<td valign="top">includes</td> <td valign="top">includes</td>
<td valign="top">comma- or space-separated list of patterns of files that must be included. <td valign="top">comma- or space-separated list of patterns of files that must be included.
@@ -207,6 +219,46 @@ XSLT specifications</a>.
</tr> </tr>
</table> </table>


<h4>attribute ('trax' processors only)</h4>
<p>Used to specify settings of the processor.
The attribute names and values are entirely processor specific
so you must be aware of the implementation to figure them out.
Read the documentation of your processor.
For example, in Xalan 2.x:
<ul>
<li>http://xml.apache.org/xalan/features/optimize (boolean)</li>
<li>http://xml.apache.org/xalan/features/incremental (boolean)</li>
<li>...</li>
</ul>
And in Saxon 7.x:
<ul>
<li>http://saxon.sf.net/feature/allow-external-functions (boolean)</li>
<li>http://saxon.sf.net/feature/timing (boolean)</li>
<li>http://saxon.sf.net/feature/traceListener (string)</li>
<li>http://saxon.sf.net/feature/treeModel (integer)</li>
<li>http://saxon.sf.net/feature/linenumbering (integer)</li>
<li>...</li>
</ul>
<h4>Parameters</h4>
<table width="60%" border="1" cellpadding="2" cellspacing="0">
<tr>
<td valign="top"><b>Attribute</b></td>
<td valign="top"><b>Description</b></td>
<td align="center" valign="top"><b>Required</b></td>
</tr>
<tr>
<td valign="top">name</td>
<td valign="top">Name of the attribute</td>
<td align="center" valign="top">Yes</td>
</tr>
<tr>
<td valign="top">value</td>
<td valign="top">value of the attribute.</td>
<td align="center" valign="top">Yes</td>
</tr>
</table>


<h3>Examples</h3> <h3>Examples</h3>
<blockquote> <blockquote>
<pre> <pre>


+ 18
- 1
src/etc/testcases/taskdefs/optional/xslt.xml View File

@@ -31,7 +31,6 @@
</style> </style>
</target> </target>



<target name="testOutputProperty" depends="init"> <target name="testOutputProperty" depends="init">
<style in="xml/test.xml" <style in="xml/test.xml"
out="xml/out/test-out.xml" out="xml/out/test-out.xml"
@@ -43,4 +42,22 @@
</style> </style>
</target> </target>
<target name="testFactory" depends="init">
<style in="xml/test.xml"
out="xml/out/test-out.xml"
style="xml/test.xsl"
factory="org.apache.xalan.processor.TransformerFactoryImpl"/>
</target>

<target name="testAttribute" depends="init">
<style in="xml/test.xml"
out="xml/out/test-out.xml"
style="xml/test.xsl"
factory="org.apache.xalan.processor.TransformerFactoryImpl">
<attribute name="http://xml.apache.org/xalan/features/optimize" value="true"/>
</style>
</target>

</project> </project>

+ 112
- 9
src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java View File

@@ -54,7 +54,6 @@


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


import java.lang.reflect.Method;
import java.io.File; import java.io.File;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Vector; import java.util.Vector;
@@ -62,12 +61,12 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.AntClassLoader; import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.DynamicConfigurator;
import org.apache.tools.ant.taskdefs.optional.TraXLiaison; import org.apache.tools.ant.taskdefs.optional.TraXLiaison;
import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference; import org.apache.tools.ant.types.Reference;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.types.XMLCatalog; import org.apache.tools.ant.types.XMLCatalog;
import org.xml.sax.EntityResolver;


/** /**
* Processes a set of XML documents via XSLT. This is * Processes a set of XML documents via XSLT. This is
@@ -79,6 +78,7 @@ import org.xml.sax.EntityResolver;
* @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="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
@author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a>
* *
* @since Ant 1.1 * @since Ant 1.1
* *
@@ -113,8 +113,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
/** Classpath to use when trying to load the XSL processor */ /** Classpath to use when trying to load the XSL processor */
private Path classpath = null; private Path classpath = null;


/** The Liason implementation to use to communicate with the XSL
* processor */
/** implementation to use to communicate with the XSL processor */
private XSLTLiaison liaison; private XSLTLiaison liaison;


/** Flag which indicates if the stylesheet has been loaded into /** Flag which indicates if the stylesheet has been loaded into
@@ -127,21 +126,21 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
/** Utilities used for file operations */ /** Utilities used for file operations */
private FileUtils fileUtils; private FileUtils fileUtils;


/** XSL output method to be used */
/** XSL output properties to be used */
private Vector outputProperties = new Vector(); private Vector outputProperties = new Vector();


/** for resolving entities such as dtds */ /** for resolving entities such as dtds */
private XMLCatalog xmlCatalog = new XMLCatalog(); private XMLCatalog xmlCatalog = new XMLCatalog();


/** Name of the TRAX Liason class */
/** Name of the TRAX Liaison class */
private static final String TRAX_LIAISON_CLASS = private static final String TRAX_LIAISON_CLASS =
"org.apache.tools.ant.taskdefs.optional.TraXLiaison"; "org.apache.tools.ant.taskdefs.optional.TraXLiaison";


/** Name of the now-deprecated XSLP Liason class */
/** Name of the now-deprecated XSLP Liaison class */
private static final String XSLP_LIAISON_CLASS = private static final String XSLP_LIAISON_CLASS =
"org.apache.tools.ant.taskdefs.optional.XslpLiaison"; "org.apache.tools.ant.taskdefs.optional.XslpLiaison";


/** Name of the Xalan liason class */
/** Name of the Xalan liaison class */
private static final String XALAN_LIAISON_CLASS = private static final String XALAN_LIAISON_CLASS =
"org.apache.tools.ant.taskdefs.optional.XalanLiaison"; "org.apache.tools.ant.taskdefs.optional.XalanLiaison";


@@ -152,6 +151,18 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*/ */
private boolean performDirectoryScan = true; private boolean performDirectoryScan = true;


/**
* the factory class name to use for TraXLiaison
* @since Ant 1.6
*/
private String factory = null;

/**
* the list of factory attributes to use for TraXLiaison
* @since Ant 1.6
*/
private Vector attributes = new Vector();

/** /**
* Creates a new XSLTProcess Task. * Creates a new XSLTProcess Task.
*/ */
@@ -170,6 +181,14 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
performDirectoryScan = b; performDirectoryScan = b;
} }


/**
* Set the factory to use for the TraXLiaison.
* @param value the name of the factory
*/
public void setFactory(String value){
factory = value;
}

/** /**
* Executes the task. * Executes the task.
* *
@@ -299,6 +318,8 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
/** /**
* Name of the stylesheet to use - given either relative * Name of the stylesheet to use - given either relative
* to the project's basedir or as an absolute path; required. * to the project's basedir or as an absolute path; required.
*
* @param xslFile the stylesheet to use
*/ */
public void setStyle(String xslFile) { public void setStyle(String xslFile) {
this.xslFile = xslFile; this.xslFile = xslFile;
@@ -579,7 +600,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
/** /**
* The Param inner class used to store XSL parameters * The Param inner class used to store XSL parameters
*/ */
public class Param {
public static class Param {
/** The parameter name */ /** The parameter name */
private String name = null; private String name = null;


@@ -690,6 +711,77 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
} }
} }



/**
* Create an instance of a factory attribute.
* @return the newly created factory attribute
* @since Ant 1.6
*/
public Attribute createAttribute() {
Attribute attr = new Attribute();
attributes.addElement(attr);
return attr;
}

/**
* A JAXP factory attribute. This is mostly processor specific, for
* example for Xalan 2.3+, the following attributes could be set:
* <ul>
* <li>http://xml.apache.org/xalan/features/optimize (true|false) </li>
* <li>http://xml.apache.org/xalan/features/incremental (true|false) </li>
* </ul>
* @since Ant 1.6
*/
public static class Attribute implements DynamicConfigurator {

/** attribute name, mostly processor specific */
private String name;

/** attribute value, often a boolean string */
private Object value;

/**
* @return the attribute name.
*/
public String getName() {
return name;
}

/**
* @return the output property value.
*/
public Object getValue() {
return value;
}

public Object createDynamicElement(String name) throws BuildException {
return null;
}

public void setDynamicAttribute(String name, String value)
throws BuildException {
// only 'name' and 'value' exist.
if ("name".equalsIgnoreCase(name)) {
this.name = value;
} else if ("value".equalsIgnoreCase(name)) {
// a value must be of a given type
// say boolean|integer|string that are mostly used.
if ("true".equalsIgnoreCase(value)
|| "false".equalsIgnoreCase(value) ){
this.value = new Boolean(value);
} else {
try {
this.value = new Integer(value);
} catch (NumberFormatException e) {
this.value = value;
}
}
} else {
throw new BuildException("Unsupported attribute: " + name);
}
}
}

/** /**
* Initialize internal instance of XMLCatalog * Initialize internal instance of XMLCatalog
*/ */
@@ -733,12 +825,23 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @param liaison the TRaXLiaison to configure. * @param liaison the TRaXLiaison to configure.
*/ */
protected void configureTraXLiaison(TraXLiaison liaison){ protected void configureTraXLiaison(TraXLiaison liaison){
if (factory != null) {
liaison.setFactory(factory);
}

// use XMLCatalog as the entity resolver and URI resolver // use XMLCatalog as the entity resolver and URI resolver
if (xmlCatalog != null) { if (xmlCatalog != null) {
liaison.setEntityResolver(xmlCatalog); liaison.setEntityResolver(xmlCatalog);
liaison.setURIResolver(xmlCatalog); liaison.setURIResolver(xmlCatalog);
} }


// configure factory attributes
for (Enumeration attrs = attributes.elements();
attrs.hasMoreElements();) {
Attribute attr = (Attribute)attrs.nextElement();
liaison.setAttribute(attr.getName(), attr.getValue());
}

// configure output properties // configure output properties
for (Enumeration props = outputProperties.elements(); for (Enumeration props = outputProperties.elements();
props.hasMoreElements();) { props.hasMoreElements();) {


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

@@ -58,6 +58,11 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.BufferedOutputStream;
import java.io.BufferedInputStream;
import java.io.OutputStream;
import java.io.InputStream;
import java.util.Vector;


import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.XSLTLiaison; import org.apache.tools.ant.taskdefs.XSLTLiaison;
@@ -80,6 +85,7 @@ import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource; import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.Source; import javax.xml.transform.Source;
import javax.xml.transform.URIResolver; import javax.xml.transform.URIResolver;
import javax.xml.transform.SourceLocator;


import javax.xml.transform.sax.SAXSource; import javax.xml.transform.sax.SAXSource;


@@ -93,118 +99,154 @@ import javax.xml.transform.sax.SAXSource;
*/ */
public class TraXLiaison implements XSLTLiaison, ErrorListener, XSLTLoggerAware { public class TraXLiaison implements XSLTLiaison, ErrorListener, XSLTLoggerAware {


/**
* the name of the factory implementation class to use
* or null for default JAXP lookup.
*/
private String factoryName = null;

/** The trax TransformerFactory */ /** The trax TransformerFactory */
private TransformerFactory tfactory = null; private TransformerFactory tfactory = null;


/** stylesheet stream, close it asap */
private FileInputStream xslStream = null;

/** Stylesheet template */
private Templates templates = null;

/** transformer */
private Transformer transformer = null;
/** stylesheet to use for transformation */
private File stylesheet;


private XSLTLogger logger; private XSLTLogger logger;


/** possible resolver for publicIds */ /** possible resolver for publicIds */
private EntityResolver entityResolver; private EntityResolver entityResolver;


/** transformer to use for processing files */
private Transformer transformer;

/** possible resolver for URIs */ /** possible resolver for URIs */
private URIResolver uriResolver; private URIResolver uriResolver;


public TraXLiaison() throws Exception {
tfactory = TransformerFactory.newInstance();
tfactory.setErrorListener(this);
}


/**
* Set the output property for the current transformer.
* Note that the stylesheet must be set prior to calling
* this method.
* @param name the output property name.
* @param value the output property value.
*/
public void setOutputProperty(String name, String value){
if (transformer == null){
throw new IllegalStateException("stylesheet must be set prior to setting the output properties");
}
transformer.setOutputProperty(name, value);
}
/** transformer output properties */
private Vector outputProperties = new Vector();


//------------------- IMPORTANT
// 1) Don't use the StreamSource(File) ctor. It won't work with
// xalan prior to 2.2 because of systemid bugs.
/** stylesheet parameters */
private Vector params = new Vector();


// 2) Use a stream so that you can close it yourself quickly
// and avoid keeping the handle until the object is garbaged.
// (always keep control), otherwise you won't be able to delete
// the file quickly on windows.
/** factory attributes */
private Vector attributes = new Vector();


// 3) Always set the systemid to the source for imports, includes...
// in xsl and xml...
public TraXLiaison() throws Exception {
}


public void setStylesheet(File stylesheet) throws Exception { public void setStylesheet(File stylesheet) throws Exception {
xslStream = new FileInputStream(stylesheet);
StreamSource src = new StreamSource(xslStream);
src.setSystemId(getSystemId(stylesheet));
templates = tfactory.newTemplates(src);
transformer = templates.newTransformer();
transformer.setErrorListener(this);
this.stylesheet = stylesheet;
} }


public void transform(File infile, File outfile) throws Exception { public void transform(File infile, File outfile) throws Exception {
FileInputStream fis = null;
FileOutputStream fos = null;
if (transformer == null) {
transformer = newTransformer();
}

InputStream fis = null;
OutputStream fos = null;
try { try {
fis = new FileInputStream(infile);
fos = new FileOutputStream(outfile);
// FIXME: need to use a SAXSource as the source for the transform
// so we can plug in our own entity resolver
Source src = null;
if (entityResolver != null) {
if (tfactory.getFeature(SAXSource.FEATURE)) {
SAXParserFactory spFactory = SAXParserFactory.newInstance();
spFactory.setNamespaceAware(true);
XMLReader reader = spFactory.newSAXParser().getXMLReader();
reader.setEntityResolver(entityResolver);
src = new SAXSource(reader, new InputSource(fis));
} else {
throw new IllegalStateException("xcatalog specified, but " +
"parser doesn't support SAX");
}
} else {
src = new StreamSource(fis);
}
src.setSystemId(getSystemId(infile));
fis = new BufferedInputStream(new FileInputStream(infile));
fos = new BufferedOutputStream(new FileOutputStream(outfile));
StreamResult res = new StreamResult(fos); StreamResult res = new StreamResult(fos);
// not sure what could be the need of this... // not sure what could be the need of this...
res.setSystemId(getSystemId(outfile)); res.setSystemId(getSystemId(outfile));

if (uriResolver != null)
transformer.setURIResolver(uriResolver);

Source src = getSource(fis, infile);
transformer.transform(src, res); transformer.transform(src, res);
} finally { } finally {
// make sure to close all handles, otherwise the garbage // make sure to close all handles, otherwise the garbage
// collector will close them...whenever possible and // collector will close them...whenever possible and
// Windows may complain about not being able to delete files. // Windows may complain about not being able to delete files.
try { try {
if (xslStream != null){
xslStream.close();
}
} catch (IOException ignored){}
try {
if (fis != null){
if (fis != null) {
fis.close(); fis.close();
} }
} catch (IOException ignored){}
} catch (IOException ignored) {
}
try { try {
if (fos != null){
if (fos != null) {
fos.close(); fos.close();
} }
} catch (IOException ignored){}
} catch (IOException ignored) {
}
}
}

/**
* Get the source instance from the stream and id of the file.
* @param is the stream containing the stylesheet data.
* @param infile the file that will be used for the systemid.
* @return the configured source instance matching the stylesheet.
* @throws Exception if there is a problem creating the source.
*/
private Source getSource(InputStream is, File infile) throws Exception {
// todo: is this comment still relevant ??
// FIXME: need to use a SAXSource as the source for the transform
// so we can plug in our own entity resolver
Source src = null;
if (entityResolver != null) {
if (getFactory().getFeature(SAXSource.FEATURE)) {
SAXParserFactory spFactory = SAXParserFactory.newInstance();
spFactory.setNamespaceAware(true);
XMLReader reader = spFactory.newSAXParser().getXMLReader();
reader.setEntityResolver(entityResolver);
src = new SAXSource(reader, new InputSource(is));
} else {
throw new IllegalStateException("xcatalog specified, but " +
"parser doesn't support SAX");
}
} else {
src = new StreamSource(is);
}
src.setSystemId(getSystemId(infile));
return src;
}

/**
* Create a new transformer based on the liaison settings
* @return the newly created and configured transformer.
* @throws Exception thrown if there is an error during creation.
* @see #setStylesheet(java.io.File)
* @see #addParam(java.lang.String, java.lang.String)
* @see #setOutputProperty(java.lang.String, java.lang.String)
*/
private Transformer newTransformer() throws Exception {
// WARN: Don't use the StreamSource(File) ctor. It won't work with
// xalan prior to 2.2 because of systemid bugs.

// Use a stream so that you can close it yourself quickly
// and avoid keeping the handle until the object is garbaged.
// (always keep control), otherwise you won't be able to delete
// the file quickly on windows.
InputStream xslStream = new BufferedInputStream(
new FileInputStream(stylesheet));
try {
StreamSource src = new StreamSource(xslStream);
// Always set the systemid to the source for imports, includes...
// in xsl and xml...
src.setSystemId(getSystemId(stylesheet));
Templates templates = getFactory().newTemplates(src);
Transformer transformer = templates.newTransformer();

// configure the transformer...
transformer.setErrorListener(this);
if (uriResolver != null) {
transformer.setURIResolver(uriResolver);
}
for (int i = 0; i < params.size(); i++) {
final String[] pair = (String[]) params.elementAt(i);
transformer.setParameter(pair[0], pair[1]);
}
for (int i = 0; i < outputProperties.size(); i++) {
final String[] pair = (String[]) outputProperties.elementAt(i);
transformer.setOutputProperty(pair[0], pair[1]);
}
return transformer;
} finally {
try {
xslStream.close();
} catch (IOException ignored) {
}
} }
} }


@@ -212,7 +254,7 @@ public class TraXLiaison implements XSLTLiaison, ErrorListener, XSLTLoggerAware
// crimson will complain that it cannot resolve relative entities // crimson will complain that it cannot resolve relative entities
// because it grabs the base uri via lastIndexOf('/') without // because it grabs the base uri via lastIndexOf('/') without
// making sure it is really a /'ed path // making sure it is really a /'ed path
protected String getSystemId(File file){
protected String getSystemId(File file) {
String path = file.getAbsolutePath(); String path = file.getAbsolutePath();
path = path.replace('\\', '/'); path = path.replace('\\', '/');


@@ -224,24 +266,107 @@ public class TraXLiaison implements XSLTLiaison, ErrorListener, XSLTLoggerAware
return FILE_PROTOCOL_PREFIX + path; return FILE_PROTOCOL_PREFIX + path;
} }


public void addParam(String name, String value){
transformer.setParameter(name, value);

/**
* return the Transformer factory associated to this liaison.
* @return the Transformer factory associated to this liaison.
* @throws BuildException thrown if there is a problem creating
* the factory.
* @see #setFactory(String)
* @since Ant 1.6
*/
private TransformerFactory getFactory() throws BuildException {
if (tfactory != null) {
return tfactory;
}
// not initialized yet, so create the factory
if (factoryName == null) {
tfactory = TransformerFactory.newInstance();
} else {
try {
Class clazz = Class.forName(factoryName);
tfactory = (TransformerFactory) clazz.newInstance();
} catch (Exception e) {
throw new BuildException(e);
}
}
tfactory.setErrorListener(this);

// specific attributes for the transformer
for (int i = 0; i < attributes.size(); i++) {
final Object[] pair = (Object[])attributes.elementAt(i);
tfactory.setAttribute((String)pair[0], pair[1]);
}
return tfactory;
}


/**
* Set the factory name to use instead of JAXP default lookup.
* @param name the fully qualified class name of the factory to use
* or null for the default JAXP look up mechanism.
* @since Ant 1.6
*/
public void setFactory(String name) {
factoryName = name;
}

/**
* Set a custom attribute for the JAXP factory implementation.
* @param name the attribute name.
* @param value the value of the attribute, usually a boolean
* string or object.
* @since Ant 1.6
*/
public void setAttribute(String name, Object value){
final Object[] pair = new Object[]{name, value};
attributes.addElement(pair);
}

/**
* Set the output property for the current transformer.
* Note that the stylesheet must be set prior to calling
* this method.
* @param name the output property name.
* @param value the output property value.
* @since Ant 1.5
*/
public void setOutputProperty(String name, String value) {
final String[] pair = new String[]{name, value};
outputProperties.addElement(pair);
}

/** Set the class to resolve entities during the transformation
*/
public void setEntityResolver(EntityResolver aResolver) {
entityResolver = aResolver;
}

/** Set the class to resolve URIs during the transformation
*/
public void setURIResolver(URIResolver aResolver) {
uriResolver = aResolver;
}

public void addParam(String name, String value) {
final String[] pair = new String[]{name, value};
params.addElement(pair);
} }


public void setLogger(XSLTLogger l) { public void setLogger(XSLTLogger l) {
logger = l; logger = l;
} }


public void error(TransformerException e) {
public void error(TransformerException e) {
logError(e, "Error"); logError(e, "Error");
} }


public void fatalError(TransformerException e) {
public void fatalError(TransformerException e) {
logError(e, "Fatal Error"); logError(e, "Fatal Error");
throw new BuildException("Fatal error during transformation", e); throw new BuildException("Fatal error during transformation", e);
} }


public void warning(TransformerException e) {
public void warning(TransformerException e) {
logError(e, "Warning"); logError(e, "Warning");
} }


@@ -251,20 +376,24 @@ public class TraXLiaison implements XSLTLiaison, ErrorListener, XSLTLoggerAware
} }


StringBuffer msg = new StringBuffer(); StringBuffer msg = new StringBuffer();
if (e.getLocator() != null) {
if (e.getLocator().getSystemId() != null) {
String url = e.getLocator().getSystemId();
SourceLocator locator = e.getLocator();
if (locator != null) {
String systemid = locator.getSystemId();
if (systemid != null) {
String url = systemid;
if (url.startsWith("file:///")) { if (url.startsWith("file:///")) {
url = url.substring(8);
url = url.substring(8);
} }
msg.append(url); msg.append(url);
} else { } else {
msg.append("Unknown file"); msg.append("Unknown file");
} }
if (e.getLocator().getLineNumber() != -1) {
msg.append(":" + e.getLocator().getLineNumber());
if (e.getLocator().getColumnNumber() != -1) {
msg.append(":" + e.getLocator().getColumnNumber());
int line = locator.getLineNumber();
if (line != -1) {
msg.append(":" + line);
int column = locator.getColumnNumber();
if (column != -1) {
msg.append(":" + column);
} }
} }
} }
@@ -277,16 +406,4 @@ public class TraXLiaison implements XSLTLiaison, ErrorListener, XSLTLoggerAware
logger.log(msg.toString()); logger.log(msg.toString());
} }


/** Set the class to resolve entities during the transformation
*/
public void setEntityResolver(EntityResolver aResolver) {
entityResolver = aResolver;
}

/** Set the class to resolve URIs during the transformation
*/
public void setURIResolver(URIResolver aResolver) {
uriResolver = aResolver;
}

} //-- TraXLiaison } //-- TraXLiaison

+ 9
- 4
src/testcases/org/apache/tools/ant/taskdefs/optional/XsltTest.java View File

@@ -53,9 +53,6 @@
*/ */
package org.apache.tools.ant.taskdefs.optional; package org.apache.tools.ant.taskdefs.optional;


import java.io.*;
import java.util.Properties;

import org.apache.tools.ant.BuildFileTest; import org.apache.tools.ant.BuildFileTest;


/** /**
@@ -114,9 +111,17 @@ public class XsltTest extends BuildFileTest {
public void testCatalog() throws Exception { public void testCatalog() throws Exception {
executeTarget("testCatalog"); executeTarget("testCatalog");
} }
public void testOutputProperty() throws Exception { public void testOutputProperty() throws Exception {
executeTarget("testOutputProperty"); executeTarget("testOutputProperty");
} }

public void testFactory() throws Exception {
executeTarget("testFactory");
}

public void testAttribute() throws Exception {
executeTarget("testAttribute");
}
} }



Loading…
Cancel
Save