From 5e6b1cc1b526803a4ddb8259e76e3ae971bf8e04 Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Wed, 10 Jan 2024 17:46:26 +0100 Subject: [PATCH] font xml config #5 --- CHANGELOG.md | 1 + .../java/doc/mod/openpdf/HtmlTypeHandler.java | 8 ++++++++ .../fugerit/java/doc/mod/openpdf/PdfTypeHandler.java | 8 ++++++++ .../fugerit/java/doc/mod/openpdf/RtfTypeHandler.java | 8 ++++++++ .../doc/mod/openpdf/helpers/OpenPDFConfigHelper.java | 12 +++++++++--- 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef7fb20..4d438b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - fj-doc-freemarker dependency +- xml font configuration ### Changed diff --git a/src/main/java/org/fugerit/java/doc/mod/openpdf/HtmlTypeHandler.java b/src/main/java/org/fugerit/java/doc/mod/openpdf/HtmlTypeHandler.java index 2a3b1ad..cd5b813 100644 --- a/src/main/java/org/fugerit/java/doc/mod/openpdf/HtmlTypeHandler.java +++ b/src/main/java/org/fugerit/java/doc/mod/openpdf/HtmlTypeHandler.java @@ -3,15 +3,18 @@ import java.io.ByteArrayOutputStream; import java.io.OutputStream; +import org.fugerit.java.core.cfg.ConfigException; 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.fugerit.java.doc.base.config.DocTypeHandlerDefault; import org.fugerit.java.doc.base.model.DocBase; +import org.fugerit.java.doc.mod.openpdf.helpers.OpenPDFConfigHelper; import org.fugerit.java.doc.mod.openpdf.helpers.OpenPpfDocHandler; import com.lowagie.text.Document; import com.lowagie.text.html.HtmlWriter; +import org.w3c.dom.Element; public class HtmlTypeHandler extends DocTypeHandlerDefault { @@ -40,4 +43,9 @@ public void handle(DocInput docInput, DocOutput docOutput) throws Exception { outputStream.close(); } + protected void handleConfigTag(Element config) throws ConfigException { + super.handleConfigTag(config); + OpenPDFConfigHelper.handleConfig( config, this.getType() ); + } + } diff --git a/src/main/java/org/fugerit/java/doc/mod/openpdf/PdfTypeHandler.java b/src/main/java/org/fugerit/java/doc/mod/openpdf/PdfTypeHandler.java index 9d76261..4fe30a6 100644 --- a/src/main/java/org/fugerit/java/doc/mod/openpdf/PdfTypeHandler.java +++ b/src/main/java/org/fugerit/java/doc/mod/openpdf/PdfTypeHandler.java @@ -3,16 +3,19 @@ import java.io.ByteArrayOutputStream; import java.io.OutputStream; +import org.fugerit.java.core.cfg.ConfigException; 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.fugerit.java.doc.base.config.DocTypeHandlerDefault; import org.fugerit.java.doc.base.model.DocBase; +import org.fugerit.java.doc.mod.openpdf.helpers.OpenPDFConfigHelper; import org.fugerit.java.doc.mod.openpdf.helpers.OpenPpfDocHandler; import com.lowagie.text.Document; import com.lowagie.text.PageSize; import com.lowagie.text.pdf.PdfWriter; +import org.w3c.dom.Element; public class PdfTypeHandler extends DocTypeHandlerDefault { @@ -59,4 +62,9 @@ public void handle(DocInput docInput, DocOutput docOutput) throws Exception { outputStream.close(); } + @Override + protected void handleConfigTag(Element config) throws ConfigException { + super.handleConfigTag(config); + OpenPDFConfigHelper.handleConfig( config, this.getType() ); + } } diff --git a/src/main/java/org/fugerit/java/doc/mod/openpdf/RtfTypeHandler.java b/src/main/java/org/fugerit/java/doc/mod/openpdf/RtfTypeHandler.java index 7549329..d445a1b 100644 --- a/src/main/java/org/fugerit/java/doc/mod/openpdf/RtfTypeHandler.java +++ b/src/main/java/org/fugerit/java/doc/mod/openpdf/RtfTypeHandler.java @@ -3,16 +3,19 @@ import java.io.ByteArrayOutputStream; import java.io.OutputStream; +import org.fugerit.java.core.cfg.ConfigException; 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.fugerit.java.doc.base.config.DocTypeHandlerDefault; import org.fugerit.java.doc.base.model.DocBase; +import org.fugerit.java.doc.mod.openpdf.helpers.OpenPDFConfigHelper; import org.fugerit.java.doc.mod.openpdf.helpers.OpenPpfDocHandler; import com.lowagie.text.Document; import com.lowagie.text.PageSize; import com.lowagie.text.rtf.RtfWriter2; +import org.w3c.dom.Element; public class RtfTypeHandler extends DocTypeHandlerDefault { @@ -45,4 +48,9 @@ public void handle(DocInput docInput, DocOutput docOutput) throws Exception { outputStream.close(); } + protected void handleConfigTag(Element config) throws ConfigException { + super.handleConfigTag(config); + OpenPDFConfigHelper.handleConfig( config, this.getType() ); + } + } diff --git a/src/main/java/org/fugerit/java/doc/mod/openpdf/helpers/OpenPDFConfigHelper.java b/src/main/java/org/fugerit/java/doc/mod/openpdf/helpers/OpenPDFConfigHelper.java index f6940f6..410ec2d 100644 --- a/src/main/java/org/fugerit/java/doc/mod/openpdf/helpers/OpenPDFConfigHelper.java +++ b/src/main/java/org/fugerit/java/doc/mod/openpdf/helpers/OpenPDFConfigHelper.java @@ -8,13 +8,19 @@ @Slf4j public class OpenPDFConfigHelper { + public static final String TAG_NAME_FONT = "font"; + + public static final String ATT_NAME = "name"; + public static final String ATT_PATH = "path"; + + public static void handleConfig( Element config, String type ) throws ConfigException { log.info( "configure for type: {}", type ); - NodeList fontList = config.getElementsByTagName( "font" ); + NodeList fontList = config.getElementsByTagName( TAG_NAME_FONT ); for ( int k=0; k OpenPpfDocHandler.registerFont( name , path ) ); }