how to prevent adding wrong attribute and wrong value in web author

Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
shikhar_472
Posts: 99
Joined: Fri Jul 01, 2022 12:08 pm

how to prevent adding wrong attribute and wrong value in web author

Post by shikhar_472 »

Hi Team,

Is there any way by which we can prevent adding the wrong attribute or wrong value to any element.

Thanks,
Shikhar.
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

Re: how to prevent adding wrong attribute and wrong value in web author

Post by mihaela »

Hello,

You can use the AuthorDocumentFilter API, it includes a method called setAttribute that is invoked before setting the value of an attribute in the specified element and you can use it to reject the wrong attribute names or values.

Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
shikhar_472
Posts: 99
Joined: Fri Jul 01, 2022 12:08 pm

Re: how to prevent adding wrong attribute and wrong value in web author

Post by shikhar_472 »

is there any option.xml configuration in oxygen which will validate according through schema and prevent to add attribute
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

Re: how to prevent adding wrong attribute and wrong value in web author

Post by mihaela »

Hi,

Can you please detail your use-case? You want the user not be able to insert an invalid attribute or just an attribute value?
For the moment there is no option like this but we can register an issue, depending on your request.

Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
shikhar_472
Posts: 99
Joined: Fri Jul 01, 2022 12:08 pm

Re: how to prevent adding wrong attribute and wrong value in web author

Post by shikhar_472 »

Thanks mihela,

It got worked for me is it possible when attribute is not getting added we can provide error message on UI of web author from right attribute pane saying attribute could not be added, because that UI is not in our control so is there any way to do that quickly
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

Re: how to prevent adding wrong attribute and wrong value in web author

Post by mihaela »

Hello,

There is no way for you to add a message in the Attributes panel from API.
You can use the AuthorDocumentFilter API that I mentioned in a previous message (setAttribute method) and check if the attribute is valid. If it is not you can reject the operation and present a message to the user.

Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
shikhar_472
Posts: 99
Joined: Fri Jul 01, 2022 12:08 pm

Re: how to prevent adding wrong attribute and wrong value in web author

Post by shikhar_472 »

how to present the message to the user from backend is it possible without having the UI control
shikhar_472
Posts: 99
Joined: Fri Jul 01, 2022 12:08 pm

Re: how to prevent adding wrong attribute and wrong value in web author

Post by shikhar_472 »

if (StringUtils.isNotBlank(value.getRawValue()) && validateAttributeAndValue(element, attributeName, value)) {
super.setAttribute(filterBypass, attributeName, value, element);
}else {

}


inside else block i want to throw error if attribute is not get added and that should be visible on UI
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

Re: how to prevent adding wrong attribute and wrong value in web author

Post by mihaela »

Hello,

You can use the following API to present a warning to the user: ro.sync.exml.workspace.api.WorkspaceUtilities.showWarningMessage(String)

The code should be something like this:

Code: Select all

authorDocumentModel.getAuthorAccess().getWorkspaceAccess().showWarningMessage("Your message");

Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
Post Reply