Access the editorOpened method via framework

Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
Posts: 29
Joined: Thu Feb 16, 2023 11:00 pm

Access the editorOpened method via framework

Post by aujunior »


We created a framework in Oxygem Web that allows us to perform updates and checks on our XML files.

We create an ExtensionsBundle and inside it we call an AuthorExtensionStateListener.

This way we were able to create our uniqueAttributesRecognizer method and call webWorkspace.addEditorChangeListener and webWorkspace.addEditingSessionLifecycleListener.

However, we noticed that the extensionBundle is adding a Listener each time it is called when opening a file. This is generating several validation problems. We also noticed that the deactivate method is not being called so that we can remove the listeners.

We saw that including addValidationProblemsFilter is very simple to do via plugin, however, we don't know the correct place to create these listeners and validators via the framework.

Can you please tell us what is the best way to access the workspace and add listeners via framework?

Code: Select all

public class AuthorExtensionStateListenerTPMS implements AuthorExtensionStateListener {

    private AuthorAccess authorAccess;
    AttributesRecognizer uniqueAttributesRecognizer;

    protected static final Logger logger = LoggerFactory.getLogger(AuthorExtensionStateListenerTPMS.class);

    public void activated(final AuthorAccess authorAccess) {
        this.authorAccess = authorAccess;
        WebappPluginWorkspace webWorkspace = (WebappPluginWorkspace) PluginWorkspaceProvider.getPluginWorkspace();

        this.uniqueAttributesRecognizer = new AttributesRecognizer();
        // Primeiramente ativo a classe para reconhecer os padroes TPMS
        // Depois chamo o metodo para criar os IDs
                authorAccess.getDocumentController().getAuthorDocumentNode().getLength(), true);

        webWorkspace.addEditorChangeListener(new WSEditorChangeListenerTPMS(authorAccess, webWorkspace), 0);
        webWorkspace.addEditingSessionLifecycleListener(new WebappEditingSessionLifecycleListenerTPMS());

        logger.error("AuthorExtensionStateListenerTPMS > activated");

    public void deactivated(AuthorAccess authorAccess) {

        //should remove listeners on deactivate?
        logger.error("AuthorExtensionStateListenerTPMS > deactivated");

Code: Select all

public class WSEditorChangeListenerTPMS extends WSEditorChangeListener {
    AuthorAccess authorAccess;
    PluginWorkspace workspace;
    protected static final Logger logger = LoggerFactory.getLogger(WSEditorChangeListenerTPMS.class);

    public void editorOpened(URL editorLocation) {
        WSEditor editor = workspace.getEditorAccess(editorLocation, PluginWorkspace.MAIN_EDITING_AREA);

        WSAuthorEditorPage authorEditorPage = (WSAuthorEditorPage) editor.getCurrentPage();
                .setDocumentFilter(new AuthorDocumentFilterTPMS(this.authorAccess));

        editor.addValidationProblemsFilter(new CheckCompletenessFilter(authorEditorPage));

        logger.error("WSEditorChangeListenerTPMS > editorOpened");


image.png (69.3 KiB) Viewed 190 times
Every time we open a file, the system adds a new listener and all listeners are called in a row.
Posts: 499
Joined: Thu Sep 04, 2014 4:22 pm

Re: Access the editorOpened method via framework

Post by cristi_talau »


An alternative to AuthorExtensionStateListener is WebappEditingSessionLifecycleListener. You need to implement "editingSessionStarted(String, AuthorDocumentModel)" and "editingSessionClosed(String, AuthorDocumentModel)". To install the filter you can like this: "authorDocumentModel.getWSEditor.addValidationProblemsFilter(...)"
We'll investigate why AuthorExtensionStateListener.deactivate isn't called.

Post Reply