Skip to content

Commit 8cc8419

Browse files
committed
docs(faq): extending handler capabilities example
1 parent 931b80e commit 8cc8419

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
[#doc-faq-extending-handler-capabilities]
3+
=== Extending handler capabilities
4+
5+
Sometimes you may want to extend current capabilities of a handler.
6+
7+
For instances, we have seen how xref:#doc-faq-reducing-fj-doc-mod-fop-pdf-size[Reduce fj-doc-mod-fop PDF size]. But to switch accessibility on and off we need a new build.
8+
9+
Let's imagine we want to change that at runtime, maybe with a system property.
10+
11+
We can simply to that by extending our base type handler :
12+
13+
[source,java]
14+
----
15+
package org.fugerit.java.doc.custom.fop;
16+
17+
import lombok.extern.slf4j.Slf4j;
18+
import org.fugerit.java.core.lang.helpers.BooleanUtils;
19+
20+
@Slf4j
21+
public class CustomPdfFopTypeHandler extends PdfFopTypeHandler {
22+
23+
public static final String ENABLE_ACCESSIBILITY = "CustomPdfFopTypeHandler.accessibility";
24+
25+
private static boolean checkAccessibility() {
26+
String enableAccessibility = System.getProperty( ENABLE_ACCESSIBILITY );
27+
log.info( "check accessibility {} : {}", ENABLE_ACCESSIBILITY, enableAccessibility );
28+
return BooleanUtils.isTrue( enableAccessibility );
29+
}
30+
31+
public CustomPdfFopTypeHandler() {
32+
super( checkAccessibility(), Boolean.FALSE );
33+
}
34+
35+
}
36+
----
37+
38+
And configuring it
39+
40+
[source,xml]
41+
----
42+
<docHandler id="pdf-fop-config" info="pdf" type="org.fugerit.java.doc.custom.fop.CustomPdfFopTypeHandler"/>
43+
----
44+
45+
Now, by the default accessibility is off, but we can turn on just adding the system property :
46+
47+
[source,txt]
48+
----
49+
-DCustomPdfFopTypeHandler.accessibility=true
50+
----
51+
52+
To our environment.
53+

fj-doc-guide/src/main/docs/asciidoc/index.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ include::chapters/07_005_doc-faq-kotlin-step.adoc[]
5151
include::chapters/07_006_doc-faq-endline-fop.adoc[]
5252
include::chapters/07_007_java-runtime-version-dependency-handling.adoc[]
5353
include::chapters/07_008-reducing-fj-doc-mod-fop-pdf-size.adoc[]
54+
include::chapters/07_009-extending-handler-capabilities.adoc[]
5455

5556
include::chapters/08_doc-optmization.adoc[]
5657
include::chapters/08_1_eager-startup.adoc[]

0 commit comments

Comments
 (0)