mirror of
https://github.com/octoleo/plantuml-server.git
synced 2024-09-22 12:09:03 +00:00
Compare commits
No commits in common. "608b58b3e086d5ad651a2f0a6440ce7a5f578616" and "d495c13e6ead36b1693b4fda69dc10d11a67713b" have entirely different histories.
608b58b3e0
...
d495c13e6e
@ -61,7 +61,7 @@
|
||||
<jetty.contextpath>/${wtp.contextName}</jetty.contextpath>
|
||||
|
||||
<!-- 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 -->
|
||||
<jetty.version>11.0.15</jetty.version>
|
||||
<!--
|
||||
|
@ -157,14 +157,10 @@ public class DiagramResponse {
|
||||
response.addHeader("Access-Control-Allow-Origin", "*");
|
||||
response.setContentType(getContentType());
|
||||
|
||||
if (idx < 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 Defines defines = getPreProcDefines();
|
||||
SourceStringReader reader = new SourceStringReader(defines, uml, CONFIG);
|
||||
if (CONFIG.size() > 0 && reader.getBlocks().get(0).getDiagram().getWarningOrError() != null) {
|
||||
reader = new SourceStringReader(uml);
|
||||
}
|
||||
|
||||
if (format == FileFormat.BASE64) {
|
||||
@ -222,27 +218,6 @@ public class DiagramResponse {
|
||||
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.
|
||||
*
|
||||
@ -289,36 +264,19 @@ public class DiagramResponse {
|
||||
* @throws IOException if an input or output exception occurred
|
||||
*/
|
||||
public void sendMap(String uml, int idx) throws IOException {
|
||||
if (idx < 0) {
|
||||
idx = 0;
|
||||
}
|
||||
response.addHeader("Access-Control-Allow-Origin", "*");
|
||||
response.setContentType(getContentType());
|
||||
|
||||
if (idx < 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;
|
||||
}
|
||||
|
||||
SourceStringReader reader = new SourceStringReader(uml);
|
||||
final BlockUml blockUml = reader.getBlocks().get(0);
|
||||
if (StringUtils.isDiagramCacheable(uml)) {
|
||||
addHeaderForCache(blockSelection.block);
|
||||
addHeaderForCache(blockUml);
|
||||
}
|
||||
final Diagram diagram = blockSelection.block.getDiagram();
|
||||
if (diagram instanceof PSystemError) {
|
||||
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||||
}
|
||||
ImageData map = diagram.exportDiagram(
|
||||
new NullOutputStream(),
|
||||
blockSelection.systemIdx,
|
||||
new FileFormatOption(FileFormat.PNG, false)
|
||||
);
|
||||
final Diagram diagram = blockUml.getDiagram();
|
||||
ImageData map = diagram.exportDiagram(new NullOutputStream(), idx,
|
||||
new FileFormatOption(FileFormat.PNG, false));
|
||||
if (map.containsCMapData()) {
|
||||
PrintWriter httpOut = response.getWriter();
|
||||
final String cmap = map.getCMapData("plantuml");
|
||||
|
@ -29,6 +29,7 @@ import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
@ -38,7 +39,11 @@ import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import net.sourceforge.plantuml.BlockUml;
|
||||
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.
|
||||
@ -103,23 +108,29 @@ public class ProxyServlet extends HttpServlet {
|
||||
final String source = request.getParameter("src");
|
||||
final String index = request.getParameter("idx");
|
||||
|
||||
final int idx = index == null ? 0 : Integer.parseInt(index);
|
||||
final URL srcUrl = validateURL(source, response);
|
||||
if (srcUrl == null) {
|
||||
return; // error is already set/handled inside `validateURL`
|
||||
}
|
||||
|
||||
// fetch diagram from URL
|
||||
final String uml = getSource(srcUrl);
|
||||
// generate the response
|
||||
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
|
||||
DiagramResponse dr = new DiagramResponse(response, getOutputFormat(fmt), request);
|
||||
try {
|
||||
// special handling for the MAP since it's not using "#sendDiagram()" like the other types
|
||||
if ("map".equals(fmt)) {
|
||||
dr.sendMap(uml, idx);
|
||||
dr.sendMap(uml, 0);
|
||||
} else {
|
||||
dr.sendDiagram(uml, idx);
|
||||
dr.sendDiagram(uml, 0);
|
||||
}
|
||||
} catch (IIOException e) {
|
||||
// Browser has closed the connection, so the HTTP OutputStream is closed
|
||||
|
Loading…
Reference in New Issue
Block a user