From 02312d367a83ad9e5a59636e9949c5243aab727a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Luis=20Rodr=C3=ADguez=20Ponce?= Date: Wed, 15 Jun 2022 10:47:24 +0200 Subject: [PATCH] [BP] Switch from iText to OpenPDF for PDF map rendering (4.0.x) (#6393) * [BP] Switch from itext to openpdf for PDF map rendering (#6343) * Switch from iText to OpenPDF for PDF map rendering. * Change to mapfish-print 2.2.x based on OpenPDF. * Remove duplicate maven-assembly-plugin for dublin-core/pom.xml resolving warning. * Change Diff to use org.bitbucket.cowwoc:diff-match-patch:1.2 dependency from maven central. This is a fork of google code diff-match-patch:diff-match-patch:current adapted to java naming conventions and available from maven central. It is by far the most popular fork of this algorithm. By adopting this dependency we avoid the need to use https://maven.repository.redhat.com/ga/ improving build times. * Use mapfish-print 2.2.0 release. Backport of https://github.com/geonetwork/core-geonetwork/pull/6343 * Remove unused import Co-authored-by: Jody Garnett --- common/pom.xml | 4 +- .../main/java/org/fao/geonet/utils/Diff.java | 15 ++- core/pom.xml | 9 ++ .../kernel/thumbnail/ThumbnailMaker.java | 20 +-- pom.xml | 114 ++++++------------ schemas/dublin-core/pom.xml | 18 --- services/pom.xml | 2 +- .../api/records/formatters/FormatterApi.java | 2 +- .../ImageReplacedElementFactory.java | 2 +- web/pom.xml | 8 ++ 10 files changed, 71 insertions(+), 123 deletions(-) diff --git a/common/pom.xml b/common/pom.xml index 79872a24145..24bb8f48ff6 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -171,8 +171,8 @@ compile - diff_match_patch - diff_match_patch + org.bitbucket.cowwoc + diff-match-patch diff --git a/common/src/main/java/org/fao/geonet/utils/Diff.java b/common/src/main/java/org/fao/geonet/utils/Diff.java index e874d69924b..edfb0c8b520 100644 --- a/common/src/main/java/org/fao/geonet/utils/Diff.java +++ b/common/src/main/java/org/fao/geonet/utils/Diff.java @@ -1,24 +1,23 @@ package org.fao.geonet.utils; -import name.fraser.neil.plaintext.diff_match_patch; -import org.jdom.Element; +import org.bitbucket.cowwoc.diffmatchpatch.DiffMatchPatch; import java.util.LinkedList; public class Diff { public static String diff(String oldVersion, String newVersion, DiffType diffType) { - diff_match_patch dmp = new diff_match_patch(); + DiffMatchPatch dmp = new DiffMatchPatch(); if (DiffType.patch.equals(diffType)) { - LinkedList diffs = - dmp.patch_make(oldVersion, newVersion); + LinkedList diffs = + dmp.patchMake(oldVersion, newVersion); return diffs.toString(); } else if (DiffType.diff.equals(diffType)) { - LinkedList diffs = dmp.diff_main(oldVersion, newVersion); + LinkedList diffs = dmp.diffMain(oldVersion, newVersion); return diffs.toString(); } else { - LinkedList diffs = dmp.diff_main(oldVersion, newVersion); - return dmp.diff_prettyHtml(diffs); + LinkedList diffs = dmp.diffMain(oldVersion, newVersion); + return dmp.diffPrettyHtml(diffs); } } } diff --git a/core/pom.xml b/core/pom.xml index 170cab71f96..cce2cd1b80d 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -373,10 +373,19 @@ + + com.github.librepdf + openpdf + org.mapfish.print print-lib + + + com.itextpdf + itextpdf + commons-httpclient commons-httpclient diff --git a/core/src/main/java/org/fao/geonet/kernel/thumbnail/ThumbnailMaker.java b/core/src/main/java/org/fao/geonet/kernel/thumbnail/ThumbnailMaker.java index 3ac0fa272d7..424ba57bbdc 100644 --- a/core/src/main/java/org/fao/geonet/kernel/thumbnail/ThumbnailMaker.java +++ b/core/src/main/java/org/fao/geonet/kernel/thumbnail/ThumbnailMaker.java @@ -1,5 +1,5 @@ //============================================================================= -//=== Copyright (C) 2001-2014 Food and Agriculture Organization of the +//=== Copyright (C) 2001-2022 Food and Agriculture Organization of the //=== United Nations (FAO-UN), United Nations World Food Programme (WFP) //=== and United Nations Environment Programme (UNEP) //=== @@ -24,8 +24,6 @@ package org.fao.geonet.kernel.thumbnail; import jeeves.server.context.ServiceContext; - -import org.dom4j.DocumentException; import org.fao.geonet.constants.Geonet; import org.fao.geonet.utils.IO; import org.fao.geonet.utils.Log; @@ -36,23 +34,17 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; -import java.awt.Graphics2D; -import java.awt.Transparency; +import javax.imageio.ImageIO; +import java.awt.*; import java.awt.image.BufferedImage; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import java.io.*; import java.nio.file.Files; import java.nio.file.Path; import java.util.HashMap; -import javax.imageio.ImageIO; - /** * Use MapFish print module to generate thumbnail. - * + *

* Created by francois on 3/25/14. */ public class ThumbnailMaker { @@ -150,7 +142,7 @@ private MapPrinter getMapPrinter() { } public Path generateThumbnail(String jsonConfig, Integer rotationAngle) - throws IOException, DocumentException, com.itextpdf.text.DocumentException { + throws IOException { PJsonObject specJson = MapPrinter.parseSpec(jsonConfig); if (Log.isDebugEnabled(LOGGER_NAME)) { diff --git a/pom.xml b/pom.xml index 462ba2fa84f..bc2a7d0a714 100644 --- a/pom.xml +++ b/pom.xml @@ -428,11 +428,11 @@ - + + com.github.librepdf + openpdf + 1.3.26 + org.apache.xmlgraphics fop @@ -813,7 +813,7 @@ org.mapfish.print print-lib - 2.1.6 + 2.2.0 @@ -912,19 +912,11 @@ mysql-connector-java 8.0.20 - - - com.oracle.database.jdbc ojdbc8 19.6.0.0 + org.codehaus.izpack @@ -1097,14 +1089,8 @@ org.xhtmlrenderer - flying-saucer-pdf-itext5 + flying-saucer-pdf-openpdf ${flying-saucer} - - - com.itextpdf - itextpdf - - com.fasterxml.jackson.core @@ -1162,9 +1148,9 @@ ${jasypt.version} - diff_match_patch - diff_match_patch - current + org.bitbucket.cowwoc + diff-match-patch + 1.2 @@ -1194,70 +1180,42 @@ - + + + + + + + + + + + + + false osgeo - OSGeo repository + OSGeo Release repository https://repo.osgeo.org/repository/release/ - - redhat - https://maven.repository.redhat.com/ga/ - - - - - - - - - - - - - - - - - - + @@ -1542,7 +1500,7 @@ 23.0 - 42.2.5 + 42.3.3 5.2.6.RELEASE 5.2.5.RELEASE @@ -1561,10 +1519,10 @@ 5.8.0 2.1.1 2.10.4 - 9.0.7 + 9.1.22 2.25.1 1.2.17 - 2.17.1 + 2.17.2 1.8.0-beta2 3.18 1.6.0 diff --git a/schemas/dublin-core/pom.xml b/schemas/dublin-core/pom.xml index 16bb148377e..2313856c9bd 100644 --- a/schemas/dublin-core/pom.xml +++ b/schemas/dublin-core/pom.xml @@ -65,24 +65,6 @@ - - maven-assembly-plugin - - - plugin-assembly - package - single - false - - false - - src/assembly/schema-plugin.xml - - - - - - diff --git a/services/pom.xml b/services/pom.xml index 1260213164d..77e35adbac6 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -147,7 +147,7 @@ org.xhtmlrenderer - flying-saucer-pdf-itext5 + flying-saucer-pdf-openpdf com.fasterxml.jackson.core diff --git a/services/src/main/java/org/fao/geonet/api/records/formatters/FormatterApi.java b/services/src/main/java/org/fao/geonet/api/records/formatters/FormatterApi.java index 31650bb710a..9480ab14cd3 100644 --- a/services/src/main/java/org/fao/geonet/api/records/formatters/FormatterApi.java +++ b/services/src/main/java/org/fao/geonet/api/records/formatters/FormatterApi.java @@ -527,7 +527,7 @@ private String getXmlFromUrl(ServiceContext context, String lang, String url, We return new String(ByteStreams.toByteArray(execute.getBody()), Constants.CHARSET); } - private void writerAsPDF(ServiceContext context, HttpServletResponse response, byte[] bytes, String lang) throws IOException, com.itextpdf.text.DocumentException { + private void writerAsPDF(ServiceContext context, HttpServletResponse response, byte[] bytes, String lang) throws IOException, com.lowagie.text.DocumentException { final String htmlContent = new String(bytes, Constants.CHARSET); try { XslUtil.setNoScript(); diff --git a/services/src/main/java/org/fao/geonet/api/records/formatters/ImageReplacedElementFactory.java b/services/src/main/java/org/fao/geonet/api/records/formatters/ImageReplacedElementFactory.java index c0a6e148b8a..25e4423b650 100644 --- a/services/src/main/java/org/fao/geonet/api/records/formatters/ImageReplacedElementFactory.java +++ b/services/src/main/java/org/fao/geonet/api/records/formatters/ImageReplacedElementFactory.java @@ -25,7 +25,7 @@ import com.google.common.collect.Sets; import com.google.common.io.Files; -import com.itextpdf.text.Image; +import com.lowagie.text.Image; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.fao.geonet.api.ApiUtils; diff --git a/web/pom.xml b/web/pom.xml index 40dfad187b2..35dd5fd7dea 100644 --- a/web/pom.xml +++ b/web/pom.xml @@ -281,10 +281,18 @@ + + com.github.librepdf + openpdf + org.mapfish.print print-lib + + com.lowagie + itext + commons-httpclient commons-httpclient