1
0
mirror of https://github.com/octoleo/plantuml-server.git synced 2024-11-11 15:20:58 +00:00

Compare commits

..

No commits in common. "608b58b3e086d5ad651a2f0a6440ce7a5f578616" and "d495c13e6ead36b1693b4fda69dc10d11a67713b" have entirely different histories.

3 changed files with 30 additions and 61 deletions

View File

@ -61,7 +61,7 @@
<jetty.contextpath>/${wtp.contextName}</jetty.contextpath> <jetty.contextpath>/${wtp.contextName}</jetty.contextpath>
<!-- main versions --> <!-- main versions -->
<plantuml.version>1.2023.10</plantuml.version> <plantuml.version>1.2023.9</plantuml.version>
<!-- Please keep the jetty version identical with the docker image --> <!-- Please keep the jetty version identical with the docker image -->
<jetty.version>11.0.15</jetty.version> <jetty.version>11.0.15</jetty.version>
<!-- <!--

View File

@ -157,14 +157,10 @@ public class DiagramResponse {
response.addHeader("Access-Control-Allow-Origin", "*"); response.addHeader("Access-Control-Allow-Origin", "*");
response.setContentType(getContentType()); response.setContentType(getContentType());
if (idx < 0) { final Defines defines = getPreProcDefines();
response.sendError(HttpServletResponse.SC_BAD_REQUEST, String.format("Invalid diagram index: {0}", idx)); SourceStringReader reader = new SourceStringReader(defines, uml, CONFIG);
return; if (CONFIG.size() > 0 && reader.getBlocks().get(0).getDiagram().getWarningOrError() != null) {
} reader = new SourceStringReader(uml);
final SourceStringReader reader = getSourceStringReader(uml);
if (reader == null) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No UML diagram found");
return;
} }
if (format == FileFormat.BASE64) { if (format == FileFormat.BASE64) {
@ -222,27 +218,6 @@ public class DiagramResponse {
return null; return null;
} }
private SourceStringReader getSourceStringReader(String uml) {
SourceStringReader reader = getSourceStringReaderWithConfig(uml);
if (reader.getBlocks().isEmpty()) {
uml = "@startuml\n" + uml + "\n@enduml";
reader = getSourceStringReaderWithConfig(uml);
if (reader.getBlocks().isEmpty()) {
return null;
}
}
return reader;
}
private SourceStringReader getSourceStringReaderWithConfig(String uml) {
final Defines defines = getPreProcDefines();
SourceStringReader reader = new SourceStringReader(defines, uml, CONFIG);
if (!CONFIG.isEmpty() && reader.getBlocks().get(0).getDiagram().getWarningOrError() != null) {
reader = new SourceStringReader(defines, uml);
}
return reader;
}
/** /**
* Get PlantUML preprocessor defines. * Get PlantUML preprocessor defines.
* *
@ -289,36 +264,19 @@ public class DiagramResponse {
* @throws IOException if an input or output exception occurred * @throws IOException if an input or output exception occurred
*/ */
public void sendMap(String uml, int idx) throws IOException { public void sendMap(String uml, int idx) throws IOException {
if (idx < 0) {
idx = 0;
}
response.addHeader("Access-Control-Allow-Origin", "*"); response.addHeader("Access-Control-Allow-Origin", "*");
response.setContentType(getContentType()); response.setContentType(getContentType());
SourceStringReader reader = new SourceStringReader(uml);
if (idx < 0) { final BlockUml blockUml = reader.getBlocks().get(0);
response.sendError(HttpServletResponse.SC_BAD_REQUEST, String.format("Invalid diagram index: {0}", idx));
return;
}
final SourceStringReader reader = getSourceStringReader(uml);
if (reader == null) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No UML diagram found");
return;
}
final BlockSelection blockSelection = getOutputBlockSelection(reader, idx);
if (blockSelection == null) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
if (StringUtils.isDiagramCacheable(uml)) { if (StringUtils.isDiagramCacheable(uml)) {
addHeaderForCache(blockSelection.block); addHeaderForCache(blockUml);
} }
final Diagram diagram = blockSelection.block.getDiagram(); final Diagram diagram = blockUml.getDiagram();
if (diagram instanceof PSystemError) { ImageData map = diagram.exportDiagram(new NullOutputStream(), idx,
response.setStatus(HttpServletResponse.SC_BAD_REQUEST); new FileFormatOption(FileFormat.PNG, false));
}
ImageData map = diagram.exportDiagram(
new NullOutputStream(),
blockSelection.systemIdx,
new FileFormatOption(FileFormat.PNG, false)
);
if (map.containsCMapData()) { if (map.containsCMapData()) {
PrintWriter httpOut = response.getWriter(); PrintWriter httpOut = response.getWriter();
final String cmap = map.getCMapData("plantuml"); final String cmap = map.getCMapData("plantuml");

View File

@ -29,6 +29,7 @@ import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.imageio.IIOException; import javax.imageio.IIOException;
@ -38,7 +39,11 @@ import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import net.sourceforge.plantuml.BlockUml;
import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.SourceStringReader;
import net.sourceforge.plantuml.core.Diagram;
import net.sourceforge.plantuml.core.UmlSource;
/** /**
* Proxy servlet of the webapp. * Proxy servlet of the webapp.
@ -103,23 +108,29 @@ public class ProxyServlet extends HttpServlet {
final String source = request.getParameter("src"); final String source = request.getParameter("src");
final String index = request.getParameter("idx"); final String index = request.getParameter("idx");
final int idx = index == null ? 0 : Integer.parseInt(index);
final URL srcUrl = validateURL(source, response); final URL srcUrl = validateURL(source, response);
if (srcUrl == null) { if (srcUrl == null) {
return; // error is already set/handled inside `validateURL` return; // error is already set/handled inside `validateURL`
} }
// fetch diagram from URL // generate the response
final String uml = getSource(srcUrl); String diagmarkup = getSource(srcUrl);
SourceStringReader reader = new SourceStringReader(diagmarkup);
int n = index == null ? 0 : Integer.parseInt(index);
List<BlockUml> blocks = reader.getBlocks();
BlockUml block = blocks.get(n);
Diagram diagram = block.getDiagram();
UmlSource umlSrc = diagram.getSource();
String uml = umlSrc.getPlainString("\n");
// generate the response // generate the response
DiagramResponse dr = new DiagramResponse(response, getOutputFormat(fmt), request); DiagramResponse dr = new DiagramResponse(response, getOutputFormat(fmt), request);
try { try {
// special handling for the MAP since it's not using "#sendDiagram()" like the other types // special handling for the MAP since it's not using "#sendDiagram()" like the other types
if ("map".equals(fmt)) { if ("map".equals(fmt)) {
dr.sendMap(uml, idx); dr.sendMap(uml, 0);
} else { } else {
dr.sendDiagram(uml, idx); dr.sendDiagram(uml, 0);
} }
} catch (IIOException e) { } catch (IIOException e) {
// Browser has closed the connection, so the HTTP OutputStream is closed // Browser has closed the connection, so the HTTP OutputStream is closed