Adding listener to save button

Alper B
Posts: 16
Joined: Mon Jan 27, 2020 6:26 pm

Adding listener to save button

Post by Alper B » Wed Jan 06, 2021 6:16 pm

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

Alper B
Posts: 16
Joined: Mon Jan 27, 2020 6:26 pm

Re: Adding listener to save button

Post by Alper B » Thu Jan 07, 2021 12:46 pm

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

Post Reply