mirror of
https://github.com/octoleo/plantuml-server.git
synced 2025-01-02 20:50:15 +00:00
Introduced parameter PLANTUML_CONFIG_FILE, that allows to specify a PlantUML config file.
This commit is contained in:
parent
820fcca9ac
commit
cf717eff0c
@ -115,6 +115,9 @@ You can set all the following variables:
|
||||
* `BASE_URL`
|
||||
* PlantUML Base URL path
|
||||
* 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`
|
||||
* Limits image width and height
|
||||
* Default value: `4096`
|
||||
|
@ -23,11 +23,15 @@
|
||||
*/
|
||||
package net.sourceforge.plantuml.servlet;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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.ImageData;
|
||||
import net.sourceforge.plantuml.error.PSystemError;
|
||||
import net.sourceforge.plantuml.preproc.Defines;
|
||||
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 List<String> CONFIG = new ArrayList<>();
|
||||
|
||||
static {
|
||||
OptionFlags.ALLOW_INCLUDE = false;
|
||||
if ("true".equalsIgnoreCase(System.getenv("ALLOW_PLANTUML_INCLUDE"))) {
|
||||
@ -114,7 +121,28 @@ public class DiagramResponse {
|
||||
public void sendDiagram(String uml, int idx) throws IOException {
|
||||
response.addHeader("Access-Control-Allow-Origin", "*");
|
||||
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) {
|
||||
byte[] imageBytes;
|
||||
try (ByteArrayOutputStream outstream = new ByteArrayOutputStream()) {
|
||||
|
Loading…
Reference in New Issue
Block a user