From f07b4c97047df0e086fd6abfe4b50cc4498e91f3 Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Wed, 28 Aug 2024 15:49:46 +0200 Subject: [PATCH] fixed [fj-doc-mod-fop] java.lang.IllegalArgumentException: Not supported: http://javax.xml.XMLConstants/property/accessExternalDTD --- CHANGELOG.md | 4 ++ .../java/doc/mod/fop/PdfFopTypeHandler.java | 63 +++++++++---------- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfcce509d..c3651a2de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- [fj-doc-mod-fop] java.lang.IllegalArgumentException: Not supported: http://javax.xml.XMLConstants/property/accessExternalDTD + ## [8.7.2] - 2024-08-28 ### Changed 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 3c76eda5f..ddffa28e4 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 @@ -24,7 +24,6 @@ import org.fugerit.java.core.lang.helpers.BooleanUtils; import org.fugerit.java.core.lang.helpers.ClassHelper; import org.fugerit.java.core.lang.helpers.StringUtils; -import org.fugerit.java.core.xml.TransformerXML; import org.fugerit.java.core.xml.dom.DOMIO; import org.fugerit.java.core.xml.dom.DOMUtils; import org.fugerit.java.doc.base.config.DocCharsetProvider; @@ -44,20 +43,20 @@ public class PdfFopTypeHandler extends FreeMarkerFopTypeHandler { public static final DocTypeHandler HANDLER = new PdfFopTypeHandler(); - + public static final String ATT_FOP_CONFIG_MODE = "fop-config-mode"; public static final String ATT_FOP_CONFIG_MODE_DEFAULT = "default"; public static final String ATT_FOP_CONFIG_MODE_CLASS_LOADER = "classloader"; public static final String ATT_FOP_CONFIG_MODE_INLINE = "inline"; - + private static final String ATT_FOP_CONFIG_MODE_CLASS_LOADER_LEGACY = "classloader-legacy"; // removed as of v2.0.1 - + public static final String ATT_FOP_CONFIG_CLASSLOADER_PATH = "fop-config-classloader-path"; - + public static final String ATT_FOP_CONFIG_RESOLVER_TYPE = "fop-config-resover-type"; 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; @@ -66,19 +65,19 @@ public class PdfFopTypeHandler extends FreeMarkerFopTypeHandler { public static final String ATT_PDF_UA_MODE = "pdf-ua-mode"; public static final String ATT_PDF_UA_MODE_PDF_UA_1 = DocConfig.FORMAT_PDF_UA_1; - + private static final String[] VALID_PDF_A = { ATT_PDF_A_MODE_PDF_A_1A, ATT_PDF_A_MODE_PDF_A_1B, ATT_PDF_A_MODE_PDF_A_2A }; public static final List VALID_PDF_A_MODES = Collections.unmodifiableList( Arrays.asList( VALID_PDF_A ) ); - + private static final String[] VALID_PDF_UA = { ATT_PDF_UA_MODE_PDF_UA_1 }; public static final List VALID_PDF_UA_MODES = Collections.unmodifiableList( Arrays.asList( VALID_PDF_UA ) ); - + private static final String ATT_FONT_BASE_CLASSLOADER_PATH = "font-base-classloader-path"; // removed as of v2.0.1 - + public static final boolean DEFAULT_ACCESSIBILITY = true; - + public static final boolean DEFAULT_KEEP_EMPTY_TAGS = false; - + public static final String ATT_FOP_SUPPRESS_EVENTS = "fop-suppress-events"; public static final String ATT_FOP_POOL_MIN = "fop-pool-min"; @@ -86,16 +85,16 @@ public class PdfFopTypeHandler extends FreeMarkerFopTypeHandler { public static final String ATT_FOP_POOL_MAX = "fop-pool-max"; private static final String FOP_CONFIG_ROOT = "fop"; - + /** - * + * */ private static final long serialVersionUID = -7394516771708L; @Getter private boolean accessibility; - + @Getter private boolean keepEmptyTags; - + private Serializable fopConfig; public FopConfig getFopConfig() { @@ -107,9 +106,9 @@ public void setFopConfig(FopConfig fopConfig) { } @Getter @Setter private String pdfAMode; - + @Getter @Setter private String pdfUAMode; - + @Getter @Setter private boolean suppressEvents; @Getter @Setter private transient int fopPoolMin; @@ -121,7 +120,7 @@ public void setFopConfig(FopConfig fopConfig) { private transient UnsafeSupplier fopWrapSupplier; private transient UnsafeConsumer fopWrapConsumer; - + public PdfFopTypeHandler( Charset charset, FopConfig fopConfig, boolean accessibility, boolean keepEmptyTags ) { super( DocConfig.TYPE_PDF, charset ); this.fopConfig = fopConfig; @@ -133,27 +132,27 @@ public PdfFopTypeHandler( Charset charset, FopConfig fopConfig, boolean accessib this.fopPoolMin = 0; this.fopPoolMax = 0; } - + public PdfFopTypeHandler( Charset charset, FopConfig fopConfig ) { this( charset, fopConfig, DEFAULT_ACCESSIBILITY, DEFAULT_KEEP_EMPTY_TAGS ); } - + public PdfFopTypeHandler( FopConfig fopConfig, boolean accessibility, boolean keepEmptyTags ) { this( DocCharsetProvider.getDefaultProvider().resolveCharset( null ), fopConfig, accessibility, keepEmptyTags ); } - + public PdfFopTypeHandler( Charset charset, boolean accessibility, boolean keepEmptyTags ) { this( charset, FopConfigDefault.DEFAULT, accessibility, keepEmptyTags ); } - + public PdfFopTypeHandler( Charset charset ) { this( charset, DEFAULT_ACCESSIBILITY, DEFAULT_KEEP_EMPTY_TAGS ); } - + public PdfFopTypeHandler( boolean accessibility, boolean keepEmptyTags ) { this( FopConfigDefault.DEFAULT, accessibility, keepEmptyTags ); } - + public PdfFopTypeHandler() { this( DEFAULT_ACCESSIBILITY, DEFAULT_KEEP_EMPTY_TAGS ); } @@ -190,7 +189,7 @@ public void handle(DocInput docInput, DocOutput docOutput) throws Exception { StreamSource xmlSource = new StreamSource( new InputStreamReader( new ByteArrayInputStream( buffer.toByteArray() ), this.getCharset() ) ); FopConfigWrap fopWrap = this.fopWrapSupplier.get(); Fop fop = fopWrap.getFopFactory().newFop(MimeConstants.MIME_PDF, fopWrap.getFoUserAgent(), docOutput.getOs()); - TransformerFactory factory = TransformerXML.newSafeTransformerFactory(); + TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); Result res = new SAXResult(fop.getDefaultHandler()); transformer.transform(xmlSource, res); @@ -211,7 +210,7 @@ protected void handleConfigTag(Element config) throws ConfigException { log.info( "pdf ua mode -> {} : {}", ATT_PDF_UA_MODE, pdfUAModConfig ); if ( VALID_PDF_UA_MODES.contains( pdfUAModConfig ) ) { this.setPdfUAMode( pdfUAModConfig ); - this.setFormat( pdfUAModConfig ); + this.setFormat( pdfUAModConfig ); } else { throw new ConfigException( ATT_PDF_UA_MODE+" not valid : "+pdfUAModConfig+"( valid modes are : "+VALID_PDF_A_MODES+")" ); } @@ -222,7 +221,7 @@ protected void handleConfigTag(Element config) throws ConfigException { log.info( "pdf a mode -> {} : {}", ATT_PDF_A_MODE, pdfAModConfig ); if ( VALID_PDF_A_MODES.contains( pdfAModConfig ) ) { this.setPdfAMode( pdfAModConfig ); - this.setFormat( pdfAModConfig ); + this.setFormat( pdfAModConfig ); } else { throw new ConfigException( ATT_PDF_A_MODE+" not valid : "+pdfAModConfig+"( valid modes are : "+VALID_PDF_A_MODES+")" ); } @@ -251,7 +250,7 @@ private void setupPool( Properties props ) throws ConfigException { } if ( StringUtils.isNotEmpty( props.getProperty( ATT_FOP_POOL_MAX ) ) ) { this.setFopPoolMax( Integer.parseInt( props.getProperty( ATT_FOP_POOL_MAX ) ) ); - } else if ( this.getFopPoolMin() > 0 ) { + } else if ( this.getFopPoolMin() > 0 ) { this.setFopPoolMax( this.getFopPoolMin() ); } } @@ -261,7 +260,7 @@ private void setupFopConfigMode( String fopConfigMode, String fopConfigResoverTy ConfigException.apply( () -> { ResourceResolver customResourceResolver = (ResourceResolver) ClassHelper.newInstance( fopConfigResoverType ); FopConfigClassLoaderWrapper fopConfigClassLoaderWrapper = new FopConfigClassLoaderWrapper(fopConfigClassloaderPath, customResourceResolver); - this.fopConfig = fopConfigClassLoaderWrapper; + this.fopConfig = fopConfigClassLoaderWrapper; } ); } else if ( ATT_FOP_CONFIG_MODE_INLINE.equalsIgnoreCase( fopConfigMode ) ) { ConfigException.apply( () -> { @@ -273,10 +272,10 @@ private void setupFopConfigMode( String fopConfigMode, String fopConfigResoverTy try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) { DOMIO.writeDOM( nl.item( 0 ) , baos); fopConfigInlineData = baos.toByteArray(); - } + } ResourceResolver customResourceResolver = (ResourceResolver) ClassHelper.newInstance( fopConfigResoverType ); FopConfigClassLoaderWrapper fopConfigClassLoaderWrapper = new FopConfigClassLoaderWrapper(fopConfigInlineData, customResourceResolver); - this.fopConfig = fopConfigClassLoaderWrapper; + this.fopConfig = fopConfigClassLoaderWrapper; } ); } else if ( ATT_FOP_CONFIG_MODE_CLASS_LOADER_LEGACY.equalsIgnoreCase( fopConfigMode ) ) { log.warn( "Activated legacy ClassLoader mode. it is now deprecated : {}", ATT_FOP_CONFIG_MODE_CLASS_LOADER_LEGACY );