Replacing words with plugin in Oxygen XML Web Author

Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
nikagra
Posts: 2
Joined: Thu Mar 21, 2019 6:43 pm

Replacing words with plugin in Oxygen XML Web Author

Post by nikagra »

Hello

I'm looking for a way to automatically replace words with Oxygen XML Web Author plugin:
  • * Plugin will propose word replacement.
    * User will accept replacement.
    * Plugin will replace all occurrences of the word in selected fragment or whole document.
Is there an operation to perform this? I've found ro.sync.ecss.extensions.commons.operations.InsertOrReplaceTextOperation but as I understand it only replaces already selected text. Is there a way to select a text or set a caret position?

It seems that XSLTOperation and XQueryOperationAlternatively might be helpful, but this operation cannot be invoked using JavaScript API. XQueryUpdateOperation is not applicable in Oxygen XML Web Author at all.

Or maybe there there is an API to access Find/Replace functionality? Any code examples are appreciated

Thanks in advance
nikagra
Posts: 2
Joined: Thu Mar 21, 2019 6:43 pm

Re: Replacing words with plugin in Oxygen XML Web Author

Post by nikagra »

Follow up: I've found MoveCaretOperation. Not sure if I can select single world/phrase with it. And I cannot make it working:

Code: Select all


	goog.events.listen(
searchButton,
goog.events.EventType.CLICK,
function (e) {
editor.getActionsManager().invokeOperation(
'ro.sync.ecss.extensions.commons.operations.MoveCaretOperation', {
"xpathLocation": "//*[text()[contains(.,'metres')]]",
"selection": "After",
"position": "Before"
},
function (err, resultString) {
if (resultString === 'ok') {
console.log("OK");
} else {
workspace.getNotificationManager().showWarning(resultString, true);
console.warn(resultString);
}
})
});
(Not sure how to make indents working)
cristi_talau
Posts: 517
Joined: Thu Sep 04, 2014 4:22 pm

Re: Replacing words with plugin in Oxygen XML Web Author

Post by cristi_talau »

Hello,

The best answer depends on how your plugin is structured and what it tries to achieve. I assume you managed to identify a word that should be changed.
  • What information do you have about the location of the word?
  • Did you manage to locate the word using the JS API or the Java API?
Given the information you already gave, I would suggest that you implement a custom Java AuthorOperation [1] and call it from JS code. In order for Web Author to pickup AuthorOperations in your plugin you should make sure that you have a custom implementation of the plugin class (specified in the plugin.xml file) - the default value of "ro.sync.exml.plugin.Plugin" is not good.

If your plugin is similar to a spellchecker, you can take a look at our LanguageTool integration [2]. It uses the Spellcheck API to implement something similar with what you described.

We are currently working on adding an API for adding text highlights using Java code. If that would be of interest for you, we can give you access to a nightly build that includes that support (which will be available in the next release).

Best,
Cristian

[1] https://www.oxygenxml.com/doc/versions/ ... ation_tips
[2] https://github.com/oxygenxml/web-author ... ool-plugin
Post Reply