[
http://jira.codehaus.org/browse/MOJO-777?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Aleksei Valikov updated MOJO-777:
---------------------------------
Attachment: xml-maven-plugin.patch
Here's the patch that implements my proposal.
I've added the transformerFactory parameter and changed the templates creation:
/**
* Transformer factory to be used.
* @parameter
*/
private String transformerFactory;
private Templates getTemplate( Resolver pResolver, File stylesheet )
throws MojoExecutionException
{
TransformerFactory tf = getTransformerFactory();
if ( pResolver != null )
{
tf.setURIResolver( pResolver );
}
try
{
return tf.newTemplates( new StreamSource( stylesheet ) );
}
catch ( TransformerConfigurationException e )
{
throw new MojoExecutionException( "Failed to parse stylesheet " +
stylesheet + ": " + e.getMessage(), e );
}
}
private TransformerFactory getTransformerFactory( ) throws
MojoExecutionException
{
if (transformerFactory == null)
{
return TransformerFactory.newInstance();
}
else
{
try {
Class providerClass = Class.forName(transformerFactory);
Object instance = providerClass.newInstance();
if (instance instanceof TransformerFactory)
{
return (TransformerFactory) instance;
}
} catch (ClassNotFoundException cnfex) {
throw new MojoExecutionException(
"Transformer factory class " + transformerFactory + " could
not be found.", cnfex);
} catch (InstantiationException ex) {
throw new MojoExecutionException(
"Transformer factory class " + transformerFactory + " could
not be instantiated. ",
ex);
} catch (IllegalAccessException ex) {
throw new MojoExecutionException(
"Transformer factory class " + transformerFactory + " could
not be instantiated. ",
ex);
}
return null;
}
}
I have also added a new integration test it7 that demonstrates/tests explicit
TransformerFactory configuration.
> Allow specifying concrete imlementation of the TransformerFactory
> -----------------------------------------------------------------
>
> Key: MOJO-777
> URL: http://jira.codehaus.org/browse/MOJO-777
> Project: Mojo
> Issue Type: New Feature
> Components: xml
> Reporter: Aleksei Valikov
> Assignee: Jochen Wiedmann
> Attachments: xml-maven-plugin.patch
>
>
> Currently, when retrieving the instance of TransformerFactory, the plugin
> relies on the standard JAXP mechanism.
> Unfortunately, this mechanism is unpredictable in many environments.
> Let's see the docs on TransformerFactory.newInstance():
> * Use the javax.xml.transform.TransformerFactory system property.
> * Use the properties file "lib/jaxp.properties" in the JRE directory. This
> configuration file is in standard java.util.Properties format and contains
> the fully qualified name of the implementation class with the key being the
> system property defined above. The jaxp.properties file is read only once by
> the JAXP implementation and it's values are then cached for future use. If
> the file does not exist when the first attempt is made to read from it, no
> further attempts are made to check for its existence. It is not possible to
> change the value of any property in jaxp.properties after it has been read
> for the first time.
> * Use the Services API (as detailed in the JAR specification), if available,
> to determine the classname. The Services API will look for a classname in the
> file META-INF/services/javax.xml.transform.TransformerFactory in jars
> available to the runtime.
> * Platform default TransformerFactory instance.
> Number 1 is allright.
> Number 2 is user environment dependent.
> Number 3 is unpredictable. There can be several JARs in the classpath
> defining the META-INF/services/javax.xml.transform.TransformerFactory
> resource file. In this case which factory will be instantiated is not
> predictable and depends on the order of the JARs in the classpath.
> Number 3 is allright.
> So numbers 2 and 3 introduce undeterministic behaviour. Some of my builds
> suffered from this unpredictability: I tried to use Saxon 8.x as the
> processor in my builds. Sometimes Xalan was used, sometimes Saxon - and there
> was no way for me to specify the exact processor to be used.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email