当前位置: 动力学知识库 > 问答 > 编程问答 >

java - What is the default TransformerFactory?

问题描述:

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?

网友答案:

"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.

网友答案:

From Oracle JDK 1.7

Class javax.xml.transform.TransformerFactory:

Default Transformer is XSLTC (originally forked from Xalan). XSLTC is the compiling version (the 'C' in XSLTC) com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl

public static TransformerFactory newInstance()
    throws TransformerFactoryConfigurationError {
    try {
        return (TransformerFactory) FactoryFinder.find(
        /* The default property name according to the JAXP spec */
        "javax.xml.transform.TransformerFactory",
        /* The fallback implementation class name, XSLTC */
        "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
    } catch (FactoryFinder.ConfigurationError e) {
        throw new TransformerFactoryConfigurationError(
            e.getException(),
            e.getMessage());
    }
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: