如何在Java中选择saxon TransformerFactory [英] How to select saxon TransformerFactory in Java

查看:511
本文介绍了如何在Java中选择saxon TransformerFactory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Web应用程序中,我需要使用Saxon TransformerFactory才能使用XSLT 2.0,但我不能使用setProperty方法,因为我在Web服务器上没有这个权限,并且有一个安全管理器。

In my web application I need to use Saxon TransformerFactory in order to use XSLT 2.0 but I can't use setProperty method because I don't have this right on the web server and there is a Security Manager.

所以我读过应该可以这样做:

So I have read that it should be possible to do this:


使用Services API (如JAR规范中所详述),如果可用,则确定类名。 Services API将在运行时可用的jar文件META-INF / services / javax.xml.transform.TransformerFactory中查找类名。

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.

我在WEB-INF / lib / saxon9.jar中找到了这个文件但是当我实现TransformerFactory时,总是选择默认工厂而不是Saxon工厂。

I found this file in WEB-INF/lib/saxon9.jar but when I istantiate a TransformerFactory, the default factory is always selected instead of a Saxon factory.

如何选择Saxon Transformer Factory?

How can I select Saxon Transformer Factory?

谢谢

推荐答案

执行此操作的正确方法是在获取新的TransformerFactory时指定工厂类。

The proper way to do this is by specifying the factory class when getting a new TransformerFactory.

我不认为调用特定的工厂实现会起作用 - 我相信默认的系统变换器可能仍然会被返回(至少那就是当我在xalan和saxon中发生的事情时) classpath)。

I dont think calling a specific factory implementation will work - I believe the default system transformer might still be returned (at least thats what happened when I had xalan and saxon in the classpath).

示例:

TransformerFactory tFactory = TransformerFactory.newInstance("org.apache.xalan.processor.TransformerFactoryImpl",null);

或saxon

TransformerFactory tFactory = TransformerFactory.newInstance("net.sf.saxon.TransformerFactoryImpl",null);

Javadocs:


从工厂类
名称获取
TransformerFactory的新实例。当

类路径中有多个提供者时,此函数很有用。它可以更好地控制应用程序
,因为它可以指定
应该加载哪个提供程序。一旦
,应用程序获得了对TransformerFactory的
引用,
可以使用工厂配置,
获取变换器实例。

Obtain a new instance of a TransformerFactory from factory class name. This function is useful when there are multiple providers in the classpath. It gives more control to the application as it can specify which provider should be loaded. Once an application has obtained a reference to a TransformerFactory it can use the factory to configure and obtain transformer instances.

这篇关于如何在Java中选择saxon TransformerFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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