Development Guide

Example - First Tagger Subrule

In this example, we are going to create our own tagger subrule type that will allow user to define subrule "StringParam equals ?".

Example Subrule Data

Our rule has to know the stringParam that user defined to the subrule, so we will create our data class:

public class ExampleTagSubruleData extends TagSubruleData {
    String stringParam;

Example Subrule Data Configurator

To let user configure subrule data, we have to create configurator component:

public class ExampleTagSubruleConfigurator extends TagSubruleConfigurator {
    private TextField stringInput;

    public ExampleTagSubruleConfigurator() throws IOException {

    public TagSubruleData getConfig() {
        return new ExampleTagSubruleData(stringInput.getText());

    public void setConfig(TagSubruleData data) {
        stringInput.setText(((ExampleTagSubruleData) data).getStringParam());

    public boolean isValid() {
        return true;

Simple FXML template:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.*?>

<fx:root xmlns:fx="" prefHeight="41.0" prefWidth="249.0" type="javafx.scene.layout.AnchorPane" xmlns="">
        <Label layoutX="7.0" layoutY="13.0" styleClass="input-label" text="String:" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="13.0"/>
        <TextField fx:id="stringInput" layoutX="90.0" layoutY="2.0" text="" AnchorPane.leftAnchor="85.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0"/>

Example Subrule

Now, let's create subrule that will tests if PDU contains configured stringParam:

public class ExampleTagSubrule extends TagSubrule {
    public ExampleTagSubrule(TagSubruleFactory factory, TagSubruleData data) {
        super(factory, data);

    public boolean test(PDU pdu) {
        if (!(pdu instanceof ExamplePdu)) {
            return false;

        // Check if string param equals configured value
        return (((ExamplePdu) pdu)
                .equals(((ExampleTagSubruleData) data).getStringParam()));

    public String toString() {
        return "StringParam equals '" + ((ExampleTagSubruleData) data).getStringParam() + "'";

Example Subrule Factory

In order to add our subrule type to the Tagger extension, we need to create subrule factory:

public class ExampleTagSubruleFactory extends TagSubruleFactory {
    public String getCode() {
        return "example-tagger";

    public String getName() {
        return "Example - String param equals";

    public TagSubrule createSubrule(TagSubruleData data) {
        return new ExampleTagSubrule(this, data);

    public Optional<Type> getConfigType() {
        return Optional.of(ExampleTagSubruleData.class);

    public Optional<TagSubruleConfigurator> createConfigPane() throws IOException {
        return Optional.of(new ExampleTagSubruleConfigurator());

Great, everything is ready, so we can register our subrule factory inside beforeInit method (implement ExtensionInitListener into PetepExtension).

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

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