Introduced parameter PLANTUML_CONFIG_FILE, that allows to specify a PlantUML config file.

This commit is contained in:
Thomas Mons 2022-07-26 13:00:58 +02:00 committed by PlantUML
parent 820fcca9ac
commit cf717eff0c
2 changed files with 32 additions and 1 deletions

View File

@ -115,6 +115,9 @@ You can set all the following variables:
* `BASE_URL` * `BASE_URL`
* PlantUML Base URL path * PlantUML Base URL path
* Default value: `ROOT` * Default value: `ROOT`
* `PLANTUML_CONFIG_FILE`
* Local path to a PlantUML configuration file (identical to the `-config` flag on the CLI)
* Default value: `null`
* `PLANTUML_LIMIT_SIZE` * `PLANTUML_LIMIT_SIZE`
* Limits image width and height * Limits image width and height
* Default value: `4096` * Default value: `4096`

View File

@ -23,11 +23,15 @@
*/ */
package net.sourceforge.plantuml.servlet; package net.sourceforge.plantuml.servlet;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
@ -46,6 +50,7 @@ import net.sourceforge.plantuml.core.Diagram;
import net.sourceforge.plantuml.core.DiagramDescription; import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.ImageData; import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.error.PSystemError; import net.sourceforge.plantuml.error.PSystemError;
import net.sourceforge.plantuml.preproc.Defines;
import net.sourceforge.plantuml.version.Version; import net.sourceforge.plantuml.version.Version;
/** /**
@ -63,6 +68,8 @@ public class DiagramResponse {
*/ */
private static final String POWERED_BY = "PlantUML Version " + Version.versionString(); private static final String POWERED_BY = "PlantUML Version " + Version.versionString();
private static final List<String> CONFIG = new ArrayList<>();
static { static {
OptionFlags.ALLOW_INCLUDE = false; OptionFlags.ALLOW_INCLUDE = false;
if ("true".equalsIgnoreCase(System.getenv("ALLOW_PLANTUML_INCLUDE"))) { if ("true".equalsIgnoreCase(System.getenv("ALLOW_PLANTUML_INCLUDE"))) {
@ -114,7 +121,28 @@ public class DiagramResponse {
public void sendDiagram(String uml, int idx) throws IOException { public void sendDiagram(String uml, int idx) throws IOException {
response.addHeader("Access-Control-Allow-Origin", "*"); response.addHeader("Access-Control-Allow-Origin", "*");
response.setContentType(getContentType()); response.setContentType(getContentType());
SourceStringReader reader = new SourceStringReader(uml);
if (CONFIG.size() == 0 && System.getenv("PLANTUML_CONFIG_FILE") != null) {
// Read config
final BufferedReader br = new BufferedReader(new FileReader(System.getenv("PLANTUML_CONFIG_FILE")));
if (br == null) {
return;
}
try {
String s = null;
while ((s = br.readLine()) != null) {
CONFIG.add(s);
}
} finally {
br.close();
}
}
SourceStringReader reader = new SourceStringReader(Defines.createEmpty(), uml, CONFIG);
if (CONFIG.size() > 0 && reader.getBlocks().get(0).getDiagram().getWarningOrError() != null) {
reader = new SourceStringReader(uml);
}
if (format == FileFormat.BASE64) { if (format == FileFormat.BASE64) {
byte[] imageBytes; byte[] imageBytes;
try (ByteArrayOutputStream outstream = new ByteArrayOutputStream()) { try (ByteArrayOutputStream outstream = new ByteArrayOutputStream()) {