mirror of
https://github.com/octoleo/plantuml-server.git
synced 2025-01-03 05:00:14 +00:00
Add diagram indexing support for all formats
This commit is contained in:
parent
45994f81bf
commit
294b2a2418
@ -29,6 +29,7 @@ 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.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
@ -57,6 +58,16 @@ import net.sourceforge.plantuml.version.Version;
|
|||||||
*/
|
*/
|
||||||
public class DiagramResponse {
|
public class DiagramResponse {
|
||||||
|
|
||||||
|
private static class BlockSelection {
|
||||||
|
private final BlockUml block;
|
||||||
|
private final int systemIdx;
|
||||||
|
|
||||||
|
BlockSelection(BlockUml blk, int idx) {
|
||||||
|
block = blk;
|
||||||
|
systemIdx = idx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* X-Powered-By http header value included in every response by default.
|
* X-Powered-By http header value included in every response by default.
|
||||||
*/
|
*/
|
||||||
@ -163,20 +174,48 @@ public class DiagramResponse {
|
|||||||
response.getOutputStream().write(encodedBytes.getBytes());
|
response.getOutputStream().write(encodedBytes.getBytes());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final BlockUml blockUml = reader.getBlocks().get(0);
|
|
||||||
if (notModified(blockUml)) {
|
final BlockSelection blockSelection = getOutputBlockSelection(reader, idx);
|
||||||
addHeaderForCache(blockUml);
|
if (blockSelection == null) {
|
||||||
|
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (notModified(blockSelection.block)) {
|
||||||
|
addHeaderForCache(blockSelection.block);
|
||||||
response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
|
response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (StringUtils.isDiagramCacheable(uml)) {
|
if (StringUtils.isDiagramCacheable(uml)) {
|
||||||
addHeaderForCache(blockUml);
|
addHeaderForCache(blockSelection.block);
|
||||||
}
|
}
|
||||||
final Diagram diagram = blockUml.getDiagram();
|
final Diagram diagram = blockSelection.block.getDiagram();
|
||||||
if (diagram instanceof PSystemError) {
|
if (diagram instanceof PSystemError) {
|
||||||
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||||||
}
|
}
|
||||||
diagram.exportDiagram(response.getOutputStream(), idx, new FileFormatOption(format));
|
diagram.exportDiagram(response.getOutputStream(), blockSelection.systemIdx, new FileFormatOption(format));
|
||||||
|
}
|
||||||
|
|
||||||
|
private BlockSelection getOutputBlockSelection(SourceStringReader reader, int numImage) {
|
||||||
|
if (numImage < 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Collection<BlockUml> blocks = reader.getBlocks();
|
||||||
|
if (blocks.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (BlockUml b : blocks) {
|
||||||
|
final Diagram system = b.getDiagram();
|
||||||
|
final int nbInSystem = system.getNbImages();
|
||||||
|
if (numImage < nbInSystem) {
|
||||||
|
return new BlockSelection(b, numImage);
|
||||||
|
}
|
||||||
|
numImage -= nbInSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user