Project

Profile

Help

Getting Configuration of TransformerFactory, 9.5 versus 9.8

Added by Martin Honnen about 7 years ago

While trying to set up a local copy of xsltransform.net and update it to use Saxon 9.8 HE I have run into a problem, the code using Saxon 9.5 HE in there (https://github.com/joepjoosten/XSL-tester/blob/master/app/net/xsltransform/plugin/Saxon9HEPlugin.java#L39) does


            Class FeatureKeysClass = saxon9HEClassLoader.loadClass("net.sf.saxon.lib.FeatureKeys");
            Class ConfigurationClass = saxon9HEClassLoader.loadClass("net.sf.saxon.Configuration");
            Class StandardErrorListenerClass = saxon9HEClassLoader.loadClass("net.sf.saxon.lib.StandardErrorListener");

            Object conf = transformerFactory.getAttribute((String)FeatureKeysClass.getField("CONFIGURATION").get(null));
            Object errorListener = ConfigurationClass.getMethod("getErrorListener").invoke(conf);
            StandardErrorListenerClass.getMethod("setErrorOutput", PrintStream.class).invoke(errorListener, new PrintStream(errors));

when I try to use that code with Saxon 9.8 HE I get an exception

Caused by: java.lang.IllegalArgumentException: Unknown configuration property http://saxon.sf.net/feature/configuration
        at net.sf.saxon.Configuration.getConfigurationProperty(Configuration.java:5021) ~[na:na]
        at net.sf.saxon.jaxp.SaxonTransformerFactory.getAttribute(SaxonTransformerFactory.java:322) ~[na:na]
        at net.xsltransform.plugin.Saxon9HEPlugin.newTransformer(Saxon9HEPlugin.java:39) ~[na:na]

on the line


            Object conf = transformerFactory.getAttribute((String)FeatureKeysClass.getField("CONFIGURATION").get(null));

Looking at the current 9.8 documentation https://www.saxonica.com/html/documentation/javadoc/net/sf/saxon/lib/FeatureKeys.html#CONFIGURATION it still says

public static final String CONFIGURATION This attribute cannot be set on the Configuration itself, but it can be set on various JAXP factory objects such as a TransformerFactory or DocumentBuilderFactory, to ensure that several such factories use the same Configuration.

which does not seem to indicate any difference to the 9.5 documentation.

Is there any way to use the JAXP @getAttribute@ method with a Saxon FeatureKeys class field to access the Configuration in 9.8?


Replies (3)

Please register to reply

RE: Getting Configuration of TransformerFactory, 9.5 versus 9.8 - Added by Michael Kay about 7 years ago

Seems the answer is no. For some reason on the factory you can do setAttribute(CONFIGURATION) but not getAttribute(CONFIGURATION). The property is special-cased in the s9api Processor on the setProperty method but not the getProperty method.

RE: Getting Configuration of TransformerFactory, 9.5 versus 9.8 - Added by Martin Honnen about 7 years ago

I have come up with


           Class ProcessorClass = saxon9HEClassLoader.loadClass("net.sf.saxon.s9api.Processor");
            
            Object proc = TransformerFactoryClass.getMethod("getProcessor").invoke(transformerFactory);

            Object conf = ProcessorClass.getMethod("getUnderlyingConfiguration").invoke(proc);

that seems to work as far as getting the configuration is concerned.

    (1-3/3)

    Please register to reply