Java API

Last modified by Vincent Massol on 2026/10/21 19:10

Reference

The components of the org.xwiki.contrib.plantuml package, in the macro-plantuml-macro module, generate PlantUML diagrams from Java. How they fit together is explained in PlantUML.

<dependency>
  <groupId>org.xwiki.contrib.plantuml</groupId>
  <artifactId>macro-plantuml-macro</artifactId>
  <version>2.5</version>
</dependency>

Components

Member Returns What it does
PlantUMLRenderer.renderDiagram(String content, String serverURL, PlantUMLDiagramFormat diagramFormat) Block Generates the diagram and returns the block displaying it: an ImageBlock pointing to a temporary resource for png, a RawBlock holding the cleaned SVG for svg, a VerbatimBlock for txt. Throws MacroExecutionException.
PlantUMLGenerator.outputImage(String input, OutputStream output, String serverURL, PlantUMLDiagramFormat format) void Writes the diagram to output. It is generated by the server at serverURL, or inside XWiki when serverURL is null or empty. Throws IOException.
PlantUMLConfiguration.getPlantUMLServerURL() String Server set in the "PlantUML" administration section, else plantuml.server, else null.
PlantUMLConfiguration.getPlantUMLOutputFormat() PlantUMLDiagramFormat Value of plantuml.format, png by default.
PlantUMLConfiguration.getPlantUMLSecurityProfile() String PlantUML Macro 2.5+ Value of plantuml.securityProfile, or null for SANDBOX.
PlantUMLConfiguration.getPlantUMLServerConnectTimeout() int PlantUML Macro 2.5+ Value of plantuml.server.connectTimeout, in seconds; 0 or less for the default.
PlantUMLConfiguration.getPlantUMLServerResponseTimeout() int PlantUML Macro 2.5+ Value of plantuml.server.responseTimeout, in seconds; 0 or less for the default.
PlantUMLConfiguration.getPlantUMLServerMaxResponseSize() long PlantUML Macro 2.5+ Value of plantuml.server.maxResponseSize, in bytes; 0 or less for the default.

Unlike the macro, renderDiagram and outputImage do not check that the server is in the trusted domains: pass the configured server, or check the URL yourself before passing it.

Enumerations

Enumeration Values
PlantUMLDiagramFormat png, svg and txt. fromString(String) returns png for an unknown value.
PlantUMLDiagramType The 13 values of the type parameter of the "plantuml" macro.

Example

Render a diagram with the server configured by the administrator, or inside XWiki when there is none:

@Inject
private PlantUMLRenderer plantUMLRenderer;

@Inject
private PlantUMLConfiguration plantUMLConfiguration;

public Block renderGreeting() throws MacroExecutionException
{
    String diagram = "@startuml
Alice -> Bob : Hello
@enduml";
    return this.plantUMLRenderer.renderDiagram(diagram, this.plantUMLConfiguration.getPlantUMLServerURL(),
        PlantUMLDiagramFormat.svg);
}

Get Connected