From 0572beadfd4805e26114cd92a24492d9cf14fec0 Mon Sep 17 00:00:00 2001 From: pdanner Date: Mon, 6 Dec 2010 17:46:57 +0000 Subject: git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@687 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../at/gv/egiz/pdfas/impl/api/PdfAsObject.java | 130 ++++++++++----------- 1 file changed, 60 insertions(+), 70 deletions(-) (limited to 'src/main/java/at/gv/egiz/pdfas') 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 e630aa3..2c9a9ad 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 @@ -624,58 +624,53 @@ public class PdfAsObject implements PdfAs * @see PdfAs#prepareSign(SignParameters) */ public SignatureDetailInformation prepareSign(SignParameters signParameters) throws PdfAsException { - try{ - CheckHelper.checkSignParameters(signParameters, true); - - if (signParameters.getProfileOverrideProperties() != null) { - OverridePropertyHolder.setOverrideProps(signParameters.getProfileOverrideProperties()); - } - - 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()); - } - } - CheckHelper.checkSignParameters(signParameters, true); - - if (signParameters.getSignatureProfileId() == null) - { - SettingsReader settings = SettingsReader.getInstance(); - String defaultProfile = settings.getValueFromKey(SignatureTypes.DEFAULT_TYPE); - signParameters.setSignatureProfileId(defaultProfile); + CheckHelper.checkSignParameters(signParameters, true); + + if (signParameters.getProfileOverrideProperties() != null) { + OverridePropertyHolder.setOverrideProps(signParameters.getProfileOverrideProperties()); + } + + 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()); } - - TablePos pos = null; - if (spd != null && spd.getTablePos() != null) - pos = spd.getTablePos(); - else - pos = PosHelper.formTablePos(signParameters.getSignaturePositioning()); - - Signator signator = createSignator(signParameters.getSignatureType()); - - SignatorInformation signatorInfo = signator.prepareSign( - new PdfDataSourceAdapter(signParameters.getDocument()), - signParameters.getSignatureProfileId(), - pos, - signParameters.getTimeStamperImpl()); - - SignatureDetailInformationImpl ret = new SignatureDetailInformationImpl(); - ret.setSignatorInformation(signatorInfo); - return ret; - } finally { - OverridePropertyHolder.removeProperties(); - DynamicSignatureProfileImpl.disposeLocalProfile(); } + CheckHelper.checkSignParameters(signParameters, true); + + if (signParameters.getSignatureProfileId() == null) + { + SettingsReader settings = SettingsReader.getInstance(); + String defaultProfile = settings.getValueFromKey(SignatureTypes.DEFAULT_TYPE); + signParameters.setSignatureProfileId(defaultProfile); + } + + TablePos pos = null; + if (spd != null && spd.getTablePos() != null) + pos = spd.getTablePos(); + else + pos = PosHelper.formTablePos(signParameters.getSignaturePositioning()); + + Signator signator = createSignator(signParameters.getSignatureType()); + + SignatorInformation signatorInfo = signator.prepareSign( + new PdfDataSourceAdapter(signParameters.getDocument()), + signParameters.getSignatureProfileId(), + pos, + signParameters.getTimeStamperImpl()); + + SignatureDetailInformationImpl ret = new SignatureDetailInformationImpl(); + ret.setSignatorInformation(signatorInfo); + return ret; } @@ -700,29 +695,24 @@ public class PdfAsObject implements PdfAs public SignResult sign(SignParameters signParameters, SignatureDetailInformation signatorInfo) throws PdfAsException { - try { - CheckHelper.checkSignParametersForSignAfterPrepare(signParameters, false); - - if (signParameters.getProfileOverrideProperties() != null) { - OverridePropertyHolder.setOverrideProps(signParameters.getProfileOverrideProperties()); - } + CheckHelper.checkSignParametersForSignAfterPrepare(signParameters, false); + + if (signParameters.getProfileOverrideProperties() != null) { + OverridePropertyHolder.setOverrideProps(signParameters.getProfileOverrideProperties()); + } - String connectorId = CommandlineConnectorChooser.chooseCommandlineConnectorForSign(signParameters.getSignatureDevice()); + String connectorId = CommandlineConnectorChooser.chooseCommandlineConnectorForSign(signParameters.getSignatureDevice()); - ConnectorParameters cp = new ConnectorParameters(); - cp.setProfileId(signParameters.getSignatureProfileId()); - cp.setSignatureKeyIdentifier(signParameters.getSignatureKeyIdentifier()); - Connector c = at.gv.egiz.pdfas.framework.ConnectorFactory.createConnector(connectorId, cp); + ConnectorParameters cp = new ConnectorParameters(); + cp.setProfileId(signParameters.getSignatureProfileId()); + cp.setSignatureKeyIdentifier(signParameters.getSignatureKeyIdentifier()); + Connector c = at.gv.egiz.pdfas.framework.ConnectorFactory.createConnector(connectorId, cp); - SignatureData sd = new SignatureDataImpl(new PdfDataSourceAdapter(signatorInfo.getSignatureData()), signatorInfo.getSignatureData().getMimeType()); - SignSignatureObject sso = PdfAS.sign(sd, c, signParameters.getTimeStamperImpl()); - ((SignatureDetailInformationImpl)signatorInfo).setSignSignatureObject(sso); - - return finishSign(signParameters, signatorInfo); - } finally { - OverridePropertyHolder.removeProperties(); - DynamicSignatureProfileImpl.disposeLocalProfile(); - } + SignatureData sd = new SignatureDataImpl(new PdfDataSourceAdapter(signatorInfo.getSignatureData()), signatorInfo.getSignatureData().getMimeType()); + SignSignatureObject sso = PdfAS.sign(sd, c, signParameters.getTimeStamperImpl()); + ((SignatureDetailInformationImpl)signatorInfo).setSignSignatureObject(sso); + + return finishSign(signParameters, signatorInfo); } public SignResult finishSign(SignParameters signParameters, SignatureDetailInformation signatureDetailInformation) -- cgit v1.2.3