Search in sources :

Example 1 with HtmlDocumentBuilder

use of org.camunda.bpm.engine.impl.form.engine.HtmlDocumentBuilder in project camunda-bpm-platform by camunda.

the class SectionedHtmlReportBuilder method addHtmlTable.

protected void addHtmlTable(HtmlDocumentBuilder builder, TabularResultSet resultSet) {
    /**
     * <table>
     */
    builder.startElement(new HtmlElementWriter("table").attribute("class", "table table-condensed table-hover table-bordered"));
    /**
     * <tr>
     */
    HtmlDocumentBuilder tableHeadRowBuilder = builder.startElement(new HtmlElementWriter("tr"));
    for (String columnName : resultSet.getResultColumnNames()) {
        tableHeadRowBuilder.startElement(new HtmlElementWriter("th").textContent(columnName)).endElement();
    }
    /**
     * </tr>
     */
    tableHeadRowBuilder.endElement();
    for (List<Object> resultRow : resultSet.getResults()) {
        /**
         * <tr>
         */
        HtmlDocumentBuilder tableRowBuilder = builder.startElement(new HtmlElementWriter("tr"));
        for (Object value : resultRow) {
            if (value instanceof TableCell) {
                tableRowBuilder.startElement(((TableCell) value).toHtmlElementWriter()).endElement();
            } else {
                tableRowBuilder.startElement(new HtmlElementWriter("td").textContent(String.valueOf(value))).endElement();
            }
        }
        /**
         * </tr>
         */
        tableRowBuilder.endElement();
    }
    /**
     * </table>
     */
    builder.endElement();
}
Also used : HtmlElementWriter(org.camunda.bpm.engine.impl.form.engine.HtmlElementWriter) HtmlDocumentBuilder(org.camunda.bpm.engine.impl.form.engine.HtmlDocumentBuilder)

Example 2 with HtmlDocumentBuilder

use of org.camunda.bpm.engine.impl.form.engine.HtmlDocumentBuilder in project camunda-bpm-platform by camunda.

the class HtmlReportBuilder method execute.

public String execute() {
    HtmlDocumentBuilder documentBuilder = new HtmlDocumentBuilder(new HtmlElementWriter("html"));
    /**
     * <head>...</head>
     */
    documentBuilder.startElement(new HtmlElementWriter("head")).startElement(new HtmlElementWriter("title").textContent(reportName)).endElement().startElement(new HtmlElementWriter("link").attribute("rel", "stylesheet").attribute("href", "http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css")).endElement().startElement(new HtmlElementWriter("link").attribute("rel", "stylesheet").attribute("href", "http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css")).endElement().endElement();
    /**
     * <body>
     */
    HtmlDocumentBuilder bodyBuilder = documentBuilder.startElement(new HtmlElementWriter("body")).startElement(new HtmlElementWriter("div").attribute("class", "container"));
    /**
     * build Headline row
     */
    bodyBuilder.startElement(new HtmlElementWriter("div").attribute("class", "row")).startElement(new HtmlElementWriter("div").attribute("class", "coll-md-12")).startElement(new HtmlElementWriter("h1").textContent(reportName)).endElement().endElement().endElement();
    if (jsonSourceFileName != null || csvSourceFileName != null) {
        HtmlDocumentBuilder sourceRow = bodyBuilder.startElement(new HtmlElementWriter("div").attribute("class", "row")).startElement(new HtmlElementWriter("div").attribute("class", "coll-md-12")).startElement(new HtmlElementWriter("p"));
        if (jsonSourceFileName != null) {
            sourceRow.startElement(new HtmlElementWriter("a").attribute("href", jsonSourceFileName).textContent("This Report as JSON")).endElement();
        }
        if (jsonSourceFileName != null) {
            sourceRow.startElement(new HtmlElementWriter("span").textContent("&nbsp;|&nbsp;")).endElement();
        }
        if (jsonSourceFileName != null) {
            sourceRow.startElement(new HtmlElementWriter("a").attribute("href", csvSourceFileName).textContent("This Report as CSV")).endElement();
        }
        sourceRow.endElement().endElement().endElement();
    }
    bodyBuilder.startElement(new HtmlElementWriter("div").attribute("class", "row")).startElement(new HtmlElementWriter("div").attribute("class", "coll-md-12"));
    writeResultTable(bodyBuilder);
    bodyBuilder.endElement().endElement();
    /**
     * </body>
     */
    bodyBuilder.endElement().endElement();
    return documentBuilder.endElement().getHtmlString();
}
Also used : HtmlElementWriter(org.camunda.bpm.engine.impl.form.engine.HtmlElementWriter) HtmlDocumentBuilder(org.camunda.bpm.engine.impl.form.engine.HtmlDocumentBuilder)

Example 3 with HtmlDocumentBuilder

use of org.camunda.bpm.engine.impl.form.engine.HtmlDocumentBuilder in project camunda-bpm-platform by camunda.

the class HtmlReportBuilder method writeResultTable.

protected void writeResultTable(HtmlDocumentBuilder bodyBuilder) {
    /**
     * <table>
     */
    HtmlDocumentBuilder tableBuilder = bodyBuilder.startElement(new HtmlElementWriter("table").attribute("class", "table table-condensed"));
    /**
     * <tr>
     */
    HtmlDocumentBuilder tableHeadRowBuilder = tableBuilder.startElement(new HtmlElementWriter("tr"));
    for (String columnName : resultSet.getResultColumnNames()) {
        tableHeadRowBuilder.startElement(new HtmlElementWriter("th").textContent(columnName)).endElement();
    }
    if (resultsBaseFolder != null) {
        tableHeadRowBuilder.startElement(new HtmlElementWriter("th", true)).endElement();
    }
    /**
     * </tr>
     */
    tableHeadRowBuilder.endElement();
    for (List<Object> resultRow : resultSet.getResults()) {
        /**
         * <tr>
         */
        HtmlDocumentBuilder tableRowBuilder = tableBuilder.startElement(new HtmlElementWriter("tr"));
        for (int i = 0; i < resultRow.size(); i++) {
            Object value = resultRow.get(i);
            if (i == 0 && isCreateImageLinks) {
                tableHeadRowBuilder.startElement(new HtmlElementWriter("td")).startElement(new HtmlElementWriter("a").attribute("href", "images/" + value + ".png").textContent(String.valueOf(value))).endElement().endElement();
            } else {
                tableHeadRowBuilder.startElement(new HtmlElementWriter("td").textContent(String.valueOf(value))).endElement();
            }
        }
        if (resultsBaseFolder != null) {
            /**
             * build link to Json file
             */
            tableHeadRowBuilder.startElement(new HtmlElementWriter("td")).startElement(new HtmlElementWriter("a").attribute("href", resultsBaseFolder + resultRow.get(0) + ".json").textContent("details")).endElement().endElement();
        }
        /**
         * </tr>
         */
        tableRowBuilder.endElement();
    }
    /**
     * </table>
     */
    tableBuilder.endElement();
}
Also used : HtmlElementWriter(org.camunda.bpm.engine.impl.form.engine.HtmlElementWriter) HtmlDocumentBuilder(org.camunda.bpm.engine.impl.form.engine.HtmlDocumentBuilder)

Example 4 with HtmlDocumentBuilder

use of org.camunda.bpm.engine.impl.form.engine.HtmlDocumentBuilder in project camunda-bpm-platform by camunda.

the class HtmlFormEngineTest method testHtmlElementWriter.

public void testHtmlElementWriter() {
    String htmlString = new HtmlDocumentBuilder(new HtmlElementWriter("someTagName")).endElement().getHtmlString();
    assertHtmlEquals("<someTagName></someTagName>", htmlString);
    htmlString = new HtmlDocumentBuilder(new HtmlElementWriter("someTagName", true)).endElement().getHtmlString();
    assertHtmlEquals("<someTagName />", htmlString);
    htmlString = new HtmlDocumentBuilder(new HtmlElementWriter("someTagName", true).attribute("someAttr", "someAttrValue")).endElement().getHtmlString();
    assertHtmlEquals("<someTagName someAttr=\"someAttrValue\" />", htmlString);
    htmlString = new HtmlDocumentBuilder(new HtmlElementWriter("someTagName").attribute("someAttr", "someAttrValue")).endElement().getHtmlString();
    assertHtmlEquals("<someTagName someAttr=\"someAttrValue\"></someTagName>", htmlString);
    htmlString = new HtmlDocumentBuilder(new HtmlElementWriter("someTagName").attribute("someAttr", null)).endElement().getHtmlString();
    assertHtmlEquals("<someTagName someAttr></someTagName>", htmlString);
    htmlString = new HtmlDocumentBuilder(new HtmlElementWriter("someTagName").textContent("someTextContent")).endElement().getHtmlString();
    assertHtmlEquals("<someTagName>someTextContent</someTagName>", htmlString);
    htmlString = new HtmlDocumentBuilder(new HtmlElementWriter("someTagName")).startElement(new HtmlElementWriter("someChildTag")).endElement().endElement().getHtmlString();
    assertHtmlEquals("<someTagName><someChildTag></someChildTag></someTagName>", htmlString);
    htmlString = new HtmlDocumentBuilder(new HtmlElementWriter("someTagName")).startElement(new HtmlElementWriter("someChildTag").textContent("someTextContent")).endElement().endElement().getHtmlString();
    assertHtmlEquals("<someTagName><someChildTag>someTextContent</someChildTag></someTagName>", htmlString);
    htmlString = new HtmlDocumentBuilder(new HtmlElementWriter("someTagName").textContent("someTextContent")).startElement(new HtmlElementWriter("someChildTag")).endElement().endElement().getHtmlString();
    assertHtmlEquals("<someTagName><someChildTag></someChildTag>someTextContent</someTagName>", htmlString);
    try {
        new HtmlElementWriter("sometagname", true).textContent("sometextcontet");
    } catch (IllegalStateException e) {
        assertTrue(e.getMessage().contains("Self-closing element cannot have text content"));
    }
}
Also used : HtmlElementWriter(org.camunda.bpm.engine.impl.form.engine.HtmlElementWriter) HtmlDocumentBuilder(org.camunda.bpm.engine.impl.form.engine.HtmlDocumentBuilder)

Example 5 with HtmlDocumentBuilder

use of org.camunda.bpm.engine.impl.form.engine.HtmlDocumentBuilder in project camunda-bpm-platform by camunda.

the class SectionedHtmlReportBuilder method execute.

public String execute() {
    HtmlDocumentBuilder builder = new HtmlDocumentBuilder(new HtmlElementWriter("html"));
    addHtmlHead(builder);
    addHtmlBody(builder);
    return builder.endElement().getHtmlString();
}
Also used : HtmlElementWriter(org.camunda.bpm.engine.impl.form.engine.HtmlElementWriter) HtmlDocumentBuilder(org.camunda.bpm.engine.impl.form.engine.HtmlDocumentBuilder)

Aggregations

HtmlDocumentBuilder (org.camunda.bpm.engine.impl.form.engine.HtmlDocumentBuilder)5 HtmlElementWriter (org.camunda.bpm.engine.impl.form.engine.HtmlElementWriter)5