Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default TransformerFactory?

Tags:

java

xslt

jaxp

I'm using JAXP XSLT APIs (javax.xml.transform) to transform xml file.

TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer(xslSource);
transformer.transform(inputSource, outputResult);

The javadoc for TransformerFactory says: It uses the following ordered lookup procedure to determine the TransformerFactory implementation class to load:

  1. Use the javax.xml.transform.TransformerFactory system property.
  2. 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.
  3. 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.
  4. Platform default TransformerFactory instance.

I wonder how to decide which is the default TransformerFactory instance?

like image 540
user3014901 Avatar asked Feb 11 '23 12:02

user3014901


1 Answers

"Platform" here is Java-speak for the Java compiler / runtime you are using. So the "platform default" means whatever the JDK decides. In the case of the Oracle JDK, it's a version of the Xalan XSLT 1.0 engine that's built in to the JDK. A different JDK could use a different default.

like image 81
Michael Kay Avatar answered Feb 13 '23 04:02

Michael Kay