Search in sources :

Example 1 with ImageData

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));
}
Also used : FileFormatOption(net.sourceforge.plantuml.FileFormatOption) ImageData(net.sourceforge.plantuml.core.ImageData) SourceStringReader(net.sourceforge.plantuml.SourceStringReader) BlockUml(net.sourceforge.plantuml.BlockUml) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DiagramDescription(net.sourceforge.plantuml.core.DiagramDescription) Diagram(net.sourceforge.plantuml.core.Diagram)

Example 2 with ImageData

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);
    }
}
Also used : FileFormatOption(net.sourceforge.plantuml.FileFormatOption) ImageData(net.sourceforge.plantuml.core.ImageData) SourceStringReader(net.sourceforge.plantuml.SourceStringReader) BlockUml(net.sourceforge.plantuml.BlockUml) Diagram(net.sourceforge.plantuml.core.Diagram) NullOutputStream(net.sourceforge.plantuml.NullOutputStream) PrintWriter(java.io.PrintWriter)

Aggregations

BlockUml (net.sourceforge.plantuml.BlockUml)2 FileFormatOption (net.sourceforge.plantuml.FileFormatOption)2 SourceStringReader (net.sourceforge.plantuml.SourceStringReader)2 Diagram (net.sourceforge.plantuml.core.Diagram)2 ImageData (net.sourceforge.plantuml.core.ImageData)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintWriter (java.io.PrintWriter)1 NullOutputStream (net.sourceforge.plantuml.NullOutputStream)1 DiagramDescription (net.sourceforge.plantuml.core.DiagramDescription)1