如何设置 Javax.xml.transform.TransformerFactory 系统属性 [英] How to set Javax.xml.transform.TransformerFactory system property

查看:70
本文介绍了如何设置 Javax.xml.transform.TransformerFactory 系统属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 javax.xml.transform.Transform 将 xml 文件转换为 PDF.这本身就可以正常工作,但项目的某些部分正在使用 Xalan,它实现了自己的 TransformerFactory,而其中的某些内容不适用于 Cyrillic.

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.

我在 https://xml.apache.org/xalan-j 找到/usagepatterns.html 有一个属性用于定义使用的工厂:

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 是一个具有静态 newInstance() 方法的抽象类,该方法实例化由 javax.xml.transform.TransformerFactory 系统属性指定的具体子类.

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

此系统属性的默认设置为 org.apache.xalan.processor.TransformerFactoryImpl.

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

我的问题是:如何设置此属性以不使用 Xalan?

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

推荐答案

要么在执行程序时从命令行静态设置它,使用 -D 标志:

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

或者在您的应用程序中动态地使用 System.setProperty():

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.

这篇关于如何设置 Javax.xml.transform.TransformerFactory 系统属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆