Page 1 of 1
Calling java method through schematron throwing error
Posted: Wed Apr 26, 2023 6:35 pm
by roopesh79
Hi Team,
Could you please share a schematron pattern that call a simple java method by adding a jar file in class path?
Regards
Roopesh
Re: Calling java method through schematron throwing error
Posted: Sat Apr 29, 2023 8:13 am
by johnwood
Here's an example Schematron pattern that calls a Java method by adding a JAR file to the classpath:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<iso:schema xmlns:iso="http://purl.oclc.org/dsdl/schematron" xmlns:jav="http://www.niso.org/schemas/jav" queryBinding="xslt2">
<iso:pattern name="javaMethod">
<iso:rule context="//*[local-name()='document']/*[local-name()='section']/*[local-name()='p']">
<iso:report test="@class = 'java'">
<iso:text>Calling Java method: </iso:text>
<jav:java>
<jav:classpath>
<jav:jar>path/to/your/jar/file.jar</jav:jar>
</jav:classpath>
<jav:call>
<jav:method>com.example.yourclass.yourMethod()</jav:method>
</jav:call>
</jav:java>
</iso:report>
</iso:rule>
</iso:pattern>
</iso:schema>
the
jav:java element specifies the JAR file to be added to the classpath, and the
jav:callwordle unlimited element specifies the Java method to be called. You will need to replace
path/to/your/jar/file.jar with the actual path to your JAR file, and
com.example.yourclass.yourMethod() with the fully qualified name of the Java class and method you want to call.
Re: Calling java method through schematron throwing error
Posted: Mon May 01, 2023 8:05 am
by Radu
Hi Roopesh,
Here's an example
https://www.oxygenxml.com/InstData/Edit ... nUtil.html
for calling from a class "ro.sync.ecss.dita.extensions.DITAXSLTExtensionFunctionUtil" a static function named "getKeyRefInfo" with two parameters of type string.
Regards,
Radu
Re: Calling java method through schematron throwing error
Posted: Tue May 02, 2023 2:50 pm
by chrispitude
Hi Roopesh,
If you want a small testcase that demonstrates the API that Radu mentioned, I can provide it.
Re: Calling java method through schematron throwing error
Posted: Wed May 03, 2023 1:01 pm
by roopesh79
Hi,
Thank you for the detailed information. It is really helpful. Please share one API test case sample also.
Thanks
Roopesh N
Re: Calling java method through schematron throwing error
Posted: Wed May 03, 2023 2:55 pm
by chrispitude
Hi Roopesh,
Here is a testcase that calls the
new keyref APIs introduced in Oxygen v25.1:
api_testcase_for_roopesh.zip
To try them out,
1. Open the OPENME1.xpr file in Oxygen v25.1.
2. Open the OPENME2.ditamap file in the DITA Maps Manager.
3. Open a topic in the Book A or Book B submap.
4. Hover your pointer over an
<xref> element to see the Schematron/API messages as tooltips.
5. Run
Validate and Check for Completeness to see the Schematron/API messages.
Re: Calling java method through schematron throwing error
Posted: Fri May 05, 2023 8:34 am
by roopesh79
Hi Tea,
I have tried the first approach and not getting the actual java response.
<iso:pattern id="javaMethod">
<iso:rule context="ol">
<iso:report test="@outputclass = 'java'">
<jav:java>
<jav:classpath>
<jav:jar>C:\Progfiles\XDocsOxygenAuthor\frameworks\validations\Oxy.jar</jav:jar>
</jav:classpath>
<jav:call>
<jav:method>net.example.Alert_Oxygen.test()</jav:method>
</jav:call>
</jav:java>
</iso:report>
</iso:rule>
</iso:pattern>
I am getting the below message(screenshot) in the oxygen with all the schematron syntax. Not getting the actual java message.
Thanks
Roopesh
Re: Calling java method through schematron throwing error
Posted: Fri May 05, 2023 8:55 am
by Radu
Hi,
The Oxygen forum is a public place, the person who recommended this solution you tried is not part of the Oxygen team and I think his answer is wrong.
Are you applying the Schematron validation on an XML document opened in Oxygen?
Usually this would mean that you have a validation scenario stage which has been configured to apply the Schematron schema on the XML document. And a validation scenario stage can specify a reference to extra JAR libraries to be used for validation:
https://www.oxygenxml.com/doc/versions/ ... xk_bgk_54b
Once you specify in the validation scenario that you want the JAR library (or libraries) to be used with Schematron validation, you can then use the Java classes directly in the Schematron schema in the way in which Chris or I mentioned:
Code: Select all
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<sch:ns uri="java:package.name.JavaClassName" prefix="myPrefix"/>
<sch:pattern>
<sch:rule context="..">
<sch:report test="myPrefix:staticMethodName(params)'">....
</sch:report>
</sch:rule>
</sch:pattern>
</sch:schema>
But usually in such cases it's best to start with an usecase and more details, for example what Oxygen version you have, what end result do you want to achieve? What does your custom Java extension do? Is it already built? Are you validating the XML documents using Schematron inside Oxygen?
Regards,
Radu
Re: Calling java method through schematron throwing error
Posted: Fri May 05, 2023 10:46 am
by roopesh79
Hi Radu,
I am using Oxygen 21.1(planning to upgrade to 23.1). I have configured the custom schematron in the document type association. Now I want to add a jar file in class path and validate the dita elements against some schematron rules which call the java method present in the jar files. My final goal is to call an external API using jar and validate dita files.
Currently I am trying to run a "hello world" kind of java progam with in schematron, but getting a different error (Cannot find a 0-argument function named {java:net.example.Alert_Oxygen}test...). Not sure the jar file is integrated correctly. I have added jar file using the "schema dialogue box" also. Please guide me on this.
image.png
Thanks
Roopesh
Re: Calling java method through schematron throwing error
Posted: Fri May 05, 2023 12:09 pm
by Radu
Hi Roopesh,
Here are some screenshots showing that when you configure a validation stage in the validation scenario you have an "Extensions" button which you can use to add references to JAR libraries:
Screenshot 2023-05-05 at 12.06.23.png
Screenshot 2023-05-05 at 12.07.07.png
Screenshot 2023-05-05 at 12.07.19.png
Screenshot 2023-05-05 at 12.07.37.png
Regards,
Radu