diff --git a/libraries/pom.xml b/libraries/pom.xml index 44be5c9c09..834c496116 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -514,6 +514,11 @@ hirondelle-date4j ${hirondelle-date4j.version} + + com.haulmont.yarg + yarg + 2.0.4 + @@ -534,6 +539,14 @@ OpenGeo Maven Repository http://repo.opengeo.org + + + false + + bintray-cuba-platform-main + bintray + http://dl.bintray.com/cuba-platform/main + 0.7.0 diff --git a/libraries/src/main/java/com/baeldung/yarg/DocumentController.java b/libraries/src/main/java/com/baeldung/yarg/DocumentController.java new file mode 100644 index 0000000000..0e1bbca561 --- /dev/null +++ b/libraries/src/main/java/com/baeldung/yarg/DocumentController.java @@ -0,0 +1,56 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.yarg; + +import com.haulmont.yarg.formatters.factory.DefaultFormatterFactory; +import com.haulmont.yarg.loaders.factory.DefaultLoaderFactory; +import com.haulmont.yarg.loaders.impl.JsonDataLoader; +import com.haulmont.yarg.reporting.Reporting; +import com.haulmont.yarg.reporting.RunParams; +import com.haulmont.yarg.structure.Report; +import com.haulmont.yarg.structure.ReportBand; +import com.haulmont.yarg.structure.ReportOutputType; +import com.haulmont.yarg.structure.impl.BandBuilder; +import com.haulmont.yarg.structure.impl.ReportBuilder; +import com.haulmont.yarg.structure.impl.ReportTemplateBuilder; +import java.io.File; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; +import org.apache.commons.io.FileUtils; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class DocumentController { + + @RequestMapping(path = "/generate/doc", method = RequestMethod.GET) + public void generateDocument(HttpServletResponse response) throws IOException { + ReportBuilder reportBuilder = new ReportBuilder(); + ReportTemplateBuilder reportTemplateBuilder = new ReportTemplateBuilder() + .documentPath("./src/main/resources/Letter.docx") + .documentName("Letter.docx") + .outputType(ReportOutputType.docx) + .readFileFromPath(); + reportBuilder.template(reportTemplateBuilder.build()); + BandBuilder bandBuilder = new BandBuilder(); + String json = FileUtils.readFileToString(new File("./src/main/resources/Data.json")); + ReportBand main = bandBuilder.name("Main") + .query("Main", "parameter=param1 $.main", "json") + .build(); + reportBuilder.band(main); + Report report = reportBuilder.build(); + + Reporting reporting = new Reporting(); + reporting.setFormatterFactory(new DefaultFormatterFactory()); + reporting.setLoaderFactory( + new DefaultLoaderFactory() + .setJsonDataLoader(new JsonDataLoader())); + response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document"); + reporting.runReport(new RunParams(report).param("param1", json), response.getOutputStream()); + } + +} diff --git a/libraries/src/main/resources/Data.json b/libraries/src/main/resources/Data.json new file mode 100644 index 0000000000..d098839d51 --- /dev/null +++ b/libraries/src/main/resources/Data.json @@ -0,0 +1,7 @@ +{ + "main": { + "title" : "INTRODUCTION TO YARG", + "name" : "Baeldung", + "content" : "This is the content of the letter, can be anything we like." + } +} diff --git a/libraries/src/main/resources/Letter.docx b/libraries/src/main/resources/Letter.docx new file mode 100644 index 0000000000..fbd01271d0 Binary files /dev/null and b/libraries/src/main/resources/Letter.docx differ