From f9e1c1419ebfccb6343460a989ed891054358bef Mon Sep 17 00:00:00 2001 From: pdanner Date: Tue, 7 Dec 2010 09:53:11 +0000 Subject: Added enable_placeholder_search config parameter git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@692 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../at/gv/egiz/pdfas/impl/api/PdfAsObject.java | 71 ++++++++++++++++------ 1 file changed, 54 insertions(+), 17 deletions(-) (limited to 'src/main/java/at/gv/egiz/pdfas/impl') 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 2c9a9ad..dc6e106 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 @@ -39,6 +39,7 @@ import at.gv.egiz.pdfas.api.xmldsig.ReconstructXMLDsigResult; import at.gv.egiz.pdfas.api.xmldsig.XMLDsigData; import at.gv.egiz.pdfas.commandline.CommandlineConnectorChooser; import at.gv.egiz.pdfas.exceptions.ErrorCode; +import at.gv.egiz.pdfas.exceptions.framework.PlaceholderExtractionException; import at.gv.egiz.pdfas.framework.ConnectorParameters; import at.gv.egiz.pdfas.framework.DataSourceHolder; import at.gv.egiz.pdfas.framework.config.SettingsHelper; @@ -73,6 +74,7 @@ import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException; import at.knowcenter.wag.egov.egiz.exceptions.OutOfMemoryException; import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException; import at.knowcenter.wag.egov.egiz.exceptions.PresentableException; +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; @@ -104,6 +106,8 @@ public class PdfAsObject implements PdfAs */ private static Log log = LogFactory.getLog(CheckHelper.class); + private static final String ENABLE_PLACEHOLDER_SEARCH_KEY = "enable_placeholder_search"; + /** * This constructor is for internal use only - use * {@link at.gv.egiz.pdfas.PdfAsFactory} instead. @@ -631,26 +635,24 @@ public class PdfAsObject implements PdfAs } signParameters.setDocument(PdfAS.applyStrictMode(signParameters.getDocument())); - - SignaturePlaceholderData spd = null; - SignaturePlaceholderContext.setSignaturePlaceholderData(null); - if (signParameters.isCheckForPlaceholder()) { - spd = SignaturePlaceholderExtractor.extract(signParameters.getDocument().createInputStream(), signParameters.getPlaceholderId(), signParameters.getPlaceholderMatchMode()); - if (spd != null){ - if (spd.getProfile() != null) - signParameters.setSignatureProfileId(spd.getProfile()); - if (spd.getType() != null) - signParameters.setSignatureType(spd.getType()); - if (spd.getKey() != null) - signParameters.setSignatureKeyIdentifier(spd.getKey()); - } + + SettingsReader settings = SettingsReader.getInstance(); + String defaultProfile = settings.getValueFromKey(SignatureTypes.DEFAULT_TYPE); + + SignaturePlaceholderData spd = getSignaturePlaceholder(signParameters, defaultProfile); + if (spd != null){ + if (spd.getProfile() != null) + signParameters.setSignatureProfileId(spd.getProfile()); + if (spd.getType() != null) + signParameters.setSignatureType(spd.getType()); + if (spd.getKey() != null) + signParameters.setSignatureKeyIdentifier(spd.getKey()); + // check again, we might have destroyed something + CheckHelper.checkSignParameters(signParameters, true); } - CheckHelper.checkSignParameters(signParameters, true); - + if (signParameters.getSignatureProfileId() == null) { - SettingsReader settings = SettingsReader.getInstance(); - String defaultProfile = settings.getValueFromKey(SignatureTypes.DEFAULT_TYPE); signParameters.setSignatureProfileId(defaultProfile); } @@ -674,6 +676,41 @@ public class PdfAsObject implements PdfAs } + private SignaturePlaceholderData getSignaturePlaceholder(SignParameters signParameters, + String defaultProfile) throws SettingsException, PDFDocumentException, PlaceholderExtractionException { + SignaturePlaceholderData spd = null; + SignaturePlaceholderContext.setSignaturePlaceholderData(null); + + SettingsReader settings = SettingsReader.getInstance(); + + // check sig_obj.PROFILID.enable_placeholder_search + String profile = signParameters.getSignatureProfileId(); + if (profile == null) + profile = defaultProfile; + String key = SignatureTypes.SIG_OBJ + profile + "." + ENABLE_PLACEHOLDER_SEARCH_KEY; + String enableSearchString = settings.getValueFromKey(key); + + if (enableSearchString == null){ + // check global enable_placeholder_search + enableSearchString = settings.getValueFromKey(ENABLE_PLACEHOLDER_SEARCH_KEY); + } + + boolean enableSearch = true; + if (enableSearchString != null && enableSearchString.trim().equalsIgnoreCase("false")) + enableSearch = false; + + if (enableSearch) + { + if (signParameters.isCheckForPlaceholder()) { + spd = SignaturePlaceholderExtractor.extract( + signParameters.getDocument().createInputStream(), + signParameters.getPlaceholderId(), + signParameters.getPlaceholderMatchMode()); + } + } + return spd; + } + private Signator createSignator(String signatureType) throws SignatorFactoryException { PdfASID signatorId = null; if (signatureType.equals(Constants.SIGNATURE_TYPE_BINARY)) -- cgit v1.2.3