Skip to content

Commit b364df1

Browse files
authored
Merge pull request #550 from fugerit-org/545-enhancement-document-chain-processing
feat: extend doc context visibility to handler #545
2 parents 12798f7 + ca2de8d commit b364df1

File tree

5 files changed

+44
-6
lines changed

5 files changed

+44
-6
lines changed

fj-doc-base/src/main/java/org/fugerit/java/doc/base/config/DocInput.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.fugerit.java.doc.base.model.DocBase;
77

88
import lombok.Getter;
9+
import org.fugerit.java.doc.base.process.DocProcessContext;
910

1011
public class DocInput {
1112

@@ -15,6 +16,8 @@ public class DocInput {
1516

1617
@Getter private int source;
1718

19+
@Getter private DocProcessContext context;
20+
1821
private DocBase doc;
1922

2023
public DocBase getDoc() {
@@ -31,11 +34,16 @@ public DocInput(String type, DocBase doc, Reader reader) {
3134
}
3235

3336
public DocInput(String type, DocBase doc, Reader reader, int source) {
37+
this(type, doc, reader, source, null);
38+
}
39+
40+
public DocInput(String type, DocBase doc, Reader reader, int source, DocProcessContext context) {
3441
super();
3542
this.type = type;
3643
this.reader = reader;
3744
this.doc = doc;
3845
this.source = source;
46+
this.context = context;
3947
}
4048

4149
public static DocInput newInput( String type, DocBase doc ) {
@@ -58,5 +66,12 @@ public static DocInput newInput( String type, DocBase doc, Reader reader, int so
5866
return new DocInput( type, doc, reader, source );
5967
}
6068

61-
69+
public static DocInput newInput( String type, Reader reader, int source, DocProcessContext context ) {
70+
return newInput( type, null, reader, source, context );
71+
}
72+
73+
public static DocInput newInput( String type, DocBase doc, Reader reader, int source, DocProcessContext context ) {
74+
return new DocInput( type, doc, reader, source, context );
75+
}
76+
6277
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,12 +2412,18 @@
24122412
}, {
24132413
"name" : "<init>",
24142414
"parameterTypes" : [ "java.lang.String", "org.fugerit.java.doc.base.model.DocBase", "java.io.Reader", "int" ]
2415+
}, {
2416+
"name" : "<init>",
2417+
"parameterTypes" : [ "java.lang.String", "org.fugerit.java.doc.base.model.DocBase", "java.io.Reader", "int", "org.fugerit.java.doc.base.process.DocProcessContext" ]
24152418
}, {
24162419
"name" : "equals",
24172420
"parameterTypes" : [ "java.lang.Object" ]
24182421
}, {
24192422
"name" : "getClass",
24202423
"parameterTypes" : [ ]
2424+
}, {
2425+
"name" : "getContext",
2426+
"parameterTypes" : [ ]
24212427
}, {
24222428
"name" : "getDoc",
24232429
"parameterTypes" : [ ]
@@ -2439,6 +2445,9 @@
24392445
}, {
24402446
"name" : "newInput",
24412447
"parameterTypes" : [ "java.lang.String", "java.io.Reader", "int" ]
2448+
}, {
2449+
"name" : "newInput",
2450+
"parameterTypes" : [ "java.lang.String", "java.io.Reader", "int", "org.fugerit.java.doc.base.process.DocProcessContext" ]
24422451
}, {
24432452
"name" : "newInput",
24442453
"parameterTypes" : [ "java.lang.String", "org.fugerit.java.doc.base.model.DocBase" ]
@@ -2448,6 +2457,9 @@
24482457
}, {
24492458
"name" : "newInput",
24502459
"parameterTypes" : [ "java.lang.String", "org.fugerit.java.doc.base.model.DocBase", "java.io.Reader", "int" ]
2460+
}, {
2461+
"name" : "newInput",
2462+
"parameterTypes" : [ "java.lang.String", "org.fugerit.java.doc.base.model.DocBase", "java.io.Reader", "int", "org.fugerit.java.doc.base.process.DocProcessContext" ]
24512463
}, {
24522464
"name" : "notify",
24532465
"parameterTypes" : [ ]

fj-doc-base/src/test/java/test/org/fugerit/java/doc/base/config/TestDocInput.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.fugerit.java.doc.base.config.DocInput;
77
import org.fugerit.java.doc.base.facade.DocFacadeSource;
88
import org.fugerit.java.doc.base.model.DocBase;
9+
import org.fugerit.java.doc.base.process.DocProcessContext;
910
import org.junit.jupiter.api.Assertions;
1011
import org.junit.jupiter.api.Test;
1112

@@ -17,24 +18,34 @@ class TestDocInput {
1718
@Test
1819
void test1() {
1920
DocInput docInput = new DocInput( DocConfig.TYPE_PDF , new DocBase(), null );
20-
log.info( "docInput : {}" , docInput );
21+
log.info( "docInput 1 : {}" , docInput );
2122
Assertions.assertNotNull( docInput.getDoc() );
2223
}
2324

2425
@Test
2526
void test2() {
2627
try ( StringReader reader = new StringReader( "<doc/>" ) ) {
2728
DocInput docInput = DocInput.newInput( DocConfig.TYPE_PDF , reader, DocFacadeSource.SOURCE_TYPE_XML );
28-
log.info( "docInput : {}" , docInput );
29+
log.info( "docInput 2 : {}" , docInput );
2930
Assertions.assertNotNull( docInput.getDoc() );
3031
}
3132
}
3233

3334
@Test
3435
void test3() {
3536
DocInput docInput = new DocInput( DocConfig.TYPE_PDF , null, null );
36-
log.info( "docInput : {}" , docInput );
37+
log.info( "docInput 3 : {}" , docInput );
3738
Assertions.assertNull( docInput.getDoc() );
3839
}
40+
41+
@Test
42+
void test4() {
43+
DocInput docInput = DocInput.newInput(
44+
DocConfig.TYPE_PDF , null,
45+
DocFacadeSource.SOURCE_TYPE_XML,
46+
DocProcessContext.newContext() );
47+
log.info( "docInput 4 : {}" , docInput );
48+
Assertions.assertNull( docInput.getDoc() );
49+
}
3950

4051
}

fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/FreemarkerDocProcessConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public DocProcessData fullProcess( String chainId, DocProcessContext context, Do
113113
log.debug( "overrideSourceType {}, for chainId : {}", overrideSourceType, chainId );
114114
context.withSourceType( overrideSourceType );
115115
}
116-
DocInput docInput = this.docInputProcess.process( DocInput.newInput( handler.getType() , data.getCurrentXmlReader(), context.getSourceType() ) );
116+
DocInput docInput = this.docInputProcess.process( DocInput.newInput( handler.getType() , data.getCurrentXmlReader(), context.getSourceType(), context ) );
117117
handler.handle( docInput , docOutput );
118118
return data;
119119
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77

88
public interface FopConfig extends Serializable {
99

10-
public FopFactory newFactory() throws ConfigException;
10+
FopFactory newFactory() throws ConfigException;
1111

1212
}

0 commit comments

Comments
 (0)