Skip to content

Commit 377ddb2

Browse files
authored
Merge pull request #561 from fugerit-org/560-chore-fj-doc-mod-fop-add-xslt-debug-option
chore: fj-doc-mod-fop, add xslt debug option #560
2 parents f51d5ff + fe30187 commit 377ddb2

File tree

11 files changed

+80
-47
lines changed

11 files changed

+80
-47
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- fj-doc-mod-fop, new mod-fop-xslt-debug property <https://github.com/fugerit-org/fj-doc/issues/560>
13+
1014
## [8.17.1] - 2025-10-28
1115

1216
### Added
1317

1418
- Image validator based on TwelveMonkeys ImageIO (currently supporting TIFF) <https://github.com/fugerit-org/fj-doc/issues/551>
15-
- fj-doc-mod-fop, new <> property <https://github.com/fugerit-org/fj-doc/issues/558>
19+
- fj-doc-mod-fop, new mod-fop-xslt-path property <https://github.com/fugerit-org/fj-doc/issues/558>
1620

1721
### Changed
1822

docs/html/doc_meta_info.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,24 @@ <h2 style="font-weight: bold;">Properties specific to Apache FOP PDF format</h2
803803
<td id="cell_0_4" style=" width: 5%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
804804
<p>8.17.1</p>
805805
</td>
806+
</tr>
807+
<tr>
808+
<td id="cell_1_0" style=" width: 20%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
809+
<span id="mod-fop-xslt-debug"></span>
810+
<p style="font-style: italic;">mod-fop-xslt-debug</p>
811+
</td>
812+
<td id="cell_1_1" style=" width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
813+
<p>If set to true, the result of the xslt transformation of the pdf fop handler will be printed in log for debugging purpose.</p>
814+
</td>
815+
<td id="cell_1_2" style=" width: 25%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
816+
<p>fj-doc-mod-fop(pdf), </p>
817+
</td>
818+
<td id="cell_1_3" style=" width: 10%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
819+
<p></p>
820+
</td>
821+
<td id="cell_1_4" style=" width: 5%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
822+
<p>8.17.2</p>
823+
</td>
806824
</tr>
807825
</tbody>
808826
</table>

fj-doc-guide/src/main/docs/asciidoc/chapters/00_2_release_notes.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Whereas the link:https://github.com/fugerit-org/fj-doc/blob/main/CHANGELOG.md[CH
66
[#doc-release-notes-unreleased]
77
==== Unreleased
88

9+
- fj-doc-mod-fop, new mod-fop-xslt-debug property link:https://github.com/fugerit-org/fj-doc/issues/560[#560]
10+
911
[#doc-release-notes-8-17-1]
1012
==== Version 8.17.1 [2025-10-28]
1113

fj-doc-guide/src/main/docs/asciidoc/chapters/06_2_mod-fop.adoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ Then fop user agent will use given XSLT in the transformation.
138138
<info name="mod-fop-xslt-path">xslt-sample/xslt-sample.xsl</info>
139139
----
140140

141+
[#doc-handler-mod-fop-xslt-debug]
142+
===== Property 'mod-fop-xslt-debug'
143+
144+
If property *mod-fop-xslt-debug* is set to true, the result of the xslt transformation of the pdf fop handler will be printed in log for debugging purpose.
145+
146+
[source,xml]
147+
----
148+
<info name="mod-fop-xslt-path">xslt-sample/xslt-sample.xsl</info>
149+
----
150+
141151
[#doc-handler-mod-fop-fo]
142152
==== FO DocHandler
143153

fj-doc-lib-autodoc/src/test/resources/docs/meta_xml/adm_standard_meta_info.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,13 @@ the 'value' is the name of the sheet to be created. i.e. 'table-1=sheet1;table-2
401401
<admeta:supportedType>pdf</admeta:supportedType>
402402
<admeta:supportedHandler>fj-doc-mod-fop(pdf)</admeta:supportedHandler>
403403
</admeta:admMetaInfo>
404+
<admeta:admMetaInfo>
405+
<admeta:name>mod-fop-xslt-debug</admeta:name>
406+
<admeta:description>If set to true, the result of the xslt transformation of the pdf fop handler will be printed in log for debugging purpose.</admeta:description>
407+
<admeta:since>8.17.2</admeta:since>
408+
<admeta:supportedType>pdf</admeta:supportedType>
409+
<admeta:supportedHandler>fj-doc-mod-fop(pdf)</admeta:supportedHandler>
410+
</admeta:admMetaInfo>
404411
</admeta:admSection>
405412

406413
</admeta:autodocMeta>

fj-doc-mod-fop/src/main/java/org/fugerit/java/doc/mod/fop/PdfFopTypeHandler.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
import java.util.*;
66
import java.util.stream.Collectors;
77

8-
import javax.xml.transform.Result;
9-
import javax.xml.transform.Transformer;
10-
import javax.xml.transform.TransformerConfigurationException;
11-
import javax.xml.transform.TransformerFactory;
8+
import javax.xml.transform.*;
129
import javax.xml.transform.sax.SAXResult;
10+
import javax.xml.transform.stream.StreamResult;
1311
import javax.xml.transform.stream.StreamSource;
1412

1513
import org.apache.fop.apps.FOUserAgent;
@@ -24,12 +22,14 @@
2422
import org.fugerit.java.core.lang.helpers.ClassHelper;
2523
import org.fugerit.java.core.lang.helpers.StringUtils;
2624
import org.fugerit.java.core.util.mvn.MavenProps;
25+
import org.fugerit.java.core.xml.TransformerXML;
2726
import org.fugerit.java.core.xml.dom.DOMIO;
2827
import org.fugerit.java.core.xml.dom.DOMUtils;
2928
import org.fugerit.java.doc.base.config.*;
3029
import org.fugerit.java.doc.base.model.DocBase;
3130
import org.fugerit.java.doc.mod.fop.config.FopConfigClassLoaderWrapper;
3231
import org.fugerit.java.doc.mod.fop.utils.ConfigUtils;
32+
import org.fugerit.java.doc.mod.fop.utils.FopHelperConstants;
3333
import org.fugerit.java.doc.mod.fop.utils.PoolUtils;
3434
import org.w3c.dom.Element;
3535
import org.w3c.dom.NodeList;
@@ -214,16 +214,31 @@ private Transformer newTransformer( TransformerFactory factory, DocBase docBase
214214
}
215215
}
216216

217+
// check if debug is activated
218+
private void xsltDebugCheck( DocBase docBase, byte[] xslContent, Transformer transformer ) throws IOException, TransformerException {
219+
boolean xsltDebug = BooleanUtils.isTrue( docBase.getStableInfo().getProperty( FopHelperConstants.INFO_KEY_MOD_FOP_XSLT_DEBUG ) );
220+
if ( xsltDebug ) {
221+
try ( ByteArrayInputStream input = new ByteArrayInputStream( xslContent );
222+
StringWriter buffer = new StringWriter() ) {
223+
transformer.transform(new StreamSource( input ), new StreamResult( buffer ));
224+
log.info( "{} activated, xslt content : \n{}", FopHelperConstants.INFO_KEY_MOD_FOP_XSLT_DEBUG, buffer.toString() );
225+
}
226+
}
227+
}
228+
217229
@SuppressWarnings("unchecked")
218230
@Override
219231
public void handle(DocInput docInput, DocOutput docOutput) throws Exception {
220-
try ( ByteArrayInputStream input = new ByteArrayInputStream(this.getXlsFoContent(docInput) ) ) {
232+
DocBase docBase = docInput.getDoc();
233+
byte[] xslContent = this.getXlsFoContent(docInput);
234+
try ( ByteArrayInputStream input = new ByteArrayInputStream( xslContent ) ) {
221235
// the XML file which provides the input
222236
StreamSource xmlSource = new StreamSource( new InputStreamReader( input, this.getCharset() ) );
223237
FopConfigWrap fopWrap = this.fopWrapSupplier.get();
224238
Fop fop = fopWrap.getFopFactory().newFop(MimeConstants.MIME_PDF, fopWrap.getFoUserAgent(), docOutput.getOs());
225-
TransformerFactory factory = TransformerFactory.newInstance();
226-
Transformer transformer = this.newTransformer( factory, docInput.getDoc() );
239+
TransformerFactory factory = TransformerXML.newSafeTransformerFactory();
240+
Transformer transformer = this.newTransformer( factory, docBase );
241+
this.xsltDebugCheck( docBase, xslContent, transformer );
227242
Result res = new SAXResult(fop.getDefaultHandler());
228243
transformer.transform(xmlSource, res);
229244
this.fopWrapConsumer.accept( fopWrap );

fj-doc-mod-fop/src/main/java/org/fugerit/java/doc/mod/fop/FopHelperConstants.java renamed to fj-doc-mod-fop/src/main/java/org/fugerit/java/doc/mod/fop/utils/FopHelperConstants.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.fugerit.java.doc.mod.fop;
1+
package org.fugerit.java.doc.mod.fop.utils;
22

33
public class FopHelperConstants {
44

@@ -9,4 +9,9 @@ private FopHelperConstants() {}
99
*/
1010
public static final String INFO_KEY_MOD_FOP_XSLT_PATH = "mod-fop-xslt-path";
1111

12+
/**
13+
* <a href="https://venusdocs.fugerit.org/docs/html/doc_meta_info.html#mod-fop-xslt-debug">See 'mod-fop-xslt-debug' documentation</a>
14+
*/
15+
public static final String INFO_KEY_MOD_FOP_XSLT_DEBUG = "mod-fop-xslt-debug";
16+
1217
}

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

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -79,36 +79,6 @@
7979
"name" : "wait",
8080
"parameterTypes" : [ "long", "int" ]
8181
} ]
82-
}, {
83-
"name" : "org.fugerit.java.doc.mod.fop.FopHelperConstants",
84-
"methods" : [ {
85-
"name" : "equals",
86-
"parameterTypes" : [ "java.lang.Object" ]
87-
}, {
88-
"name" : "getClass",
89-
"parameterTypes" : [ ]
90-
}, {
91-
"name" : "hashCode",
92-
"parameterTypes" : [ ]
93-
}, {
94-
"name" : "notify",
95-
"parameterTypes" : [ ]
96-
}, {
97-
"name" : "notifyAll",
98-
"parameterTypes" : [ ]
99-
}, {
100-
"name" : "toString",
101-
"parameterTypes" : [ ]
102-
}, {
103-
"name" : "wait",
104-
"parameterTypes" : [ ]
105-
}, {
106-
"name" : "wait",
107-
"parameterTypes" : [ "long" ]
108-
}, {
109-
"name" : "wait",
110-
"parameterTypes" : [ "long", "int" ]
111-
} ]
11282
}, {
11383
"name" : "org.fugerit.java.doc.mod.fop.FreeMarkerFopTypeHandler",
11484
"methods" : [ {

fj-doc-mod-fop/src/test/java/test/org/fugerit/java/doc/mod/fop/TestXslt.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@ private boolean testHelper( DocTypeHandler handler, String xmlName ) {
4242

4343
@Test
4444
void testXslt01Ok() {
45-
for ( int k=0; k<HANDLERS.length; k++ ) {
46-
boolean ok = this.testHelper(HANDLERS[k], "xslt-sample-01");
47-
Assertions.assertTrue(ok);
48-
}
45+
for (DocTypeHandler handler : HANDLERS) {
46+
boolean ok = this.testHelper(handler, "xslt-sample-01");
47+
Assertions.assertTrue(ok);
48+
}
4949
}
5050

5151
@Test
5252
void testXslt02Ok() {
53-
for ( int k=0; k<HANDLERS.length; k++ ) {
54-
boolean ok = this.testHelper(HANDLERS[k], "xslt-sample-02");
55-
Assertions.assertTrue(ok);
56-
}
53+
for (DocTypeHandler handler : HANDLERS) {
54+
boolean ok = this.testHelper(handler, "xslt-sample-02");
55+
Assertions.assertTrue(ok);
56+
}
5757
}
5858

5959
}

fj-doc-mod-fop/src/test/resources/xslt-sample/xslt-sample-01.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<!-- property specific for csv -->
2727
<info name="csv-table-id">data-table</info>
2828
<info name="mod-fop-xslt-path">xslt-sample/xslt-sample.xsl</info>
29+
<info name="mod-fop-xslt-debug">true</info>
2930
<footer-ext>
3031
<para align="right">${currentPage} / ${pageCount}</para>
3132
</footer-ext>

0 commit comments

Comments
 (0)