New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds the ability to use integrated extension functions fo Saxon HE v. >= 9.2 #2880

Merged
merged 1 commit into from Jan 28, 2018

Conversation

Projects
3 participants
@mironovalexey
Contributor

mironovalexey commented Jan 19, 2018

Signed-off-by: Alexey Mironov mironovalexey@yandex.ru

Description

Adds the ability to use integrated extension functions (IEF) from within XSLT templates for Saxon HE.

Plugin developer have to implement IEF as a pair of Java classes - net.sf.saxon.lib.ExtensionFunctionDefinition and net.sf.saxon.lib.ExtensionFunctionCall (https://www.saxonica.com/html/documentation/extensibility/integratedfunctions/ext-full-J.html). The class that implements net.sf.saxon.lib.ExtensionFunctionDefinition should be declared as service provider (https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html) in the directory META-INF/services of jar file.

Motivation and Context

Starting with the version 9.2
"The traditional mechanism for binding extension functions by reflexion (searching the classpath for matching names) is now available only in Saxon-PE and Saxon-EE. In Saxon-HE, the only way to define extension functions is the new mechanism of "integrated extension functions", which need to be explicitly registered with the Configuration."
https://www.saxonica.com/html/documentation/changes/v9.2/installation.html

How Has This Been Tested?

Type of Changes

  • New feature (non-breaking change which adds functionality)

Checklist

// Registering full integrated function definitions (instances of net.sf.saxon.lib.ExtensionFunctionDefinition abstract class).
// https://www.saxonica.com/html/documentation/extensibility/integratedfunctions/ext-full-J.html
if (tf.getClass().isAssignableFrom(net.sf.saxon.TransformerFactoryImpl.class)) {

This comment has been minimized.

@jelovirt

jelovirt Jan 19, 2018

Member

This block should be in its own method, e.g. configureExtensions.

net.sf.saxon.TransformerFactoryImpl tfi = (net.sf.saxon.TransformerFactoryImpl) tf;
net.sf.saxon.Configuration conf = tfi.getConfiguration();
final Iterator<ExtensionFunctionDefinition> fullIefDefinitions = ServiceLoader.load(ExtensionFunctionDefinition.class).iterator();

This comment has been minimized.

@jelovirt

jelovirt Jan 19, 2018

Member

Instead of iterator + while-loop, use for-loop.

throw new RuntimeException("Failed to register " + def.getFunctionQName().getDisplayName()
+ ". Cannot create instance of " + def.getClass().getName() + ": " + e.getMessage(), e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e.getMessage(), e);

This comment has been minimized.

@jelovirt

jelovirt Jan 19, 2018

Member

Use new RuntimeException(e) when there's not custom message.

@jelovirt jelovirt added this to To Do in 3.1 via automation Jan 19, 2018

@jelovirt jelovirt moved this from To Do to In progress in 3.1 Jan 19, 2018

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

This comment has been minimized.

@jelovirt

jelovirt Jan 27, 2018

Member

Remove this file

}
}
// Registering full integrated function definitions (instances of net.sf.saxon.lib.ExtensionFunctionDefinition abstract class).

This comment has been minimized.

@jelovirt

jelovirt Jan 27, 2018

Member

Convert this to Javadoc

// Registering full integrated function definitions (instances of net.sf.saxon.lib.ExtensionFunctionDefinition abstract class).
// https://www.saxonica.com/html/documentation/extensibility/integratedfunctions/ext-full-J.html
private void configureSaxonExtensions(net.sf.saxon.TransformerFactoryImpl tfi) {
net.sf.saxon.Configuration conf = tfi.getConfiguration();

This comment has been minimized.

@jelovirt

jelovirt Jan 27, 2018

Member

Use final variable declarations

This comment has been minimized.

@eerohele

eerohele Jan 27, 2018

Member

Could also maybe import net.sf.saxon.TransformerFactoryImpl?

This comment has been minimized.

@mironovalexey

mironovalexey Jan 27, 2018

Contributor

I intentionally use fully qualified name to avoid the intersection with Xalan's TransformerFactoryImpl. XSLT module supports both processors.

@jelovirt jelovirt moved this from In progress to Review in 3.1 Jan 27, 2018

Adds the ability to use integrated extension functions (IE) from with…
…in XSLT templates for Saxon HE.

Starting with the version 9.2
"The traditional mechanism for binding extension functions by reflexion (searching the classpath for matching names) is now available only in Saxon-PE and Saxon-EE. In Saxon-HE, the only way to define extension functions is the new mechanism of "integrated extension functions", which need to be explicitly registered with the Configuration."
https://www.saxonica.com/html/documentation/changes/v9.2/installation.html

Plugin developer have to implement IEF as a pair of Java classes - net.sf.saxon.lib.ExtensionFunctionDefinition and net.sf.saxon.lib.ExtensionFunctionCall (https://www.saxonica.com/html/documentation/extensibility/integratedfunctions/ext-full-J.html). The class that implements net.sf.saxon.lib.ExtensionFunctionDefinition should be declared as service provider  (https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html) in the directory META-INF/services of jar file.

Signed-off-by: Alexey Mironov <mironovalexey@yandex.ru>

@jelovirt jelovirt merged commit 0b3e3d2 into dita-ot:develop Jan 28, 2018

2 checks passed

DCO All commits have a DCO sign-off from the author
continuous-integration/travis-ci/pr The Travis CI build passed
Details

3.1 automation moved this from Review to Done Jan 28, 2018

@jelovirt jelovirt added this to the Next milestone Jan 28, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment