Skip to content

Commit 65b475c

Browse files
authored
Merge pull request #41 from fugerit-org/feature/issue_40_simpletable
1.2.0-rc.001 (2023-07-07)
2 parents 0c7049f + 7480ef0 commit 65b475c

File tree

28 files changed

+396
-27
lines changed

28 files changed

+396
-27
lines changed

docgen/release-notes.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
1.1.2-rc.001 (2023-07-03)
1+
1.2.0-rc.001 (2023-07-07)
2+
------------------
3+
+ Added module fj-doc-lib-simpletable-import to convert xlsx or csv to simple table
4+
5+
1.1.2-rc.001 (2023-07-03)
26
------------------
37
+ Updated quarkus version to 3.1.3.Final
48
+ Added generation time on playgroud quarkus

fj-doc-base-json/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-doc</artifactId>
10-
<version>1.1.2-rc.001</version>
10+
<version>1.2.0-rc.001</version>
1111
</parent>
1212

1313
<name>fj-doc-base-json</name>

fj-doc-base-yaml/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-doc</artifactId>
10-
<version>1.1.2-rc.001</version>
10+
<version>1.2.0-rc.001</version>
1111
</parent>
1212

1313
<name>fj-doc-base-yaml</name>

fj-doc-base/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-doc</artifactId>
10-
<version>1.1.2-rc.001</version>
10+
<version>1.2.0-rc.001</version>
1111
</parent>
1212

1313
<name>fj-doc-base</name>

fj-doc-bom-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-doc</artifactId>
10-
<version>1.1.2-rc.001</version>
10+
<version>1.2.0-rc.001</version>
1111
</parent>
1212

1313
<name>fj-doc-bom-core</name>

fj-doc-bom-fop/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-doc</artifactId>
10-
<version>1.1.2-rc.001</version>
10+
<version>1.2.0-rc.001</version>
1111
</parent>
1212

1313
<name>fj-doc-bom-fop</name>

fj-doc-freemarker/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-doc</artifactId>
10-
<version>1.1.2-rc.001</version>
10+
<version>1.2.0-rc.001</version>
1111
</parent>
1212

1313
<name>fj-doc-freemarker</name>

fj-doc-lib-autodoc/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-doc</artifactId>
10-
<version>1.1.2-rc.001</version>
10+
<version>1.2.0-rc.001</version>
1111
</parent>
1212

1313
<name>fj-doc-lib-autodoc</name>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog for module fj-doc-lib-simpletable-import
2+
3+
## version 1.1.2-rc.001- 2023-07-07
4+
* Basic support for xlsx to simple table conversion
5+
* Basic support for csv to simple table conversion
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Fugerit Document Generation Framework (fj-doc)
2+
3+
## Bundle library : simple table (fj-doc-lib-simpletable-import)
4+
5+
[back to fj-doc index](../README.md)
6+
7+
*Description* :
8+
This is a simple library to convert xlsx or csv document to SimpleTable
9+
10+
*Status* :
11+
All basic features are implemented.
12+
13+
14+
*Quickstart* :
15+
16+
For CSV :
17+
18+
```
19+
20+
try ( FileInputStream is = new FileInputStream( inputFile );
21+
FileOutputStream os = new FileOutputStream( outputFile )) {
22+
ConvertCsvToSimpleTableFacade.getInstance().processCsv(is, os, XlsxPoiTypeHandler.HANDLER, new Properties());
23+
} catch (Exception e) {
24+
...
25+
}
26+
27+
```
28+
29+
For XLSX :
30+
31+
```
32+
33+
try ( FileInputStream is = new FileInputStream( inputFile );
34+
FileOutputStream os = new FileOutputStream( outputFile )) {
35+
ConvertXlsxToSimpleTableFacade.getInstance().processXlsx(is, os, XlsxPoiTypeHandler.HANDLER, new Properties());
36+
} catch (Exception e) {
37+
...
38+
}
39+
40+
```

fj-doc-lib-simpletable-import/pom.xml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<artifactId>fj-doc-lib-simpletable-import</artifactId>
6+
7+
<parent>
8+
<groupId>org.fugerit.java</groupId>
9+
<artifactId>fj-doc</artifactId>
10+
<version>1.2.0-rc.001</version>
11+
</parent>
12+
13+
<name>fj-doc-lib-simpletable-import</name>
14+
<description>Offers a simple API for importing Excel or CSV as a simpletable</description>
15+
16+
<licenses>
17+
<license>
18+
<name>Apache License, Version 2.0</name>
19+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
20+
<distribution>repo</distribution>
21+
</license>
22+
</licenses>
23+
24+
<properties>
25+
</properties>
26+
27+
<build>
28+
29+
</build>
30+
31+
<dependencies>
32+
33+
<dependency>
34+
<groupId>org.fugerit.java</groupId>
35+
<artifactId>fj-core</artifactId>
36+
</dependency>
37+
38+
<dependency>
39+
<groupId>org.fugerit.java</groupId>
40+
<artifactId>fj-doc-base</artifactId>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>org.fugerit.java</groupId>
45+
<artifactId>fj-doc-freemarker</artifactId>
46+
</dependency>
47+
48+
<dependency>
49+
<groupId>org.fugerit.java</groupId>
50+
<artifactId>fj-doc-lib-simpletable</artifactId>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>org.fugerit.java</groupId>
55+
<artifactId>fj-doc-mod-poi</artifactId>
56+
</dependency>
57+
58+
<dependency>
59+
<groupId>org.fugerit.java</groupId>
60+
<artifactId>fj-doc-mod-opencsv</artifactId>
61+
</dependency>
62+
63+
</dependencies>
64+
65+
<organization>
66+
<url>https://www.fugerit.org</url>
67+
<name>Fugerit</name>
68+
</organization>
69+
70+
<url>https://www.fugerit.org/perm/venus/</url>
71+
72+
<profiles>
73+
74+
<profile>
75+
<id>full</id>
76+
<build>
77+
<plugins>
78+
<plugin>
79+
<groupId>org.apache.maven.plugins</groupId>
80+
<artifactId>maven-source-plugin</artifactId>
81+
<executions>
82+
<execution>
83+
<id>attach-sources</id>
84+
<goals>
85+
<goal>jar</goal>
86+
</goals>
87+
</execution>
88+
</executions>
89+
</plugin>
90+
<plugin>
91+
<groupId>org.apache.maven.plugins</groupId>
92+
<artifactId>maven-javadoc-plugin</artifactId>
93+
<configuration>
94+
<stylesheetfile>src/main/javadoc/stylesheet.css</stylesheetfile>
95+
</configuration>
96+
<executions>
97+
<execution>
98+
<id>attach-javadocs</id>
99+
<goals>
100+
<goal>jar</goal>
101+
</goals>
102+
</execution>
103+
</executions>
104+
</plugin>
105+
</plugins>
106+
</build>
107+
</profile>
108+
109+
</profiles>
110+
111+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package org.fugerit.java.doc.lib.simpletableimport;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.io.InputStreamReader;
6+
import java.io.OutputStream;
7+
import java.util.Properties;
8+
9+
import org.fugerit.java.core.cfg.ConfigException;
10+
import org.fugerit.java.doc.base.config.DocException;
11+
import org.fugerit.java.doc.base.config.DocTypeHandler;
12+
import org.fugerit.java.doc.lib.simpletable.SimpleTableDocConfig;
13+
import org.fugerit.java.doc.lib.simpletable.SimpleTableFacade;
14+
import org.fugerit.java.doc.lib.simpletable.SimpleTableHelper;
15+
import org.fugerit.java.doc.lib.simpletable.model.SimpleTable;
16+
17+
import com.opencsv.CSVReader;
18+
import com.opencsv.exceptions.CsvValidationException;
19+
20+
public class ConvertCsvToSimpleTableFacade {
21+
22+
private static final ConvertCsvToSimpleTableFacade INSTANCE = new ConvertCsvToSimpleTableFacade();
23+
24+
public static ConvertCsvToSimpleTableFacade getInstance() {
25+
return INSTANCE;
26+
}
27+
28+
public SimpleTable convertCsv( InputStream csvStream, Properties params ) throws ConfigException {
29+
SimpleTable table = null;
30+
try ( CSVReader reader = new CSVReader( new InputStreamReader( csvStream ) ) ) {
31+
int columnCount = -1;
32+
SimpleTableHelper helper = SimpleTableFacade.newHelper();
33+
String[] currentLine = reader.readNext();
34+
while ( currentLine != null ) {
35+
if ( columnCount != -1 && columnCount != currentLine.length ) {
36+
throw new ConfigException( "Wrong column count : "+currentLine.length );
37+
} else {
38+
columnCount = currentLine.length;
39+
}
40+
if ( table == null ) {
41+
// creates a fixed columns table
42+
table = helper.newTable( helper.newFixedColumns( columnCount ) );
43+
}
44+
table.addRow( helper.newNormalRow( currentLine ) );
45+
currentLine = reader.readNext();
46+
}
47+
} catch (IOException | CsvValidationException e) {
48+
throw new ConfigException( e );
49+
}
50+
return table;
51+
}
52+
53+
public void processCsv( InputStream xlsxStream, OutputStream os, DocTypeHandler handler, Properties params ) throws ConfigException, DocException {
54+
SimpleTable table = this.convertCsv(xlsxStream, params);
55+
SimpleTableDocConfig docConfig = SimpleTableDocConfig.newConfig();
56+
docConfig.processSimpleTable(table, handler, os);
57+
}
58+
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package org.fugerit.java.doc.lib.simpletableimport;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.io.OutputStream;
6+
import java.util.Iterator;
7+
import java.util.Properties;
8+
9+
import org.apache.poi.ss.usermodel.Cell;
10+
import org.apache.poi.ss.usermodel.Row;
11+
import org.apache.poi.ss.usermodel.Sheet;
12+
import org.apache.poi.ss.usermodel.Workbook;
13+
import org.apache.poi.xssf.usermodel.XSSFCell;
14+
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
15+
import org.fugerit.java.core.cfg.ConfigException;
16+
import org.fugerit.java.doc.base.config.DocException;
17+
import org.fugerit.java.doc.base.config.DocTypeHandler;
18+
import org.fugerit.java.doc.lib.simpletable.SimpleTableDocConfig;
19+
import org.fugerit.java.doc.lib.simpletable.SimpleTableFacade;
20+
import org.fugerit.java.doc.lib.simpletable.SimpleTableHelper;
21+
import org.fugerit.java.doc.lib.simpletable.model.SimpleTable;
22+
23+
public class ConvertXlsxToSimpleTableFacade {
24+
25+
private static final ConvertXlsxToSimpleTableFacade INSTANCE = new ConvertXlsxToSimpleTableFacade();
26+
27+
public static ConvertXlsxToSimpleTableFacade getInstance() {
28+
return INSTANCE;
29+
}
30+
31+
public SimpleTable convertXlsx( InputStream xlsxStream, Properties params ) throws ConfigException {
32+
SimpleTable table = null;
33+
try ( Workbook workbook = new XSSFWorkbook( xlsxStream ) ) {
34+
Sheet sheet = workbook.getSheetAt( 0 );
35+
Iterator<Row> itRows = sheet.iterator();
36+
SimpleTableHelper helper = SimpleTableFacade.newHelper();
37+
short columnCount = -1;
38+
while ( itRows.hasNext() ) {
39+
Row row = itRows.next();
40+
boolean isHeaderRow = true;
41+
if ( columnCount != -1 && columnCount != row.getLastCellNum() ) {
42+
throw new ConfigException( "Wrong column count : "+row.getLastCellNum() );
43+
} else {
44+
columnCount = row.getLastCellNum();
45+
}
46+
if ( table == null ) {
47+
// creates a fixed columns table
48+
table = helper.newTable( helper.newFixedColumns( columnCount ) );
49+
}
50+
Iterator<Cell> itCells = row.iterator();
51+
String line[] = new String[ columnCount ];
52+
int colIndex = 0;
53+
while ( itCells.hasNext() ) {
54+
Cell cell = itCells.next();
55+
XSSFCell xssfCell = (XSSFCell) cell;
56+
isHeaderRow = isHeaderRow && xssfCell.getCellStyle().getFont().getBold();
57+
line[colIndex] = cell.getStringCellValue();
58+
colIndex++;
59+
}
60+
if ( isHeaderRow ) {
61+
table.addRow( helper.newHeaderRow( line ) );
62+
} else {
63+
table.addRow( helper.newNormalRow( line ) );
64+
}
65+
}
66+
} catch (IOException e) {
67+
throw new ConfigException( e );
68+
}
69+
return table;
70+
}
71+
72+
public void processXlsx( InputStream xlsxStream, OutputStream os, DocTypeHandler handler, Properties params ) throws ConfigException, DocException {
73+
SimpleTable table = this.convertXlsx(xlsxStream, params);
74+
SimpleTableDocConfig docConfig = SimpleTableDocConfig.newConfig();
75+
docConfig.processSimpleTable(table, handler, os);
76+
}
77+
78+
}

0 commit comments

Comments
 (0)