From f179c8db3574d03bb1b6b5be1bd86c9ea04073ad Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Fri, 20 Mar 2015 14:41:50 +0100 Subject: added Placeholder ID and Mode configuration settings --- .../pdfas/common/exceptions/ErrorConstants.java | 1 + .../at/gv/egiz/pdfas/common/settings/Settings.java | 1 - .../resources/resources/messages/error.properties | 4 +++- .../configuration/cfg/advancedconfig.properties | 12 +++++++++++ .../pdfas/lib/api/IConfigurationConstants.java | 3 +++ .../placeholder/PlaceholderExtractorConstants.java | 11 ++++++++++ .../lib/impl/placeholder/PlaceholderFilter.java | 24 ++++++++++++++++++++-- .../placeholder/SignaturePlaceholderExtractor.java | 8 ++------ 8 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderExtractorConstants.java diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/ErrorConstants.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/ErrorConstants.java index cf57f742..7c2fb03c 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/ErrorConstants.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/ErrorConstants.java @@ -25,4 +25,5 @@ public interface ErrorConstants { // Configuration Errors: public static final long ERROR_SET_INVALID_SETTINGS_OBJ = 13001; public static final long ERROR_INVALID_CERTIFICATE = 13002; + public static final long ERROR_INVALID_PLACEHOLDER_MODE = 13003; } diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/Settings.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/Settings.java index 1cb85f7f..f37ae452 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/Settings.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/Settings.java @@ -28,7 +28,6 @@ import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; -import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.List; diff --git a/pdf-as-common/src/main/resources/resources/messages/error.properties b/pdf-as-common/src/main/resources/resources/messages/error.properties index 386a824a..4f67fff6 100644 --- a/pdf-as-common/src/main/resources/resources/messages/error.properties +++ b/pdf-as-common/src/main/resources/resources/messages/error.properties @@ -22,4 +22,6 @@ 11018=Given Alias contains no private key 11019=Signature was created for wrong certificate -13001=Invalid Configuration Objects \ No newline at end of file +13001=Invalid Configuration Objects +13002=Given certificate is invalid +13003=Configured placeholder mode is invalid \ No newline at end of file diff --git a/pdf-as-lib/src/configuration/cfg/advancedconfig.properties b/pdf-as-lib/src/configuration/cfg/advancedconfig.properties index cfe6ffbc..ec88b448 100644 --- a/pdf-as-lib/src/configuration/cfg/advancedconfig.properties +++ b/pdf-as-lib/src/configuration/cfg/advancedconfig.properties @@ -21,6 +21,18 @@ #enable_placeholder_search=true +# These values should be configured at runtime: + +# Set this for placeholder Identifier +# default is unset +#placeholder_id= + +# Set this for placeholder Mode +# MATCH_MODE_STRICT = 0 +# MATCH_MODE_MODERATE = 1 +# MATCH_MODE_LENIENT = 2 +#placeholder_mode= + ################## # Signaturdienste diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java index 24af4ad8..c1fd4fe5 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java @@ -43,6 +43,9 @@ public interface IConfigurationConstants { public static final String LEGACY_POSITIONING = ".legacy.pos"; + public static final String PLACEHOLDER_ID = "placeholder_id"; + public static final String PLACEHOLDER_MODE = "placeholder_mode"; + public static final String PLACEHOLDER_SEARCH_ENABLED = "enable_placeholder_search"; public static final String DEFAULT_SIGNATURE_PROFILE = SIG_OBJECT + SEPERATOR + TYPE + SEPERATOR + DEFAULT; diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderExtractorConstants.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderExtractorConstants.java new file mode 100644 index 00000000..2d898dd5 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderExtractorConstants.java @@ -0,0 +1,11 @@ +package at.gv.egiz.pdfas.lib.impl.placeholder; + +public interface PlaceholderExtractorConstants { + public static final String QR_PLACEHOLDER_IDENTIFIER = "PDF-AS-POS"; + public static final int PLACEHOLDER_MATCH_MODE_STRICT = 0; + public static final int PLACEHOLDER_MATCH_MODE_MODERATE = 1; + public static final int PLACEHOLDER_MATCH_MODE_LENIENT = 2; + + public static final int PLACEHOLDER_MODE_MIN = 0; + public static final int PLACEHOLDER_MODE_MAX = 2; +} 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 1417f634..19ea496d 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 @@ -25,12 +25,15 @@ package at.gv.egiz.pdfas.lib.impl.placeholder; import java.io.IOException; +import at.gv.egiz.pdfas.common.exceptions.PDFASError; +import at.gv.egiz.pdfas.common.exceptions.PdfAsErrorCarrier; import at.gv.egiz.pdfas.common.exceptions.PdfAsException; import at.gv.egiz.pdfas.common.settings.ISettings; import at.gv.egiz.pdfas.lib.api.IConfigurationConstants; import at.gv.egiz.pdfas.lib.impl.status.OperationStatus; -public class PlaceholderFilter implements IConfigurationConstants { +public class PlaceholderFilter implements IConfigurationConstants, + PlaceholderExtractorConstants { public static SignaturePlaceholderData checkPlaceholderSignature( OperationStatus status, ISettings settings) throws PdfAsException, @@ -39,8 +42,25 @@ public class PlaceholderFilter implements IConfigurationConstants { if (status.getPlaceholderConfiguration().isGlobalPlaceholderEnabled()) { PlaceholderExtractor extractor = status.getBackend() .getPlaceholderExtractor(); + String placeholderID = settings.getValue(PLACEHOLDER_ID); + String placeholderModeString = settings.getValue(PLACEHOLDER_MODE); + int placeholderMode = PLACEHOLDER_MATCH_MODE_MODERATE; + if (placeholderModeString != null) { + 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)); + } + } SignaturePlaceholderData signaturePlaceholderData = extractor - .extract(status.getPdfObject(), null, 1); + .extract(status.getPdfObject(), placeholderID, placeholderMode); return signaturePlaceholderData; } diff --git a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox/placeholder/SignaturePlaceholderExtractor.java b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox/placeholder/SignaturePlaceholderExtractor.java index 9d2f7717..85849109 100644 --- a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox/placeholder/SignaturePlaceholderExtractor.java +++ b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox/placeholder/SignaturePlaceholderExtractor.java @@ -73,6 +73,7 @@ import org.slf4j.LoggerFactory; import at.gv.egiz.pdfas.common.exceptions.PDFIOException; import at.gv.egiz.pdfas.common.exceptions.PdfAsException; import at.gv.egiz.pdfas.common.exceptions.PlaceholderExtractionException; +import at.gv.egiz.pdfas.lib.impl.placeholder.PlaceholderExtractorConstants; import at.gv.egiz.pdfas.lib.impl.placeholder.SignaturePlaceholderContext; import at.gv.egiz.pdfas.lib.impl.placeholder.SignaturePlaceholderData; import at.knowcenter.wag.egov.egiz.pdf.TablePos; @@ -94,18 +95,13 @@ import com.google.zxing.common.HybridBinarizer; * @author exthex * */ -public class SignaturePlaceholderExtractor extends PDFStreamEngine { +public class SignaturePlaceholderExtractor extends PDFStreamEngine implements PlaceholderExtractorConstants{ /** * The log. */ private static Logger logger = LoggerFactory .getLogger(SignaturePlaceholderExtractor.class); - public static final String QR_PLACEHOLDER_IDENTIFIER = "PDF-AS-POS"; - public static final int PLACEHOLDER_MATCH_MODE_STRICT = 0; - public static final int PLACEHOLDER_MATCH_MODE_MODERATE = 1; - public static final int PLACEHOLDER_MATCH_MODE_LENIENT = 2; - private List placeholders = new Vector(); private int currentPage = 0; -- cgit v1.2.3