Skip to content

Commit a03947d

Browse files
authored
Merge pull request #404 from fugerit-org/403-chore-fj-doc-mod-poi-element-phrase-it-is-not-correcly-rendered
[fj-doc-mod-poi] element phrase it is not correcly rendered #403
2 parents 954753f + 71f0cc5 commit a03947d

File tree

5 files changed

+270
-38
lines changed

5 files changed

+270
-38
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Fixed
1515

16+
- [fj-doc-mod-poi] element phrase it is not correcly rendered <https://github.com/fugerit-org/fj-doc/pull/403>
1617
- [fj-doc-freemarker] handling link in asciidoc handler <https://github.com/fugerit-org/fj-doc/pull/399>
1718

1819
## [8.13.3] - 2025-04-24

fj-doc-mod-poi/src/main/java/org/fugerit/java/doc/mod/poi/BasicPoiTypeHandler.java

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,9 @@
1010
import java.util.HashSet;
1111
import java.util.Iterator;
1212

13-
import org.apache.poi.ss.usermodel.BorderStyle;
14-
import org.apache.poi.ss.usermodel.Cell;
15-
import org.apache.poi.ss.usermodel.CellStyle;
16-
import org.apache.poi.ss.usermodel.CreationHelper;
17-
import org.apache.poi.ss.usermodel.Font;
18-
import org.apache.poi.ss.usermodel.HorizontalAlignment;
19-
import org.apache.poi.ss.usermodel.Row;
20-
import org.apache.poi.ss.usermodel.Sheet;
21-
import org.apache.poi.ss.usermodel.VerticalAlignment;
22-
import org.apache.poi.ss.usermodel.Workbook;
13+
import lombok.Setter;
14+
import org.apache.poi.common.usermodel.HyperlinkType;
15+
import org.apache.poi.ss.usermodel.*;
2316
import org.apache.poi.ss.util.CellRangeAddress;
2417
import org.fugerit.java.core.function.SafeFunction;
2518
import org.fugerit.java.core.lang.helpers.BooleanUtils;
@@ -28,13 +21,7 @@
2821
import org.fugerit.java.doc.base.config.DocInput;
2922
import org.fugerit.java.doc.base.config.DocOutput;
3023
import org.fugerit.java.doc.base.config.DocTypeHandlerDefault;
31-
import org.fugerit.java.doc.base.model.DocBase;
32-
import org.fugerit.java.doc.base.model.DocBorders;
33-
import org.fugerit.java.doc.base.model.DocCell;
34-
import org.fugerit.java.doc.base.model.DocElement;
35-
import org.fugerit.java.doc.base.model.DocPara;
36-
import org.fugerit.java.doc.base.model.DocRow;
37-
import org.fugerit.java.doc.base.model.DocTable;
24+
import org.fugerit.java.doc.base.model.*;
3825
import org.fugerit.java.doc.base.typehelper.excel.ExcelHelperConsts;
3926
import org.fugerit.java.doc.base.typehelper.excel.ExcelHelperUtils;
4027
import org.fugerit.java.doc.base.typehelper.excel.TableMatrix;
@@ -188,35 +175,61 @@ private void checkFormat( WorkbookDataWrapper wrapper, Collection<PoiCellStyleMo
188175
private void iterateCellMatrix( WorkbookDataWrapper wrapper , boolean ignoreFormat, HashSet<PoiCellStyleModel> styleSet , int rn, int cn, Row currentRow ) throws Exception {
189176
TableMatrix matrix = wrapper.getTableMatrix();
190177
Workbook workbook = wrapper.getWorkbook();
191-
String type = null;
192-
String format = null;
193178
DocCell cell = matrix.getCell( rn, cn );
194179
DocCell parent = matrix.getParent( rn, cn );
195-
String text = "";
196-
DocPara currentePara = null;
180+
CellHolder holder = new CellHolder();
197181
if ( cell != null ) {
198-
Iterator<DocElement> it1 = cell.docElements();
199-
DocElement current = it1.next();
200-
if ( current instanceof DocPara ) {
201-
currentePara = ((DocPara)current);
202-
text = currentePara.getText();
203-
type = currentePara.getType();
204-
format = currentePara.getFormat();
205-
} else {
206-
text = String.valueOf( current );
207-
currentePara = null;
208-
}
209-
} else {
210-
currentePara = null;
182+
this.handleElement( holder, cell );
211183
}
212184
Cell currentCell = currentRow.getCell( cn );
213185
if ( currentCell == null ) {
214186
currentCell = currentRow.createCell( cn );
215187
}
188+
this.handleHyperLink( holder.getLink(), workbook, currentCell );
216189
if ( cell != null && parent != null && !ignoreFormat ) {
217-
this.checkFormat( wrapper, styleSet, currentePara, cell, rn, cn, currentCell );
190+
this.checkFormat( wrapper, styleSet, holder.getCurrentePara(), cell, rn, cn, currentCell );
218191
}
219-
this.setCellValue( workbook, currentCell, type, format, text);
192+
this.setCellValue( workbook, currentCell, holder.getType(), holder.getFormat(), holder.getText());
193+
}
194+
195+
private void handleElement( CellHolder holder, DocCell cell ) throws Exception {
196+
Iterator<DocElement> it1 = cell.docElements();
197+
DocElement current = it1.next();
198+
if ( current instanceof DocPara ) {
199+
holder.setCurrentePara((DocPara) current);
200+
holder.setText(holder.getCurrentePara().getText());
201+
holder.setType(holder.getCurrentePara().getType());
202+
holder.setFormat(holder.getCurrentePara().getFormat());
203+
} else if ( current instanceof DocPhrase) {
204+
DocPhrase phrase = (DocPhrase) current;
205+
holder.setText(phrase.getText());
206+
holder.setLink(phrase.getLink());
207+
holder.setCurrentePara(null);
208+
} else {
209+
holder.setText( String.valueOf( current ) );
210+
holder.setCurrentePara(null);
211+
}
212+
}
213+
214+
private class CellHolder {
215+
@Getter @Setter
216+
private String text = "";
217+
@Getter @Setter
218+
private String link;
219+
@Getter @Setter
220+
private String type;
221+
@Getter @Setter
222+
private String format;
223+
@Getter @Setter
224+
private DocPara currentePara;
225+
}
226+
227+
private void handleHyperLink( String link, Workbook workbook, Cell currentCell ) {
228+
if ( StringUtils.isNotEmpty(link) ) {
229+
Hyperlink hyperlink = workbook.getCreationHelper().createHyperlink(HyperlinkType.URL);
230+
hyperlink.setAddress( link );
231+
currentCell.setHyperlink( hyperlink );
232+
}
220233
}
221234

222235
private void handleSubmatrix( TableMatrix matrix, boolean ignoreFormat, Sheet sheet, WorkbookHelper helper, HashSet<PoiCellStyleModel> styleSet ) throws Exception {

fj-doc-mod-poi/src/main/resources/META-INF/native-image/org.fugerit.java/fj-doc-mod-poi/reflect-config.json

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,37 @@
11
[ {
2+
"condition" : {
3+
"typeReachable" : "org.fugerit.java.doc.base.facade.DocFacadeSource"
4+
},
5+
"name" : "org.fugerit.java.doc.mod.poi.BasicPoiTypeHandler$1",
6+
"methods" : [ {
7+
"name" : "equals",
8+
"parameterTypes" : [ "java.lang.Object" ]
9+
}, {
10+
"name" : "getClass",
11+
"parameterTypes" : [ ]
12+
}, {
13+
"name" : "hashCode",
14+
"parameterTypes" : [ ]
15+
}, {
16+
"name" : "notify",
17+
"parameterTypes" : [ ]
18+
}, {
19+
"name" : "notifyAll",
20+
"parameterTypes" : [ ]
21+
}, {
22+
"name" : "toString",
23+
"parameterTypes" : [ ]
24+
}, {
25+
"name" : "wait",
26+
"parameterTypes" : [ ]
27+
}, {
28+
"name" : "wait",
29+
"parameterTypes" : [ "long" ]
30+
}, {
31+
"name" : "wait",
32+
"parameterTypes" : [ "long", "int" ]
33+
} ]
34+
}, {
235
"condition" : {
336
"typeReachable" : "org.fugerit.java.doc.base.facade.DocFacadeSource"
437
},
@@ -79,6 +112,69 @@
79112
"name" : "wait",
80113
"parameterTypes" : [ "long", "int" ]
81114
} ]
115+
}, {
116+
"condition" : {
117+
"typeReachable" : "org.fugerit.java.doc.base.facade.DocFacadeSource"
118+
},
119+
"name" : "org.fugerit.java.doc.mod.poi.BasicPoiTypeHandler$CellHolder",
120+
"methods" : [ {
121+
"name" : "equals",
122+
"parameterTypes" : [ "java.lang.Object" ]
123+
}, {
124+
"name" : "getClass",
125+
"parameterTypes" : [ ]
126+
}, {
127+
"name" : "getCurrentePara",
128+
"parameterTypes" : [ ]
129+
}, {
130+
"name" : "getFormat",
131+
"parameterTypes" : [ ]
132+
}, {
133+
"name" : "getLink",
134+
"parameterTypes" : [ ]
135+
}, {
136+
"name" : "getText",
137+
"parameterTypes" : [ ]
138+
}, {
139+
"name" : "getType",
140+
"parameterTypes" : [ ]
141+
}, {
142+
"name" : "hashCode",
143+
"parameterTypes" : [ ]
144+
}, {
145+
"name" : "notify",
146+
"parameterTypes" : [ ]
147+
}, {
148+
"name" : "notifyAll",
149+
"parameterTypes" : [ ]
150+
}, {
151+
"name" : "setCurrentePara",
152+
"parameterTypes" : [ "org.fugerit.java.doc.base.model.DocPara" ]
153+
}, {
154+
"name" : "setFormat",
155+
"parameterTypes" : [ "java.lang.String" ]
156+
}, {
157+
"name" : "setLink",
158+
"parameterTypes" : [ "java.lang.String" ]
159+
}, {
160+
"name" : "setText",
161+
"parameterTypes" : [ "java.lang.String" ]
162+
}, {
163+
"name" : "setType",
164+
"parameterTypes" : [ "java.lang.String" ]
165+
}, {
166+
"name" : "toString",
167+
"parameterTypes" : [ ]
168+
}, {
169+
"name" : "wait",
170+
"parameterTypes" : [ ]
171+
}, {
172+
"name" : "wait",
173+
"parameterTypes" : [ "long" ]
174+
}, {
175+
"name" : "wait",
176+
"parameterTypes" : [ "long", "int" ]
177+
} ]
82178
}, {
83179
"condition" : {
84180
"typeReachable" : "org.fugerit.java.doc.base.facade.DocFacadeSource"

fj-doc-mod-poi/src/test/java/test/org/fugerit/java/doc/mod/poi/coverage/TestPoiCoverage.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package test.org.fugerit.java.doc.mod.poi.coverage;
22

3-
import java.io.ByteArrayOutputStream;
4-
import java.io.InputStreamReader;
3+
import java.io.*;
54
import java.util.Arrays;
65

76
import org.fugerit.java.core.function.SafeFunction;
@@ -43,5 +42,19 @@ void test01() {
4342
} );
4443
Assertions.assertTrue( Boolean.TRUE );
4544
}
45+
46+
@Test
47+
void testDoc() throws Exception {
48+
String fileName = "test_doc";
49+
DocTypeHandler handler = XlsxPoiTypeHandler.HANDLER;
50+
String inputXml = String.format( "coverage/xml/%s.xml", fileName );
51+
String outputFile = String.format( "target/%s.%s", fileName, handler.getType() );
52+
File output = new File( outputFile );
53+
try ( FileOutputStream fos = new FileOutputStream( output );
54+
InputStreamReader reader = new InputStreamReader( ClassHelper.loadFromDefaultClassLoader(inputXml) );) {
55+
handler.handle( DocInput.newInput( handler.getType(), reader ), DocOutput.newOutput( fos ) );
56+
}
57+
Assertions.assertTrue( output.exists() );
58+
}
4659

4760
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<doc
3+
xmlns="http://javacoredoc.fugerit.org"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://javacoredoc.fugerit.org https://www.fugerit.org/data/java/doc/xsd/doc-2-1.xsd" >
6+
7+
<metadata>
8+
<!-- Margin for document : left;right;top;bottom -->
9+
<info name="margins">10;10;10;30</info>
10+
<info name="excel-table-id">excel-table=print,excel-table-1=print1</info>
11+
<!-- documenta meta information -->
12+
<info name="doc-title">Basic example</info>
13+
<info name="doc-subject">fj doc venus sample source xml</info>
14+
<info name="doc-author">fugerit79</info>
15+
<info name="doc-language">en</info>
16+
<!-- additional properties -->
17+
<info name="set-total-page">true</info>
18+
<info name="html-css-link">/css/test.css</info>
19+
<header-ext>
20+
<para align="center" fore-color="#eeeeee">header test</para>
21+
</header-ext>
22+
<footer-ext>
23+
<para align="left">test</para>
24+
<para align="center">${r"${currentPage}"} / ${r"${pageCount}"}</para>
25+
<para align="right">test</para>
26+
</footer-ext>
27+
<bookmark-tree>
28+
<bookmark ref="title">Test</bookmark>
29+
</bookmark-tree>
30+
</metadata>
31+
<body>
32+
<h id="title" head-level="1">main title h1</h>
33+
<para font-name="times-roman" style="bold">Test times roman</para>
34+
<para font-name="courier" style="bolditalic">Courier</para>
35+
<para font-name="symbol" style="italic">Symbol</para>
36+
<para font-name="helvetica" style="underline">Symbol</para>
37+
<para size="3" fore-color="#dddddd">Test default font</para>
38+
<br/>
39+
<page-break/>
40+
<table columns="3" colwidths="30;30;40" width="100" id="excel-table" padding="2">
41+
<row>
42+
<cell align="center" border-color="#000000" border-width="1"><para style="bold">Name</para></cell>
43+
<cell align="center"><para style="bold">Surname</para></cell>
44+
<cell align="center"><para style="bold">Title</para></cell>
45+
</row>
46+
<row>
47+
<cell valign="top"><para><![CDATA[Thorin]]></para></cell>
48+
<cell valign="bottom"><para><![CDATA[Oakshield]]></para></cell>
49+
<cell valign="middle"><para><![CDATA[King]]></para></cell>
50+
</row>
51+
<row>
52+
<cell fore-color="#000000" back-color="#ffffff"><para><![CDATA[Luthien]]></para></cell>
53+
<cell><para><![CDATA[Tinuviel]]></para></cell>
54+
<cell><para><![CDATA[Queen]]></para></cell>
55+
</row>
56+
<row>
57+
<cell valign="top"><para><![CDATA[Thorin]]></para></cell>
58+
<cell valign="bottom"><para><![CDATA[Oakshield]]></para></cell>
59+
<cell valign="middle"><para><![CDATA[King]]></para></cell>
60+
</row>
61+
<row>
62+
<cell align="left"><phrase><![CDATA[Phrase]]></phrase></cell>
63+
<cell align="right"><phrase anchor="1"><![CDATA[Oakshield]]></phrase></cell>
64+
<cell><phrase link="https:///www.fugerit.org"><![CDATA[King]]></phrase></cell>
65+
</row>
66+
<row>
67+
<cell rowspan="2"><phrase>rowspan 2</phrase></cell>
68+
<cell colspan="2"><phrase>colspn 2</phrase></cell>
69+
</row>
70+
<row>
71+
<cell colspan="2"><phrase>colspn 2</phrase></cell>
72+
</row>
73+
</table>
74+
<table columns="3" colwidths="30;30;40" width="100" id="excel-table-1" padding="2">
75+
<row>
76+
<cell align="center" border-color="#000000" border-width="1"><para style="bold">Name</para></cell>
77+
<cell align="center"><para style="bold">Surname</para></cell>
78+
<cell align="center"><para style="bold">Title</para></cell>
79+
</row>
80+
<row>
81+
<cell valign="top"><para><![CDATA[Thorin]]></para></cell>
82+
<cell valign="bottom"><para><![CDATA[Oakshield]]></para></cell>
83+
<cell valign="middle"><para><![CDATA[King]]></para></cell>
84+
</row>
85+
</table>
86+
<list>
87+
<li><para>test 1</para></li>
88+
</list>
89+
<list list-type="ul">
90+
<li><para>test 2</para></li>
91+
</list>
92+
<list list-type="ol">
93+
<li><para>test 3</para></li>
94+
</list>
95+
<list list-type="uld">
96+
<li><para>test 4</para></li>
97+
</list>
98+
<list list-type="ulm">
99+
<li><para>test 5</para></li>
100+
</list>
101+
<list list-type="oll">
102+
<li><para>test 6</para></li>
103+
</list>
104+
<list list-type="oln">
105+
<li><para>test 7</para></li>
106+
</list>
107+
</body>
108+
109+
</doc>

0 commit comments

Comments
 (0)