use of net.sourceforge.plantuml.core.ImageData in project plantuml-server by plantuml.
the class DiagramResponse method sendDiagram.
void sendDiagram(String uml, int idx) throws IOException {
response.addHeader("Access-Control-Allow-Origin", "*");
response.setContentType(getContentType());
SourceStringReader reader = new SourceStringReader(uml);
if (format == FileFormat.BASE64) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final DiagramDescription result = reader.outputImage(baos, idx, new FileFormatOption(FileFormat.PNG));
baos.close();
final String encodedBytes = "data:image/png;base64," + Base64Coder.encodeLines(baos.toByteArray()).replaceAll("\\s", "");
response.getOutputStream().write(encodedBytes.getBytes());
return;
}
final BlockUml blockUml = reader.getBlocks().get(0);
if (notModified(blockUml)) {
addHeaderForCache(blockUml);
response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
if (StringUtils.isDiagramCacheable(uml)) {
addHeaderForCache(blockUml);
}
final Diagram diagram = blockUml.getDiagram();
final ImageData result = diagram.exportDiagram(response.getOutputStream(), idx, new FileFormatOption(format));
}
use of net.sourceforge.plantuml.core.ImageData in project plantuml-server by plantuml.
the class DiagramResponse method sendMap.
void sendMap(String uml) throws IOException {
response.setContentType(getContentType());
SourceStringReader reader = new SourceStringReader(uml);
final BlockUml blockUml = reader.getBlocks().get(0);
if (StringUtils.isDiagramCacheable(uml)) {
addHeaderForCache(blockUml);
}
final Diagram diagram = blockUml.getDiagram();
ImageData map = diagram.exportDiagram(new NullOutputStream(), 0, new FileFormatOption(FileFormat.PNG, false));
if (map.containsCMapData()) {
PrintWriter httpOut = response.getWriter();
final String cmap = map.getCMapData("plantuml");
httpOut.print(cmap);
}
}
Aggregations