Search in sources :

Example 1 with DocxBuilder

use of com.centurylink.mdw.designer.utils.DocxBuilder 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)

Example 2 with DocxBuilder

use of com.centurylink.mdw.designer.utils.DocxBuilder in project mdw-designer by CenturyLinkCloud.

the class ExportHelper method printProcessDocx.

private DocxBuilder printProcessDocx(Graph process, DesignerCanvas canvas) throws Exception {
    DocxBuilder builder = new DocxBuilder();
    // title
    String title = "Workflow: \"" + process.getName() + "\"";
    builder.addParagraph("Heading1", title);
    // process image
    int zoomSave = process.zoom;
    process.zoom = 100;
    byte[] imgBytes = printImage(-1f, canvas, process.getGraphSize(), "png");
    process.zoom = zoomSave;
    builder.addImage(imgBytes);
    printProcessBodyDocx(builder, process);
    // embedded subprocesses
    for (SubGraph subprocess : process.getSubgraphs(nodeIdType)) {
        String id = subprocess.getDisplayId(nodeIdType);
        String spTitle = "Embedded Subprocess " + id + ": \"" + subprocess.getName() + "\"";
        builder.addParagraph("Heading1", spTitle);
        printProcessBodyDocx(builder, subprocess);
    }
    // process variables
    if (options.contains(VARIABLES)) {
        List<VariableVO> variables = process.getProcessVO().getVariables();
        if (variables != null && !variables.isEmpty()) {
            builder.addParagraph("Heading2", "Process Variables");
            String[] headers = new String[] { "Name", "Type", "Mode", "Description" };
            String[][] values = new String[4][variables.size()];
            for (int i = 0; i < variables.size(); i++) {
                VariableVO var = variables.get(i);
                values[0][i] = var.getName();
                values[1][i] = var.getVariableType();
                values[2][i] = VariableVO.VariableCategories[var.getVariableCategory()];
                values[3][i] = var.getVariableReferredAs();
            }
            builder.addTable(headers, values, 11, 120);
        }
    }
    return builder;
}
Also used : DocxBuilder(com.centurylink.mdw.designer.utils.DocxBuilder) VariableVO(com.centurylink.mdw.model.value.variable.VariableVO) SubGraph(com.centurylink.mdw.designer.display.SubGraph)

Example 3 with DocxBuilder

use of com.centurylink.mdw.designer.utils.DocxBuilder in project mdw-designer by CenturyLinkCloud.

the class ExportHelper method printHtmlParagraphsPdf.

private void printHtmlParagraphsPdf(Section section, String content, int parentLevel) throws Exception {
    if (content == null || content.length() == 0)
        return;
    String vContent = content;
    if (isBase64Encoded(content) || "true".equals(System.getProperty("mdw.designer.force.msword"))) {
        byte[] docBytes = decodeBase64(content);
        vContent = new DocxBuilder(docBytes).toHtml();
        vContent = vContent.replaceAll("&nbsp;", "&#160;");
    }
    JEditorPane documentation = new JEditorPane();
    documentation.setContentType("text/html");
    documentation.setText(vContent);
    javax.swing.text.Document swingdoc = documentation.getDocument();
    Element[] elements = swingdoc.getRootElements();
    for (Element e : elements) {
        Object gen = generateElementHtml(e, 0, normalFont);
        addSectionContentPdf(section, gen, parentLevel);
    }
}
Also used : DocxBuilder(com.centurylink.mdw.designer.utils.DocxBuilder) AbstractElement(javax.swing.text.AbstractDocument.AbstractElement) Element(javax.swing.text.Element) JEditorPane(javax.swing.JEditorPane)

Aggregations

DocxBuilder (com.centurylink.mdw.designer.utils.DocxBuilder)3 BPMNHelper (com.centurylink.mdw.common.utilities.bpmn.BPMNHelper)1 SubGraph (com.centurylink.mdw.designer.display.SubGraph)1 VariableVO (com.centurylink.mdw.model.value.variable.VariableVO)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 JEditorPane (javax.swing.JEditorPane)1 AbstractElement (javax.swing.text.AbstractDocument.AbstractElement)1 BadLocationException (javax.swing.text.BadLocationException)1 Element (javax.swing.text.Element)1 HTMLDocument (javax.swing.text.html.HTMLDocument)1