Skip to content

Commit cd068d7

Browse files
committed
1.3.0-rc.006 (2023-07-12)
+ [New freemarker configuration model, compatibility mode](https://github.com/fugerit-org/fj-bom/issues/38) [TODO : xsd]
1 parent 1a4b3a0 commit cd068d7

File tree

33 files changed

+216
-269
lines changed

33 files changed

+216
-269
lines changed

docgen/parameters.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"title" : "Venus (Fugerit Document Generation Framework)",
33
"name": "Venus",
4-
"version" : "1.3.0-rc.004",
5-
"date" : "11/07/2023",
4+
"version" : "1.3.0-rc.006",
5+
"date" : "12/07/2023",
66
"organization" : {
77
"name" : "Fugerit Org",
88
"url" : "https://www.fugerit.org"

docgen/release-notes.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
1.3.0-rc.004 (2023-07-11)
1+
1.3.0-rc.006 (2023-07-12)
2+
------------------
3+
+ [New freemarker configuration model, compatibility mode](https://github.com/fugerit-org/fj-bom/issues/38) [TODO : xsd]
4+
5+
1.3.0-rc.004 (2023-07-11)
26
------------------
37
+ fj-bom updated to 1.2.3
48

fj-doc-base-json/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-doc</artifactId>
10-
<version>1.3.0-rc.004</version>
10+
<version>1.3.0-rc.006</version>
1111
</parent>
1212

1313
<name>fj-doc-base-json</name>

fj-doc-base-yaml/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-doc</artifactId>
10-
<version>1.3.0-rc.004</version>
10+
<version>1.3.0-rc.006</version>
1111
</parent>
1212

1313
<name>fj-doc-base-yaml</name>

fj-doc-base/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-doc</artifactId>
10-
<version>1.3.0-rc.004</version>
10+
<version>1.3.0-rc.006</version>
1111
</parent>
1212

1313
<name>fj-doc-base</name>

fj-doc-bom-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-doc</artifactId>
10-
<version>1.3.0-rc.004</version>
10+
<version>1.3.0-rc.006</version>
1111
</parent>
1212

1313
<name>fj-doc-bom-core</name>

fj-doc-bom-fop/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-doc</artifactId>
10-
<version>1.3.0-rc.004</version>
10+
<version>1.3.0-rc.006</version>
1111
</parent>
1212

1313
<name>fj-doc-bom-fop</name>

fj-doc-freemarker/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-doc</artifactId>
10-
<version>1.3.0-rc.004</version>
10+
<version>1.3.0-rc.006</version>
1111
</parent>
1212

1313
<name>fj-doc-freemarker</name>
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.fugerit.java.doc.freemarker.process;
22

33
import java.io.Serializable;
4+
import java.util.Properties;
45

56
import lombok.Data;
67

@@ -9,6 +10,8 @@ public class ChainStepModel implements Serializable {
910

1011
private static final long serialVersionUID = 622077549080786391L;
1112

12-
private String type;
13+
private String stepType;
14+
15+
private Properties attributes;
1316

1417
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected void process( DocChainModel model, DocProcessContext context, DocProce
8383
}
8484
map.putAll( this.getGeneralContext() );
8585
for ( ChainStepModel step : model.getChainStepList() ) {
86-
DocProcessorBasic docStep = (DocProcessorBasic) ClassHelper.newInstance( step.getType() );
86+
DocProcessorBasic docStep = (DocProcessorBasic) ClassHelper.newInstance( step.getStepType() );
8787
int res = docStep.apply(context, data);
8888
log.debug( "docStep {} -> {}", docStep, res );
8989
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.fugerit.java.doc.freemarker.process;
2+
3+
import org.fugerit.java.core.util.filterchain.MiniFilterChain;
4+
5+
public interface DefaultChainProvider {
6+
7+
public MiniFilterChain newDefaultChain( String id );
8+
9+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public class DocChainModel implements IdConfigType, KeyString, Serializable {
2929

3030
private String mapAtts = MAP_ATTS_DEFAULT;
3131

32+
private String parent;
33+
3234
private Properties mapAttsEnum;
3335

3436
private List<ChainStepModel> chainStepList = new ArrayList<>();
Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,66 @@
11
package org.fugerit.java.doc.freemarker.process;
22

33
import java.io.Serializable;
4+
import java.util.HashMap;
5+
import java.util.Map;
46

57
import org.fugerit.java.core.cfg.xml.ListMapConfig;
8+
import org.fugerit.java.core.util.filterchain.MiniFilterChain;
69
import org.fugerit.java.doc.base.process.DocProcessConfig;
710
import org.fugerit.java.doc.base.process.DocProcessContext;
811
import org.fugerit.java.doc.base.process.DocProcessData;
912

1013
import lombok.Getter;
14+
import lombok.extern.slf4j.Slf4j;
1115

16+
@Slf4j
1217
public class FreemarkerDocProcessConfig extends DocProcessConfig implements Serializable {
1318

1419
private static final long serialVersionUID = -6761081877582850120L;
1520

16-
@Getter
17-
private ListMapConfig<ConfigInitModel> configInitList;
18-
1921
@Getter
2022
private ListMapConfig<DocChainModel> docChainList;
2123

24+
private Map<String, MiniFilterChain> additionalChans;
25+
2226
protected FreemarkerDocProcessConfig() {
23-
this.configInitList = new ListMapConfig<>();
27+
super();
2428
this.docChainList = new ListMapConfig<>();
29+
this.additionalChans = new HashMap<>();
30+
}
31+
32+
private DefaultChainProvider defaultChain;
33+
34+
protected void setDefaultChain( DefaultChainProvider defaultChain ) {
35+
this.defaultChain = defaultChain;
36+
}
37+
38+
protected DefaultChainProvider getDefaultChain() {
39+
return this.defaultChain;
2540
}
2641

27-
public void process( String configId, String chainId, DocProcessContext context, DocProcessData data ) throws Exception {
28-
ConfigInitModel configInitModel = this.getConfigInitList().get( configId );
29-
DocChainModel docChainModel = this.getChainOrDefault(chainId);
30-
configInitModel.process(docChainModel, context, data);
42+
public void process( String chainId, DocProcessContext context, DocProcessData data ) throws Exception {
43+
MiniFilterChain chain = this.getChainCache( chainId );
44+
log.info( "chain list {}", this.getIdSet() );
45+
chain.apply( context , data );
3146
}
3247

33-
private DocChainModel getChainOrDefault( String id ) {
34-
DocChainModel model = this.getDocChainList().get( id );
35-
if ( model == null ) {
36-
model = new DocChainModel();
37-
model.setId( id );
48+
@Override
49+
public MiniFilterChain getChain(String id) throws Exception {
50+
MiniFilterChain chain = null;
51+
if ( this.getDataList( id ) != null ) {
52+
chain = this.getChain( id );
53+
} else if ( this.additionalChans.containsKey( id ) ) {
54+
chain = this.additionalChans.get( id );
55+
} else if ( this.getDefaultChain() != null ) {
56+
chain = this.getDefaultChain().newDefaultChain(id);
57+
this.addAdditionalChain(chain);
3858
}
39-
return model;
59+
return chain;
60+
}
61+
62+
protected void addAdditionalChain( MiniFilterChain chain ) {
63+
this.additionalChans.put(chain.getChainId(), chain);
4064
}
4165

4266
}
Lines changed: 89 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.fugerit.java.doc.freemarker.process;
22

33
import java.io.Reader;
4-
import java.util.Enumeration;
54
import java.util.Properties;
65

76
import javax.xml.parsers.DocumentBuilder;
@@ -10,8 +9,15 @@
109
import org.fugerit.java.core.cfg.ConfigException;
1110
import org.fugerit.java.core.cfg.xml.XmlBeanHelper;
1211
import org.fugerit.java.core.lang.helpers.ClassHelper;
12+
import org.fugerit.java.core.lang.helpers.StringUtils;
13+
import org.fugerit.java.core.util.filterchain.MiniFilterBase;
14+
import org.fugerit.java.core.util.filterchain.MiniFilterChain;
1315
import org.fugerit.java.core.xml.dom.DOMUtils;
16+
import org.fugerit.java.doc.base.config.DocException;
17+
import org.fugerit.java.doc.freemarker.config.FreeMarkerComplexProcessStep;
1418
import org.fugerit.java.doc.freemarker.config.FreeMarkerConfigStep;
19+
import org.fugerit.java.doc.freemarker.config.FreeMarkerFunctionStep;
20+
import org.fugerit.java.doc.freemarker.config.FreeMarkerMapStep;
1521
import org.w3c.dom.Document;
1622
import org.w3c.dom.Element;
1723
import org.w3c.dom.NodeList;
@@ -23,20 +29,40 @@
2329
@Slf4j
2430
public class FreemarkerDocProcessConfigFacade {
2531

32+
public static final String ATT_DOC_CHAIN = "docChain";
33+
34+
public static final String ATT_CHAIN_STEP = "chainStep";
35+
2636
public static FreemarkerDocProcessConfig newSimpleConfig( String id, String templatePath ) throws ConfigException {
2737
FreemarkerDocProcessConfig config = new FreemarkerDocProcessConfig();
28-
ConfigInitModel model = new ConfigInitModel();
29-
model.setId(id);
30-
model.setPath( templatePath );
31-
try {
32-
addConfiguration(model);
33-
} catch (Exception e) {
34-
throw new ConfigException( "Error configuring FreemarkerDocProcessConfig : "+e , e );
35-
}
36-
config.getConfigInitList().add(model);
38+
config.setDefaultChain(
39+
new DefaultChainProvider() {
40+
@Override
41+
public MiniFilterChain newDefaultChain(String id) {
42+
MiniFilterChain defaultChain = new MiniFilterChain( "DEFAULT_CHAIN_"+id+"_"+System.currentTimeMillis(), MiniFilterChain.CONTINUE );
43+
defaultChain.setChainId( defaultChain.getKey() );
44+
// config step
45+
FreeMarkerConfigStep configStep = new FreeMarkerConfigStep();
46+
Properties configParams = new Properties();
47+
configParams.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_PATH , templatePath );
48+
configStep.setParam01( id );
49+
configStep.setCustomConfig( convertConfiguration( configParams ) );
50+
defaultChain.getFilterChain().add( configStep );
51+
// default step
52+
FreeMarkerComplexProcessStep processStep = new FreeMarkerComplexProcessStep();
53+
Properties processAtts = new Properties();
54+
processAtts.setProperty( "template-path" , "${chainId}.ftl" );
55+
processAtts.setProperty( "map-atts" , "simpleTableModel" );
56+
processStep.setCustomConfig( processAtts );
57+
processStep.setChainId( id );
58+
defaultChain.getFilterChain().add( processStep );
59+
return defaultChain;
60+
}
61+
}
62+
);
3763
return config;
3864
}
39-
65+
4066
public static FreemarkerDocProcessConfig loadConfig( Reader xmlReader ) throws ConfigException {
4167
FreemarkerDocProcessConfig result = null;
4268
try {
@@ -45,29 +71,8 @@ public static FreemarkerDocProcessConfig loadConfig( Reader xmlReader ) throws C
4571
dbf.setNamespaceAware( true );
4672
DocumentBuilder db = dbf.newDocumentBuilder();
4773
Document doc = db.parse( new InputSource( xmlReader ) );
48-
NodeList configInitList = doc.getElementsByTagName( "configInit" );
49-
for ( int k=0; k<configInitList.getLength(); k++ ) {
50-
Element currentTag = (Element) configInitList.item( k );
51-
ConfigInitModel model = new ConfigInitModel();
52-
XmlBeanHelper.setFromElement( model, currentTag );
53-
config.getConfigInitList().add(model);
54-
addConfiguration(model);
55-
// functions map
56-
NodeList functionsMap = currentTag.getElementsByTagName( "functionsMap" );
57-
if ( functionsMap.getLength() > 0 ) {
58-
for ( int i=0; i<functionsMap.getLength(); i++ ) {
59-
Element currentFM = (Element)functionsMap.item(i);
60-
Properties currentFMProps = DOMUtils.attributesToProperties( currentFM );
61-
Enumeration<Object> efm = currentFMProps.keys();
62-
while ( efm.hasMoreElements() ) {
63-
String key = efm.nextElement().toString();
64-
String value = currentFMProps.getProperty( key );
65-
model.getGeneralContext().put( key , ClassHelper.newInstance(value) );
66-
}
67-
}
68-
}
69-
}
70-
NodeList docChainLisgt = doc.getElementsByTagName( "docChain" );
74+
// docChain reading
75+
NodeList docChainLisgt = doc.getElementsByTagName( ATT_DOC_CHAIN );
7176
for ( int k=0; k<docChainLisgt.getLength(); k++ ) {
7277
Element currentTag = (Element) docChainLisgt.item( k );
7378
DocChainModel model = new DocChainModel();
@@ -78,36 +83,72 @@ public static FreemarkerDocProcessConfig loadConfig( Reader xmlReader ) throws C
7883
model.setMapAttsEnum( DOMUtils.attributesToProperties( mapAttsEnumTag ) );
7984
log.debug( "chain att enum {} -> {}", model.getId(), model.getMapAttsEnum() );
8085
}
86+
if ( StringUtils.isNotEmpty( model.getParent() ) ) {
87+
DocChainModel parent = config.getDocChainList().get( model.getParent() );
88+
if ( parent == null ) {
89+
throw new DocException( "No parent found : "+model.getParent() );
90+
} else {
91+
model.getChainStepList().addAll( parent.getChainStepList() );
92+
}
93+
}
8194
// chain step
82-
NodeList chainStepList = currentTag.getElementsByTagName( "chainStep" );
95+
NodeList chainStepList = currentTag.getElementsByTagName( ATT_CHAIN_STEP );
8396
for ( int i=0; i<chainStepList.getLength(); i++ ) {
8497
Element currentChainStepTag = (Element) chainStepList.item(i);
8598
ChainStepModel chainStepModel = new ChainStepModel();
86-
XmlBeanHelper.setFromElement( chainStepModel, currentChainStepTag );
99+
Properties atts = DOMUtils.attributesToProperties( currentChainStepTag );
100+
chainStepModel.setStepType( atts.getProperty( "stepType" ) );
101+
atts.remove( "stepType" );
102+
chainStepModel.setAttributes(atts);
87103
model.getChainStepList().add(chainStepModel);
88104
}
89105
config.getDocChainList().add(model);
90106
}
91107
result = config;
92108
log.info( "loadConfig ok : {}", result );
109+
// populate mini filter chain model
110+
for ( DocChainModel docChainModel : config.getDocChainList() ) {
111+
MiniFilterChain chain = new MiniFilterChain( docChainModel.getId(), MiniFilterChain.CONTINUE );
112+
chain.setChainId( docChainModel.getId() );
113+
for ( ChainStepModel chainStepModel : docChainModel.getChainStepList() ) {
114+
String type = BUILT_IN_STEPS.getProperty( chainStepModel.getStepType(), chainStepModel.getStepType() );
115+
MiniFilterBase step = (MiniFilterBase) ClassHelper.newInstance( type );
116+
step.setCustomConfig( chainStepModel.getAttributes() );
117+
if ( FreeMarkerConfigStep.class.getName().equalsIgnoreCase( type ) ) {
118+
step.setParam01( chainStepModel.getAttributes().getProperty( "id" ) );
119+
Properties configProps = convertConfiguration( chainStepModel.getAttributes() ) ;
120+
step.setCustomConfig( configProps );
121+
}
122+
step.setChainId( chain.getChainId() );
123+
chain.getFilterChain().add( step );
124+
}
125+
config.addAdditionalChain(chain);
126+
}
93127
} catch (Exception e) {
94128
throw new ConfigException( "Error configuring FreemarkerDocProcessConfig : "+e , e );
95129
}
96130
return result;
97131
}
98132

99-
private static void addConfiguration( ConfigInitModel model ) throws Exception {
133+
private static final Properties BUILT_IN_STEPS = new Properties();
134+
static {
135+
BUILT_IN_STEPS.setProperty( "config" , FreeMarkerConfigStep.class.getName() );
136+
BUILT_IN_STEPS.setProperty( "function" , FreeMarkerFunctionStep.class.getName() );
137+
BUILT_IN_STEPS.setProperty( "complex" , FreeMarkerComplexProcessStep.class.getName() );
138+
BUILT_IN_STEPS.setProperty( "map" , FreeMarkerMapStep.class.getName() );
139+
}
140+
141+
private static Properties convertConfiguration( Properties props ) {
100142
Properties params = new Properties();
101-
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_VERSION , model.getVersion() );
102-
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_MODE , model.getMode() );
103-
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_PATH , model.getPath() );
104-
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_CLASS , model.getClassName() );
105-
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_EXCEPTION_HANDLER , model.getExceptionHandler() );
106-
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_LOG_EXCEPTION , model.getLogException() );
107-
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_WRAP_UNCHECKED_EXCEPTION , model.getWrapUncheckedExceptions() );
108-
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_FALLBACK_ON_NULL_LOOP_VARIABLE , model.getFallbackOnNullLoopVariable() );
109-
Configuration conf = FreemarkerConfigHelper.getConfig( model.getId(), params );
110-
model.setFreemarkerConfiguration( conf );
143+
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_VERSION , props.getProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_VERSION, ConfigInitModel.DEFAULT_VERSION ) );
144+
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_MODE , props.getProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_MODE, ConfigInitModel.DEFAULT_MODE) );
145+
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_PATH , props.getProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_PATH ) );
146+
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_CLASS , props.getProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_CLASS, ConfigInitModel.DEFAULT_CLASS_NAME) );
147+
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_EXCEPTION_HANDLER , props.getProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_EXCEPTION_HANDLER, ConfigInitModel.DEFAULT_EXCEPTION_HANDLER) );
148+
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_LOG_EXCEPTION , props.getProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_LOG_EXCEPTION, ConfigInitModel.DEFAULT_LOG_EXCEPTION) );
149+
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_WRAP_UNCHECKED_EXCEPTION , props.getProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_WRAP_UNCHECKED_EXCEPTION, ConfigInitModel.DEFAULT_WRAP_UNCHECKED_EXCEPTION) );
150+
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_FALLBACK_ON_NULL_LOOP_VARIABLE , props.getProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_FALLBACK_ON_NULL_LOOP_VARIABLE, ConfigInitModel.DEFAULT_FALL_BACK_ON_NULL_LOOP_VARIABLE) );
151+
return params;
111152
}
112153

113154
}
@@ -121,3 +162,4 @@ protected static Configuration getConfig( String key, Properties config ) throws
121162
}
122163

123164
}
165+

0 commit comments

Comments
 (0)