From aa45585a4cb9e7aff0ef3da3c6a6fe43b9ace98c Mon Sep 17 00:00:00 2001 From: Alexander Marsalek Date: Tue, 20 Apr 2021 21:12:16 +0200 Subject: fix? --- .../lib/impl/placeholder/PlaceholderExtractor.java | 4 ++ .../lib/impl/placeholder/PlaceholderFilter.java | 63 ++++++++++++++++++++++ 2 files changed, 67 insertions(+) (limited to 'pdf-as-lib/src/main/java') diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderExtractor.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderExtractor.java index 4c352b90..0a55b834 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderExtractor.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderExtractor.java @@ -3,6 +3,10 @@ package at.gv.egiz.pdfas.lib.impl.placeholder; import at.gv.egiz.pdfas.common.exceptions.PdfAsException; import at.gv.egiz.pdfas.lib.impl.status.PDFObject; +import java.util.List; + public interface PlaceholderExtractor { SignaturePlaceholderData extract(PDFObject doc, String placeholderId, int matchMode) throws PdfAsException; + + List extractList(PDFObject pdfObject, String placeholderID, int placeholderMode) throws PdfAsException; } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderFilter.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderFilter.java index 500b9e24..99c09295 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderFilter.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderFilter.java @@ -24,6 +24,7 @@ package at.gv.egiz.pdfas.lib.impl.placeholder; import java.io.IOException; +import java.util.List; import at.gv.egiz.pdfas.common.exceptions.PDFASError; import at.gv.egiz.pdfas.common.exceptions.PdfAsErrorCarrier; @@ -102,4 +103,66 @@ public class PlaceholderFilter implements IConfigurationConstants, return null; } + public static List checkPlaceholderSignatureLocationList(OperationStatus status, ISettings settings, String signatureLocation) throws PdfAsException, + IOException { + String placeholderID; + + if (status.getPlaceholderConfiguration().isGlobalPlaceholderEnabled()) { + PlaceholderExtractor extractor = status.getBackend().getPlaceholderExtractor(); + + if(StringUtils.isNotEmpty(signatureLocation)) { + placeholderID = signatureLocation; + } else { + placeholderID = PlaceholderWebConfiguration.getValue(PLACEHOLDER_WEB_ID); + if(StringUtils.isEmpty(placeholderID)) { + placeholderID = settings.getValue(PLACEHOLDER_ID); + } + } + + String placeholderModeString = settings.getValue(PLACEHOLDER_MODE); + int placeholderMode = PLACEHOLDER_MATCH_MODE_MODERATE; + if (StringUtils.isNotEmpty(placeholderModeString)) { + try { + placeholderMode = Integer.parseInt(placeholderModeString); + if (placeholderMode < PLACEHOLDER_MODE_MIN + || placeholderMode > PLACEHOLDER_MODE_MAX) { + throw new PdfAsErrorCarrier(new PDFASError( + PDFASError.ERROR_INVALID_PLACEHOLDER_MODE)); + } + } catch (NumberFormatException e) { + throw new PdfAsErrorCarrier(new PDFASError( + PDFASError.ERROR_INVALID_PLACEHOLDER_MODE, e)); + } + } + return extractor.extractList(status.getPdfObject(), placeholderID, + placeholderMode); + + } else if (status.getPlaceholderConfiguration().isProfileConfigurationEnabled(status.getRequestedSignature().getSignatureProfileID())) { + //filter for local placeholder in selected profiles + PlaceholderExtractor extractor = status.getBackend().getPlaceholderExtractor(); + int placeholderMode = PLACEHOLDER_MATCH_MODE_SORTED; + + placeholderID = status.getPlaceholderConfiguration().getProfilePlaceholderID(status.getRequestedSignature().getSignatureProfileID()); + if(StringUtils.isNotEmpty(placeholderID)) { + placeholderMode = PLACEHOLDER_MATCH_MODE_MODERATE; + } + String placeholderModeString = settings.getValue(PLACEHOLDER_MODE); + if (StringUtils.isNotEmpty(placeholderModeString)) { + try { + placeholderMode = Integer.parseInt(placeholderModeString); + if (placeholderMode < PLACEHOLDER_MODE_MIN + || placeholderMode > PLACEHOLDER_MODE_MAX) { + throw new PdfAsErrorCarrier(new PDFASError( + PDFASError.ERROR_INVALID_PLACEHOLDER_MODE)); + } + } catch (NumberFormatException e) { + throw new PdfAsErrorCarrier(new PDFASError( + PDFASError.ERROR_INVALID_PLACEHOLDER_MODE, e)); + } + } + return extractor.extractList(status.getPdfObject(), placeholderID, + placeholderMode); + } + return null; + } } \ No newline at end of file -- cgit v1.2.3