Skip to content

Commit

Permalink
0.5.4 (2022-11-24)
Browse files Browse the repository at this point in the history
+ fj-doc-mod-opencsv, added module for handling CSV format [CSV
format](#8)
  • Loading branch information
Matteo Franci committed Nov 24, 2022
1 parent 54ea102 commit f1c4c70
Show file tree
Hide file tree
Showing 20 changed files with 241 additions and 19 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ There are five kinds of components (each components README.md contains module st
* [FreeMarker template, (fj-doc-freemarker)](fj-doc-freemarker/README.md) (contains a simple renderer for [HTML](fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/html/FreeMarkerHtmlTypeHandler.java) and [HTML FRAGMENT](fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/html/FreeMarkerHtmlFragmentTypeHandler.java))
* [Apache POI Module (fj-doc-mod-poi)](fj-doc-mod-poi/README.md) ([XLS](fj-doc-mod-poi/src/main/java/org/fugerit/java/doc/mod/poi/XlsPoiTypeHandler.java)/[XLSX](fj-doc-mod-poi/src/main/java/org/fugerit/java/doc/mod/poi/XlsPoiTypeHandler.java))
* [Apache FOP Module (fj-doc-mod-fop)](fj-doc-mod-fop/README.md) ([PDF](fj-doc-mod-fop/src/main/java/org/fugerit/java/doc/mod/fop/PdfFopTypeHandler.java)/[FO](fj-doc-mod-fop/src/main/java/org/fugerit/java/doc/mod/fop/FreeMarkerFopTypeHandler.java))
* [OpenCSV Module (fj-doc-mod-opencsv)](fj-doc-mod-opencsv/README.md) ([CSV](fj-doc-mod-opencsv/src/main/java/org/fugerit/java/doc/mod/opencsv/OpenCSVTypeHandler.java))


### 3. Available type handlers :
* [MD BASIC](fj-doc-base/src/main/java/org/fugerit/java/doc/base/typehandler/markdown/SimpleMarkdownBasicTypeHandler.java) - (fj-doc-core) output as Markdown basic language
Expand All @@ -29,6 +31,7 @@ There are five kinds of components (each components README.md contains module st
* [XLSX](fj-doc-mod-poi/src/main/java/org/fugerit/java/doc/mod/poi/XlsPoiTypeHandler.java) - (fj-doc-mod-poi) output as Microsoft XLSX using Apache POI
* [PDF](fj-doc-mod-fop/src/main/java/org/fugerit/java/doc/mod/fop/PdfFopTypeHandler.java) - (fj-doc-mod-fop) - output as PDF using Apache FOP
* [FO](fj-doc-mod-fop/src/main/java/org/fugerit/java/doc/mod/fop/FreeMarkerFopTypeHandler.java) - (fj-doc-mod-fop) - output as FO using Apache FOP
* [CSV](fj-doc-mod-opencsv/src/main/java/org/fugerit/java/doc/mod/opencsv/OpenCSVTypeHandler.java) - (fj-doc-mod-opencsv) - output as CSV using OpenCSV

### 4. Tutorial :
* [Samples and Quickstart (fj-doc-sample)](fj-doc-sample/README.md)
Expand Down
4 changes: 2 additions & 2 deletions docgen/parameters.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"title" : "Venus (Fugerit Document Generation Framework)",
"name": "Venus",
"version" : "0.5.3",
"date" : "21/11/2022",
"version" : "0.5.4",
"date" : "24/11/2022",
"organization" : {
"name" : "Fugerit Org",
"url" : "https://www.fugerit.org"
Expand Down
6 changes: 5 additions & 1 deletion docgen/release-notes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
0.5.3 (2022-11-21)
0.5.4 (2022-11-24)
------------------
+ fj-doc-mod-opencsv, added module for handling CSV format [CSV format](https://github.com/fugerit-org/fj-doc/issues/8)

0.5.3 (2022-11-21)
------------------
+ fj-doc-base fixed xsd version comparison (before was a normal string comparison)
+ fj-doc-mod-fop Fixed legacy compatibility of FopConfigClassLoader see [0.5.2](https://github.com/fugerit-org/fj-doc/issues/7)
Expand Down
4 changes: 2 additions & 2 deletions fj-doc-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc</artifactId>
<version>0.5.3</version>
<version>0.5.4</version>
</parent>

<name>fj-doc-base</name>
<description></description>
<description>Basic Framework functionalities (including a simple Renderer for Markdown)</description>

<licenses>
<license>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class DocConfig {

public static final String VERSION = " FUGERIT DOC Version 0.1 (2019-11-06) ";
public static final String VERSION = " FUGERIT DOC Version 0.5 (2022-11-24) ";

public static final String TYPE_XML = "xml";

Expand All @@ -22,4 +22,6 @@ public class DocConfig {

public static final String TYPE_MD = "md";

public static final String TYPE_CSV = "csv";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.fugerit.java.doc.base.typehelper.csv;

public class CsvHelperConsts {

public final static String PROP_CSV_TABLE_ID = "csv-table-id";

}
4 changes: 2 additions & 2 deletions fj-doc-freemarker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc</artifactId>
<version>0.5.3</version>
<version>0.5.4</version>
</parent>

<name>fj-doc-freemarker</name>
<description></description>
<description>Common freemarker functionalities and Renderer for HTML using Freemarker</description>

<licenses>
<license>
Expand Down
4 changes: 2 additions & 2 deletions fj-doc-mod-fop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc</artifactId>
<version>0.5.3</version>
<version>0.5.4</version>
</parent>

<name>fj-doc-mod-fop</name>
<description></description>
<description>Rendered for PDF using Apache FOP</description>

<licenses>
<license>
Expand Down
13 changes: 13 additions & 0 deletions fj-doc-mod-opencsv/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Fugerit Document Generation Framework (fj-doc)

## OpenCSV Render (CSV)(fj-doc-mod-opencsv)

[back to fj-doc index](../README.md)

*Status* :
Basic features implemented. (Sample JUnit [TestFreeMarker01](../fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/freemarker/TestFreeMarker01.java) is now working).
For the intrinsic limitations of the CSV format, is possibile to choose a sinlge table in the document and outputs it as CSV.

*Quickstart* :
Basically this is only a type handler, see core library [fj-doc-base](../fj-doc-base/README.md).
NOTE: If you have any special need you can open a pull request or create your own handler based on this.
98 changes: 98 additions & 0 deletions fj-doc-mod-opencsv/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>fj-doc-mod-opencsv</artifactId>

<parent>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc</artifactId>
<version>0.5.4</version>
</parent>

<name>fj-doc-mod-opencsv</name>
<description>Rendere for CSV using OpenCSV</description>

<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<properties>
<opencsv-version>5.7.1</opencsv-version>
</properties>

<build>

</build>

<dependencies>

<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>${opencsv-version}</version>
</dependency>

<dependency>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-core</artifactId>
</dependency>

<dependency>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc-base</artifactId>
</dependency>

</dependencies>

<organization>
<url>https://www.fugerit.org</url>
<name>Fugerit</name>
</organization>

<url>https://www.fugerit.org/perm/venus/</url>

<profiles>

<profile>
<id>full</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<stylesheetfile>src/main/javadoc/stylesheet.css</stylesheetfile>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.fugerit.java.doc.mod.opencsv;

import java.io.OutputStreamWriter;

import org.fugerit.java.doc.base.config.DocInput;
import org.fugerit.java.doc.base.config.DocOutput;
import org.fugerit.java.doc.base.config.DocTypeHandlerDefault;
import org.fugerit.java.doc.base.model.DocBase;
import org.fugerit.java.doc.base.model.DocCell;
import org.fugerit.java.doc.base.model.DocElement;
import org.fugerit.java.doc.base.model.DocPara;
import org.fugerit.java.doc.base.model.DocPhrase;
import org.fugerit.java.doc.base.model.DocRow;
import org.fugerit.java.doc.base.model.DocTable;
import org.fugerit.java.doc.base.typehelper.csv.CsvHelperConsts;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.opencsv.CSVWriter;

public class OpenCSVTypeHandler extends DocTypeHandlerDefault {

private static final Logger log = LoggerFactory.getLogger( OpenCSVTypeHandler.class );

/**
*
*/
private static final long serialVersionUID = -1832379566311585295L;

public static final String TYPE_CSV = "csv";
public static final String MODULE = "csv";
public static final String MIME = "text/csv";

public static final OpenCSVTypeHandler HANDLER = new OpenCSVTypeHandler();

public OpenCSVTypeHandler() {
super(TYPE_CSV, MODULE, MIME);
}

@Override
public void handle(DocInput docInput, DocOutput docOutput) throws Exception {
DocBase docBase = docInput.getDoc();
CSVWriter writer = new CSVWriter( new OutputStreamWriter( docOutput.getOs() ) );
String csvTableId = docBase.getInfo().getProperty( CsvHelperConsts.PROP_CSV_TABLE_ID );
DocTable table = (DocTable)docBase.getElementById( csvTableId );
if ( table == null ) {
log.warn( "table id {} not found!", csvTableId );
} else {
log.info( "handling table id {}", csvTableId );
String[] currentRow = new String[ table.getColumns() ];
for ( DocElement currentElement : table.getElementList() ) {
DocRow row = (DocRow) currentElement;
int count = 0;
for ( DocElement currentCell : row.getElementList() ) {
DocCell cell = (DocCell) currentCell;
StringBuilder currentContent = new StringBuilder();
for ( DocElement contentElement : cell.getElementList() ) {
if ( contentElement instanceof DocPara ) {
DocPara para = (DocPara) contentElement;
currentContent.append( para.getText() );
} else if ( contentElement instanceof DocPhrase ) {
DocPhrase para = (DocPhrase) contentElement;
currentContent.append( para.getText() );
}
}
currentRow[count] = currentContent.toString();
count++;
}
writer.writeNext( currentRow );
}
writer.flush();
}
}

}
3 changes: 2 additions & 1 deletion fj-doc-mod-poi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
[back to fj-doc index](../README.md)

*Status* :
Most basic features implemented. (proper color and font handling missing).
Most basic features implemented. (proper color and font handling missing).
For the intrinsic limitations of the XLS/XLSX format, it is possibile to choose a some tables in the document and output it as excel sheets.

*Quickstart* :
Basically this is only a type handler, see core library [fj-doc-base](../fj-doc-base/README.md).
Expand Down
4 changes: 2 additions & 2 deletions fj-doc-mod-poi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc</artifactId>
<version>0.5.3</version>
<version>0.5.4</version>
</parent>

<name>fj-doc-mod-poi</name>
<description></description>
<description>Renderer for XLS/XLSX using Apache POI</description>

<licenses>
<license>
Expand Down
7 changes: 6 additions & 1 deletion fj-doc-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc</artifactId>
<version>0.5.3</version>
<version>0.5.4</version>
</parent>

<name>fj-doc-sample</name>
Expand Down Expand Up @@ -52,6 +52,11 @@
<artifactId>fj-doc-mod-poi</artifactId>
</dependency>

<dependency>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc-mod-opencsv</artifactId>
</dependency>

</dependencies>

<organization>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
<config fop-config-classloader-path="fop-config.xml" font-base-classloader-path="font/"/>
</data>
<data id="html-fm" info="html" type="org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandler" />
<data id="html-fragment-fm" info="fhtml" type="org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlFragmentTypeHandler" />
<data id="html-fragment-fm" info="fhtml" type="org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlFragmentTypeHandler" />
<data id="csv-opencsv" info="csv" type="org.fugerit.java.doc.mod.opencsv.OpenCSVTypeHandler"/>
</factory>

</doc-handler-config>
5 changes: 4 additions & 1 deletion fj-doc-sample/src/main/resources/free_marker/basic.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
-->

<meta>
<!-- id table to be used for xlsx output -->
<info name="excel-table-id">excel-table=print</info>
<info name="excel-width-multiplier">450</info>
<info name="excel-width-multiplier">450</info>
<!-- id table to be used for xsv output -->
<info name="csv-table-id">excel-table</info>
</meta>

<body>
Expand Down
3 changes: 3 additions & 0 deletions fj-doc-sample/src/main/resources/free_marker/test_01.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
<!-- Margin for document : left;right;top;bottom -->
<info name="margins">10;10;10;30</info>

<!-- id table to be used for xlsx output -->
<info name="excel-table-id">excel-table=print</info>
<info name="excel-width-multiplier">450</info>
<!-- id table to be used for xsv output -->
<info name="csv-table-id">excel-table</info>

<!-- you need to escape free marker expression for currentPage -->
<footer-ext numbered="true" align="right">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class BasicFreeMarkerTest extends BasicFacadeTest {

public BasicFreeMarkerTest() {
this( "basic", DocConfig.TYPE_PDF, DocConfig.TYPE_XLS, DocConfig.TYPE_HTML );
this( "basic", DocConfig.TYPE_PDF, DocConfig.TYPE_XLS, DocConfig.TYPE_HTML, DocConfig.TYPE_CSV );
}

protected BasicFreeMarkerTest(String nameBase, String... typeList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class TestFreeMarker01 extends BasicFreeMarkerTest {
public TestFreeMarker01() {
super( "free-marker-01", DocConfig.TYPE_FO,
DocConfig.TYPE_XML, DocConfig.TYPE_PDF, DocConfig.TYPE_XLS,
DocConfig.TYPE_HTML, DocConfig.TYPE_XLSX );
DocConfig.TYPE_HTML, DocConfig.TYPE_XLSX, DocConfig.TYPE_CSV );
}


Expand Down
Loading

0 comments on commit f1c4c70

Please sign in to comment.