XProc and Java Extensions

Having trouble installing <oXygen/>? Got a bug to report? Post it all here.
fsteimke
Posts: 58
Joined: Tue Jan 01, 2013 3:19 pm

XProc and Java Extensions

Post by fsteimke » Sun Nov 22, 2020 8:19 pm

Hi,
i have a Question regarding the configuration of XProc Transformations.

I started with a regular XSLT Transformation Scenario. The Script preprocess.xsl uses a extension function written in Java. I had to add the jar File as an Extension in the Scenario, and it works fine.

Now i want to use the same script as Part of an XProc Pipeline (Calabash shipped with Oxygen). So i set up a simple XProc Script with only one p:xslt Step, referencing the same preprocess.xsl Script. After that i created an XProc Scenario with Input- and Output Ports, nothing more.

The XProc Transformation fails with an error message, indicating "Cannot find a 1-argument function named Q{java:de.kosit.docbook.utils.Image}getDimensions(). Cannot load Java class java:de.kosit.docbook.utils.Image".

Obviously, i have to find the place in the XProc Transformation where i can add a reference to the *jar file. Something equivalent to the Extensions in XSLT Transformation Scenario. Where is this for XProc?

Environment is Oxygen 23 at Windows 10.

Thanks in Advance,
Frank

Radu
Posts: 7434
Joined: Fri Jul 09, 2004 5:18 pm

Re: XProc and Java Extensions

Post by Radu » Mon Nov 23, 2020 8:58 am

Hi Frank,

I'm afraid we do not have settings to add JAR extensions directly in the XProc transformation scenario.
So for now you should edit the "OXYGEN_INSTALL_DIR/lib/xproc/calabash/engine.xml" configuration file and add a new library reference there, then restart Oxygen.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

fsteimke
Posts: 58
Joined: Tue Jan 01, 2013 3:19 pm

Re: XProc and Java Extensions

Post by fsteimke » Tue Nov 24, 2020 1:06 am

Hi Radu,
so i have to reference a jar file, which is part of my framework, from the engine.xml file which is part of $ OXYGEN_HOME. Sounds like i have to use an absolute path.
I am afraid that this won't work fo me, since i'd like to distribute the framework to our staff, where everyone has his or her own place for local Oxygen Projektects. Or is there any way to use environment variables like ${pdu}?

Some Oxygen versions ago i'd say that i place my jar file somewhere in $ OXYGEN_HOME/lib, but as far as i know this is not allowed anymore.

Maybe there is another solution especially in my case. The only reason for this Java Extension is the need to calculate intrinsic size of PNG images. Is there any way to do this from XSLT without my own extension functions?

Or would it be possible to extend the Action for the "Insert Image ..." Menu Entry, so that not only the url of the image is inserted, but also the intrinsic size?

Only workarounds, of course. It would be nice if i could place extensions in XProc Transformations in the same way as i do in XSLT Scenarions

Thanks,
Frank

Radu
Posts: 7434
Joined: Fri Jul 09, 2004 5:18 pm

Re: XProc and Java Extensions

Post by Radu » Tue Nov 24, 2020 9:58 am

Hi Frank,

Please see some answers below:
so i have to reference a jar file, which is part of my framework, from the engine.xml file which is part of $ OXYGEN_HOME. Sounds like i have to use an absolute path.
I am afraid that this won't work fo me, since i'd like to distribute the framework to our staff, where everyone has his or her own place for local Oxygen Projektects. Or is there any way to use environment variables like ${pdu}?
There is a type of Oxygen plugin which can contribute JAR libraries to Oxygen's global classpath.
We have a sample add-on here:
https://github.com/oxygenxml/oxygenxml.xlsx.import
It's plugin.xml references all libraries in a "lib" folder:

https://github.com/oxygenxml/oxygenxml. ... plugin.xml

and the addon.xml references a zip containing the plugin folder:

https://github.com/oxygenxml/oxygenxml. ... /addon.xml

People can use the Oxygen main menu Help->"Install new add-ons" to install add-ons on their side, add-ons hosted by you on a web server or in the case of the sample plugin above hosted on GitHub.
I think contributing the JAR libraries like this should make them accessible to XProc.

https://www.oxygenxml.com/doc/versions/ ... ddons.html
Maybe there is another solution especially in my case. The only reason for this Java Extension is the need to calculate intrinsic size of PNG images. Is there any way to do this from XSLT without my own extension functions?

I would assume not.
Or would it be possible to extend the Action for the "Insert Image ..." Menu Entry, so that not only the url of the image is inserted, but also the intrinsic size?
It is possible to compose two author actions so that they get executed one after the other:
https://blog.oxygenxml.com/topics/compo ... tions.html

so the first action would be the "Insert image" and the second could call a custom Java implementation of the AuthorOperation API:

https://www.oxygenxml.com/doc/versions/ ... HowTo.html

What I don't like about this is that it's redundant, the same information resides also inside the image. Also maybe the end user at some point modifies the image on disk but forgets to modify the attributes.
Only workarounds, of course. It would be nice if i could place extensions in XProc Transformations in the same way as i do in XSLT Scenarions
We have an issue to do that, we'll update this forum thread when an improvement becomes available.

Maybe another approach would be to create in your framework a custom ANT build file which first pre-processes the XML to add the sizes, then calls the XProc script.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

fsteimke
Posts: 58
Joined: Tue Jan 01, 2013 3:19 pm

Re: XProc and Java Extensions

Post by fsteimke » Wed Nov 25, 2020 10:12 am

Thanks, Radu, for these hints and suggestions.

I wonder if there is a way to do the whole thing in XProc. I found the metadata-extractor is an extensions shipped with calabash. So i asked in the xproc-dev mailing list and got an answer immediatly, see https://lists.w3.org/Archives/Public/xp ... /0020.html.

I have tried, but got an complaint about missing classes. Inspecting the calabash/engine.xml configuration file i found, that there is no reference to the library lib/xmlcalabash1-metadata-extractor-1.2.0.jar, although the jar file is part of the lib directory.

i added the reference to this jar file manually and restarted Oxygen.
But when i run the XProc Transformation, i still get an NoClassDefFoundError for com/drew/imaging/jpeg/JpegProcessingException.

Is there any misconfiguration? It is suspicious that there was no reference to this particular library in the xproc config file.

Thanks,
Frank

Radu
Posts: 7434
Joined: Fri Jul 09, 2004 5:18 pm

Re: XProc and Java Extensions

Post by Radu » Wed Nov 25, 2020 10:38 am

Hi Frank,

As a disclaimer we do not use XProc internally much and I have not previously tested the "metadata-extractor".
Looking in the Oxygen 23 installation folder in the "OXYGEN_INSTALL_DIR/lib/xproc/calabash/lib" folder I do not see the "metadata-extractor-1.2.0.jar" there. So did you download it from here:
https://github.com/ndw/xmlcalabash1-met ... r/releases
?

I unpacked the JAR library "xmlcalabash1-metadata-extractor-1.2.0.jar" but did not find any package with the com/drew/imaging/jpeg/ prefix so I guess an extra JAR is also needed, probably a JAR library produced by this project:
https://github.com/drewnoakes/metadata-extractor
The Jar can be downloaded from here:

https://search.maven.org/search?q=g:com ... -extractor

and maybe you can add it as well to the engine.xml as a reference.
If that does not work maybe you can ask around on the Calabash users list, see if there are people who made it work.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

fsteimke
Posts: 58
Joined: Tue Jan 01, 2013 3:19 pm

Re: XProc and Java Extensions

Post by fsteimke » Wed Nov 25, 2020 12:57 pm

Oops ... i'm afraid you are right. Maybe it was me who put the metadata extractor in the lib directory. Sorry for that.

And thanks for your hints. I will follow them and see where it goes.

Frank

Post Reply