Page 1 of 1

Adding listener to save button

Posted: Wed Jan 06, 2021 6:16 pm
by Alper B
Hi,

I need to call a WS after each document saving. What is the best way to do it?

I found a WSEditorListener that provides editorSaved method. Should I create un plugin to implement it?

Should I be inspired by this plugin? -> https://github.com/oxygenxml/web-author ... sAccess.js

Regards.
Alper

Re: Adding listener to save button

Posted: Thu Jan 07, 2021 12:46 pm
by Alper B
I solved my problem.

Code: Select all

public class AfterSaveActionExtension implements WorkspaceAccessPluginExtension {

    private static final Logger logger = LogManager.getLogger(AfterSaveActionExtension.class);

    public void applicationStarted(StandalonePluginWorkspace pluginWorkspaceAccess) {
        WebappPluginWorkspace ws = (WebappPluginWorkspace) pluginWorkspaceAccess;
        ws.addEditingSessionLifecycleListener(new WebappEditingSessionLifecycleListener() {

            @Override
            public void editingSessionStarted(String id, AuthorDocumentModel model) {
                model.getWSEditor().addEditorListener(new WSEditorSaveListener());
            }
        });
    }

    private final class WSEditorSaveListener extends WSEditorListener {

        @Override
        public void editorSaved(int var1) {
            logger.info("Document saved. Ready to be sent to Manager.");
            // TODO: Call manager WS
        }
    }

    public boolean applicationClosing() {
        return true;
    }
}
Best regards