Search in sources :

Example 1 with DiagramDescription

use of net.sourceforge.plantuml.core.DiagramDescription in project plantuml-server by plantuml.

the class DiagramResponse method sendCheck.

void sendCheck(String uml) throws IOException {
    response.setContentType(getContentType());
    SourceStringReader reader = new SourceStringReader(uml);
    DiagramDescription desc = reader.outputImage(new NullOutputStream(), new FileFormatOption(FileFormat.PNG, false));
    PrintWriter httpOut = response.getWriter();
    httpOut.print(desc.getDescription());
}
Also used : FileFormatOption(net.sourceforge.plantuml.FileFormatOption) SourceStringReader(net.sourceforge.plantuml.SourceStringReader) DiagramDescription(net.sourceforge.plantuml.core.DiagramDescription) NullOutputStream(net.sourceforge.plantuml.NullOutputStream) PrintWriter(java.io.PrintWriter)

Example 2 with DiagramDescription

use of net.sourceforge.plantuml.core.DiagramDescription 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)

Aggregations

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