From 61a2d23ef72630934c603fe9ffb96ebebff6ee09 Mon Sep 17 00:00:00 2001 From: netconomy Date: Thu, 29 Nov 2007 12:00:22 +0000 Subject: PDF-AS API git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@233 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../at/gv/egiz/pdfas/impl/api/CheckHelper.java | 213 +++++++++++++++++++++ 1 file changed, 213 insertions(+) create mode 100644 src/main/java/at/gv/egiz/pdfas/impl/api/CheckHelper.java (limited to 'src/main/java/at/gv/egiz/pdfas/impl/api/CheckHelper.java') diff --git a/src/main/java/at/gv/egiz/pdfas/impl/api/CheckHelper.java b/src/main/java/at/gv/egiz/pdfas/impl/api/CheckHelper.java new file mode 100644 index 0000000..467113f --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/impl/api/CheckHelper.java @@ -0,0 +1,213 @@ +/** + * + */ +package at.gv.egiz.pdfas.impl.api; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.gv.egiz.pdfas.api.analyze.AnalyzeParameters; +import at.gv.egiz.pdfas.api.commons.Constants; +import at.gv.egiz.pdfas.api.io.DataSource; +import at.gv.egiz.pdfas.api.sign.SignParameters; +import at.gv.egiz.pdfas.api.sign.pos.SignaturePositioning; +import at.gv.egiz.pdfas.api.verify.VerifyAfterAnalysisParameters; +import at.gv.egiz.pdfas.api.verify.VerifyParameters; +import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException; +import at.knowcenter.wag.egov.egiz.exceptions.SignatureTypesException; +import at.knowcenter.wag.egov.egiz.sig.SignatureTypes; + +/** + * Contains check methods frequently used by the {@link PdfAsObject} to check + * input parameters. + * + * @author wprinz + * + */ +public final class CheckHelper +{ + /** + * The log. + */ + private static Log log = LogFactory.getLog(CheckHelper.class); + + /** + * Hidden default constructor. + */ + private CheckHelper() + { + // empty block + } + + /** + * Checks the SignParameters for integrity. + * + * @param sp + * The {@link SignParameters} + */ + public static void checkSignParameters(SignParameters sp) + { + if (sp == null) + { + throw new IllegalArgumentException("The signParameters must not be null."); + } + + checkDocument(sp.getDocument()); + if (sp.getOutput() == null) + { + throw new IllegalArgumentException("The output DataSink must not be null."); + } + checkSignatureType(sp.getSignatureType()); + checkSignatureDevice(sp.getSignatureDevice()); + if (sp.getSignatureProfileId() != null) + { + checkProfileId(sp.getSignatureProfileId()); + } + if (sp.getSignaturePositioning() != null) + { + checkSignaturePositioning(sp.getSignaturePositioning()); + } + } + + /** + * Checks the VerifyParameters for integrity. + * + * @param vp + * The {@link VerifyParameters} + */ + public static void checkVerifyParameters(VerifyParameters vp) + { + if (vp == null) + { + throw new IllegalArgumentException("The verifyParameters must not be null."); + } + + checkDocument(vp.getDocument()); + checkVerifyMode(vp.getVerifyMode()); + checkSignatureDevice(vp.getSignatureDevice()); + if (vp.getSignatureToVerify() < Constants.VERIFY_ALL) + { + throw new IllegalArgumentException("The signatureToVerify parameter is incorrect. " + vp.getSignatureToVerify()); + } + } + + /** + * Checks the AnalyzeParameters for integrity. + * + * @param ap + * The {@link AnalyzeParameters} + */ + public static void checkAnalyzeParameters(AnalyzeParameters ap) + { + if (ap == null) + { + throw new IllegalArgumentException("The analyzeParameters must not be null."); + } + + checkDocument(ap.getDocument()); + checkVerifyMode(ap.getVerifyMode()); + } + + /** + * Checks the VerifyAfterAnalysisParameters for integrity. + * + * @param vaap + * The {@link VerifyAfterAnalysisParameters} + */ + public static void checkVerifyAfterAnalysisParameters(VerifyAfterAnalysisParameters vaap) + { + if (vaap == null) + { + throw new IllegalArgumentException("The analyzeParameters must not be null."); + } + + if (vaap.getAnalyzeResult() == null) + { + throw new IllegalArgumentException("The analyzeResult must not be null."); + } + checkSignatureDevice(vaap.getSignatureDevice()); + } + + protected static void checkDocument(DataSource document) + { + if (document == null) + { + throw new IllegalArgumentException("The document DataSource must not be null."); + } + } + + protected static void checkSignatureType(String signatureType) + { + if (signatureType == null) + { + throw new IllegalArgumentException("The signatureType must not be null."); + } + if (!(signatureType.equals(Constants.SIGNATURE_TYPE_BINARY) || signatureType.equals(Constants.SIGNATURE_TYPE_TEXTUAL) || signatureType.equals(Constants.SIGNATURE_TYPE_DETACHEDTEXTUAL))) + { + throw new IllegalArgumentException("The signatureType must be one of the Constants.SIGNATURE_TYPE_* constants. " + signatureType); + } + } + + protected static void checkProfileId(String profileId) + { + if (profileId == null) + { + throw new IllegalArgumentException("The profileId must not be null."); + } + try + { + if (!SignatureTypes.getInstance().getSignatureTypes().contains(profileId)) + { + throw new IllegalArgumentException("The profileId must be defined in the configuration file. " + profileId); + } + } + catch (SignatureTypesException e) + { + String msg = "Error while checking the profileId parameter - cannot get list of valid profiles. " + profileId; + log.error(msg, e); + throw new IllegalArgumentException(msg); + } + } + + protected static void checkSignaturePositioning(SignaturePositioning signaturePositioning) + { + if (signaturePositioning == null) + { + throw new IllegalArgumentException("The signaturePosition must not be null."); + } + try + { + PosHelper.formTablePos(signaturePositioning); + } + catch (PDFDocumentException e) + { + String msg = "The signaturePosition string is not valid. " + signaturePositioning; + log.error(msg, e); + throw new IllegalArgumentException(msg); + } + } + + protected static void checkVerifyMode(String verifyMode) + { + if (verifyMode == null) + { + throw new IllegalArgumentException("The verifyMode must not be null."); + } + if (!(verifyMode.equals(Constants.VERIFY_MODE_BINARY_ONLY) || verifyMode.equals(Constants.VERIFY_MODE_SEMI_CONSERVATIVE) || verifyMode.equals(Constants.VERIFY_MODE_FULL_CONSERVATIVE))) + { + throw new IllegalArgumentException("The verifyMode must be one of the Constants.VERIFY_MODE_* constants. " + verifyMode); + } + } + + protected static void checkSignatureDevice(String signatureDevice) + { + if (signatureDevice == null) + { + throw new IllegalArgumentException("The signatureDevice must not be null."); + } + if (!(signatureDevice.equals(Constants.SIGNATURE_DEVICE_BKU) || signatureDevice.equals(Constants.SIGNATURE_DEVICE_MOA))) + { + throw new IllegalArgumentException("The signatureDevice must be one of the Constants.SIGNATURE_DEVICE_* constants. " + signatureDevice); + } + } +} -- cgit v1.2.3