Java Extensions with Saxon

Here should go questions about transforming XML with XSLT and FOP.
William
Posts: 42
Joined: Sun Jul 15, 2012 12:26 pm
Location: London

Java Extensions with Saxon

Post by William »

Hello,

I am trying to create an XSLT transformer that gets some of its data from a Java object. I am using

Code: Select all


<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:RM="java:you.RM.Definition" exclude-result-prefixes="xs RM">
and inside my template I am using

Code: Select all

<xsl:variable name="Def" select="RM:new()" />
but I get told "Saxon-PE 9.4.0.4 cannot find a matching 0-argument function named {java:you.RM.Definition}new()". However the only constructor for this Class is parameterless.

Viewing the jar file added to the transformer's extensions I can plainly see the class in question so I am a little confused here. I have tried both PE and SE to no avail.

Any help with this would be appreciated.

P.S. I also get this: For diagnostics on calls to Java methods, use the -TJ command line option or set the Configuration property FeatureKeys.TRACE_EXTERNAL_FUNCTIONS but passing -TJ via the start up shell script doesn't work and I see no other obvious way to do this.

--
William
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Java Extensions with Saxon

Post by adrian »

Hello,

It should have worked, I don't see any problems in the XSLT code, the problem lies elsewhere.

Is the constructor of the java class (you.RM.Definition) public?
Make sure the folder path from the jar (open it with a ZIP tool) is structured correctly: you/RM/Definition.class

Have you tested the jar from Java code, independent from Oxygen?
Try to instantiate the class from a main class/method directly in Java (new you.RM.Definition()), but make sure you use the jar in the classpath instead of the actual Java .class files.

In Oxygen make sure you have added the correct jar to the Extensions from the transformation scenario dialog.

e.g. I've tested with this:

Code: Select all

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:java="java:org.dita.dost.util.XMLGrammarPoolImplUtils"
exclude-result-prefixes="java"
version="2.0">

<xsl:variable name="Def" select="java:new()" />

<xsl:template match="/">
<xsl:value-of select="$Def"/>
</xsl:template>
</xsl:stylesheet>
And I've added to the Extensions from the transformation scenario the jar (use this exact URL):
${frameworks}/dita/DITA-OT/lib/dost.jar
It's an utility jar from DITA-OT. I'm using this because it should be available with any version of Oxygen.

When you transform this, it should output something like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>org.dita.dost.util.XMLGrammarPoolImplUtils@47a9b32
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
William
Posts: 42
Joined: Sun Jul 15, 2012 12:26 pm
Location: London

Re: Java Extensions with Saxon

Post by William »

adrian wrote:Hello,

It should have worked, I don't see any problems in the XSLT code, the problem lies elsewhere.

Is the constructor of the java class (you.RM.Definition) public?
Yes.
adrian wrote: Make sure the folder path from the jar (open it with a ZIP tool) is structured correctly: you/RM/Definition.class
Yes again this is correct when viewed using FileRoller 2.30.2.
adrian wrote: Have you tested the jar from Java code, independent from Oxygen?
Yes, I can construct an instance of it and call its various methods.
adrian wrote: Try to instantiate the class from a main class/method directly in Java (new you.RM.Definition()), but make sure you use the jar in the classpath instead of the actual Java .class files.
I can do this again without issue.
adrian wrote: In Oxygen make sure you have added the correct jar to the Extensions from the transformation scenario dialog.
I had triple checked this prior to my submission as as far as I was concerned I was doing everything right and it should have worked.
adrian wrote: e.g. I've tested with this:

Code: Select all

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:java="java:org.dita.dost.util.XMLGrammarPoolImplUtils"
exclude-result-prefixes="java"
version="2.0">

<xsl:variable name="Def" select="java:new()" />

<xsl:template match="/">
<xsl:value-of select="$Def"/>
</xsl:template>
</xsl:stylesheet>
And I've added to the Extensions from the transformation scenario the jar (use this exact URL):
${frameworks}/dita/DITA-OT/lib/dost.jar
It's an utility jar from DITA-OT. I'm using this because it should be available with any version of Oxygen.

When you transform this, it should output something like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>org.dita.dost.util.XMLGrammarPoolImplUtils@47a9b32
Regards,
Adrian
I tried this and I got : org.dita.dost.util.XMLGrammarPoolImplUtils@46db97c0

So this is even stranger! It would appear that the issue is between the seat and the keyboard but for the life of me I cannot see what I am doing wrong.

I deleted the jar file from the file system and (obviously) I get an error, but in this case the same error. Not a missing "jar" file error so does this imply that it is path related?

Also, can you please tell me how I can turn on FeatureKeys.TRACE_EXTERNAL_FUNCTIONS please within the IDE please.

--
William
William
Posts: 42
Joined: Sun Jul 15, 2012 12:26 pm
Location: London

Re: Java Extensions with Saxon

Post by William »

Hello.

OK I've found the problem it is my fault (well sort of) but better error messages would be beneficial. The original jar file is built using v1.7.0_07 of the JDK but when I create 1.6 compatible test jar it works! I can't change the Java code so how can I make oxygen compatible with 1.7.0_07 JRE?

--
William
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Java Extensions with Saxon

Post by adrian »

Hi,

Saxon probably catches the Java exception and provides that generic error message. We'll look into it and forward it to Saxonica if appropriate.

If you can't recompile that specific jar with the 1.6 compatibility flag, you could bypass or change Oxygen's bundled JRE (for Windows and Linux) to Java SE 7.

You can download Java SE 7 JRE here:
http://www.oracle.com/technetwork/java/ ... index.html
Make sure you download a JRE with the same architecture (32/64 bit) as the Oxygen kit you have installed. You can check the architecture in Help > About, System Properties, look for the property: sun.arch.data.model.

To bypass the JRE bundled with Oxygen (Windows and Linux) and use the one installed on your system, quit Oxygen, navigate to the Oxygen installation folder and rename the 'jre' folder. e.g. 'jreold'. When you start Oxygen, it will automatically pick up and use your system installed Java VM. You can check the JVM version in Oxygen in: Help > About, System properties, java.runtime.version.

Alternatively you can copy an installed JRE to the Oxygen folder in place of the old 'jre' folder. Make sure that the path to java (or javaw) is [Oxygen-folder]/jre/bin/java.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
William
Posts: 42
Joined: Sun Jul 15, 2012 12:26 pm
Location: London

Re: Java Extensions with Saxon

Post by William »

Thank you very much Adrian. I've now changed oxygen to use the 1.7.0._07 JRE by following your instructions and all of my errors have now disappeared :D, so thank you again for your time.

--
William
Post Reply