Fork me on GitHub

EXTEND WITHOUT FORKING

Your rules.
Your extension.

Install trusted Java or Kotlin code to add private transformations or document formats. Templates only select registered behavior; they cannot download or install code.

Value pipes

Transform a JSON-compatible value into another value, with positional arguments and chaining. Implement TemplatePipe against nuaforma-contracts. Values may be null, scalars or nested maps/lists, not arbitrary JVM objects.

Example after installing your pipe: {customer.name | prefix("Customer: ")}.

Document providers

Implement DocumentProvider to add your own input/output formats or a complete generator. Providers use ServiceLoader declarations and static compatibility metadata, or explicit embedded registration. Format identifiers are extensible, not a closed enum.

Independent Java provider example ↗

Download a working starter

Choose Maven or Gradle and build one Java 17 JAR with three basic pipes. Both downloads contain the same Java implementations, registration resources, a README and executable tests against published 0.3.0-alpha.2. The starters deliberately retain their independently verified alpha.2 SPI dependency and are compatible with the alpha.3 server. The Gradle build uses Kotlin DSL and includes the pinned wrapper. Maven requires Maven 3.9.6 or later; both variants require JDK 17. No NuaForma checkout, Word or Docker is needed to build and test them.

Maven

mvn verify
# target/nuaforma-pipe-starter-1.0.0.jar

Gradle

./gradlew build
# Windows: gradlew.bat build
# build/libs/nuaforma-pipe-starter-1.0.0.jar
  • prefix("Hello ") adds a string prefix.
  • uppercase() uses the generation's explicit locale.
  • select("name") selects a JSON object member and deliberately returns null when the member is absent.
{customer | select("name") | uppercase() | prefix("Customer: ")}
# With customer.name = "Ada": Customer: ADA

Tests load the actual packaged JAR and verify discovery, chaining, nulls, invalid inputs, bounds, locale, cancellation and concurrent requests. Main sources depend only on contracts; the JAR contains no duplicate NuaForma/Kotlin classes. Install one variant's JAR in your trusted extension directory and restart. Adapt the package names, pipe names and metadata together, and avoid registering the same names twice. These are value pipes, not generator-owned content pipes.

1. Implement a value pipe

This minimal Kotlin pipe adds an explicit prefix to a string. Null stays null. Arguments are declared in the definition; the engine validates them before calling the implementation.

example/PrefixPipe.kt
package example

import dev.nuaforma.contracts.OptionDefinition
import dev.nuaforma.contracts.OptionType
import dev.nuaforma.contracts.TemplatePipe
import dev.nuaforma.contracts.TemplatePipeContext
import dev.nuaforma.contracts.TemplatePipeDefinition

class PrefixPipe : TemplatePipe {
    override val definition = TemplatePipeDefinition(
        "prefix", "Add a prefix to a string",
        listOf(OptionDefinition(
            "prefix", OptionType.STRING, "Text prefix", required = true
        ))
    )

    override fun apply(
        value: Any?,
        arguments: List<Any?>,
        context: TemplatePipeContext
    ): Any? {
        context.checkActive()
        if (value == null) return null
        require(value is String)
        return (arguments.single() as String) + value
    }
}

New alpha/beta/RC and snapshot library versions use separate public Nexus repositories. Existing pinned Central dependencies in the starter downloads keep working. See Maven and Gradle repository configuration before upgrading a development version.

Compile for Java 17 for broad embedded compatibility. Use the matching published contracts, currently dev.nuaforma:nuaforma-contracts:0.5.0-alpha.7, preferably as a compile-only/provided dependency. Do not package duplicate NuaForma or Kotlin runtime classes. Start with the complete Kotlin extension and independent consumer for build setup and executable tests.

2. Register it in the same JAR

Add these two resources. The service file names the implementation; the properties file declares its identity and minimum contract. Release version and contract version are separate.

src/main/resources/META-INF/services/dev.nuaforma.contracts.TemplatePipe
example.PrefixPipe
src/main/resources/META-INF/nuaforma/pipes/example.PrefixPipe.properties
pipe.name=prefix
pipe.class=example.PrefixPipe
pipe.version=1.0.0
contract.major=0
contract.minor=2

The class must be public with a no-argument constructor. Registration resources and the class must originate from the same artifact. Names must be unique; built-in formatter names cannot be replaced. A provider requiring contract 0.2 needs a compatible runtime with the same major and a minor of at least 2. See the full discovery and argument rules.

3. Install, restart and discover

On the server, mount a directory of trusted extension JARs read-only at /opt/nuaforma/extensions. The published Compose kits already include this mount. Put your JAR in the host-side directory mapped there, make it readable by UID/GID 1000, then restart the container. Follow the operator mount guide for dependency restrictions and budgets. Do not upload executable JARs as document resources.

Inspect GET /api/v1/capabilities for the chosen provider's actual pipe catalog and availability. The development-only Playground uses the same advertised definitions. Then test a Word placeholder such as {customer.name | prefix("Customer: ")} with data.customer.name set to "Ada": the result is Customer: Ada.

Embedded applications may put the extension on their trusted classpath and discover it, or compose an explicit registry with TemplatePipes.of(listOf(PrefixPipe())). See the runnable consumer for the matching engine/template composition; registry creation alone does not modify an unrelated provider.

What about images and other content?

Content pipes produce structured document content rather than chainable values. They belong to the generator that knows how to insert that content. The built-in DOCX generator already supplies image for PNG/JPEG Base64 values; see the template examples. Alpha.5 also supplies richText("rtf") for bounded formatted text; see the RTF examples.

A new content pipe is not automatically activated in the stock DOCX generator by dropping a JAR into the mount. Supply/configure a generator that registers the implementation, recognizes its bounded ContentResult and exposes its definitions through ContentPipeProvider. Content pipes must be the only pipe in their marker. Follow the generator-owned content guide.

Treat extensions as application code

Installed extensions run with application-process permissions: they are not sandboxed by the template language. Keep implementations thread-safe, do not retain request data, bound allocations/work, and cooperate with context.checkActive(). Test null/missing values, invalid types and arguments, concurrent requests, registration conflicts and actual generation. Check layout, fonts and PDF/profile behavior when output is affected.

Private code and its dependencies are your responsibility. Preserve the container limits and separately bounded validator processes. Extensions run in the application process; their JARs are not added to the fixed validator classpath. Do not pass secrets or unrelated request state to a pipe.

Available from 0.3.0-alpha.2; APIs are still an evaluation draft. This page explains extensions, not a new product release or a hosted execution service.