aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/pdfas/impl/api/CheckHelper.java
diff options
context:
space:
mode:
authornetconomy <netconomy@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2007-11-29 12:00:22 +0000
committernetconomy <netconomy@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2007-11-29 12:00:22 +0000
commit61a2d23ef72630934c603fe9ffb96ebebff6ee09 (patch)
treece05c4470d3a7a2743b4956f512288d6d0d62187 /src/main/java/at/gv/egiz/pdfas/impl/api/CheckHelper.java
parent00809217ec7c890a844f9a7c667c71b550ad92a6 (diff)
downloadpdf-as-3-61a2d23ef72630934c603fe9ffb96ebebff6ee09.tar.gz
pdf-as-3-61a2d23ef72630934c603fe9ffb96ebebff6ee09.tar.bz2
pdf-as-3-61a2d23ef72630934c603fe9ffb96ebebff6ee09.zip
PDF-AS API
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@233 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src/main/java/at/gv/egiz/pdfas/impl/api/CheckHelper.java')
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/api/CheckHelper.java213
1 files changed, 213 insertions, 0 deletions
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);
+ }
+ }
+}