diff --git a/fj-doc-freemarker/src/main/docs/fdp_xsd_config_ref.html b/fj-doc-freemarker/src/main/docs/fdp_xsd_config_ref.html index ed13b0d02..374a3eeb6 100644 --- a/fj-doc-freemarker/src/main/docs/fdp_xsd_config_ref.html +++ b/fj-doc-freemarker/src/main/docs/fdp_xsd_config_ref.html @@ -439,7 +439,7 @@

Reference xsd documentation for Venus - Fugerit sourceType - The source type : xml (default), json or yaml + The source type : xml (default), json or yaml. (since 8.9.6) sourceType , base : string , enumeration : [ xml , json , yaml ] @@ -479,7 +479,7 @@

Reference xsd documentation for Venus - Fugerit stepType - Can be a java type value implementing DocProcessorBasic or a fixed value for 'config', 'map', 'function', 'complex' + Can be a java type value implementing DocProcessorBasic or a fixed value for 'config', 'map', 'function', 'complex', 'skipfm' (skip FreeMarkerProcessing) string diff --git a/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/config/FreeMarkerComplexProcessStep.java b/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/config/FreeMarkerComplexProcessStep.java index e72833583..f2e24886c 100644 --- a/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/config/FreeMarkerComplexProcessStep.java +++ b/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/config/FreeMarkerComplexProcessStep.java @@ -22,21 +22,25 @@ public class FreeMarkerComplexProcessStep extends FreeMarkerProcessStep { public static final String ATT_MAP_ALL = "map-all"; public static final String ATT_MAP_ATTS = "map-atts"; - + + public static String overrideTemplatePath( Properties atts, String chainId ) throws ConfigException { + String templatePath = atts.getProperty( ATT_TEMPLATE_PATH ); + if ( StringUtils.isEmpty( templatePath ) ) { + throw new ConfigException( "Template must be provided" ); + } + ParamFinder finder = ParamFinder.newFinder(); + Properties params = new Properties(); + params.setProperty( CHAIN_ID_PARAM , chainId ); + templatePath = finder.substitute( templatePath , params ); + return templatePath; + } + @Override public int process(DocProcessContext context, DocProcessData data) throws Exception { Properties atts = this.getCustomConfig(); // override template path if ( StringUtils.isEmpty( this.getParam01() ) ) { - String templatePath = atts.getProperty( ATT_TEMPLATE_PATH ); - if ( StringUtils.isEmpty( templatePath ) ) { - throw new ConfigException( "Template must be provided" ); - } - ParamFinder finder = ParamFinder.newFinder(); - Properties params = new Properties(); - params.setProperty( CHAIN_ID_PARAM , this.getChainId() ); - templatePath = finder.substitute( templatePath , params ); - this.setParam01( templatePath ); + this.setParam01( overrideTemplatePath( atts, this.getChainId() ) ); } // map attributes Map map = FreeMarkerConstants.getFreeMarkerMap( context ); diff --git a/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/config/FreeMarkerSkipProcessStep.java b/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/config/FreeMarkerSkipProcessStep.java new file mode 100644 index 000000000..49c147044 --- /dev/null +++ b/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/config/FreeMarkerSkipProcessStep.java @@ -0,0 +1,44 @@ +package org.fugerit.java.doc.freemarker.config; + +import freemarker.cache.TemplateLoader; +import freemarker.template.Configuration; +import org.fugerit.java.core.io.StreamIO; +import org.fugerit.java.core.lang.helpers.StringUtils; +import org.fugerit.java.doc.base.process.DocProcessContext; +import org.fugerit.java.doc.base.process.DocProcessData; + +import java.io.Reader; +import java.nio.charset.StandardCharsets; +import java.util.Properties; + +public class FreeMarkerSkipProcessStep extends FreeMarkerProcessStep { + + /** + * + */ + private static final long serialVersionUID = -7009153804877056158L; + + public static final String ATT_TEMPLATE_PATH = "template-path"; + public static final String CHAIN_ID_PARAM = "chainId"; + + public static final String ATT_MAP_ALL = "map-all"; + public static final String ATT_MAP_ATTS = "map-atts"; + + @Override + public int process(DocProcessContext context, DocProcessData data) throws Exception { + Properties atts = this.getCustomConfig(); + // override template path + if ( StringUtils.isEmpty( this.getParam01() ) ) { + this.setParam01( FreeMarkerComplexProcessStep.overrideTemplatePath( atts, this.getChainId() ) ); + } + Configuration cfg = (Configuration) context.getAttribute( FreeMarkerConstants.ATT_FREEMARKER_CONFIG ); + TemplateLoader templateLoader = cfg.getTemplateLoader(); + String path = this.getParam01(); + Object templateSource = templateLoader.findTemplateSource( path ); + try (Reader reader = templateLoader.getReader( templateSource, StandardCharsets.UTF_8.name() ) ) { + data.setCurrentXmlData(StreamIO.readString(reader)); + } + return CONTINUE; + } + +} diff --git a/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/config/FreemarkerApplyHelper.java b/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/config/FreemarkerApplyHelper.java index 1101c496c..94fb9f89e 100644 --- a/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/config/FreemarkerApplyHelper.java +++ b/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/config/FreemarkerApplyHelper.java @@ -26,8 +26,8 @@ public static void setupFreemarkerMap( Configuration cfg, Map ma public static void addStaticAccess( Configuration cfg, Map map, String key, Class c ) throws TemplateModelException { BeansWrapper wrapper = new BeansWrapperBuilder( cfg.getIncompatibleImprovements() ).build(); TemplateHashModel staticModels = wrapper.getStaticModels(); - TemplateHashModel docConfigStatis = (TemplateHashModel) staticModels.get( c.getName() ); - map.put( key , docConfigStatis); + TemplateHashModel docConfigStatic = (TemplateHashModel) staticModels.get( c.getName() ); + map.put( key , docConfigStatic); } } diff --git a/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/FreemarkerDocProcessConfigFacade.java b/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/FreemarkerDocProcessConfigFacade.java index 30bb490bd..ea0a20c63 100644 --- a/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/FreemarkerDocProcessConfigFacade.java +++ b/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/FreemarkerDocProcessConfigFacade.java @@ -23,10 +23,7 @@ import org.fugerit.java.core.xml.dom.DOMUtils; import org.fugerit.java.doc.base.config.DocException; import org.fugerit.java.doc.base.config.DocTypeHandler; -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.fugerit.java.doc.freemarker.config.*; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -47,13 +44,30 @@ private FreemarkerDocProcessConfigFacade() {} public static final String ATT_CHAIN_STEP = "chainStep"; public static final String ATT_STEP_TYPE = "stepType"; - + + /** + * Corresponding to type : org.fugerit.java.doc.freemarker.config.FreeMarkerConfigStep + */ public static final String STEP_TYPE_CONFIG = "config"; - + + /** + * Corresponding to type : org.fugerit.java.doc.freemarker.config.FreeMarkerFunctionStep + */ public static final String STEP_TYPE_FUNCTION = "function"; - + + /** + * Corresponding to type : org.fugerit.java.doc.freemarker.config.FreeMarkerComplexProcessStep + */ public static final String STEP_TYPE_COMPLEX = "complex"; - + + /** + * Corresponding to type : org.fugerit.java.doc.freemarker.config.FreeMarkerSkipProcessStep + */ + public static final String STEP_TYPE_SKIPFM = "skipfm"; + + /** + * Corresponding to type : org.fugerit.java.doc.freemarker.config.FreeMarkerMapStep + */ public static final String STEP_TYPE_MAP = "map"; /** @@ -278,6 +292,7 @@ private static void generalPropertiesSetup( FreemarkerDocProcessConfig config , BUILT_IN_STEPS.setProperty( STEP_TYPE_CONFIG , FreeMarkerConfigStep.class.getName() ); BUILT_IN_STEPS.setProperty( STEP_TYPE_FUNCTION , FreeMarkerFunctionStep.class.getName() ); BUILT_IN_STEPS.setProperty( STEP_TYPE_COMPLEX , FreeMarkerComplexProcessStep.class.getName() ); + BUILT_IN_STEPS.setProperty( STEP_TYPE_SKIPFM , FreeMarkerSkipProcessStep.class.getName() ); BUILT_IN_STEPS.setProperty( STEP_TYPE_MAP , FreeMarkerMapStep.class.getName() ); BUILT_IN_STEPS.keySet().stream().forEach( k -> BUILT_IN_STEPS_REVERSE.put( BUILT_IN_STEPS.get( k ) , k ) ); } diff --git a/fj-doc-freemarker/src/main/resources/config_fm_xsd/freemarker-doc-process-1-0.xsd b/fj-doc-freemarker/src/main/resources/config_fm_xsd/freemarker-doc-process-1-0.xsd index f644192d1..4b7c72680 100644 --- a/fj-doc-freemarker/src/main/resources/config_fm_xsd/freemarker-doc-process-1-0.xsd +++ b/fj-doc-freemarker/src/main/resources/config_fm_xsd/freemarker-doc-process-1-0.xsd @@ -6,7 +6,7 @@ * * @project : fj-doc-freemarker * @creation : 2023-07-12 - * @version : 1.0.0-rc.4 (2024-10-20) + * @version : 1.0.0-rc.5 (2024-10-20) * * XSD for Freemarker Doc Process Configuration */ @@ -147,9 +147,9 @@ A chain parent (will inherits all the chainStep) - + - The source type : xml (default), json or yaml + The source type : xml (default), json or yaml. (since 8.9.6) @@ -168,7 +168,7 @@ - Can be a java type value implementing DocProcessorBasic or a fixed value for 'config', 'map', 'function', 'complex' + Can be a java type value implementing DocProcessorBasic or a fixed value for 'config', 'map', 'function', 'complex', 'skipfm' (skip FreeMarkerProcessing) diff --git a/fj-doc-freemarker/src/test/java/test/org/fugerit/java/doc/freemarker/process/TestFreemarkerDocProcessConfig.java b/fj-doc-freemarker/src/test/java/test/org/fugerit/java/doc/freemarker/process/TestFreemarkerDocProcessConfig.java index ec8790798..afd092977 100644 --- a/fj-doc-freemarker/src/test/java/test/org/fugerit/java/doc/freemarker/process/TestFreemarkerDocProcessConfig.java +++ b/fj-doc-freemarker/src/test/java/test/org/fugerit/java/doc/freemarker/process/TestFreemarkerDocProcessConfig.java @@ -3,6 +3,7 @@ import static org.junit.Assert.fail; import java.io.*; +import java.util.Properties; import org.fugerit.java.core.cfg.ConfigException; import org.fugerit.java.core.cfg.ConfigRuntimeException; @@ -17,6 +18,9 @@ import org.fugerit.java.doc.base.process.DocProcessContext; import org.fugerit.java.doc.base.process.DocProcessData; import org.fugerit.java.doc.freemarker.config.FreeMarkerConfigStep; +import org.fugerit.java.doc.freemarker.config.FreeMarkerConstants; +import org.fugerit.java.doc.freemarker.config.FreeMarkerSkipProcessStep; +import org.fugerit.java.doc.freemarker.config.FreemarkerApplyHelper; import org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlFragmentTypeHandlerEscapeUTF8; import org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandler; import org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandlerEscapeUTF8; @@ -76,12 +80,31 @@ public void testSource() throws Exception { config.fullProcess( currentChainId, DocProcessContext.newContext(), type, fos ); } } + // test template does not exist try ( ByteArrayOutputStream os = new ByteArrayOutputStream() ) { DocProcessContext context = DocProcessContext.newContext(); Assert.assertThrows( ConfigRuntimeException.class, () -> config.fullProcess( "not-exists", context, DocConfig.TYPE_HTML, os ) ); } } + @Test + public void testSkipFM() throws Exception { + DocProcessContext context = DocProcessContext.newContext(); + DocProcessData data = new DocProcessData(); + FreeMarkerConfigStep configStep = new FreeMarkerConfigStep(); + configStep.setParam01( "FJ_DOC_TEST_CUSTOM" ); + Properties customConfig = new Properties(); + customConfig.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_MODE, FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_MODE_CLASS ); + customConfig.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_PATH, "/fj_doc_test/template/" ); + configStep.setCustomConfig( customConfig ); + configStep.process( context, data ); + // test skip fm + FreeMarkerSkipProcessStep step = new FreeMarkerSkipProcessStep(); + step.setParam01( "asciidoc-xml.ftl" ); + step.process( context, data ); + Assert.assertNotNull( data.getCurrentXmlData() ); + } + @Test public void testConfigFail01() { Assert.assertThrows( ConfigRuntimeException.class , () -> FreemarkerDocProcessConfigFacade.loadConfigSafe( "cl://not-exists.xml" ) ); diff --git a/fj-doc-freemarker/src/test/resources/fj_doc_test/freemarker-doc-process.xml b/fj-doc-freemarker/src/test/resources/fj_doc_test/freemarker-doc-process.xml index 341ea2c0c..617e98833 100644 --- a/fj-doc-freemarker/src/test/resources/fj_doc_test/freemarker-doc-process.xml +++ b/fj-doc-freemarker/src/test/resources/fj_doc_test/freemarker-doc-process.xml @@ -35,15 +35,15 @@ - + - + - + diff --git a/fj-doc-freemarker/src/test/resources/fj_doc_test/template/asciidoc-json.ftl b/fj-doc-freemarker/src/test/resources/fj_doc_test/template/asciidoc-json.ftl index f04e8ddfc..affc9b6ed 100644 --- a/fj-doc-freemarker/src/test/resources/fj_doc_test/template/asciidoc-json.ftl +++ b/fj-doc-freemarker/src/test/resources/fj_doc_test/template/asciidoc-json.ftl @@ -58,7 +58,7 @@ }, { "align" : "center", "_t" : "para", - "_v" : "${r"${currentPage}"} / ${r"${pageCount}"}" + "_v" : "${currentPage} / ${pageCount}" }, { "align" : "right", "_t" : "para", diff --git a/fj-doc-freemarker/src/test/resources/fj_doc_test/template/asciidoc-xml.ftl b/fj-doc-freemarker/src/test/resources/fj_doc_test/template/asciidoc-xml.ftl index df7289379..5630c6080 100644 --- a/fj-doc-freemarker/src/test/resources/fj_doc_test/template/asciidoc-xml.ftl +++ b/fj-doc-freemarker/src/test/resources/fj_doc_test/template/asciidoc-xml.ftl @@ -23,7 +23,11 @@ test - ${r"${currentPage}"} / ${r"${pageCount}"} + + ${currentPage} / ${pageCount} test diff --git a/fj-doc-freemarker/src/test/resources/fj_doc_test/template/asciidoc-yaml.ftl b/fj-doc-freemarker/src/test/resources/fj_doc_test/template/asciidoc-yaml.ftl index 02b07f2c5..4ab4d7413 100644 --- a/fj-doc-freemarker/src/test/resources/fj_doc_test/template/asciidoc-yaml.ftl +++ b/fj-doc-freemarker/src/test/resources/fj_doc_test/template/asciidoc-yaml.ftl @@ -46,7 +46,9 @@ _e: _v: "test" - align: "center" _t: "para" - _v: "${r"${currentPage}"} / ${r"${pageCount}"}" + # if going throw freemarker processing should be : + # "${r"${currentPage}"} / ${r"${pageCount}"}" + _v: "${currentPage} / ${pageCount}" - align: "right" _t: "para" _v: "test" diff --git a/fj-doc-guide/src/main/docs/asciidoc/chapters/04_1_doc_freemarker_config.adoc b/fj-doc-guide/src/main/docs/asciidoc/chapters/04_1_doc_freemarker_config.adoc index 3346d7f3d..9ef225404 100644 --- a/fj-doc-guide/src/main/docs/asciidoc/chapters/04_1_doc_freemarker_config.adoc +++ b/fj-doc-guide/src/main/docs/asciidoc/chapters/04_1_doc_freemarker_config.adoc @@ -100,13 +100,35 @@ And one or more document process step : ==== Build in step types -[cols="3*", options="header"] +[cols="1,2,3", options="header"] |======================================================================================================================================== -| name | type | description -| config | org.fugerit.java.doc.freemarker.config.FreeMarkerConfigStep | responsable for freemarker and venus configuration -| function | org.fugerit.java.doc.freemarker.config.FreeMarkerFunctionStep | add freemarker functions to the data model -| complex | org.fugerit.java.doc.freemarker.config.FreeMarkerComplexProcessStep | it apply the freemarker template and render the output -| map | org.fugerit.java.doc.freemarker.config.FreeMarkerMapStep | Venus data model to Freemarker data model mapping + +| name +| type +| description + +| config +| org.fugerit.java.doc.freemarker.config.​FreeMarkerConfigStep +| responsable for freemarker and venus configuration + +| function +| org.fugerit.java.doc.freemarker.config.​FreeMarkerFunctionStep +| add freemarker functions to the data model + +| complex +| org.fugerit.java.doc.freemarker.config.​FreeMarkerComplexProcessStep +| it apply the freemarker template and render the output + +| map +| org.fugerit.java.doc.freemarker.config.​FreeMarkerMapStep +| Venus data model to Freemarker data model mapping + +| skipfm +| org.fugerit.java.doc.freemarker.config.​FreeMarkerSkipProcessStep +| When using this step, freemarker apply template will be skipped. (Since _8.9.7_) + |======================================================================================================================================== NOTE: Additional step can be added setting the fully qualified class name in the type attribute. + +NOTE: When using *skipfm* no FreeMarker template syntax should be used in the template. \ No newline at end of file