Skip to content

[ENHANCEMENT]: [fj-doc-core] check table columns and rows integrity #480

@fugerit79

Description

@fugerit79

Enhancement type

Improvements of existing feature

Do you want to contribute?

all

Goal of the proposal

Report problem on table structure, especially about number of columns and rows

Brief description

We want to help fix error caused by wrong number of colums / rows

Detailed description

Fugerit Venus Doc users should ensures that table columns and rows are correctly set, even when colspan and rowspan attributes are set, for instance, this table structure is correct :

Image

While this table structure can lead to an error :

Image

The second row has three columns defined, not taking into account the rowpsan=2 of the first cell in the first row.

We want to implement a check for the table structure.

we will introduce a new project parameter

<info name="table-check-integrity">warn</info>

table-check-integrity will accept the following options :

value description
disabled no integrity check (behaviour as before this feature is introduced - default value if not set)
warn will report a warning in the log at runtime
fail will report an error and fail with an exception

Is a proof of concept available

For instance, the following xml source document will lead to a fop exception when rendered with fop type handler in PDF :

org.apache.fop.fo.ValidationException :
null:65:8: The column-number or number of cells in the row overflows the number of fo:table-columns specified for the table. (See position 65:8)
<?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>
		<!-- documenta meta information -->
		<info name="doc-title">colspan / rowspan sample</info>
		<info name="doc-subject">fj doc venus sample source FreeMarker Template XML</info>
		<info name="doc-author">fugerit79</info>
		<info name="doc-language">en</info>
		<!-- font must be loaded -->
		<info name="default-font-name">TitilliumWeb</info>
		<!-- property specific for xls/xlsx -->
		<info name="excel-table-id">data-table=print</info>
		<!-- property specific for csv -->
		<info name="csv-table-id">data-table</info>
		<footer-ext>
			<para align="right">${currentPage} / ${pageCount}</para>
		</footer-ext>
	</metadata>
	<body>
		<para>colspan / rowspan sample</para>
		<table columns="3" colwidths="30;30;40"  width="100" id="data-table" padding="2">
			<row header="true">
				<cell rowspan="2" align="center"><para>Title</para></cell>
				<cell colspan="2" align="center"><para>Data</para></cell>
			</row>
			<row header="true">
			    <cell align="center"><para>Title</para></cell>
				<cell align="center"><para>Name</para></cell>
				<cell align="center"><para>Surname</para></cell>
			</row>
			<row>
				<cell><para>Queen</para></cell>
				<cell><para>Luthien</para></cell>
				<cell><para>Tinuviel</para></cell>
			</row>
			<row>
				<cell><para>King</para></cell>
				<cell><para>Thorin</para></cell>
				<cell><para>Oakshield</para></cell>
			</row>
			<row>
				<cell><para>Ring bearer</para></cell>
				<cell><para>Bilbo</para></cell>
				<cell><para>Bagging</para></cell>
			</row>
			<row>
				<cell><para>Eldest</para></cell>
				<cell><para>Tom</para></cell>
				<cell><para>Bombadil</para></cell>
			</row>
		</table>
	</body>

</doc>

When

Here is a fixed version

<?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>
		<!-- documenta meta information -->
		<info name="doc-title">colspan / rowspan sample</info>
		<info name="doc-subject">fj doc venus sample source FreeMarker Template XML</info>
		<info name="doc-author">fugerit79</info>
		<info name="doc-language">en</info>
		<!-- font must be loaded -->
		<info name="default-font-name">TitilliumWeb</info>
		<!-- property specific for xls/xlsx -->
		<info name="excel-table-id">data-table=print</info>
		<!-- property specific for csv -->
		<info name="csv-table-id">data-table</info>
		<footer-ext>
			<para align="right">${currentPage} / ${pageCount}</para>
		</footer-ext>
	</metadata>
	<body>
		<para>colspan / rowspan sample</para>
		<table columns="3" colwidths="30;30;40"  width="100" id="data-table" padding="2">
			<row header="true">
				<cell rowspan="2" align="center"><para>Title</para></cell>
				<cell colspan="2" align="center"><para>Data</para></cell>
			</row>
			<row header="true">
				<cell align="center"><para>Name</para></cell>
				<cell align="center"><para>Surname</para></cell>
			</row>
			<row>
				<cell><para>Queen</para></cell>
				<cell><para>Luthien</para></cell>
				<cell><para>Tinuviel</para></cell>
			</row>
			<row>
				<cell><para>King</para></cell>
				<cell><para>Thorin</para></cell>
				<cell><para>Oakshield</para></cell>
			</row>
			<row>
				<cell><para>Ring bearer</para></cell>
				<cell><para>Bilbo</para></cell>
				<cell><para>Bagging</para></cell>
			</row>
			<row>
				<cell><para>Eldest</para></cell>
				<cell><para>Tom</para></cell>
				<cell><para>Bombadil</para></cell>
			</row>
		</table>
	</body>

</doc>

Where we removed the extra column in the second header row :

			<row header="true">
			       *<cell align="center"><para>Title</para></cell>*
				<cell align="center"><para>Name</para></cell>
				<cell align="center"><para>Surname</para></cell>
			</row>

NOTE: even when not leading to exception, wrong columns / rows structure can lead to unexpected rendering.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions