Development Guide

Tagger

Internal Tagger extension allows developers to create their own tagging subrules.

Tag Subrule Data

Tag Subrule Data has no restrictions on what it has to implement. It is up to you what you will store inside it.

com.warxim.petep.extension.internal.tagger.factory.TagSubruleData
/**
 * Tag subrule data.
 * <p>Can contain any serializable data for tag subrule.</p>
 * <p>Data should be immutable!</p>
 */
@PetepAPI
public abstract class TagSubruleData {
}

Tag Subrule

Tag Subrule contains the main logic (method test() that returns true is should be tagger).

com.warxim.petep.extension.internal.tagger.factory.TagSubrule
/**
 * Tag subrule.
 */
@Getter
@AllArgsConstructor
@PetepAPI
public abstract class TagSubrule {
    protected final TagSubruleFactory factory;
    protected TagSubruleData data;

    /**
     * Checks whether the PDU matches the subrule.
     * @param pdu PDU to check
     * @return {@code true} if the PDU matches the subrule
     */
    public abstract boolean test(PDU pdu);

    /**
     * Creates deep copy of the Tag Subrule.
     * @return Deep copy of the Tag Subrule
     */
    public TagSubrule copy() {
        return factory.createSubrule(data);
    }

    @Override
    public String toString() {
        return factory.getName();
    }
}

Tag Subrule Configurator

Configurator is graphical element used for configuration of the subrule.

com.warxim.petep.extension.internal.tagger.factory.TagSubruleConfigurator
/**
 * Base configurator class for tag subrules.
 * <p>Implementation should contain JavaFX controls for configuring the tag subrule data for specific factory.</p>
 */
@PetepAPI
public abstract class TagSubruleConfigurator extends ConfigPane<TagSubruleData> {
    /**
     * Constructs tag subrule configurator.
     * @param template Path to FXML template
     * @throws IOException If the template could not be loaded
     */
    protected TagSubruleConfigurator(String template) throws IOException {
        super(template);
    }
}

Tag Subrule Factory

Tag Subrule Factory creates the subrule and also provides configuration pane (if it exists).

com.warxim.petep.extension.internal.tagger.factory.TagSubruleFactory
/**
 * Tag subrule factory.
 */
@PetepAPI
public abstract class TagSubruleFactory {
    /**
     * Obtains factory code (for configuration purposes).
     * @return Factory code for identification of the factory
     */
    public abstract String getCode();

    /**
     * Obtains factory name (visible for user).
     * @return Factory name for displaying in GUI
     */
    public abstract String getName();

    /**
     * Creates subrule using given data.
     * @param data Data for the subrule
     * @return Created tag subrule
     */
    public abstract TagSubrule createSubrule(TagSubruleData data);

    /**
     * Obtains type of configuration, so it can be deserialized from JSON configuration.
     * @return Type of configuration for deserialization from JSON or empty optional if no configuration is needed
     */
    public abstract Optional<Type> getConfigType();

    /**
     * Creates config pane for subrule data.
     * @return Tag subrule configurator for configuring modifier data or empty optional if no configurator is needed
     * @throws IOException If there was problem with loading the configuration pane
     */
    public abstract Optional<TagSubruleConfigurator> createConfigPane() throws IOException;

    @Override
    public String toString() {
        return getName();
    }
}

Registration

In order to register TagSubruleFactory, you have to use the beforeInit method in your extension:

petep.PetepExtension: public void beforeInit(ExtensionHelper helper)
var maybeTagger = helper.getExtension("tagger");
if (maybeTagger.isEmpty()) {
    return;
}
var tagger = (TaggerApi) maybeTagger.get();

if (tagger.registerSubruleFactory(new ExampleTagSubruleFactory())) {
    Logger.getGlobal().info("Example tag subrule registered!");
}