Validate XML and throw error progrmatically

Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
ganem2
Posts: 20
Joined: Wed Jun 29, 2022 8:49 am

Validate XML and throw error progrmatically

Post by ganem2 »

Hi Team,
I have scenarios where i need to check for few validations based on the content of xml and throw dynamic error messages. I have done few basic validations using schematron file as per customization guide. But i could not find any JAV API or approach to achieve same programmatically in customization guide. Could you please share a guide/document which can help me?

Oxygen XML Web author Version: 25
For basic validation Schematron file is supplied with Framework.
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

Re: Validate XML and throw error progrmatically

Post by mihaela »

Hello,

There is a possibility to add a ro.sync.exml.workspace.api.editor.validation.ValidationProblemsFilter that allows you to update the list of validation problems.

Here is a sample plugin that uses this API:
https://github.com/oxygenxml/web-author ... ems-filter

Is this API suitable for your use case?

Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
ganem2
Posts: 20
Joined: Wed Jun 29, 2022 8:49 am

Re: Validate XML and throw error progrmatically

Post by ganem2 »

Hello,

I tried to use ValidationProblemsFilter as per your suggestion and i was able to validate and throw custom error message, but when I click on message it does not select the error xml node.
for Schematron validation scenarios on click of error message target element is selected and cursor focus is shifted to error element.
below is the code snippet i used for creating custom error message. could you please let me know what i am missing here?

Code: Select all

@Override
public void filterValidationProblems(ValidationProblems validationProblems) {
		AuthorNode node = getErrorXMLNode(); // method to get author node where error scenario exists.
		List<DocumentPositionedInfo> problems = validationProblems.getProblemsList();
		if(null == problems) { // If there are no errors in document getProblemsList returns null.
			problems = new ArrayList<>(); 
		}
		AuthorDocumentPositionedInfo positionInfo = new AuthorDocumentPositionedInfo(
			DocumentPositionedInfo.SEVERITY_WARN, "Custom error message", node);
		problems.add(positionInfo)
		validationProblems.setProblemsList(problems);
}
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

Re: Validate XML and throw error progrmatically

Post by mihaela »

Hello,

I tested and in my case, the node is selected. Can you log the node that you obtain from the getErrorXMLNode() method to see if it returns the expected node? Maybe it returns null (in this case the validation error is listed but nothing happens when you click on it).

Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
ganem2
Posts: 20
Joined: Wed Jun 29, 2022 8:49 am

Re: Validate XML and throw error progrmatically

Post by ganem2 »

Hello,

I reverified my logic and i amde sure that i am not getting any null objects in place of node. for testing urpose i simplified my logic for getErrorXMLNode() as below.

Code: Select all

	public AuhorNode getErrorXMLNode(WSAuthorEditorPage page) throws AuthorOperationException{
		//getting all 'paratext' xml nodes in current document.
		AuthorNode[] nodes = page.getDocumentController().findNodesByXPath("//paratext", true, true, true);
		if (nodes.length > 0) {
			log.info("returning first para " + nodes[0].getDisplayName());
			return nodes[0];
		} else {
			throw new AuthorOperationException("Operation Failed");
		}
	}
I have verified through logs that above method is returning proper node. but still on click of warning message 'Custom error message' cursor is not getting focused on the element in this case first paratext node in document.
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

Re: Validate XML and throw error progrmatically

Post by mihaela »

Hi,

We need your help to reproduce this problem. Any details would be helpful for us.
Are there any other validation items in the Validation view? When you select other item the corresponding element is selected?
Where is the focus when you select your validation item?

Can you send us a sample XML file, a video, and maybe your plugin to reproduce the problem? You can send them to support@oxygenxml.com if you want.

Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
ganem2
Posts: 20
Joined: Wed Jun 29, 2022 8:49 am

Re: Validate XML and throw error progrmatically

Post by ganem2 »

Hi,

Yes i have configured schematron file validation through framework. schematron file is shared along with framework i.e inside teh custom framework directory. In this scenario along with my custom error message there is 1 more message due to schematron validation.
on clik of error message generated by schematron file target element is selected and focus is set on editor. when i click on custo error message focus remain in validation message right panel and no element is selectd in editor.

I will check with my Info team on what can be shared outside organization. If sharing is not option i will try to set up dummy plugin with reproducible code and share it.
ganem2
Posts: 20
Joined: Wed Jun 29, 2022 8:49 am

Re: Validate XML and throw error progrmatically

Post by ganem2 »

Hi,
I have attached the plugin code with sample xml. please take a look into this. use "mvn clean package" command to build plugin. after build jar will be placed under 'target\dist\plugins' folder
Development.zip
(7.74 KiB) Downloaded 268 times
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

Re: Validate XML and throw error progrmatically

Post by mihaela »

Hello,

Thank you for the plugin. We uploaded it on a fresh installation of Web Author version 25.0 and the custom validation item appears in the Validation view. When clicking on it, the first paratext element is selected:
selection.png
selection.png (52 KiB) Viewed 2025 times
Is there any other customization in your test environment that could affect the selection?

Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
ganem2
Posts: 20
Joined: Wed Jun 29, 2022 8:49 am

Re: Validate XML and throw error progrmatically

Post by ganem2 »

Hello,

I tried again with fresh installation of web author to see if any other items are causing issue but still facing the same issue. on click of error message nothing happens.
image.png
image.png (34.46 KiB) Viewed 2019 times
My web author version: Running oXygen XML Web Author 25.0, build 2022100711/2022100714 Copyright (c) 2022 Syncro Soft SRL
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

Re: Validate XML and throw error progrmatically

Post by mihaela »

Hi,

Can you please tell us what browser are you using?

Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
ganem2
Posts: 20
Joined: Wed Jun 29, 2022 8:49 am

Re: Validate XML and throw error progrmatically

Post by ganem2 »

Google Chrome Version 108.0.5359.125 (Official Build) (64-bit)
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

Re: Validate XML and throw error progrmatically

Post by mihaela »

Hi,

Thank you, we also tested using this version of Chrome.

Other things to try:
1. Can you please check the Elements tab from the browser developer tools when the div corresponding to the "Custom error message" is selected, to see what are the values of data-start-pos and data-end-pos attributes?
image.png
image.png (135.24 KiB) Viewed 1970 times
2. Also, please look in the Console tab from the browser developer tools to see if there is an error in it.

Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
ganem2
Posts: 20
Joined: Wed Jun 29, 2022 8:49 am

Re: Validate XML and throw error progrmatically

Post by ganem2 »

Hi,
I did not see any errors on console. below is the response which i saw in network log. also error message div's dont have any start and end position like shown in your screenshot.
image.png
image.png (19.88 KiB) Viewed 1962 times

Code: Select all

{
    "errors": [{
        "errorMessage": "There is no schema or DTD associated with the document. You can create an association either with the Associate Schema action or configuring in the Options the Preferences/Document Type Association list, or by creating a Validation Scenario.",
        "severity": "error",
        "startPosition": "",
        "endPosition": "",
        "nodeIds": [],
        "docTypeName": null,
        "scenarioName": null,
        "quickFixes": [],
        "additionalInfo": null
    }, {
        "errorMessage": "Custom error message paratext",
        "severity": "error",
        "startPosition": "",
        "endPosition": "",
        "nodeIds": [],
        "docTypeName": null,
        "scenarioName": null,
        "quickFixes": [],
        "additionalInfo": null
    }],
    "complete": true
}
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

Re: Validate XML and throw error progrmatically

Post by mihaela »

Hello,

Thank you for the details. It seems that the start and end positions (for selection) are not set from the server side. This happens for example when the system Id of the editor does not correspond with the system id determined from the AuthorDocumentPositionedInfo.

Can you please modify your plugin to use the AuthorDocumentPositionedInfo constructor that also receives the systemID parameter and check again to see if the selection works in this case? The systemID can be obtained using controller.getAuthorDocument().getSystemID().

Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
ganem2
Posts: 20
Joined: Wed Jun 29, 2022 8:49 am

Re: Validate XML and throw error progrmatically

Post by ganem2 »

Hello,
Thank you for your reply, adding systemID to postionedInfo constructor solved the issue. :D .
Post Reply