Skip to content

[fj-doc-mod-poi] element phrase it is not correcly rendered #403 #404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

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

## [8.13.3] - 2025-04-24
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,9 @@
import java.util.HashSet;
import java.util.Iterator;

import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import lombok.Setter;
import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.fugerit.java.core.function.SafeFunction;
import org.fugerit.java.core.lang.helpers.BooleanUtils;
Expand All @@ -28,13 +21,7 @@
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.DocBorders;
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.DocRow;
import org.fugerit.java.doc.base.model.DocTable;
import org.fugerit.java.doc.base.model.*;
import org.fugerit.java.doc.base.typehelper.excel.ExcelHelperConsts;
import org.fugerit.java.doc.base.typehelper.excel.ExcelHelperUtils;
import org.fugerit.java.doc.base.typehelper.excel.TableMatrix;
Expand Down Expand Up @@ -188,35 +175,61 @@ private void checkFormat( WorkbookDataWrapper wrapper, Collection<PoiCellStyleMo
private void iterateCellMatrix( WorkbookDataWrapper wrapper , boolean ignoreFormat, HashSet<PoiCellStyleModel> styleSet , int rn, int cn, Row currentRow ) throws Exception {
TableMatrix matrix = wrapper.getTableMatrix();
Workbook workbook = wrapper.getWorkbook();
String type = null;
String format = null;
DocCell cell = matrix.getCell( rn, cn );
DocCell parent = matrix.getParent( rn, cn );
String text = "";
DocPara currentePara = null;
CellHolder holder = new CellHolder();
if ( cell != null ) {
Iterator<DocElement> it1 = cell.docElements();
DocElement current = it1.next();
if ( current instanceof DocPara ) {
currentePara = ((DocPara)current);
text = currentePara.getText();
type = currentePara.getType();
format = currentePara.getFormat();
} else {
text = String.valueOf( current );
currentePara = null;
}
} else {
currentePara = null;
this.handleElement( holder, cell );
}
Cell currentCell = currentRow.getCell( cn );
if ( currentCell == null ) {
currentCell = currentRow.createCell( cn );
}
this.handleHyperLink( holder.getLink(), workbook, currentCell );
if ( cell != null && parent != null && !ignoreFormat ) {
this.checkFormat( wrapper, styleSet, currentePara, cell, rn, cn, currentCell );
this.checkFormat( wrapper, styleSet, holder.getCurrentePara(), cell, rn, cn, currentCell );
}
this.setCellValue( workbook, currentCell, type, format, text);
this.setCellValue( workbook, currentCell, holder.getType(), holder.getFormat(), holder.getText());
}

private void handleElement( CellHolder holder, DocCell cell ) throws Exception {
Iterator<DocElement> it1 = cell.docElements();
DocElement current = it1.next();
if ( current instanceof DocPara ) {
holder.setCurrentePara((DocPara) current);
holder.setText(holder.getCurrentePara().getText());
holder.setType(holder.getCurrentePara().getType());
holder.setFormat(holder.getCurrentePara().getFormat());
} else if ( current instanceof DocPhrase) {
DocPhrase phrase = (DocPhrase) current;
holder.setText(phrase.getText());
holder.setLink(phrase.getLink());
holder.setCurrentePara(null);
} else {
holder.setText( String.valueOf( current ) );
holder.setCurrentePara(null);
}
}

private class CellHolder {
@Getter @Setter
private String text = "";
@Getter @Setter
private String link;
@Getter @Setter
private String type;
@Getter @Setter
private String format;
@Getter @Setter
private DocPara currentePara;
}

private void handleHyperLink( String link, Workbook workbook, Cell currentCell ) {
if ( StringUtils.isNotEmpty(link) ) {
Hyperlink hyperlink = workbook.getCreationHelper().createHyperlink(HyperlinkType.URL);
hyperlink.setAddress( link );
currentCell.setHyperlink( hyperlink );
}
}

private void handleSubmatrix( TableMatrix matrix, boolean ignoreFormat, Sheet sheet, WorkbookHelper helper, HashSet<PoiCellStyleModel> styleSet ) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
[ {
"condition" : {
"typeReachable" : "org.fugerit.java.doc.base.facade.DocFacadeSource"
},
"name" : "org.fugerit.java.doc.mod.poi.BasicPoiTypeHandler$1",
"methods" : [ {
"name" : "equals",
"parameterTypes" : [ "java.lang.Object" ]
}, {
"name" : "getClass",
"parameterTypes" : [ ]
}, {
"name" : "hashCode",
"parameterTypes" : [ ]
}, {
"name" : "notify",
"parameterTypes" : [ ]
}, {
"name" : "notifyAll",
"parameterTypes" : [ ]
}, {
"name" : "toString",
"parameterTypes" : [ ]
}, {
"name" : "wait",
"parameterTypes" : [ ]
}, {
"name" : "wait",
"parameterTypes" : [ "long" ]
}, {
"name" : "wait",
"parameterTypes" : [ "long", "int" ]
} ]
}, {
"condition" : {
"typeReachable" : "org.fugerit.java.doc.base.facade.DocFacadeSource"
},
Expand Down Expand Up @@ -79,6 +112,69 @@
"name" : "wait",
"parameterTypes" : [ "long", "int" ]
} ]
}, {
"condition" : {
"typeReachable" : "org.fugerit.java.doc.base.facade.DocFacadeSource"
},
"name" : "org.fugerit.java.doc.mod.poi.BasicPoiTypeHandler$CellHolder",
"methods" : [ {
"name" : "equals",
"parameterTypes" : [ "java.lang.Object" ]
}, {
"name" : "getClass",
"parameterTypes" : [ ]
}, {
"name" : "getCurrentePara",
"parameterTypes" : [ ]
}, {
"name" : "getFormat",
"parameterTypes" : [ ]
}, {
"name" : "getLink",
"parameterTypes" : [ ]
}, {
"name" : "getText",
"parameterTypes" : [ ]
}, {
"name" : "getType",
"parameterTypes" : [ ]
}, {
"name" : "hashCode",
"parameterTypes" : [ ]
}, {
"name" : "notify",
"parameterTypes" : [ ]
}, {
"name" : "notifyAll",
"parameterTypes" : [ ]
}, {
"name" : "setCurrentePara",
"parameterTypes" : [ "org.fugerit.java.doc.base.model.DocPara" ]
}, {
"name" : "setFormat",
"parameterTypes" : [ "java.lang.String" ]
}, {
"name" : "setLink",
"parameterTypes" : [ "java.lang.String" ]
}, {
"name" : "setText",
"parameterTypes" : [ "java.lang.String" ]
}, {
"name" : "setType",
"parameterTypes" : [ "java.lang.String" ]
}, {
"name" : "toString",
"parameterTypes" : [ ]
}, {
"name" : "wait",
"parameterTypes" : [ ]
}, {
"name" : "wait",
"parameterTypes" : [ "long" ]
}, {
"name" : "wait",
"parameterTypes" : [ "long", "int" ]
} ]
}, {
"condition" : {
"typeReachable" : "org.fugerit.java.doc.base.facade.DocFacadeSource"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package test.org.fugerit.java.doc.mod.poi.coverage;

import java.io.ByteArrayOutputStream;
import java.io.InputStreamReader;
import java.io.*;
import java.util.Arrays;

import org.fugerit.java.core.function.SafeFunction;
Expand Down Expand Up @@ -43,5 +42,19 @@ void test01() {
} );
Assertions.assertTrue( Boolean.TRUE );
}

@Test
void testDoc() throws Exception {
String fileName = "test_doc";
DocTypeHandler handler = XlsxPoiTypeHandler.HANDLER;
String inputXml = String.format( "coverage/xml/%s.xml", fileName );
String outputFile = String.format( "target/%s.%s", fileName, handler.getType() );
File output = new File( outputFile );
try ( FileOutputStream fos = new FileOutputStream( output );
InputStreamReader reader = new InputStreamReader( ClassHelper.loadFromDefaultClassLoader(inputXml) );) {
handler.handle( DocInput.newInput( handler.getType(), reader ), DocOutput.newOutput( fos ) );
}
Assertions.assertTrue( output.exists() );
}

}
109 changes: 109 additions & 0 deletions fj-doc-mod-poi/src/test/resources/coverage/xml/test_doc.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="utf-8"?>
<doc
xmlns="http://javacoredoc.fugerit.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://javacoredoc.fugerit.org https://www.fugerit.org/data/java/doc/xsd/doc-2-1.xsd" >

<metadata>
<!-- Margin for document : left;right;top;bottom -->
<info name="margins">10;10;10;30</info>
<info name="excel-table-id">excel-table=print,excel-table-1=print1</info>
<!-- documenta meta information -->
<info name="doc-title">Basic example</info>
<info name="doc-subject">fj doc venus sample source xml</info>
<info name="doc-author">fugerit79</info>
<info name="doc-language">en</info>
<!-- additional properties -->
<info name="set-total-page">true</info>
<info name="html-css-link">/css/test.css</info>
<header-ext>
<para align="center" fore-color="#eeeeee">header test</para>
</header-ext>
<footer-ext>
<para align="left">test</para>
<para align="center">${r"${currentPage}"} / ${r"${pageCount}"}</para>
<para align="right">test</para>
</footer-ext>
<bookmark-tree>
<bookmark ref="title">Test</bookmark>
</bookmark-tree>
</metadata>
<body>
<h id="title" head-level="1">main title h1</h>
<para font-name="times-roman" style="bold">Test times roman</para>
<para font-name="courier" style="bolditalic">Courier</para>
<para font-name="symbol" style="italic">Symbol</para>
<para font-name="helvetica" style="underline">Symbol</para>
<para size="3" fore-color="#dddddd">Test default font</para>
<br/>
<page-break/>
<table columns="3" colwidths="30;30;40" width="100" id="excel-table" padding="2">
<row>
<cell align="center" border-color="#000000" border-width="1"><para style="bold">Name</para></cell>
<cell align="center"><para style="bold">Surname</para></cell>
<cell align="center"><para style="bold">Title</para></cell>
</row>
<row>
<cell valign="top"><para><![CDATA[Thorin]]></para></cell>
<cell valign="bottom"><para><![CDATA[Oakshield]]></para></cell>
<cell valign="middle"><para><![CDATA[King]]></para></cell>
</row>
<row>
<cell fore-color="#000000" back-color="#ffffff"><para><![CDATA[Luthien]]></para></cell>
<cell><para><![CDATA[Tinuviel]]></para></cell>
<cell><para><![CDATA[Queen]]></para></cell>
</row>
<row>
<cell valign="top"><para><![CDATA[Thorin]]></para></cell>
<cell valign="bottom"><para><![CDATA[Oakshield]]></para></cell>
<cell valign="middle"><para><![CDATA[King]]></para></cell>
</row>
<row>
<cell align="left"><phrase><![CDATA[Phrase]]></phrase></cell>
<cell align="right"><phrase anchor="1"><![CDATA[Oakshield]]></phrase></cell>
<cell><phrase link="https:///www.fugerit.org"><![CDATA[King]]></phrase></cell>
</row>
<row>
<cell rowspan="2"><phrase>rowspan 2</phrase></cell>
<cell colspan="2"><phrase>colspn 2</phrase></cell>
</row>
<row>
<cell colspan="2"><phrase>colspn 2</phrase></cell>
</row>
</table>
<table columns="3" colwidths="30;30;40" width="100" id="excel-table-1" padding="2">
<row>
<cell align="center" border-color="#000000" border-width="1"><para style="bold">Name</para></cell>
<cell align="center"><para style="bold">Surname</para></cell>
<cell align="center"><para style="bold">Title</para></cell>
</row>
<row>
<cell valign="top"><para><![CDATA[Thorin]]></para></cell>
<cell valign="bottom"><para><![CDATA[Oakshield]]></para></cell>
<cell valign="middle"><para><![CDATA[King]]></para></cell>
</row>
</table>
<list>
<li><para>test 1</para></li>
</list>
<list list-type="ul">
<li><para>test 2</para></li>
</list>
<list list-type="ol">
<li><para>test 3</para></li>
</list>
<list list-type="uld">
<li><para>test 4</para></li>
</list>
<list list-type="ulm">
<li><para>test 5</para></li>
</list>
<list list-type="oll">
<li><para>test 6</para></li>
</list>
<list list-type="oln">
<li><para>test 7</para></li>
</list>
</body>

</doc>