Skip to content

Commit

Permalink
1.3.0-rc.006 (2023-07-12)
Browse files Browse the repository at this point in the history
+ [New freemarker configuration model, compatibility
mode](https://github.com/fugerit-org/fj-bom/issues/38) [TODO : xsd]
  • Loading branch information
fugerit79 committed Jul 12, 2023
1 parent 1a4b3a0 commit cd068d7
Show file tree
Hide file tree
Showing 33 changed files with 216 additions and 269 deletions.
4 changes: 2 additions & 2 deletions docgen/parameters.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"title" : "Venus (Fugerit Document Generation Framework)",
"name": "Venus",
"version" : "1.3.0-rc.004",
"date" : "11/07/2023",
"version" : "1.3.0-rc.006",
"date" : "12/07/2023",
"organization" : {
"name" : "Fugerit Org",
"url" : "https://www.fugerit.org"
Expand Down
6 changes: 5 additions & 1 deletion docgen/release-notes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
1.3.0-rc.004 (2023-07-11)
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.3.0-rc.004 (2023-07-11)
------------------
+ fj-bom updated to 1.2.3

Expand Down
2 changes: 1 addition & 1 deletion fj-doc-base-json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc</artifactId>
<version>1.3.0-rc.004</version>
<version>1.3.0-rc.006</version>
</parent>

<name>fj-doc-base-json</name>
Expand Down
2 changes: 1 addition & 1 deletion fj-doc-base-yaml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc</artifactId>
<version>1.3.0-rc.004</version>
<version>1.3.0-rc.006</version>
</parent>

<name>fj-doc-base-yaml</name>
Expand Down
2 changes: 1 addition & 1 deletion fj-doc-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc</artifactId>
<version>1.3.0-rc.004</version>
<version>1.3.0-rc.006</version>
</parent>

<name>fj-doc-base</name>
Expand Down
2 changes: 1 addition & 1 deletion fj-doc-bom-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc</artifactId>
<version>1.3.0-rc.004</version>
<version>1.3.0-rc.006</version>
</parent>

<name>fj-doc-bom-core</name>
Expand Down
2 changes: 1 addition & 1 deletion fj-doc-bom-fop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc</artifactId>
<version>1.3.0-rc.004</version>
<version>1.3.0-rc.006</version>
</parent>

<name>fj-doc-bom-fop</name>
Expand Down
2 changes: 1 addition & 1 deletion fj-doc-freemarker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc</artifactId>
<version>1.3.0-rc.004</version>
<version>1.3.0-rc.006</version>
</parent>

<name>fj-doc-freemarker</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.fugerit.java.doc.freemarker.process;

import java.io.Serializable;
import java.util.Properties;

import lombok.Data;

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

private static final long serialVersionUID = 622077549080786391L;

private String type;
private String stepType;

private Properties attributes;

}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected void process( DocChainModel model, DocProcessContext context, DocProce
}
map.putAll( this.getGeneralContext() );
for ( ChainStepModel step : model.getChainStepList() ) {
DocProcessorBasic docStep = (DocProcessorBasic) ClassHelper.newInstance( step.getType() );
DocProcessorBasic docStep = (DocProcessorBasic) ClassHelper.newInstance( step.getStepType() );
int res = docStep.apply(context, data);
log.debug( "docStep {} -> {}", docStep, res );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.fugerit.java.doc.freemarker.process;

import org.fugerit.java.core.util.filterchain.MiniFilterChain;

public interface DefaultChainProvider {

public MiniFilterChain newDefaultChain( String id );

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class DocChainModel implements IdConfigType, KeyString, Serializable {

private String mapAtts = MAP_ATTS_DEFAULT;

private String parent;

private Properties mapAttsEnum;

private List<ChainStepModel> chainStepList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,66 @@
package org.fugerit.java.doc.freemarker.process;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import org.fugerit.java.core.cfg.xml.ListMapConfig;
import org.fugerit.java.core.util.filterchain.MiniFilterChain;
import org.fugerit.java.doc.base.process.DocProcessConfig;
import org.fugerit.java.doc.base.process.DocProcessContext;
import org.fugerit.java.doc.base.process.DocProcessData;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class FreemarkerDocProcessConfig extends DocProcessConfig implements Serializable {

private static final long serialVersionUID = -6761081877582850120L;

@Getter
private ListMapConfig<ConfigInitModel> configInitList;

@Getter
private ListMapConfig<DocChainModel> docChainList;

private Map<String, MiniFilterChain> additionalChans;

protected FreemarkerDocProcessConfig() {
this.configInitList = new ListMapConfig<>();
super();
this.docChainList = new ListMapConfig<>();
this.additionalChans = new HashMap<>();
}

private DefaultChainProvider defaultChain;

protected void setDefaultChain( DefaultChainProvider defaultChain ) {
this.defaultChain = defaultChain;
}

protected DefaultChainProvider getDefaultChain() {
return this.defaultChain;
}

public void process( String configId, String chainId, DocProcessContext context, DocProcessData data ) throws Exception {
ConfigInitModel configInitModel = this.getConfigInitList().get( configId );
DocChainModel docChainModel = this.getChainOrDefault(chainId);
configInitModel.process(docChainModel, context, data);
public void process( String chainId, DocProcessContext context, DocProcessData data ) throws Exception {
MiniFilterChain chain = this.getChainCache( chainId );
log.info( "chain list {}", this.getIdSet() );
chain.apply( context , data );
}

private DocChainModel getChainOrDefault( String id ) {
DocChainModel model = this.getDocChainList().get( id );
if ( model == null ) {
model = new DocChainModel();
model.setId( id );
@Override
public MiniFilterChain getChain(String id) throws Exception {
MiniFilterChain chain = null;
if ( this.getDataList( id ) != null ) {
chain = this.getChain( id );
} else if ( this.additionalChans.containsKey( id ) ) {
chain = this.additionalChans.get( id );
} else if ( this.getDefaultChain() != null ) {
chain = this.getDefaultChain().newDefaultChain(id);
this.addAdditionalChain(chain);
}
return model;
return chain;
}

protected void addAdditionalChain( MiniFilterChain chain ) {
this.additionalChans.put(chain.getChainId(), chain);
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.fugerit.java.doc.freemarker.process;

import java.io.Reader;
import java.util.Enumeration;
import java.util.Properties;

import javax.xml.parsers.DocumentBuilder;
Expand All @@ -10,8 +9,15 @@
import org.fugerit.java.core.cfg.ConfigException;
import org.fugerit.java.core.cfg.xml.XmlBeanHelper;
import org.fugerit.java.core.lang.helpers.ClassHelper;
import org.fugerit.java.core.lang.helpers.StringUtils;
import org.fugerit.java.core.util.filterchain.MiniFilterBase;
import org.fugerit.java.core.util.filterchain.MiniFilterChain;
import org.fugerit.java.core.xml.dom.DOMUtils;
import org.fugerit.java.doc.base.config.DocException;
import org.fugerit.java.doc.freemarker.config.FreeMarkerComplexProcessStep;
import org.fugerit.java.doc.freemarker.config.FreeMarkerConfigStep;
import org.fugerit.java.doc.freemarker.config.FreeMarkerFunctionStep;
import org.fugerit.java.doc.freemarker.config.FreeMarkerMapStep;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
Expand All @@ -23,20 +29,40 @@
@Slf4j
public class FreemarkerDocProcessConfigFacade {

public static final String ATT_DOC_CHAIN = "docChain";

public static final String ATT_CHAIN_STEP = "chainStep";

public static FreemarkerDocProcessConfig newSimpleConfig( String id, String templatePath ) throws ConfigException {
FreemarkerDocProcessConfig config = new FreemarkerDocProcessConfig();
ConfigInitModel model = new ConfigInitModel();
model.setId(id);
model.setPath( templatePath );
try {
addConfiguration(model);
} catch (Exception e) {
throw new ConfigException( "Error configuring FreemarkerDocProcessConfig : "+e , e );
}
config.getConfigInitList().add(model);
config.setDefaultChain(
new DefaultChainProvider() {
@Override
public MiniFilterChain newDefaultChain(String id) {
MiniFilterChain defaultChain = new MiniFilterChain( "DEFAULT_CHAIN_"+id+"_"+System.currentTimeMillis(), MiniFilterChain.CONTINUE );
defaultChain.setChainId( defaultChain.getKey() );
// config step
FreeMarkerConfigStep configStep = new FreeMarkerConfigStep();
Properties configParams = new Properties();
configParams.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_PATH , templatePath );
configStep.setParam01( id );
configStep.setCustomConfig( convertConfiguration( configParams ) );
defaultChain.getFilterChain().add( configStep );
// default step
FreeMarkerComplexProcessStep processStep = new FreeMarkerComplexProcessStep();
Properties processAtts = new Properties();
processAtts.setProperty( "template-path" , "${chainId}.ftl" );
processAtts.setProperty( "map-atts" , "simpleTableModel" );
processStep.setCustomConfig( processAtts );
processStep.setChainId( id );
defaultChain.getFilterChain().add( processStep );
return defaultChain;
}
}
);
return config;
}

public static FreemarkerDocProcessConfig loadConfig( Reader xmlReader ) throws ConfigException {
FreemarkerDocProcessConfig result = null;
try {
Expand All @@ -45,29 +71,8 @@ public static FreemarkerDocProcessConfig loadConfig( Reader xmlReader ) throws C
dbf.setNamespaceAware( true );
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse( new InputSource( xmlReader ) );
NodeList configInitList = doc.getElementsByTagName( "configInit" );
for ( int k=0; k<configInitList.getLength(); k++ ) {
Element currentTag = (Element) configInitList.item( k );
ConfigInitModel model = new ConfigInitModel();
XmlBeanHelper.setFromElement( model, currentTag );
config.getConfigInitList().add(model);
addConfiguration(model);
// functions map
NodeList functionsMap = currentTag.getElementsByTagName( "functionsMap" );
if ( functionsMap.getLength() > 0 ) {
for ( int i=0; i<functionsMap.getLength(); i++ ) {
Element currentFM = (Element)functionsMap.item(i);
Properties currentFMProps = DOMUtils.attributesToProperties( currentFM );
Enumeration<Object> efm = currentFMProps.keys();
while ( efm.hasMoreElements() ) {
String key = efm.nextElement().toString();
String value = currentFMProps.getProperty( key );
model.getGeneralContext().put( key , ClassHelper.newInstance(value) );
}
}
}
}
NodeList docChainLisgt = doc.getElementsByTagName( "docChain" );
// docChain reading
NodeList docChainLisgt = doc.getElementsByTagName( ATT_DOC_CHAIN );
for ( int k=0; k<docChainLisgt.getLength(); k++ ) {
Element currentTag = (Element) docChainLisgt.item( k );
DocChainModel model = new DocChainModel();
Expand All @@ -78,36 +83,72 @@ public static FreemarkerDocProcessConfig loadConfig( Reader xmlReader ) throws C
model.setMapAttsEnum( DOMUtils.attributesToProperties( mapAttsEnumTag ) );
log.debug( "chain att enum {} -> {}", model.getId(), model.getMapAttsEnum() );
}
if ( StringUtils.isNotEmpty( model.getParent() ) ) {
DocChainModel parent = config.getDocChainList().get( model.getParent() );
if ( parent == null ) {
throw new DocException( "No parent found : "+model.getParent() );
} else {
model.getChainStepList().addAll( parent.getChainStepList() );
}
}
// chain step
NodeList chainStepList = currentTag.getElementsByTagName( "chainStep" );
NodeList chainStepList = currentTag.getElementsByTagName( ATT_CHAIN_STEP );
for ( int i=0; i<chainStepList.getLength(); i++ ) {
Element currentChainStepTag = (Element) chainStepList.item(i);
ChainStepModel chainStepModel = new ChainStepModel();
XmlBeanHelper.setFromElement( chainStepModel, currentChainStepTag );
Properties atts = DOMUtils.attributesToProperties( currentChainStepTag );
chainStepModel.setStepType( atts.getProperty( "stepType" ) );
atts.remove( "stepType" );
chainStepModel.setAttributes(atts);
model.getChainStepList().add(chainStepModel);
}
config.getDocChainList().add(model);
}
result = config;
log.info( "loadConfig ok : {}", result );
// populate mini filter chain model
for ( DocChainModel docChainModel : config.getDocChainList() ) {
MiniFilterChain chain = new MiniFilterChain( docChainModel.getId(), MiniFilterChain.CONTINUE );
chain.setChainId( docChainModel.getId() );
for ( ChainStepModel chainStepModel : docChainModel.getChainStepList() ) {
String type = BUILT_IN_STEPS.getProperty( chainStepModel.getStepType(), chainStepModel.getStepType() );
MiniFilterBase step = (MiniFilterBase) ClassHelper.newInstance( type );
step.setCustomConfig( chainStepModel.getAttributes() );
if ( FreeMarkerConfigStep.class.getName().equalsIgnoreCase( type ) ) {
step.setParam01( chainStepModel.getAttributes().getProperty( "id" ) );
Properties configProps = convertConfiguration( chainStepModel.getAttributes() ) ;
step.setCustomConfig( configProps );
}
step.setChainId( chain.getChainId() );
chain.getFilterChain().add( step );
}
config.addAdditionalChain(chain);
}
} catch (Exception e) {
throw new ConfigException( "Error configuring FreemarkerDocProcessConfig : "+e , e );
}
return result;
}

private static void addConfiguration( ConfigInitModel model ) throws Exception {
private static final Properties BUILT_IN_STEPS = new Properties();
static {
BUILT_IN_STEPS.setProperty( "config" , FreeMarkerConfigStep.class.getName() );
BUILT_IN_STEPS.setProperty( "function" , FreeMarkerFunctionStep.class.getName() );
BUILT_IN_STEPS.setProperty( "complex" , FreeMarkerComplexProcessStep.class.getName() );
BUILT_IN_STEPS.setProperty( "map" , FreeMarkerMapStep.class.getName() );
}

private static Properties convertConfiguration( Properties props ) {
Properties params = new Properties();
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_VERSION , model.getVersion() );
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_MODE , model.getMode() );
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_PATH , model.getPath() );
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_CLASS , model.getClassName() );
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_EXCEPTION_HANDLER , model.getExceptionHandler() );
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_LOG_EXCEPTION , model.getLogException() );
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_WRAP_UNCHECKED_EXCEPTION , model.getWrapUncheckedExceptions() );
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_FALLBACK_ON_NULL_LOOP_VARIABLE , model.getFallbackOnNullLoopVariable() );
Configuration conf = FreemarkerConfigHelper.getConfig( model.getId(), params );
model.setFreemarkerConfiguration( conf );
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_VERSION , props.getProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_VERSION, ConfigInitModel.DEFAULT_VERSION ) );
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_MODE , props.getProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_MODE, ConfigInitModel.DEFAULT_MODE) );
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_PATH , props.getProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_PATH ) );
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_CLASS , props.getProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_CLASS, ConfigInitModel.DEFAULT_CLASS_NAME) );
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_EXCEPTION_HANDLER , props.getProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_EXCEPTION_HANDLER, ConfigInitModel.DEFAULT_EXCEPTION_HANDLER) );
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_LOG_EXCEPTION , props.getProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_LOG_EXCEPTION, ConfigInitModel.DEFAULT_LOG_EXCEPTION) );
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) );
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) );
return params;
}

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

}

Loading

0 comments on commit cd068d7

Please sign in to comment.