From b0b9a063b8ef0641839206fd574dc62f96da162c Mon Sep 17 00:00:00 2001 From: tknall Date: Fri, 28 Jan 2011 11:06:52 +0000 Subject: Logging in case of too small signature blocks extended (now a warning is logged regardless the fact WHY a signature block is small (API, Placeholder or Configuration)). The default threshold value is 150. An optional configuration key (global "default.signature_block_width_warning_threshold=xyz" and local per profile "sig_obj.PROFILE.signature_block_width_warning_threshold=xyz") has been added in order to make the threshold configurable (there might be profiles some day that need to be small, e.g. some versions of minimal layout blocks). git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@739 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../at/gv/egiz/pdfas/impl/api/PdfAsObject.java | 61 +++++++++++++++++++--- .../impl/signator/binary/BinarySignator_1_0_0.java | 2 +- 2 files changed, 54 insertions(+), 9 deletions(-) (limited to 'src/main/java/at/gv') diff --git a/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java b/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java index 4cc6b69..4bf41d4 100644 --- a/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java +++ b/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java @@ -79,6 +79,7 @@ import at.knowcenter.wag.egov.egiz.exceptions.SettingsException; import at.knowcenter.wag.egov.egiz.exceptions.SignatorFactoryException; import at.knowcenter.wag.egov.egiz.exceptions.SignatureException; import at.knowcenter.wag.egov.egiz.framework.SignatorFactory; +import at.knowcenter.wag.egov.egiz.pdf.AdobeSignatureHelper; import at.knowcenter.wag.egov.egiz.pdf.BinarySignatureHolder; import at.knowcenter.wag.egov.egiz.pdf.NoSignatureHolder; import at.knowcenter.wag.egov.egiz.pdf.ObjectExtractor; @@ -109,6 +110,17 @@ public class PdfAsObject implements PdfAs private static final String ENABLE_PLACEHOLDER_SEARCH_KEY = "enable_placeholder_search"; + /** + * Configuration key for minimal signature block width threshold. Any width below this certain value will lead to a warning log entry." + */ + private static final String SIGNATURE_BLOCK_WIDTH_THRESHOLD_FOR_WARNING_KEY = "signature_block_width_warning_threshold"; + + /** + * Minimal signature block width. If a width below that value is defined (by parameter, by placeholder or by configuration) a warning log entry is created. + */ + public static final float DEFAULT_SIGNATURE_BLOCK_WIDTH_THRESHOLD = 150; + + /** * This constructor is for internal use only - use * {@link at.gv.egiz.pdfas.PdfAsFactory} instead. @@ -652,21 +664,54 @@ public class PdfAsObject implements PdfAs } boolean fromPlaceholder = false; + boolean fromSignParameters = false; + boolean fromConfig = false; TablePos pos = null; if (spd != null && spd.getTablePos() != null){ + // position and width is determined by placeholder image fromPlaceholder = true; pos = spd.getTablePos(); } else { + // position and width is determined by api sign parameters pos = PosHelper.formTablePos(signParameters.getSignaturePositioning()); + if (pos != null) { + fromSignParameters = true; + } } - - if (pos != null && !pos.isWauto() && pos.getWidth() < 150) { - // very small, warn user - String msg = "The {0} for the signature ({1}) is very small. The signature block might not get placed correcty."; - String[] arguments = new String[]{ "given width", "" + pos.getWidth()}; - if (fromPlaceholder) - arguments[0] = "width of the placeholder image that will be used"; - log.warn(MessageFormat.format(msg, arguments)); + + TablePos effectivePos = pos; + if (effectivePos == null) { + String pos_string = settings.getSetting(SignatureTypes.SIG_OBJ + signParameters.getSignatureProfileId() + ".pos", null); + if (pos_string != null) { + // position and width is determined by profile configuration + effectivePos = PdfAS.parsePositionFromPosString(pos_string); + fromConfig = true; + } + } + if (effectivePos != null) { + // check if width is lower than the smallest meaningful width + String thresholdString = AdobeSignatureHelper.getDefaultableConfigProperty(signParameters.getSignatureProfileId(), SIGNATURE_BLOCK_WIDTH_THRESHOLD_FOR_WARNING_KEY, String.valueOf(DEFAULT_SIGNATURE_BLOCK_WIDTH_THRESHOLD)); + float threshold = DEFAULT_SIGNATURE_BLOCK_WIDTH_THRESHOLD; + try { + threshold = Float.parseFloat(thresholdString); + } catch (NumberFormatException e) { + if (log.isDebugEnabled()) { + log.debug("Unable to parse threshold value (\"" + thresholdString + "\") of configuration value \"" + SIGNATURE_BLOCK_WIDTH_THRESHOLD_FOR_WARNING_KEY + "\". Using default value: " + DEFAULT_SIGNATURE_BLOCK_WIDTH_THRESHOLD); + } + } + if (!effectivePos.isWauto() && effectivePos.getWidth() < threshold) { + String msg = "The {0} for the signature block is very small ({1}). The signature block might not get placed correcty."; + String[] arguments = new String[]{ "given width", "" + effectivePos.getWidth()}; + // very small, warn user + if (fromPlaceholder) { + arguments[0] = "width given by the placeholder image"; + } else if (fromSignParameters) { + arguments[0] = "width defined by the sign parameters"; + } else if (fromConfig) { + arguments[0] = "width defined by the profile " + signParameters.getSignatureProfileId(); + } + log.warn(MessageFormat.format(msg, arguments)); + } } Signator signator = createSignator(signParameters.getSignatureType()); diff --git a/src/main/java/at/gv/egiz/pdfas/impl/signator/binary/BinarySignator_1_0_0.java b/src/main/java/at/gv/egiz/pdfas/impl/signator/binary/BinarySignator_1_0_0.java index 3d4be31..821d633 100644 --- a/src/main/java/at/gv/egiz/pdfas/impl/signator/binary/BinarySignator_1_0_0.java +++ b/src/main/java/at/gv/egiz/pdfas/impl/signator/binary/BinarySignator_1_0_0.java @@ -140,7 +140,7 @@ public class BinarySignator_1_0_0 implements Signator boolean baikEnabled = "true".equalsIgnoreCase(baikStr); if (baikEnabled) { - log.debug("found baik enabled signature"); + log.debug("BAIK enabled signature"); } SignatureObject signature_object = PdfAS.createSignatureObjectFromType(profile); -- cgit v1.2.3