Search in sources :

Example 1 with FileFormatOption

use of net.sourceforge.plantuml.FileFormatOption in project plantuml-server by plantuml.

the class OldProxyServlet method handleImageProxy.

private void handleImageProxy(HttpServletResponse response, String num, String source) throws IOException {
    SourceStringReader reader = new SourceStringReader(getSource(source));
    int n = num == null ? 0 : Integer.parseInt(num);
    reader.generateImage(response.getOutputStream(), n, new FileFormatOption(getOutputFormat(), false));
}
Also used : FileFormatOption(net.sourceforge.plantuml.FileFormatOption) SourceStringReader(net.sourceforge.plantuml.SourceStringReader)

Example 2 with FileFormatOption

use of net.sourceforge.plantuml.FileFormatOption 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 3 with FileFormatOption

use of net.sourceforge.plantuml.FileFormatOption 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 4 with FileFormatOption

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

Example 5 with FileFormatOption

use of net.sourceforge.plantuml.FileFormatOption in project netbeans-mmd-plugin by raydac.

the class PlantUmlTextEditor method exportAsFile.

private void exportAsFile() {
    final JFileChooser fileChooser = new JFileChooser(lastExportedFile);
    fileChooser.setAcceptAllFileFilterUsed(false);
    final FileFilter fileFiterSVG = new FileFilter() {

        @Override
        public boolean accept(@Nonnull final File f) {
            return f.isDirectory() || f.getName().toLowerCase(Locale.ENGLISH).endsWith(".svg");
        }

        @Nonnull
        @Override
        public String getDescription() {
            return "SVG images (*.svg)";
        }
    };
    final FileFilter fileFiterPNG = new FileFilter() {

        @Override
        public boolean accept(@Nonnull final File f) {
            return f.isDirectory() || f.getName().toLowerCase(Locale.ENGLISH).endsWith(".png");
        }

        @Nonnull
        @Override
        public String getDescription() {
            return "PNG images (*.png)";
        }
    };
    final FileFilter fileFiterLTX = new FileFilter() {

        @Override
        public boolean accept(@Nonnull final File f) {
            return f.isDirectory() || f.getName().toLowerCase(Locale.ENGLISH).endsWith(".tex");
        }

        @Nonnull
        @Override
        public String getDescription() {
            return "LaTeX text files (*.tex)";
        }
    };
    fileChooser.setApproveButtonText("Export");
    fileChooser.setDialogTitle("Export PlantUML image as File");
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.addChoosableFileFilter(fileFiterPNG);
    fileChooser.addChoosableFileFilter(fileFiterSVG);
    fileChooser.addChoosableFileFilter(fileFiterLTX);
    if (fileChooser.showSaveDialog(this.mainPanel) == JFileChooser.APPROVE_OPTION) {
        lastExportedFile = fileChooser.getSelectedFile();
        final FileFilter fileFilter = fileChooser.getFileFilter();
        final SourceStringReader reader = new SourceStringReader(this.editor.getText());
        final FileFormatOption option;
        final String ext;
        if (fileFilter == fileFiterSVG) {
            option = new FileFormatOption(FileFormat.SVG);
            ext = ".svg";
        } else if (fileFilter == fileFiterPNG) {
            option = new FileFormatOption(FileFormat.PNG);
            ext = ".png";
        } else if (fileFilter == fileFiterLTX) {
            option = new FileFormatOption(FileFormat.LATEX);
            ext = ".tex";
        } else {
            throw new Error("Unexpected situation");
        }
        final ByteArrayOutputStream buffer = new ByteArrayOutputStream(131072);
        if (!lastExportedFile.getName().contains(".") || !lastExportedFile.getName().endsWith(ext)) {
            lastExportedFile = new File(lastExportedFile.getParent(), lastExportedFile.getName() + ext);
        }
        try {
            reader.outputImage(buffer, option);
            FileUtils.writeByteArrayToFile(lastExportedFile, buffer.toByteArray());
            LOGGER.info("Exported plant uml image as file : " + lastExportedFile);
        } catch (Exception ex) {
            LOGGER.error("Can't export plant uml image", ex);
            JOptionPane.showMessageDialog(this.mainPanel, "Error during export, see log!", "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
}
Also used : FileFormatOption(net.sourceforge.plantuml.FileFormatOption) Nonnull(javax.annotation.Nonnull) SourceStringReader(net.sourceforge.plantuml.SourceStringReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) CannotUndoException(javax.swing.undo.CannotUndoException) CannotRedoException(javax.swing.undo.CannotRedoException) IOException(java.io.IOException)

Aggregations

FileFormatOption (net.sourceforge.plantuml.FileFormatOption)6 SourceStringReader (net.sourceforge.plantuml.SourceStringReader)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 BlockUml (net.sourceforge.plantuml.BlockUml)2 NullOutputStream (net.sourceforge.plantuml.NullOutputStream)2 Diagram (net.sourceforge.plantuml.core.Diagram)2 DiagramDescription (net.sourceforge.plantuml.core.DiagramDescription)2 ImageData (net.sourceforge.plantuml.core.ImageData)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 Nonnull (javax.annotation.Nonnull)1 FileFilter (javax.swing.filechooser.FileFilter)1 CannotRedoException (javax.swing.undo.CannotRedoException)1 CannotUndoException (javax.swing.undo.CannotUndoException)1