diff --git a/CHANGELOG.md b/CHANGELOG.md index 852601154..c8846397a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- [fj-mod-doc-openpdf-ext] basic list implementation +- info suppress-wrong-type-error, some type error will be ignored if set to true and '1' + ### Changed - quarkus-version set to 3.17.2 across al the modules diff --git a/docs/html/doc_meta_info.html b/docs/html/doc_meta_info.html index ebe221c80..75e677e82 100644 --- a/docs/html/doc_meta_info.html +++ b/docs/html/doc_meta_info.html @@ -285,6 +285,24 @@

Properties for generic metadata

1.4.5

+ + + + +

suppress-wrong-type-error

+ + +

If set to 'a' or 'true' it will set suppress some type error.

+ + +

fj-doc-mod-openpdf-ext(pdf), fj-doc-mod-openrtf-ext(rtf),

+ + +

false

+ + +

8.11.5

+ diff --git a/fj-doc-base/src/main/java/org/fugerit/java/doc/base/typehelper/generic/GenericConsts.java b/fj-doc-base/src/main/java/org/fugerit/java/doc/base/typehelper/generic/GenericConsts.java index 9b8cdffd5..8c580b91b 100644 --- a/fj-doc-base/src/main/java/org/fugerit/java/doc/base/typehelper/generic/GenericConsts.java +++ b/fj-doc-base/src/main/java/org/fugerit/java/doc/base/typehelper/generic/GenericConsts.java @@ -194,6 +194,11 @@ private GenericConsts() {} * See 'default-font-style' documentation. */ public static final String DOC_DEFAULT_FONT_STYLE = "default-font-style"; + + /** + * See 'suppress-wrong-type-error' documentation. + */ + public static final String DOC_SUPPRESS_WRONG_TYPE_ERROR = "suppress-wrong-type-error"; } diff --git a/fj-doc-lib-autodoc/src/test/resources/docs/meta_xml/adm_standard_meta_info.xml b/fj-doc-lib-autodoc/src/test/resources/docs/meta_xml/adm_standard_meta_info.xml index bb797db80..7215f0ee6 100644 --- a/fj-doc-lib-autodoc/src/test/resources/docs/meta_xml/adm_standard_meta_info.xml +++ b/fj-doc-lib-autodoc/src/test/resources/docs/meta_xml/adm_standard_meta_info.xml @@ -189,6 +189,16 @@ fj-doc-mod-openpdf-ext(pdf) fj-doc-mod-openrtf-ext(rtf) + + suppress-wrong-type-error + If set to 'a' or 'true' it will set suppress some type error. + false + 8.11.5 + pdf + rtf + fj-doc-mod-openpdf-ext(pdf) + fj-doc-mod-openrtf-ext(rtf) + diff --git a/fj-doc-mod-openpdf-ext/src/main/java/org/fugerit/java/doc/mod/openpdf/ext/helpers/OpenPdfHelper.java b/fj-doc-mod-openpdf-ext/src/main/java/org/fugerit/java/doc/mod/openpdf/ext/helpers/OpenPdfHelper.java index b45b625f5..26ea3f3a7 100644 --- a/fj-doc-mod-openpdf-ext/src/main/java/org/fugerit/java/doc/mod/openpdf/ext/helpers/OpenPdfHelper.java +++ b/fj-doc-mod-openpdf-ext/src/main/java/org/fugerit/java/doc/mod/openpdf/ext/helpers/OpenPdfHelper.java @@ -1,9 +1,14 @@ package org.fugerit.java.doc.mod.openpdf.ext.helpers; +import java.io.IOException; import java.util.Properties; import com.lowagie.text.pdf.PdfWriter; +import lombok.extern.slf4j.Slf4j; +import org.fugerit.java.core.lang.helpers.BooleanUtils; +import org.fugerit.java.doc.base.typehelper.generic.GenericConsts; +@Slf4j public class OpenPdfHelper { public OpenPdfHelper() { @@ -59,5 +64,13 @@ public PdfWriter getPdfWriter() { public void setPdfWriter(PdfWriter pdfWriter) { this.pdfWriter = pdfWriter; } + + public void handelError( String message ) throws IOException { + if (BooleanUtils.isTrue( this.getParams().getProperty(GenericConsts.DOC_SUPPRESS_WRONG_TYPE_ERROR ) ) ) { + log.warn( "Suppressed type error : {}", message ); + } else { + throw new IOException(message); + } + } } diff --git a/fj-doc-mod-openpdf-ext/src/main/java/org/fugerit/java/doc/mod/openpdf/ext/helpers/OpenPpfDocHandler.java b/fj-doc-mod-openpdf-ext/src/main/java/org/fugerit/java/doc/mod/openpdf/ext/helpers/OpenPpfDocHandler.java index 544cd7209..3705b4fad 100644 --- a/fj-doc-mod-openpdf-ext/src/main/java/org/fugerit/java/doc/mod/openpdf/ext/helpers/OpenPpfDocHandler.java +++ b/fj-doc-mod-openpdf-ext/src/main/java/org/fugerit/java/doc/mod/openpdf/ext/helpers/OpenPpfDocHandler.java @@ -8,41 +8,16 @@ import java.util.List; import java.util.Properties; -import org.fugerit.java.core.cfg.ConfigRuntimeException; +import com.lowagie.text.*; import org.fugerit.java.core.function.SafeFunction; import org.fugerit.java.core.lang.helpers.StringUtils; import org.fugerit.java.core.util.regex.ParamFinder; import org.fugerit.java.doc.base.config.DocConfig; import org.fugerit.java.doc.base.helper.SourceResolverHelper; -import org.fugerit.java.doc.base.model.DocBarcode; -import org.fugerit.java.doc.base.model.DocBase; -import org.fugerit.java.doc.base.model.DocElement; -import org.fugerit.java.doc.base.model.DocFooter; -import org.fugerit.java.doc.base.model.DocHeader; -import org.fugerit.java.doc.base.model.DocHeaderFooter; -import org.fugerit.java.doc.base.model.DocImage; -import org.fugerit.java.doc.base.model.DocInfo; -import org.fugerit.java.doc.base.model.DocPageBreak; -import org.fugerit.java.doc.base.model.DocPara; -import org.fugerit.java.doc.base.model.DocPhrase; -import org.fugerit.java.doc.base.model.DocStyle; -import org.fugerit.java.doc.base.model.DocTable; +import org.fugerit.java.doc.base.model.*; import org.fugerit.java.doc.base.typehelper.generic.GenericConsts; import org.fugerit.java.doc.base.xml.DocModelUtils; -import com.lowagie.text.Anchor; -import com.lowagie.text.BadElementException; -import com.lowagie.text.Chunk; -import com.lowagie.text.Document; -import com.lowagie.text.DocumentException; -import com.lowagie.text.Element; -import com.lowagie.text.Font; -import com.lowagie.text.Header; -import com.lowagie.text.HeaderFooter; -import com.lowagie.text.Image; -import com.lowagie.text.Paragraph; -import com.lowagie.text.Phrase; -import com.lowagie.text.Rectangle; import com.lowagie.text.html.HtmlTags; import com.lowagie.text.pdf.Barcode; import com.lowagie.text.pdf.Barcode128; @@ -277,12 +252,12 @@ private void handleTypeSpecific( Properties info ) { } protected void handleHeaderExt( DocHeader docHeader, PdfHelper pdfHelper, OpenPdfHelper docHelper ) throws DocumentException { - log.trace( "docHelper : {}", docHelper ); + log.trace( "handleHeaderExt docHelper : {}", docHelper ); pdfHelper.setDocHeader( docHeader ); } protected void handleFooterExt( DocFooter docFooter, PdfHelper pdfHelper, OpenPdfHelper docHelper ) throws DocumentException { - log.trace( "docHelper : {}", docHelper ); + log.trace( "handleFooterExt docHelper : {}", docHelper ); pdfHelper.setDocFooter( docFooter ); } @@ -352,11 +327,7 @@ public void handleDoc(DocBase docBase) throws DocumentException, IOException { } public static void handleElementsSafe( Document document, Iterator itDoc, OpenPdfHelper docHelper ) { - try { - handleElements(document, itDoc, docHelper); - } catch (Exception e) { - throw new ConfigRuntimeException( e ); - } + SafeFunction.apply( () -> handleElements(document, itDoc, docHelper) ); } public static void handleElements( Document document, Iterator itDoc, OpenPdfHelper docHelper ) throws DocumentException, IOException { @@ -365,35 +336,53 @@ public static void handleElements( Document document, Iterator itDoc getElement(document, docElement, true, docHelper ); } } - + + public static void checkAddElement( DocumentParent documentParent, boolean addElement, Element result ) { + if ( addElement ) { + documentParent.add( result ); + } + } + public static Element getElement( Document document, DocElement docElement, boolean addElement, OpenPdfHelper docHelper ) throws DocumentException, IOException { Element result = null; DocumentParent documentParent = new DocumentParent( document ); if ( docElement instanceof DocPhrase ) { result = createPhrase( (DocPhrase)docElement, docHelper ); - if ( addElement ) { - documentParent.add( result ); - } + checkAddElement( documentParent, addElement, result ); } else if ( docElement instanceof DocPara ) { result = createPara( (DocPara)docElement, docHelper ); - if ( addElement ) { - documentParent.add( result ); - } + checkAddElement( documentParent, addElement, result ); } else if ( docElement instanceof DocTable ) { result = OpenPdfDocTableHelper.createTable( (DocTable)docElement, docHelper ); - if ( addElement ) { - document.add( result ); - } + checkAddElement( documentParent, addElement, result ); } else if ( docElement instanceof DocImage ) { result = createImage( (DocImage)docElement ); - if ( addElement ) { - documentParent.add( result ); - } + checkAddElement( documentParent, addElement, result ); + } else if ( docElement instanceof DocList) { + result = createList( (DocList)docElement, docHelper ); + checkAddElement( documentParent, addElement, result ); } else if ( docElement instanceof DocPageBreak ) { document.newPage(); } return result; } + + private static com.lowagie.text.List createList( DocList docList, OpenPdfHelper docHelper ) throws IOException { + com.lowagie.text.List list = new com.lowagie.text.List( docList.isOrdered() ); + for ( DocElement element : docList.getElementList() ) { + if ( element instanceof DocLi ) { + DocLi li = (DocLi) element; + if ( li.getContent() instanceof DocPara ) { + list.add( new ListItem( createPara( (DocPara)li.getContent(), docHelper ) ) ); + } else { + docHelper.handelError( String.format( "unsupported type %s", li.getContent().getClass().getSimpleName() ) ); + } + } else { + docHelper.handelError( String.format( "wrong children%s", element.getClass().getSimpleName() ) ); + } + } + return list; + } private void handleHeaderFooterElement( DocElement docElement, float inputLeading, OpenPdfHelper docHelper , Phrase phrase ) throws DocumentException, IOException { float leading = inputLeading; diff --git a/fj-doc-mod-openpdf-ext/src/test/java/test/org/fugerit/java/doc/mod/openpdf/ext/TestOpenPdfHelper.java b/fj-doc-mod-openpdf-ext/src/test/java/test/org/fugerit/java/doc/mod/openpdf/ext/TestOpenPdfHelper.java index 01c17308f..c7e16365e 100644 --- a/fj-doc-mod-openpdf-ext/src/test/java/test/org/fugerit/java/doc/mod/openpdf/ext/TestOpenPdfHelper.java +++ b/fj-doc-mod-openpdf-ext/src/test/java/test/org/fugerit/java/doc/mod/openpdf/ext/TestOpenPdfHelper.java @@ -1,5 +1,15 @@ package test.org.fugerit.java.doc.mod.openpdf.ext; +import com.lowagie.text.Document; +import lombok.experimental.Helper; +import org.fugerit.java.core.function.SafeFunction; +import org.fugerit.java.core.lang.helpers.BooleanUtils; +import org.fugerit.java.doc.base.model.DocLi; +import org.fugerit.java.doc.base.model.DocList; +import org.fugerit.java.doc.base.model.DocTable; +import org.fugerit.java.doc.base.typehelper.generic.GenericConsts; +import org.fugerit.java.doc.mod.openpdf.ext.helpers.OpenPdfHelper; +import org.fugerit.java.doc.mod.openpdf.ext.helpers.OpenPpfDocHandler; import org.fugerit.java.doc.mod.openpdf.ext.helpers.PhraseParent; import org.junit.Assert; import org.junit.Test; @@ -7,6 +17,8 @@ import com.lowagie.text.Paragraph; import com.lowagie.text.Phrase; +import java.io.IOException; + public class TestOpenPdfHelper { @Test @@ -15,5 +27,23 @@ public void test001() throws Exception { parent.add( new Paragraph() ); Assert.assertNotNull( parent ); } - + + @Test + public void testList() { + OpenPdfHelper helper = new OpenPdfHelper(); + try ( Document document = new Document() ) { + DocList list1 = new DocList(); + list1.addElement( new DocTable() ); + list1.setListType(DocList.LIST_TYPE_OL); + Assert.assertThrows( IOException.class, () -> OpenPpfDocHandler.getElement( document, list1, false, helper ) ); + DocList list2 = new DocList(); + list2.setListType(DocList.LIST_TYPE_UL); + DocLi li2 = new DocLi(); + li2.addElement( new DocTable() ); + list2.addElement( li2 ); + helper.getParams().setProperty(GenericConsts.DOC_SUPPRESS_WRONG_TYPE_ERROR, BooleanUtils.BOOLEAN_1 ); + SafeFunction.apply( () -> OpenPpfDocHandler.getElement( document, list2, false, helper ) ); + } + } + } diff --git a/fj-doc-mod-openpdf-ext/src/test/java/test/org/fugerit/java/doc/mod/openpdf/ext/TestPdfHelper.java b/fj-doc-mod-openpdf-ext/src/test/java/test/org/fugerit/java/doc/mod/openpdf/ext/TestPdfHelper.java index a09918f73..39f42b571 100644 --- a/fj-doc-mod-openpdf-ext/src/test/java/test/org/fugerit/java/doc/mod/openpdf/ext/TestPdfHelper.java +++ b/fj-doc-mod-openpdf-ext/src/test/java/test/org/fugerit/java/doc/mod/openpdf/ext/TestPdfHelper.java @@ -25,7 +25,7 @@ public void testSetGet() { @Test public void testTandleElementSafe() { - Assert.assertThrows( ConfigRuntimeException.class , () -> OpenPpfDocHandler.handleElementsSafe(null, null, null) ); + Assert.assertThrows( NullPointerException.class , () -> OpenPpfDocHandler.handleElementsSafe(null, null, null) ); } @Test diff --git a/fj-doc-mod-openpdf-ext/src/test/resources/xml/default_doc.xml b/fj-doc-mod-openpdf-ext/src/test/resources/xml/default_doc.xml index 7e293e90b..d4ce79cc6 100644 --- a/fj-doc-mod-openpdf-ext/src/test/resources/xml/default_doc.xml +++ b/fj-doc-mod-openpdf-ext/src/test/resources/xml/default_doc.xml @@ -31,7 +31,12 @@ Courier Symbol Symbol - Test default font + Test default font 1 + +
  • list a
  • +
  • list b
  • +
  • list c
  • +
    Name