-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ 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
Showing
20 changed files
with
241 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
fj-doc-base/src/main/java/org/fugerit/java/doc/base/typehelper/csv/CsvHelperConsts.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
75 changes: 75 additions & 0 deletions
75
fj-doc-mod-opencsv/src/main/java/org/fugerit/java/doc/mod/opencsv/OpenCSVTypeHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.