Search in sources :

Example 1 with BPMNHelper

use of com.centurylink.mdw.common.utilities.bpmn.BPMNHelper in project mdw-designer by CenturyLinkCloud.

the class ExportHelper method exportProcess.

/**
 * Export a process
 *
 * @param filename
 *            the file name (including path) where the document will be
 *            generated
 * @param format
 *            can be docx, pdf, rtf, html and bpmn
 * @param canvas
 *            for printing process images
 * @param graph
 *            the process to be printed.
 */
public void exportProcess(String filename, String format, Graph process, DesignerCanvas canvas) throws Exception {
    initialize(false);
    String oldNodeIdType = process.getNodeIdType();
    try {
        process.setNodeIdType(nodeIdType);
        options.add(SECTION_NUMBER);
        if (format.equals(DOCX)) {
            DocxBuilder builder = printProcessDocx(process, canvas);
            builder.save(new java.io.File(filename));
            return;
        } else if (format.equals(HTML)) {
            StringBuilder sb = printPrologHtml("Process " + process.getName());
            printProcessHtml(sb, canvas, 0, process, filename);
            printEpilogHtml(sb, filename);
            return;
        } else if (format.equals(JPG) || format.equals(PNG)) {
            byte[] imgBytes = printImage(-1f, canvas, process.getGraphSize(), format.equals(JPG) ? "jpeg" : "png");
            try (OutputStream os = new FileOutputStream(new File(filename))) {
                os.write(imgBytes);
                return;
            } catch (Exception ex) {
                ex.printStackTrace();
                throw ex;
            }
        } else if (format.equals(BPMN2)) {
            new BPMNHelper().exportProcess(process.getProcessVO(), filename);
        } else {
            // itext processor
            Document document = new Document();
            try {
                DocWriter writer = null;
                if (format.equals(RTF)) {
                    writer = RtfWriter2.getInstance(document, new FileOutputStream(filename));
                } else if (format.equals(PDF)) {
                    writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
                }
                document.open();
                document.setPageSize(PageSize.LETTER);
                Rectangle pageSize = document.getPageSize();
                Chapter chapter = printOneProcessPdf(writer, canvas, format, 1, process, filename, pageSize);
                document.add(chapter);
            } catch (Exception ex) {
                ex.printStackTrace();
                throw ex;
            } finally {
                // step 5: we close the document
                document.close();
            }
        }
    } finally {
        process.setNodeIdType(oldNodeIdType);
    }
}
Also used : DocxBuilder(com.centurylink.mdw.designer.utils.DocxBuilder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Rectangle(com.lowagie.text.Rectangle) Chapter(com.lowagie.text.Chapter) BPMNHelper(com.centurylink.mdw.common.utilities.bpmn.BPMNHelper) HTMLDocument(javax.swing.text.html.HTMLDocument) Document(com.lowagie.text.Document) DocWriter(com.lowagie.text.DocWriter) File(java.io.File) BadLocationException(javax.swing.text.BadLocationException) BadElementException(com.lowagie.text.BadElementException) IOException(java.io.IOException) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

BPMNHelper (com.centurylink.mdw.common.utilities.bpmn.BPMNHelper)1 DocxBuilder (com.centurylink.mdw.designer.utils.DocxBuilder)1 BadElementException (com.lowagie.text.BadElementException)1 Chapter (com.lowagie.text.Chapter)1 DocWriter (com.lowagie.text.DocWriter)1 Document (com.lowagie.text.Document)1 Rectangle (com.lowagie.text.Rectangle)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 BadLocationException (javax.swing.text.BadLocationException)1 HTMLDocument (javax.swing.text.html.HTMLDocument)1