Calling java method through schematron throwing error
Having trouble installing Oxygen? Got a bug to report? Post it all here.
-
- Posts: 5
- Joined: Sat Apr 29, 2023 8:05 am
Re: Calling java method through schematron throwing error
Here's an example Schematron pattern that calls a Java method by adding a JAR file to the classpath:
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.
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>
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Calling java method through schematron throwing error
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
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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 922
- Joined: Thu May 02, 2019 2:32 pm
Re: Calling java method through schematron throwing error
Post by chrispitude »
Hi Roopesh,
If you want a small testcase that demonstrates the API that Radu mentioned, I can provide it.
If you want a small testcase that demonstrates the API that Radu mentioned, I can provide it.
-
- Posts: 922
- Joined: Thu May 02, 2019 2:32 pm
Re: Calling java method through schematron throwing error
Post by chrispitude »
Hi Roopesh,
Here is a testcase that calls the new keyref APIs introduced in Oxygen v25.1:
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.
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.
You do not have the required permissions to view the files attached to this post.
-
- Posts: 27
- Joined: Fri Jul 29, 2022 9:55 am
Re: Calling java method through schematron throwing error
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
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
You do not have the required permissions to view the files attached to this post.
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Calling java method through schematron throwing error
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:
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
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>
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 27
- Joined: Fri Jul 29, 2022 9:55 am
Re: Calling java method through schematron throwing error
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.
Roopesh
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
ThanksRoopesh
You do not have the required permissions to view the files attached to this post.
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Calling java method through schematron throwing error
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:
Radu
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
You do not have the required permissions to view the files attached to this post.
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service