Contribute to this guideReport an issue

guideEvents

The CKFinder 3 for Java connector provides a set of events that can be used for changing the default application behavior. Each of the events is identified by its type and can be listened to by any number of listeners. The request lifecycle diagram may help you understand which events and in what order are emitted by the CKFinder connector.

To create a listener for a given type of event, you need to register a component that implements the parametrized Listener interface. For example, to create an event listener for an event of the type RequestEvent, the stub of the listener component should look like presented below.

package com.cksource.ckfinder.listener;

import com.cksource.ckfinder.event.RequestEvent;
import com.cksource.ckfinder.listener.Listener;

import jakarta.inject.Named;

@Named
public class CustomListener implements Listener<RequestEvent> {
    @Override
    public void onApplicationEvent(RequestEvent requestEvent) {
        // Processing logic.
    }
}

# LoadConfigEvent

The LoadConfigEvent is emitted only once, at the start of the application. This event indicates that the main CKFinder configuration file has just been loaded.

# GetConfigForRequestEvent

For each request, the connector makes a deep copy of the main configuration object created at the start of the application, when the LoadConfigEvent is emitted. The GetConfigForRequestEvent event indicates that a deep copy of the configuration was created for the current HTTP request scope.

This event is a convenient place to change the connector configuration dynamically per request. You may want to use it, for example, to alter backend root definitions, so each user of the application has their own private directory managed by CKFinder (see the Private folders per user tutorial).

# RequestEvent

An event emitted when the connector receives an HTTP request. If one of the listeners sets the ResponseEntity for the event object, the HTTP response is immediately sent to the client.

# ResolveCommandEvent

An event emitted to obtain a concrete class of Command to handle the current HTTP request.

# BeforeCommandEvent

BeforeCommandEvent is emitted after a particular command is resolved, i.e. it is decided which command class should be used to handle the current request.

In events listeners it is possible to provide any additional code that will be executed before the command. If one of the listeners sets the ResponseEntity for the event object, the HTTP response is immediately sent to the client.

# AfterCommandEvent

AfterCommandEvent is emitted after a concrete Command returned the ResponseEntity. This is the moment when CKFinder finished processing the command logic and it is about to send the HTTP response back to the client.

# ResponseEvent

ResponseEvent is emitted after the ResponseEntity object is created. You can use it to modify or replace the ResponseEntity before the HTTP response is assembled and sent to the client.

# ExceptionEvent

ExceptionEvent is emitted if any error occurs during the processing of the current HTTP request.