javaxslt-1.0xsl-foxalan

How to set javax.xml.transform.TransformerFactory system property


I am using javax.xml.transform.Transform to convert an XML file to a PDF. This works fine on its own, but some part of the project is using Xalan, which implements its own TransformerFactory, and something in there doesn't work with Cyrillic.

I have found at https://xml.apache.org/xalan-j/usagepatterns.html that there is a property which is used to define the used factory :

TransformerFactory is an abstract class with a static newInstance() method that instantiates the concrete subclass designated by the javax.xml.transform.TransformerFactory system property.

The default setting for this system property is org.apache.xalan.processor.TransformerFactoryImpl.

My question is : How do I set this property to not use Xalan ?


Solution

  • Either set it statically from the command line when you execute your program, using the -D flag:

    java -Dorg.apache.xalan.processor.TransformerFactoryImpl=com.xyz.YourFactory YourApp
    

    Or dynamically from within your application, using System.setProperty():

    System.setProperty("org.apache.xalan.processor.TransformerFactoryImpl",
            "com.xyz.YourFactory");
    

    Note that you need to use the fully qualified class name of the factory class, and that the factory needs to be on your classpath for either of these to work.