From 3904aaf4cc95ba5d011920fcc5a2f3b7ccc9ae70 Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Wed, 12 Jul 2023 18:38:13 +0200 Subject: [PATCH 1/6] Fix to release notes --- docgen/release-notes.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docgen/release-notes.txt b/docgen/release-notes.txt index 1c3e578e2..1f6874915 100644 --- a/docgen/release-notes.txt +++ b/docgen/release-notes.txt @@ -1,6 +1,6 @@ 1.3.0-rc.007 (2023-07-12) ------------------ -+ [New freemarker configuration model, compatibility mode](https://github.com/fugerit-org/fj-bom/issues/38) ++ [New freemarker configuration model, compatibility mode](https://github.com/fugerit-org/fj-doc/issues/38) 1.3.0-rc.004 (2023-07-11) ------------------ @@ -8,7 +8,7 @@ 1.3.0-rc.001 (2023-07-09) ------------------ -+ [New freemarker configuration model](https://github.com/fugerit-org/fj-bom/issues/38) ++ [New freemarker configuration model](https://github.com/fugerit-org/fj-doc/issues/38) 1.2.0-rc.001 (2023-07-07) ------------------ From be915d6f51997e48e2b46a230a947b0a7e217b05 Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Thu, 13 Jul 2023 02:55:15 +0200 Subject: [PATCH 2/6] Added handlers loading for new config #38 --- .../process/FreemarkerDocProcessConfig.java | 5 ++ .../FreemarkerDocProcessConfigFacade.java | 20 ++++++ .../java/doc/sample/facade/SampleFacade.java | 69 ------------------- .../resources/config/doc-handler-sample.xml | 32 --------- .../config/freemarker-doc-process.xml | 32 +++++++++ .../doc/sample/facade/BasicFacadeTest.java | 20 +++++- .../freemarker/BasicFreeMarkerTest.java | 16 ----- 7 files changed, 74 insertions(+), 120 deletions(-) delete mode 100644 fj-doc-sample/src/main/java/org/fugerit/java/doc/sample/facade/SampleFacade.java diff --git a/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/FreemarkerDocProcessConfig.java b/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/FreemarkerDocProcessConfig.java index 87ac177ae..645059348 100644 --- a/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/FreemarkerDocProcessConfig.java +++ b/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/FreemarkerDocProcessConfig.java @@ -6,6 +6,7 @@ import org.fugerit.java.core.cfg.xml.ListMapConfig; import org.fugerit.java.core.util.filterchain.MiniFilterChain; +import org.fugerit.java.doc.base.facade.DocHandlerFacade; import org.fugerit.java.doc.base.process.DocProcessConfig; import org.fugerit.java.doc.base.process.DocProcessContext; import org.fugerit.java.doc.base.process.DocProcessData; @@ -23,10 +24,14 @@ public class FreemarkerDocProcessConfig extends DocProcessConfig implements Seri private Map additionalChans; + @Getter + private DocHandlerFacade facade; + protected FreemarkerDocProcessConfig() { super(); this.docChainList = new ListMapConfig<>(); this.additionalChans = new HashMap<>(); + this.facade = new DocHandlerFacade(); } private DefaultChainProvider defaultChain; 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 cde992638..fd55adc52 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 @@ -7,6 +7,8 @@ import javax.xml.parsers.DocumentBuilderFactory; import org.fugerit.java.core.cfg.ConfigException; +import org.fugerit.java.core.cfg.xml.FactoryType; +import org.fugerit.java.core.cfg.xml.FactoryTypeHelper; import org.fugerit.java.core.cfg.xml.XmlBeanHelper; import org.fugerit.java.core.lang.helpers.ClassHelper; import org.fugerit.java.core.lang.helpers.StringUtils; @@ -14,6 +16,7 @@ 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.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; @@ -29,6 +32,8 @@ @Slf4j public class FreemarkerDocProcessConfigFacade { + public static final String ATT_DOC_HANDLER_CONFIG = "docHandlerConfig"; + public static final String ATT_DOC_CHAIN = "docChain"; public static final String ATT_CHAIN_STEP = "chainStep"; @@ -39,6 +44,8 @@ public class FreemarkerDocProcessConfigFacade { public static final String STEP_TYPE_MAP = "map"; + private static final FactoryTypeHelper HELPER = FactoryTypeHelper.newInstance( DocTypeHandler.class ); + public static FreemarkerDocProcessConfig newSimpleConfig( String id, String templatePath ) throws ConfigException { FreemarkerDocProcessConfig config = new FreemarkerDocProcessConfig(); config.setDefaultChain( @@ -77,6 +84,19 @@ public static FreemarkerDocProcessConfig loadConfig( Reader xmlReader ) throws C dbf.setNamespaceAware( true ); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse( new InputSource( xmlReader ) ); + // docHandlerConfig reading + NodeList docHandlerConfigList = doc.getElementsByTagName( ATT_DOC_HANDLER_CONFIG ); + if ( docHandlerConfigList.getLength() == 1 ) { + Element docHandlerConfigTag = (Element) docHandlerConfigList.item( 0 ); + NodeList docHandlerList = docHandlerConfigTag.getElementsByTagName( "data" ); + log.info( "docHandlerList -> {}", docHandlerList.getLength() ); + for ( int k=0; k - Fugerit Java Library org.fugerit.java.doc.ent - - Copyright (c) 2019 Fugerit - - All rights reserved. This program and the accompanying materials - are made available under the terms of the Apache License v2.0 - which accompanies this distribution, and is available at - http://www.apache.org/licenses/ - (txt version : http://www.apache.org/licenses/LICENSE-2.0.txt - html version : http://www.apache.org/licenses/LICENSE-2.0.html) - - This product includes software developed at - The Apache Software Foundation (http://www.apache.org/). - -*****************************************************************/ -/* - * @(#)SampleFacade.java - * - * @project : org.fugerit.java.doc.ent - * @package : org.fugerit.java.doc.sample.facade - * @creation : 13/set/06 - * @license : META-INF/LICENSE.TXT - */ -package org.fugerit.java.doc.sample.facade; - -import org.fugerit.java.doc.base.facade.DocHandlerFacade; -import org.fugerit.java.doc.base.facade.DocHandlerFactory; - -/** - * - * - * @author mfranci - * - */ -public class SampleFacade { - - private static DocHandlerFactory init( String path ) { - DocHandlerFactory factory = null; - try { - factory = DocHandlerFactory.newInstance( path ); - } catch (Exception e) { - throw new RuntimeException( e ); - } - return factory; - } - - private static DocHandlerFactory FACTORY = init( "cl://config/doc-handler-sample.xml" ); - - public static final String MAIN_FACTORY = "default-complete"; - - public static final String ALT_COMPLETE_FACTORY = "alternate-complete"; - - public static final String ALT_FOP_FACTORY = "alternate-fop"; - - public static final String ALT_HTML_FM = "alternate-html-fm"; - - public static final String ALT_FULL_FACADE = "full-facade"; - - public static DocHandlerFacade getFacade( String id ) { - return FACTORY.get( id ); - } - - public static DocHandlerFacade getInstance() { - return getFacade( MAIN_FACTORY ) ; - } - -} diff --git a/fj-doc-sample/src/main/resources/config/doc-handler-sample.xml b/fj-doc-sample/src/main/resources/config/doc-handler-sample.xml index 6be82e3a7..b2e1b730e 100644 --- a/fj-doc-sample/src/main/resources/config/doc-handler-sample.xml +++ b/fj-doc-sample/src/main/resources/config/doc-handler-sample.xml @@ -1,36 +1,4 @@ - - - - - - - - - - - - - - - diff --git a/fj-doc-sample/src/main/resources/config/freemarker-doc-process.xml b/fj-doc-sample/src/main/resources/config/freemarker-doc-process.xml index 4257d030b..70a7f5bc0 100644 --- a/fj-doc-sample/src/main/resources/config/freemarker-doc-process.xml +++ b/fj-doc-sample/src/main/resources/config/freemarker-doc-process.xml @@ -4,6 +4,38 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://freemarkerdocprocess.fugerit.org https://www.fugerit.org/data/java/doc/xsd/freemarker-doc-process-1-0.xsd" > + + + + + + + + + + + + + + + diff --git a/fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/facade/BasicFacadeTest.java b/fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/facade/BasicFacadeTest.java index d3b4934cc..33f084e59 100644 --- a/fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/facade/BasicFacadeTest.java +++ b/fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/facade/BasicFacadeTest.java @@ -3,11 +3,13 @@ import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; +import java.io.InputStreamReader; import java.io.Reader; import java.util.ArrayList; import java.util.List; import org.fugerit.java.core.cfg.ConfigException; +import org.fugerit.java.core.lang.helpers.ClassHelper; import org.fugerit.java.core.util.checkpoint.CheckpointFormatHelper; import org.fugerit.java.core.util.checkpoint.Checkpoints; import org.fugerit.java.doc.base.config.DocConfig; @@ -20,7 +22,8 @@ import org.fugerit.java.doc.base.model.DocBase; import org.fugerit.java.doc.base.parser.DocParser; import org.fugerit.java.doc.base.parser.DocValidationResult; -import org.fugerit.java.doc.sample.facade.SampleFacade; +import org.fugerit.java.doc.freemarker.process.FreemarkerDocProcessConfig; +import org.fugerit.java.doc.freemarker.process.FreemarkerDocProcessConfigFacade; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,7 +58,6 @@ protected BasicFacadeTest( String nameBase, String ...typeList ) { for ( String current : typeList ) { types.add( current ); } - this.setFacadeId( SampleFacade.MAIN_FACTORY ); this.validate = VALIDATE_DEFAULT; } @@ -75,6 +77,18 @@ public String getNameBase() { return this.nameBase; } + private static FreemarkerDocProcessConfig init() { + FreemarkerDocProcessConfig config = null; + try ( InputStreamReader xmlReader = new InputStreamReader( ClassHelper.loadFromDefaultClassLoader( "config/freemarker-doc-process.xml" ) ) ) { + config = FreemarkerDocProcessConfigFacade.loadConfig( xmlReader ); + } catch (Exception e) { + throw new RuntimeException( e ); + } + return config; + } + + protected static FreemarkerDocProcessConfig PROCESS_CONFIG = init(); + private int getSourceType() { int sourceType = DocFacadeSource.SOURCE_TYPE_DEFAULT; if ( this.getNameBase().endsWith( "json" ) ) { @@ -128,7 +142,7 @@ protected DocBase getDocBase() throws Exception { } public void produce( File outputFolder, String facadeId, DocBase doc, Reader reader, String baseName, String type ) throws Exception { - DocHandlerFacade facade = SampleFacade.getFacade( facadeId ); + DocHandlerFacade facade = PROCESS_CONFIG.getFacade(); DocTypeHandler handler = facade.findHandler( type ); StringBuilder append = new StringBuilder(); if ( handler == null ) { diff --git a/fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/freemarker/BasicFreeMarkerTest.java b/fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/freemarker/BasicFreeMarkerTest.java index 750e1dc79..838f028c3 100644 --- a/fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/freemarker/BasicFreeMarkerTest.java +++ b/fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/freemarker/BasicFreeMarkerTest.java @@ -1,14 +1,10 @@ package test.org.fugerit.java.doc.sample.freemarker; -import java.io.InputStreamReader; import java.io.Reader; -import org.fugerit.java.core.lang.helpers.ClassHelper; import org.fugerit.java.doc.base.config.DocConfig; import org.fugerit.java.doc.base.process.DocProcessContext; import org.fugerit.java.doc.base.process.DocProcessData; -import org.fugerit.java.doc.freemarker.process.FreemarkerDocProcessConfig; -import org.fugerit.java.doc.freemarker.process.FreemarkerDocProcessConfigFacade; import test.org.fugerit.java.doc.sample.facade.BasicFacadeTest; @@ -22,18 +18,6 @@ protected BasicFreeMarkerTest(String nameBase, String... typeList) { super(nameBase, typeList); } - private static FreemarkerDocProcessConfig init() { - FreemarkerDocProcessConfig config = null; - try ( InputStreamReader xmlReader = new InputStreamReader( ClassHelper.loadFromDefaultClassLoader( "config/freemarker-doc-process.xml" ) ) ) { - config = FreemarkerDocProcessConfigFacade.loadConfig( xmlReader ); - } catch (Exception e) { - throw new RuntimeException( e ); - } - return config; - } - - private static FreemarkerDocProcessConfig PROCESS_CONFIG = init(); - @Override protected Reader getXmlReader() throws Exception { return this.process( this.getNameBase() ); From bd370a5c3a54930461a519d5f315a82ee3335bb0 Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Thu, 13 Jul 2023 17:14:46 +0200 Subject: [PATCH 3/6] Removed unused classes --- .../freemarker/process/ConfigInitModel.java | 123 ------------------ 1 file changed, 123 deletions(-) delete mode 100644 fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/ConfigInitModel.java diff --git a/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/ConfigInitModel.java b/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/ConfigInitModel.java deleted file mode 100644 index 9b2d4dc9a..000000000 --- a/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/ConfigInitModel.java +++ /dev/null @@ -1,123 +0,0 @@ -package org.fugerit.java.doc.freemarker.process; - -import java.io.Serializable; -import java.io.StringWriter; -import java.io.Writer; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -import org.fugerit.java.core.cfg.xml.IdConfigType; -import org.fugerit.java.core.lang.helpers.BooleanUtils; -import org.fugerit.java.core.lang.helpers.ClassHelper; -import org.fugerit.java.core.util.collection.KeyString; -import org.fugerit.java.core.util.regex.ParamFinder; -import org.fugerit.java.doc.base.process.DocProcessContext; -import org.fugerit.java.doc.base.process.DocProcessData; -import org.fugerit.java.doc.base.process.DocProcessorBasic; -import org.fugerit.java.doc.freemarker.config.FreeMarkerConstants; -import org.fugerit.java.doc.freemarker.config.FreemarkerApplyHelper; - -import freemarker.template.Configuration; -import freemarker.template.Template; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -@Data -public class ConfigInitModel implements IdConfigType, KeyString, Serializable { - - public static final String VERSION_2_3_31 = "2.3.31"; - public static final String DEFAULT_VERSION = VERSION_2_3_31; - - public static final String DEFAULT_CLASS_NAME = FreemarkerDocProcessConfigFacade.class.getName(); - - public static final String DEFAULT_MODE = "class"; - - public static final String DEFAULT_EXCEPTION_HANDLER = "RETHROW_HANDLER"; - - public static final String DEFAULT_LOG_EXCEPTION = BooleanUtils.BOOLEAN_FALSE; - - public static final String DEFAULT_WRAP_UNCHECKED_EXCEPTION = BooleanUtils.BOOLEAN_TRUE; - - public static final String DEFAULT_FALL_BACK_ON_NULL_LOOP_VARIABLE = BooleanUtils.BOOLEAN_FALSE; - - private static final long serialVersionUID = -59587465058736934L; - - private String id; - - private String version = DEFAULT_VERSION; - - private String path; - - private String mode = DEFAULT_MODE; - - private String className = DEFAULT_CLASS_NAME; - - private String exceptionHandler = DEFAULT_EXCEPTION_HANDLER; - - private String logException = DEFAULT_LOG_EXCEPTION; - - private String wrapUncheckedExceptions = DEFAULT_WRAP_UNCHECKED_EXCEPTION; - - private String fallbackOnNullLoopVariable = DEFAULT_FALL_BACK_ON_NULL_LOOP_VARIABLE; - - private Configuration freemarkerConfiguration; - - private Map generalContext = new HashMap<>(); - - public static final String CHAIN_ID_PARAM = "chainId"; - - protected void process( DocChainModel model, DocProcessContext context, DocProcessData data ) throws Exception { - // override template path - String templatePath = model.getTemplatePath(); - ParamFinder finder = ParamFinder.newFinder(); - Properties params = new Properties(); - params.setProperty( CHAIN_ID_PARAM , model.getId() ); - templatePath = finder.substitute( templatePath , params ); - // map attributes - Map map = FreeMarkerConstants.getFreeMarkerMap( context ); - if ( map == null ) { - map = new HashMap<>(); - } - map.putAll( this.getGeneralContext() ); - for ( ChainStepModel step : model.getChainStepList() ) { - DocProcessorBasic docStep = (DocProcessorBasic) ClassHelper.newInstance( step.getStepType() ); - int res = docStep.apply(context, data); - log.debug( "docStep {} -> {}", docStep, res ); - } - log.debug( "mapsAtt mode -> {} -> {}", model.getId(), model.getMapAtts() ); - if ( DocChainModel.MAP_ATTS_ENUM.equalsIgnoreCase( model.getMapAtts() ) ) { - Enumeration ea = model.getMapAttsEnum().keys(); - while ( ea.hasMoreElements() ) { - String key = ea.nextElement().toString(); - String value = model.getMapAttsEnum().getProperty( key ); - map.put( value , context.getAttribute( key ) ); - log.info( "map att enum -> {} -> {}", key, value ); - } - } else { - map.putAll( context.toMap() ); - } - Template template = this.getFreemarkerConfiguration().getTemplate( templatePath ); - FreemarkerApplyHelper.setupFreemarkerMap( this.freemarkerConfiguration, map); - Writer out = new StringWriter(); - template.process( map, out); - data.setCurrentXmlData( out.toString() ); - } - - @Override - public String getKey() { - return this.getId(); - } - - @Override - public String toString() { - return "ConfigInitModel [id=" + id + ", version=" + version + ", path=" + path + ", mode=" + mode - + ", className=" + className + ", exceptionHandler=" + exceptionHandler + ", logException=" - + logException + ", wrapUncheckedExceptions=" + wrapUncheckedExceptions - + ", fallbackOnNullLoopVariable=" + fallbackOnNullLoopVariable + ", freemarkerConfiguration=" - + freemarkerConfiguration + "]"; - } - -} From d44045b7738681842ac3e3f828b0e41fc5bba868 Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Thu, 13 Jul 2023 17:16:40 +0200 Subject: [PATCH 4/6] Added pdf a support #43 --- .../src/main/docs/fdp_xsd_config_ref.html | 220 ++++++++++++++++-- .../java/doc/base/config/DocConfig.java | 2 + .../java/doc/base/config/DocTypeHandler.java | 2 + .../base/config/DocTypeHandlerDefault.java | 53 ++++- .../doc/base/facade/DocHandlerFacade.java | 24 +- .../config/FreeMarkerConfigStep.java | 5 +- .../FreemarkerDocProcessConfigFacade.java | 60 +++-- .../freemarker-doc-process-1-0.xsd | 63 ++++- .../java/doc/mod/fop/PdfFopTypeHandler.java | 60 +++-- 9 files changed, 413 insertions(+), 76 deletions(-) diff --git a/fj-doc-base/src/main/docs/fdp_xsd_config_ref.html b/fj-doc-base/src/main/docs/fdp_xsd_config_ref.html index 266f1f907..3ca3a20d8 100644 --- a/fj-doc-base/src/main/docs/fdp_xsd_config_ref.html +++ b/fj-doc-base/src/main/docs/fdp_xsd_config_ref.html @@ -57,6 +57,8 @@

Reference xsd documentation for Venus - Fuger ( + docHandlerConfig + , docChain ) [1-1] @@ -64,27 +66,65 @@

Reference xsd documentation for Venus - Fuger - docChain + docHandlerConfig - A document processing chain + Configuration for DocHandlerFacade containing all needed DocTypeHandlers ( - chainStep + docHandler ) [1-1] - chainStep + docHandler - A step in a docChain + Configuration of a specific DocTypeHandler as FactoryType ( + docHandlerCustomConfig + ) [1-1] + + + + + + docHandlerCustomConfig + + + Custom configuration of a doc handler + + + + + + + docChain + + + A document processing chain + + + ( + chainStep + ) [1-1] + + + + + + chainStep + + + A step in a docChain + + + ( config | function @@ -95,33 +135,33 @@

Reference xsd documentation for Venus - Fuger - + config - + Will creates a new free marker configuration - + - + function - + The data of a freemarker function to map (the 'name' attributes will be the key, and a new instance of the 'value' attribute as value) - + - + map - + An object will be mapped from DocProcessContext to Freemarker Map (the 'name' attributes will be the key, and the 'value' will be used to search in the DocProcessContext attributes) - + @@ -162,6 +202,158 @@

Reference xsd documentation for Venus - Fuger
top + + + + + + + + + + + + + + + + + + + +
+ Element : docHandlerConfig +
+ Configuration for DocHandlerFacade containing all needed DocTypeHandlers +
+ Attribute + + Description + + Note +
+ This element does not have attributes +
+
+ top + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Element : docHandler +
+ Configuration of a specific DocTypeHandler as FactoryType +
+ Attribute + + Description + + Note +
+ id + + Id of the handler + + string +
+ info + + Type of the handler + + string +
+ type + + Type of the handler (fully qualified class name implementing DocTypeHandler) + + string +
+ unsafe + + 'true' is the handler is too be considered unsafe + + boolean +
+ unsafeMode + + Unsafe handling message, ( 'log-message' for simple message or 'log-trace' for full trace) + + string +
+
+ top + + + + + + + + + + + + + + + + + + + +
+ Element : docHandlerCustomConfig +
+ Custom configuration of a doc handler +
+ Attribute + + Description + + Note +
+ This element does not have attributes +
+
+ top diff --git a/fj-doc-base/src/main/java/org/fugerit/java/doc/base/config/DocConfig.java b/fj-doc-base/src/main/java/org/fugerit/java/doc/base/config/DocConfig.java index ad9c345f9..39ee6e8da 100644 --- a/fj-doc-base/src/main/java/org/fugerit/java/doc/base/config/DocConfig.java +++ b/fj-doc-base/src/main/java/org/fugerit/java/doc/base/config/DocConfig.java @@ -7,6 +7,8 @@ public class DocConfig { public static final String TYPE_XML = "xml"; public static final String TYPE_PDF = "pdf"; + public static final String FORMAT_PDF_A_1A = "PDF/A-1a"; + public static final String FORMAT_PDF_A_1B = "PDF/A-1b"; public static final String TYPE_RTF = "rtf"; diff --git a/fj-doc-base/src/main/java/org/fugerit/java/doc/base/config/DocTypeHandler.java b/fj-doc-base/src/main/java/org/fugerit/java/doc/base/config/DocTypeHandler.java index 62447e930..b5f5bc0f5 100644 --- a/fj-doc-base/src/main/java/org/fugerit/java/doc/base/config/DocTypeHandler.java +++ b/fj-doc-base/src/main/java/org/fugerit/java/doc/base/config/DocTypeHandler.java @@ -12,6 +12,8 @@ public interface DocTypeHandler extends KeyString { String getMime(); + String getFormat(); + Charset getCharset(); void handle( DocInput docInput, DocOutput docOutput ) throws Exception; diff --git a/fj-doc-base/src/main/java/org/fugerit/java/doc/base/config/DocTypeHandlerDefault.java b/fj-doc-base/src/main/java/org/fugerit/java/doc/base/config/DocTypeHandlerDefault.java index 9ea1e41fa..b76e84b29 100644 --- a/fj-doc-base/src/main/java/org/fugerit/java/doc/base/config/DocTypeHandlerDefault.java +++ b/fj-doc-base/src/main/java/org/fugerit/java/doc/base/config/DocTypeHandlerDefault.java @@ -10,6 +10,11 @@ import org.w3c.dom.Element; import org.w3c.dom.NodeList; +import lombok.AccessLevel; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; + +@Slf4j public class DocTypeHandlerDefault extends XMLConfigurableObject implements DocTypeHandler, Serializable { /** @@ -19,6 +24,8 @@ public class DocTypeHandlerDefault extends XMLConfigurableObject implements DocT public static final String TAG_NAME_CONFIG = "config"; + public static final String TAG_NAME_CONFIG_ALT = "docHandlerCustomConfig"; + public static final String ATT_NAME_CHARSET = "charset"; private String type; @@ -27,6 +34,8 @@ public class DocTypeHandlerDefault extends XMLConfigurableObject implements DocT private String mime; + @Setter(value = AccessLevel.PROTECTED) private String format; + private Charset charset; @Override @@ -40,7 +49,7 @@ public String getMime() { @Override public String getKey() { - return createKey( this.getType() , this.getModule() ) ; + return createKey( this.getFormat() , this.getModule() ) ; } @Override @@ -53,6 +62,11 @@ public String getModule() { return module; } + @Override + public String getFormat() { + return StringUtils.valueWithDefault( this.format , this.getType() ); + } + @Override public Charset getCharset() { return charset; @@ -64,10 +78,15 @@ public void handle(DocInput docInput, DocOutput docOutput) throws Exception { } public DocTypeHandlerDefault(String type, String module, String mime, Charset charset) { + this( type, module, mime, charset, null ); + } + + public DocTypeHandlerDefault(String type, String module, String mime, Charset charset, String format) { super(); this.type = type; this.module = module; this.mime = mime; + this.format = format; this.charset = DocCharsetProvider.getDefaultProvider().resolveCharset(charset); } @@ -87,17 +106,37 @@ protected void handleConfigTag( Element config ) throws ConfigException { } - @Override - public void configure(Element tag) throws ConfigException { - NodeList nl = tag.getElementsByTagName( TAG_NAME_CONFIG ); + private Element lookupConfig( Element tag, String tagName ) { + Element configTag = null; + NodeList nl = tag.getElementsByTagName( tagName ); if ( nl.getLength() > 0 ) { - Element config = (Element)nl.item( 0 ); - String charsetAtt = config.getAttribute( ATT_NAME_CHARSET ); + configTag = (Element)nl.item( 0 ); + String charsetAtt = configTag.getAttribute( ATT_NAME_CHARSET ); if ( StringUtils.isNotEmpty( charsetAtt ) ) { this.charset = Charset.forName( charsetAtt ); } - this.handleConfigTag(config); + } + return configTag; + } + + @Override + public void configure(Element tag) throws ConfigException { + log.info( "configure : {}", tag.getAttribute( "id" ) ); + Element configTag = this.lookupConfig(tag, TAG_NAME_CONFIG_ALT ); + if ( configTag == null ) { + configTag = this.lookupConfig(tag, TAG_NAME_CONFIG ); + } + if ( configTag != null ) { + this.handleConfigTag(configTag); } } + @Override + public String toString() { + return this.getClass().getSimpleName()+" [type=" + type + ", module=" + module + ", format=" + format + "]"; + } + + + + } diff --git a/fj-doc-base/src/main/java/org/fugerit/java/doc/base/facade/DocHandlerFacade.java b/fj-doc-base/src/main/java/org/fugerit/java/doc/base/facade/DocHandlerFacade.java index fbf709689..7dda49a1a 100644 --- a/fj-doc-base/src/main/java/org/fugerit/java/doc/base/facade/DocHandlerFacade.java +++ b/fj-doc-base/src/main/java/org/fugerit/java/doc/base/facade/DocHandlerFacade.java @@ -12,8 +12,8 @@ import org.fugerit.java.doc.base.config.DocInput; import org.fugerit.java.doc.base.config.DocOutput; import org.fugerit.java.doc.base.config.DocTypeHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import lombok.extern.slf4j.Slf4j; /** * DocHandlerFacade @@ -24,10 +24,9 @@ * @author fugerit * */ +@Slf4j public class DocHandlerFacade implements Serializable { - private static final Logger logger = LoggerFactory.getLogger( DocHandlerFacade.class ); - /** * */ @@ -47,12 +46,12 @@ public DocHandlerFacade() { } private void doRegister( DocTypeHandler handler, String id ) { - logger.info( "Registering handler with id {} : {}", id, handler.getClass().getName() ); + log.info( "Registering handler with id {} : {}", id, handler.getClass().getName() ); this.mapHandlers.put( id, handler ); - ListMapStringKey list = this.mapTypeHandlers.get( handler.getType() ); + ListMapStringKey list = this.mapTypeHandlers.get( handler.getFormat() ); if ( list == null ) { list = new ListMapStringKey(); - this.mapTypeHandlers.put( handler.getType() , list ); + this.mapTypeHandlers.put( handler.getFormat() , list ); } list.add( handler ); } @@ -60,17 +59,20 @@ private void doRegister( DocTypeHandler handler, String id ) { public void registerHandler( DocTypeHandler handler, boolean registerForType, boolean errorOnDuplicate ) throws Exception { doRegister( handler, handler.getKey() ); if ( registerForType ) { + String format = handler.getFormat(); String type = handler.getType(); - DocTypeHandler previous = this.mapHandlers.get( type ); + DocTypeHandler previous = this.mapHandlers.get( format ); if ( previous != null ) { if ( errorOnDuplicate ) { - throw new ConfigException( "Duplicate handler for type : "+type ); + throw new ConfigException( "Duplicate handler for format : "+format+" (type:"+type+")" ); } else { - logger.warn( "Warning duplicate handler for type, {} will replace {}", type, handler.getKey(), previous.getKey() ); + log.warn( "Warning duplicate handler for format, {} will replace {}", format, handler.getKey(), previous.getKey() ); } } - doRegister(handler, type); + doRegister(handler, format); } + log.info( "list keys current -> {} : list {}", handler, this.mapHandlers.keySet() ); + log.debug( "test" ); } public void registerHandler( DocTypeHandler handler ) throws Exception { diff --git a/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/config/FreeMarkerConfigStep.java b/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/config/FreeMarkerConfigStep.java index 1b9f1e52f..d338e8333 100644 --- a/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/config/FreeMarkerConfigStep.java +++ b/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/config/FreeMarkerConfigStep.java @@ -11,7 +11,6 @@ import org.fugerit.java.doc.base.process.DocProcessContext; import org.fugerit.java.doc.base.process.DocProcessData; import org.fugerit.java.doc.base.process.DocProcessorBasic; -import org.fugerit.java.doc.freemarker.process.ConfigInitModel; import freemarker.template.Configuration; import freemarker.template.TemplateExceptionHandler; @@ -22,10 +21,10 @@ public class FreeMarkerConfigStep extends DocProcessorBasic { public static final String ATT_DEFAULT = "FreeMarkerConfigStep.DEFAULT"; public static final String ATT_FREEMARKER_CONFIG_KEY_VERSION = "version"; - public static final String ATT_FREEMARKER_CONFIG_KEY_VERSION_2_3_31 = ConfigInitModel.VERSION_2_3_31; + public static final String ATT_FREEMARKER_CONFIG_KEY_VERSION_2_3_31 = "2.3.31"; public static final String ATT_FREEMARKER_CONFIG_KEY_VERSION_2_3_30 = "2.3.30"; public static final String ATT_FREEMARKER_CONFIG_KEY_VERSION_2_3_29 = "2.3.29"; - public static final String ATT_FREEMARKER_CONFIG_KEY_VERSION_DEFAULT = ConfigInitModel.DEFAULT_VERSION; + public static final String ATT_FREEMARKER_CONFIG_KEY_VERSION_DEFAULT = ATT_FREEMARKER_CONFIG_KEY_VERSION_2_3_31; public static final String ATT_FREEMARKER_CONFIG_KEY_MODE = "mode"; public static final String ATT_FREEMARKER_CONFIG_KEY_MODE_CLASS = "class"; 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 fd55adc52..c9269f28c 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 @@ -7,8 +7,8 @@ import javax.xml.parsers.DocumentBuilderFactory; import org.fugerit.java.core.cfg.ConfigException; -import org.fugerit.java.core.cfg.xml.FactoryType; -import org.fugerit.java.core.cfg.xml.FactoryTypeHelper; +import org.fugerit.java.core.cfg.ConfigurableObject; +import org.fugerit.java.core.cfg.helpers.UnsafeHelper; import org.fugerit.java.core.cfg.xml.XmlBeanHelper; import org.fugerit.java.core.lang.helpers.ClassHelper; import org.fugerit.java.core.lang.helpers.StringUtils; @@ -38,14 +38,14 @@ public class FreemarkerDocProcessConfigFacade { public static final String ATT_CHAIN_STEP = "chainStep"; + public static final String ATT_STEP_TYPE = "stepType"; + public static final String STEP_TYPE_CONFIG = "config"; public static final String STEP_TYPE_FUNCTION = "function"; public static final String STEP_TYPE_MAP = "map"; - private static final FactoryTypeHelper HELPER = FactoryTypeHelper.newInstance( DocTypeHandler.class ); - public static FreemarkerDocProcessConfig newSimpleConfig( String id, String templatePath ) throws ConfigException { FreemarkerDocProcessConfig config = new FreemarkerDocProcessConfig(); config.setDefaultChain( @@ -76,6 +76,22 @@ public MiniFilterChain newDefaultChain(String id) { return config; } + private static DocTypeHandler createHelper( Element docHandlerConfig ) throws ConfigException { + String type = docHandlerConfig.getAttribute( "type" ); + log.info( "factoryType : {} , resultType : {}", docHandlerConfig, type ); + DocTypeHandler res = null; + try { + res = (DocTypeHandler)ClassHelper.newInstance( type ); + if ( res instanceof ConfigurableObject ) { + log.info( "ConfigurableObject -> try configure()" ); + ((ConfigurableObject)res).configure( (Element)docHandlerConfig ); + } + } catch (Exception | NoClassDefFoundError e) { + UnsafeHelper.handleUnsafe( new ConfigException( "Type cannot be loaded : "+e, e ), docHandlerConfig.getAttribute( "unsafe"), docHandlerConfig.getAttribute( "unsafeMode") ); + } + return res; + } + public static FreemarkerDocProcessConfig loadConfig( Reader xmlReader ) throws ConfigException { FreemarkerDocProcessConfig result = null; try { @@ -88,12 +104,12 @@ public static FreemarkerDocProcessConfig loadConfig( Reader xmlReader ) throws C NodeList docHandlerConfigList = doc.getElementsByTagName( ATT_DOC_HANDLER_CONFIG ); if ( docHandlerConfigList.getLength() == 1 ) { Element docHandlerConfigTag = (Element) docHandlerConfigList.item( 0 ); - NodeList docHandlerList = docHandlerConfigTag.getElementsByTagName( "data" ); + NodeList docHandlerList = docHandlerConfigTag.getElementsByTagName( "docHandler" ); log.info( "docHandlerList -> {}", docHandlerList.getLength() ); for ( int k=0; k + + + + Configuration for DocHandlerFacade containing all needed DocTypeHandlers + + + + + + + + + + + + Configuration of a specific DocTypeHandler as FactoryType + + + + + + + + + + + Id of the handler + + + + + Type of the handler + + + + + Type of the handler (fully qualified class name implementing DocTypeHandler) + + + + + 'true' is the handler is too be considered unsafe + + + + + Unsafe handling message, ( 'log-message' for simple message or 'log-trace' for full trace) + + + + + + + Custom configuration of a doc handler + + + + + + + A document processing chain diff --git a/fj-doc-mod-fop/src/main/java/org/fugerit/java/doc/mod/fop/PdfFopTypeHandler.java b/fj-doc-mod-fop/src/main/java/org/fugerit/java/doc/mod/fop/PdfFopTypeHandler.java index ddbb2e094..bcaeb18be 100644 --- a/fj-doc-mod-fop/src/main/java/org/fugerit/java/doc/mod/fop/PdfFopTypeHandler.java +++ b/fj-doc-mod-fop/src/main/java/org/fugerit/java/doc/mod/fop/PdfFopTypeHandler.java @@ -4,6 +4,9 @@ import java.io.ByteArrayOutputStream; import java.io.InputStreamReader; import java.nio.charset.Charset; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import java.util.Properties; import javax.xml.transform.Result; @@ -19,6 +22,7 @@ import org.apache.xmlgraphics.io.ResourceResolver; import org.fugerit.java.core.cfg.ConfigException; import org.fugerit.java.core.lang.helpers.ClassHelper; +import org.fugerit.java.core.lang.helpers.CollectionUtils; import org.fugerit.java.core.lang.helpers.StringUtils; import org.fugerit.java.core.xml.dom.DOMUtils; import org.fugerit.java.doc.base.config.DocCharsetProvider; @@ -30,6 +34,11 @@ import org.fugerit.java.doc.mod.fop.config.FopConfigClassLoaderWrapper; import org.w3c.dom.Element; +import lombok.Getter; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; + +@Slf4j public class PdfFopTypeHandler extends FreeMarkerFopTypeHandler { public static final DocTypeHandler HANDLER = new PdfFopTypeHandler(); @@ -46,24 +55,33 @@ public class PdfFopTypeHandler extends FreeMarkerFopTypeHandler { public static final String ATT_FOP_CONFIG_RESOLVER_TYPE_DEFAULT = FopConfigClassLoaderWrapper.DEFAULT_RESOURCE_RESOLVER.getClass().getName(); + public static final String ATT_PDF_A_MODE = "pdf-a-mode"; + public static final String ATT_PDF_A_MODE_PDF_A_1A = DocConfig.FORMAT_PDF_A_1A; + public static final String ATT_PDF_A_MODE_PDF_A_1B = DocConfig.FORMAT_PDF_A_1B; + + private static final String[] VALID_PDF_A = { ATT_PDF_A_MODE_PDF_A_1A, ATT_PDF_A_MODE_PDF_A_1B }; + public static final List VALID_PDF_A_MODES = Arrays.asList( VALID_PDF_A ); + @Deprecated public static final String ATT_FONT_BASE_CLASSLOADER_PATH = "font-base-classloader-path"; public static final boolean DEFAULT_ACCESSIBILITY = true; public static final boolean DEFAULT_KEEP_EMPTY_TAGS = false; - + /** * */ private static final long serialVersionUID = -7394516771708L; - private boolean accessibility; + @Getter private boolean accessibility; - private boolean keepEmptyTags; + @Getter private boolean keepEmptyTags; - private FopConfig fopConfig; + @Setter @Getter private FopConfig fopConfig; + @Getter @Setter private String pdfAMode; + public PdfFopTypeHandler( Charset charset, FopConfig fopConfig, boolean accessibility, boolean keepEmptyTags ) { super( DocConfig.TYPE_PDF, charset ); this.fopConfig = fopConfig; @@ -95,6 +113,7 @@ public PdfFopTypeHandler() { this( DEFAULT_ACCESSIBILITY, DEFAULT_KEEP_EMPTY_TAGS ); } + @SuppressWarnings("unchecked") @Override public void handle(DocInput docInput, DocOutput docOutput) throws Exception { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); @@ -105,6 +124,9 @@ public void handle(DocInput docInput, DocOutput docOutput) throws Exception { // create an instance of fop factory FopFactory fopFactory = this.fopConfig.newFactory(); FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); + if ( StringUtils.isNotEmpty( this.getPdfAMode() ) ) { + foUserAgent.getRendererOptions().put("pdf-a-mode", this.getPdfAMode() ); + } foUserAgent.setAccessibility( this.isAccessibility() ); foUserAgent.setKeepEmptyTags( this.isKeepEmptyTags() ); Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, docOutput.getOs()); @@ -114,22 +136,6 @@ public void handle(DocInput docInput, DocOutput docOutput) throws Exception { transformer.transform(xmlSource, res); } - public boolean isAccessibility() { - return accessibility; - } - - public boolean isKeepEmptyTags() { - return keepEmptyTags; - } - - public FopConfig getFopConfig() { - return fopConfig; - } - - public void setFopConfig(FopConfig fopConfig) { - this.fopConfig = fopConfig; - } - @Override protected void handleConfigTag(Element config) throws ConfigException { super.handleConfigTag(config); @@ -138,10 +144,21 @@ protected void handleConfigTag(Element config) throws ConfigException { String fopConfigClassloaderPath = props.getProperty( ATT_FOP_CONFIG_CLASSLOADER_PATH ); String fopConfigResoverType = props.getProperty( ATT_FOP_CONFIG_RESOLVER_TYPE, ATT_FOP_CONFIG_RESOLVER_TYPE_DEFAULT ); String fontBaseClassloaderPath = props.getProperty( ATT_FONT_BASE_CLASSLOADER_PATH ); + String pdfAModConfig = props.getProperty( ATT_PDF_A_MODE ); + // config pdf a + if ( StringUtils.isNotEmpty( pdfAModConfig ) ) { + log.info( "pdf a mode -> {} : {}", ATT_PDF_A_MODE, pdfAModConfig ); + if ( VALID_PDF_A_MODES.contains( pdfAModConfig ) ) { + this.setPdfAMode( pdfAModConfig ); + this.setFormat( pdfAModConfig ); + } else { + throw new ConfigException( ATT_PDF_A_MODE+" not valid : "+pdfAModConfig+"( valid modes are : "+VALID_PDF_A_MODES+")" ); + } + } // legacy class loader mode if ( StringUtils.isEmpty( fopConfigMode ) && StringUtils.isNotEmpty( fopConfigClassloaderPath ) && StringUtils.isNotEmpty( fontBaseClassloaderPath ) ) { fopConfigMode = ATT_FOP_CONFIG_MODE_CLASS_LOADER_LEGACY; - logger.warn( "Activated legacy ClassLoader mode. It is strongly recomended to update te configuration {} -> {}", ATT_FOP_CONFIG_MODE_CLASS_LOADER_LEGACY, FopConfigClassLoader.MIN_VERSION_NEW_CLASSLOADER_MODE ); + log.warn( "Activated legacy ClassLoader mode. It is strongly recomended to update te configuration {} -> {}", ATT_FOP_CONFIG_MODE_CLASS_LOADER_LEGACY, FopConfigClassLoader.MIN_VERSION_NEW_CLASSLOADER_MODE ); } if ( ATT_FOP_CONFIG_MODE_CLASS_LOADER.equalsIgnoreCase( fopConfigMode ) ) { try { @@ -155,7 +172,6 @@ protected void handleConfigTag(Element config) throws ConfigException { FopConfigClassLoader fopConfigClassLoader = new FopConfigClassLoader(fopConfigClassloaderPath, fontBaseClassloaderPath); this.fopConfig = fopConfigClassLoader; } - } } \ No newline at end of file From a3dd21e57758113b7c1f45fe385f912b8a451e59 Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Thu, 13 Jul 2023 17:16:55 +0200 Subject: [PATCH 5/6] Added samples for pdf-a #43 --- .../config/freemarker-doc-process.xml | 30 +++++++++------ .../src/main/resources/fop-config.xml | 8 ++-- .../main/resources/free_marker/pdf_a_test.ftl | 38 +++++++++++++++++++ .../doc/sample/facade/BasicFacadeTest.java | 15 +++++--- .../sample/freemarker/TestFreeMarker01.java | 4 +- .../TestFreemarkerConfigValidation.java | 4 +- .../java/doc/sample/freemarker/TestPdfA.java | 11 ++++++ 7 files changed, 85 insertions(+), 25 deletions(-) create mode 100644 fj-doc-sample/src/main/resources/free_marker/pdf_a_test.ftl create mode 100644 fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/freemarker/TestPdfA.java diff --git a/fj-doc-sample/src/main/resources/config/freemarker-doc-process.xml b/fj-doc-sample/src/main/resources/config/freemarker-doc-process.xml index 70a7f5bc0..281aaf6ca 100644 --- a/fj-doc-sample/src/main/resources/config/freemarker-doc-process.xml +++ b/fj-doc-sample/src/main/resources/config/freemarker-doc-process.xml @@ -5,12 +5,15 @@ xsi:schemaLocation="https://freemarkerdocprocess.fugerit.org https://www.fugerit.org/data/java/doc/xsd/freemarker-doc-process-1-0.xsd" > - - - - - - + + + + + + + + + - - - - - + + + + + @@ -80,5 +82,9 @@ + + + + diff --git a/fj-doc-sample/src/main/resources/fop-config.xml b/fj-doc-sample/src/main/resources/fop-config.xml index 933b54a33..3cd9c788c 100644 --- a/fj-doc-sample/src/main/resources/fop-config.xml +++ b/fj-doc-sample/src/main/resources/fop-config.xml @@ -15,16 +15,16 @@ - + - + - + - + + + + + + 10;10;10;30 + + + excel-table=print + 450 + + excel-table + + TitilliumWeb + + + Bookmark 1 + + + + + + + Heading test level 1 default font + + + + \ No newline at end of file diff --git a/fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/facade/BasicFacadeTest.java b/fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/facade/BasicFacadeTest.java index 33f084e59..bd1c2c647 100644 --- a/fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/facade/BasicFacadeTest.java +++ b/fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/facade/BasicFacadeTest.java @@ -141,26 +141,29 @@ protected DocBase getDocBase() throws Exception { return docBase; } - public void produce( File outputFolder, String facadeId, DocBase doc, Reader reader, String baseName, String type ) throws Exception { + public void produce( File outputFolder, String facadeId, DocBase doc, Reader reader, String baseName, String format ) throws Exception { DocHandlerFacade facade = PROCESS_CONFIG.getFacade(); - DocTypeHandler handler = facade.findHandler( type ); + DocTypeHandler handler = facade.findHandler( format ); StringBuilder append = new StringBuilder(); if ( handler == null ) { - throw new ConfigException( "No handler with id : "+type ); - } else if ( !handler.getType().equalsIgnoreCase( type ) ) { + throw new ConfigException( "No handler with id : "+format ); + } else if ( !handler.getType().equalsIgnoreCase( format ) ) { append.append( "_" ); append.append( handler.getModule() ); } append.append( "." ); append.append( handler.getType() ); + if ( !handler.getType().equalsIgnoreCase( handler.getFormat() ) ) { + baseName = baseName+"_"+handler.getFormat().replaceAll( "/" , "_"); + } File file = new File( outputFolder, baseName + append.toString() ); logger.info("Create file {}", file.getCanonicalPath()); try (FileOutputStream fos = new FileOutputStream(file)) { long start = System.currentTimeMillis(); - DocInput input = DocInput.newInput( type , reader, this.getSourceType() ); + DocInput input = DocInput.newInput( format , reader, this.getSourceType() ); DocOutput output = DocOutput.newOutput( fos ); facade.handle( input , output ); - this.checkpoints.addCheckpointFromStartTime( "PRODUCE-"+type, start ); + this.checkpoints.addCheckpointFromStartTime( "PRODUCE-"+format, start ); } } diff --git a/fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/freemarker/TestFreeMarker01.java b/fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/freemarker/TestFreeMarker01.java index cd165caad..a1bec3adf 100644 --- a/fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/freemarker/TestFreeMarker01.java +++ b/fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/freemarker/TestFreeMarker01.java @@ -6,8 +6,8 @@ public class TestFreeMarker01 extends BasicFreeMarkerTest { public TestFreeMarker01() { super( "free-marker-01", DocConfig.TYPE_FO, - DocConfig.TYPE_XML, DocConfig.TYPE_PDF, DocConfig.TYPE_XLS, - DocConfig.TYPE_HTML, DocConfig.TYPE_XLSX, DocConfig.TYPE_CSV ); + DocConfig.TYPE_XML, DocConfig.TYPE_PDF, + DocConfig.TYPE_HTML); } diff --git a/fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/freemarker/TestFreemarkerConfigValidation.java b/fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/freemarker/TestFreemarkerConfigValidation.java index f2605ff67..e7ce718bd 100644 --- a/fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/freemarker/TestFreemarkerConfigValidation.java +++ b/fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/freemarker/TestFreemarkerConfigValidation.java @@ -4,6 +4,7 @@ import org.fugerit.java.core.lang.helpers.ClassHelper; import org.fugerit.java.doc.freemarker.process.FreemarkerDocProcessConfigValidator; +import org.junit.Assert; import org.junit.Test; public class TestFreemarkerConfigValidation { @@ -11,7 +12,8 @@ public class TestFreemarkerConfigValidation { @Test public void testValidation() { try ( InputStreamReader xmlReader = new InputStreamReader( ClassHelper.loadFromDefaultClassLoader( "config/freemarker-doc-process.xml" ) ) ) { - FreemarkerDocProcessConfigValidator.logValidation( xmlReader ); + boolean valid = FreemarkerDocProcessConfigValidator.logValidation( xmlReader ); + Assert.assertTrue( "Xml non valido", valid ); } catch (Exception e) { throw new RuntimeException( e ); } diff --git a/fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/freemarker/TestPdfA.java b/fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/freemarker/TestPdfA.java new file mode 100644 index 000000000..fd3f145fe --- /dev/null +++ b/fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/freemarker/TestPdfA.java @@ -0,0 +1,11 @@ +package test.org.fugerit.java.doc.sample.freemarker; + +import org.fugerit.java.doc.base.config.DocConfig; + +public class TestPdfA extends BasicFreeMarkerTest { + + public TestPdfA() { + super( "pdf_a_test", DocConfig.TYPE_FO, DocConfig.FORMAT_PDF_A_1A, DocConfig.TYPE_PDF ); + } + +} From 5a5351ab44dd9630b6a3ecfc1463d42a5de40ae7 Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Thu, 13 Jul 2023 17:18:24 +0200 Subject: [PATCH 6/6] 1.3.1-rc.001 (2023-07-13) + [[fj-doc-mod-fop] add pdf/a support](https://github.com/fugerit-org/fj-doc/issues/43) --- docgen/parameters.json | 4 ++-- docgen/release-notes.txt | 6 +++++- fj-doc-base-json/pom.xml | 2 +- fj-doc-base-yaml/pom.xml | 2 +- fj-doc-base/pom.xml | 2 +- fj-doc-bom-core/pom.xml | 2 +- fj-doc-bom-fop/pom.xml | 2 +- fj-doc-freemarker/pom.xml | 2 +- fj-doc-lib-autodoc/pom.xml | 2 +- fj-doc-lib-simpletable-import/pom.xml | 2 +- fj-doc-lib-simpletable/pom.xml | 2 +- fj-doc-mod-fop/pom.xml | 2 +- fj-doc-mod-opencsv/pom.xml | 2 +- fj-doc-mod-poi/pom.xml | 2 +- fj-doc-playground-quarkus/pom.xml | 2 +- fj-doc-sample/pom.xml | 2 +- fj-doc-val-core/pom.xml | 2 +- fj-doc-val-pdfbox/pom.xml | 2 +- fj-doc-val-poi/pom.xml | 2 +- fj-doc-val/pom.xml | 2 +- pom.xml | 2 +- 21 files changed, 26 insertions(+), 22 deletions(-) diff --git a/docgen/parameters.json b/docgen/parameters.json index ea7dfdb08..0e56b9bb0 100644 --- a/docgen/parameters.json +++ b/docgen/parameters.json @@ -1,8 +1,8 @@ { "title" : "Venus (Fugerit Document Generation Framework)", "name": "Venus", - "version" : "1.3.0-rc.007", - "date" : "12/07/2023", + "version" : "1.3.1-rc.001", + "date" : "13/07/2023", "organization" : { "name" : "Fugerit Org", "url" : "https://www.fugerit.org" diff --git a/docgen/release-notes.txt b/docgen/release-notes.txt index 1f6874915..94173c685 100644 --- a/docgen/release-notes.txt +++ b/docgen/release-notes.txt @@ -1,4 +1,8 @@ -1.3.0-rc.007 (2023-07-12) +1.3.1-rc.001 (2023-07-13) +------------------ ++ [[fj-doc-mod-fop] add pdf/a support](https://github.com/fugerit-org/fj-doc/issues/43) + +1.3.0-rc.007 (2023-07-12) ------------------ + [New freemarker configuration model, compatibility mode](https://github.com/fugerit-org/fj-doc/issues/38) diff --git a/fj-doc-base-json/pom.xml b/fj-doc-base-json/pom.xml index 66bf3e250..29530958b 100644 --- a/fj-doc-base-json/pom.xml +++ b/fj-doc-base-json/pom.xml @@ -7,7 +7,7 @@ org.fugerit.java fj-doc - 1.3.0-rc.007 + 1.3.1-rc.001 fj-doc-base-json diff --git a/fj-doc-base-yaml/pom.xml b/fj-doc-base-yaml/pom.xml index 14b7be09a..1fe6aaacf 100644 --- a/fj-doc-base-yaml/pom.xml +++ b/fj-doc-base-yaml/pom.xml @@ -7,7 +7,7 @@ org.fugerit.java fj-doc - 1.3.0-rc.007 + 1.3.1-rc.001 fj-doc-base-yaml diff --git a/fj-doc-base/pom.xml b/fj-doc-base/pom.xml index 279245903..3a2b7b0ab 100644 --- a/fj-doc-base/pom.xml +++ b/fj-doc-base/pom.xml @@ -7,7 +7,7 @@ org.fugerit.java fj-doc - 1.3.0-rc.007 + 1.3.1-rc.001 fj-doc-base diff --git a/fj-doc-bom-core/pom.xml b/fj-doc-bom-core/pom.xml index 889b0fee2..597d9b6b2 100644 --- a/fj-doc-bom-core/pom.xml +++ b/fj-doc-bom-core/pom.xml @@ -7,7 +7,7 @@ org.fugerit.java fj-doc - 1.3.0-rc.007 + 1.3.1-rc.001 fj-doc-bom-core diff --git a/fj-doc-bom-fop/pom.xml b/fj-doc-bom-fop/pom.xml index 92cd7552c..49bce4630 100644 --- a/fj-doc-bom-fop/pom.xml +++ b/fj-doc-bom-fop/pom.xml @@ -7,7 +7,7 @@ org.fugerit.java fj-doc - 1.3.0-rc.007 + 1.3.1-rc.001 fj-doc-bom-fop diff --git a/fj-doc-freemarker/pom.xml b/fj-doc-freemarker/pom.xml index 71bd1d74d..71ac5ecfc 100644 --- a/fj-doc-freemarker/pom.xml +++ b/fj-doc-freemarker/pom.xml @@ -7,7 +7,7 @@ org.fugerit.java fj-doc - 1.3.0-rc.007 + 1.3.1-rc.001 fj-doc-freemarker diff --git a/fj-doc-lib-autodoc/pom.xml b/fj-doc-lib-autodoc/pom.xml index ab3282d5d..8e965e21b 100644 --- a/fj-doc-lib-autodoc/pom.xml +++ b/fj-doc-lib-autodoc/pom.xml @@ -7,7 +7,7 @@ org.fugerit.java fj-doc - 1.3.0-rc.007 + 1.3.1-rc.001 fj-doc-lib-autodoc diff --git a/fj-doc-lib-simpletable-import/pom.xml b/fj-doc-lib-simpletable-import/pom.xml index 82372dd68..d109e1cb6 100644 --- a/fj-doc-lib-simpletable-import/pom.xml +++ b/fj-doc-lib-simpletable-import/pom.xml @@ -7,7 +7,7 @@ org.fugerit.java fj-doc - 1.3.0-rc.007 + 1.3.1-rc.001 fj-doc-lib-simpletable-import diff --git a/fj-doc-lib-simpletable/pom.xml b/fj-doc-lib-simpletable/pom.xml index 133b5f212..f968cdca9 100644 --- a/fj-doc-lib-simpletable/pom.xml +++ b/fj-doc-lib-simpletable/pom.xml @@ -7,7 +7,7 @@ org.fugerit.java fj-doc - 1.3.0-rc.007 + 1.3.1-rc.001 fj-doc-lib-simpletable diff --git a/fj-doc-mod-fop/pom.xml b/fj-doc-mod-fop/pom.xml index dcfa7e38c..e9971414e 100644 --- a/fj-doc-mod-fop/pom.xml +++ b/fj-doc-mod-fop/pom.xml @@ -7,7 +7,7 @@ org.fugerit.java fj-doc - 1.3.0-rc.007 + 1.3.1-rc.001 fj-doc-mod-fop diff --git a/fj-doc-mod-opencsv/pom.xml b/fj-doc-mod-opencsv/pom.xml index 2e55e9f40..d0eb74edf 100644 --- a/fj-doc-mod-opencsv/pom.xml +++ b/fj-doc-mod-opencsv/pom.xml @@ -7,7 +7,7 @@ org.fugerit.java fj-doc - 1.3.0-rc.007 + 1.3.1-rc.001 fj-doc-mod-opencsv diff --git a/fj-doc-mod-poi/pom.xml b/fj-doc-mod-poi/pom.xml index 86cbe2166..c98d79be6 100644 --- a/fj-doc-mod-poi/pom.xml +++ b/fj-doc-mod-poi/pom.xml @@ -7,7 +7,7 @@ org.fugerit.java fj-doc - 1.3.0-rc.007 + 1.3.1-rc.001 fj-doc-mod-poi diff --git a/fj-doc-playground-quarkus/pom.xml b/fj-doc-playground-quarkus/pom.xml index af315a04f..fa8f61c32 100644 --- a/fj-doc-playground-quarkus/pom.xml +++ b/fj-doc-playground-quarkus/pom.xml @@ -4,7 +4,7 @@ org.fugerit.java fj-doc - 1.3.0-rc.007 + 1.3.1-rc.001 fj-doc-playground-quarkus diff --git a/fj-doc-sample/pom.xml b/fj-doc-sample/pom.xml index b4470c70e..ab11dbbac 100644 --- a/fj-doc-sample/pom.xml +++ b/fj-doc-sample/pom.xml @@ -7,7 +7,7 @@ org.fugerit.java fj-doc - 1.3.0-rc.007 + 1.3.1-rc.001 fj-doc-sample diff --git a/fj-doc-val-core/pom.xml b/fj-doc-val-core/pom.xml index 8842210f7..4b7178015 100644 --- a/fj-doc-val-core/pom.xml +++ b/fj-doc-val-core/pom.xml @@ -7,7 +7,7 @@ org.fugerit.java fj-doc - 1.3.0-rc.007 + 1.3.1-rc.001 fj-doc-val-core diff --git a/fj-doc-val-pdfbox/pom.xml b/fj-doc-val-pdfbox/pom.xml index 534ed44da..2f0e11a1b 100644 --- a/fj-doc-val-pdfbox/pom.xml +++ b/fj-doc-val-pdfbox/pom.xml @@ -7,7 +7,7 @@ org.fugerit.java fj-doc - 1.3.0-rc.007 + 1.3.1-rc.001 fj-doc-val-pdfbox diff --git a/fj-doc-val-poi/pom.xml b/fj-doc-val-poi/pom.xml index 4395e3cee..bb7e9316c 100644 --- a/fj-doc-val-poi/pom.xml +++ b/fj-doc-val-poi/pom.xml @@ -7,7 +7,7 @@ org.fugerit.java fj-doc - 1.3.0-rc.007 + 1.3.1-rc.001 fj-doc-val-poi diff --git a/fj-doc-val/pom.xml b/fj-doc-val/pom.xml index 569ca3965..50eafc9a1 100644 --- a/fj-doc-val/pom.xml +++ b/fj-doc-val/pom.xml @@ -7,7 +7,7 @@ org.fugerit.java fj-doc - 1.3.0-rc.007 + 1.3.1-rc.001 fj-doc-val diff --git a/pom.xml b/pom.xml index a29f3fad3..4b4e909d0 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ fj-doc - 1.3.0-rc.007 + 1.3.1-rc.001 pom fj-doc