Skip to content

Commit

Permalink
[fj-doc-mod-fop] better init check for PdfFopTypeHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
fugerit79 committed Nov 26, 2024
1 parent 9b3ba9b commit f144407
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
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

### Changed

- [fj-doc-mod-fop] better init check for PdfFopTypeHandler
- quarkus-version set to 3.17.0 across al the modules
- [fj-doc-maven-plugin] micronaut flavour version set to 4.7.0
- [fj-doc-maven-plugin] spring-boot flavour version set to 3.3.6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.apache.fop.apps.FopFactoryBuilder;
import org.apache.xmlgraphics.io.ResourceResolver;
import org.fugerit.java.core.cfg.ConfigException;
import org.fugerit.java.core.cfg.ConfigRuntimeException;
import org.fugerit.java.core.function.SafeFunction;
import org.fugerit.java.core.io.StreamIO;
import org.fugerit.java.core.lang.helpers.ClassHelper;
Expand Down Expand Up @@ -68,6 +69,9 @@ public FopConfigClassLoaderWrapper(String fopConfigPath, ResourceResolver custom
this.fopConfigPath = fopConfigPath;
this.fopConfigData = SafeFunction.get( () -> {
try ( InputStream fopConfigStream = ClassHelper.loadFromDefaultClassLoader( this.getFopConfigPath() ) ) {
if ( fopConfigStream == null ) {
throw new ConfigRuntimeException( String.format( "Cannot find fop config path %s", this.getFopConfigPath() ) );
}
return StreamIO.readBytes( fopConfigStream );
}
} );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package test.org.fugerit.java.doc.mod.fop;

import org.fugerit.java.core.cfg.ConfigRuntimeException;
import org.fugerit.java.doc.freemarker.process.FreemarkerDocProcessConfigFacade;
import org.junit.Assert;
import org.junit.Test;

public class TestInitFreeMarkerConfig {

@Test
public void restError() {
try {
FreemarkerDocProcessConfigFacade.loadConfigSafe( "cl://fj-test-error-config.xml" );
} catch (ConfigRuntimeException e) {
Assert.assertTrue( e.getMessage().contains( "Cannot find fop config path" ) );
}

}

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

<!--
Configuration stub version : 006 (2024-10-31)
-->


<docHandlerConfig registerById="true" allowDuplicatedId="false">

<!-- Simple default PDF FOP Type handler with no added configuration -->
<docHandler id="pdf-fop" info="pdf" type="org.fugerit.java.doc.mod.fop.PdfFopTypeHandler"/>

<!-- PDF FOP Type handler, set charset to UTF-8, needs a fop configuration file in a specific class loader path -->
<docHandler id="pdf-fop" info="pdf" type="org.fugerit.java.doc.mod.fop.PdfFopTypeHandler">
<docHandlerCustomConfig charset="UTF-8" fop-config-mode="classloader" fop-config-classloader-path="fop-config-not-exists.xml"/>
</docHandler>

</docHandlerConfig>


<docChain id="shared">
<chainStep stepType="config">
<config
id="FJ_DOC_LIB_AUTODOC"
class="org.fugerit.java.doc.lib.autodoc.AutodocModule"
exception-handler="RETHROW_HANDLER"
fallback-on-null-loop-variable="false"
log-exception="false"
mode="class"
path="/fj_doc_lib_autodoc/template/"
version="2.3.29"
wrap-unchecked-exceptions="true"
/>
</chainStep>
</docChain>


</freemarker-doc-process-config>

0 comments on commit f144407

Please sign in to comment.