From 3231b0d2c665d5493e3a1e63106b8bc934d9094b Mon Sep 17 00:00:00 2001 From: tknall Date: Thu, 14 Jan 2010 17:03:02 +0000 Subject: - Errorcode for unsupported signature method introduced - Errorcode for unknown (internal error) introduced - Fixed issue: in case of unexpected error (RunTimeException for instance) the output file was not deleted - Some System.out.println commands replaced by log.debug messages - Typos fixed - "can-break-after" character list extended: "." added - Configuration updated - DefaultConfiguration updated - internal version set to 3.1 in preparation for release - maven2-repository updated (pdfbox-0.7.2-pdfas-2 compiled for log4j) - pdfbox-0.7.2-pdfas-2 updated (some debug messages) git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@552 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../commandline/CommandlineConnectorChooser.java | 3 ++- .../java/at/gv/egiz/pdfas/commandline/Main.java | 23 ++++++++++++++++++++-- .../at/gv/egiz/pdfas/exceptions/ErrorCode.java | 2 ++ 3 files changed, 25 insertions(+), 3 deletions(-) (limited to 'src/main/java/at/gv/egiz') diff --git a/src/main/java/at/gv/egiz/pdfas/commandline/CommandlineConnectorChooser.java b/src/main/java/at/gv/egiz/pdfas/commandline/CommandlineConnectorChooser.java index c0532a4..50678db 100644 --- a/src/main/java/at/gv/egiz/pdfas/commandline/CommandlineConnectorChooser.java +++ b/src/main/java/at/gv/egiz/pdfas/commandline/CommandlineConnectorChooser.java @@ -3,6 +3,7 @@ */ package at.gv.egiz.pdfas.commandline; +import at.gv.egiz.pdfas.exceptions.ErrorCode; import at.gv.egiz.pdfas.framework.ConnectorFactory; import org.apache.commons.logging.Log; @@ -118,7 +119,7 @@ public class CommandlineConnectorChooser return chooseDetachedMultipartConnector(connectorType); } - throw new ConnectorException(310, "The SIG_KZ version '" + sig_kz.getVersion() + "' is unknown."); + throw new ConnectorException(ErrorCode.UNSUPPORTED_SIGNATURE_METHOD, "The SIG_KZ version '" + sig_kz.getVersion() + "' is unknown."); } protected static String chooseEnvelopingBase64ConnectorOld(String sig_app) throws ConnectorException diff --git a/src/main/java/at/gv/egiz/pdfas/commandline/Main.java b/src/main/java/at/gv/egiz/pdfas/commandline/Main.java index c4895c0..2e0e674 100644 --- a/src/main/java/at/gv/egiz/pdfas/commandline/Main.java +++ b/src/main/java/at/gv/egiz/pdfas/commandline/Main.java @@ -519,9 +519,10 @@ public abstract class Main } DataSink dataSink = null; + File outputFile = null; try { - File outputFile = new File(output); + outputFile = new File(output); dataSink = new FileBasedDataSink(outputFile); } @@ -530,7 +531,25 @@ public abstract class Main throw new PDFDocumentException(ErrorCode.CANNOT_WRITE_PDF, e); } - processSign(dataSource, connector, signature_mode, signature_type, pos_string, dataSink); + try { + processSign(dataSource, connector, signature_mode, signature_type, pos_string, dataSink); + } catch (Exception e) { + // Exception caught in order to delete file based datasink + if (outputFile != null && outputFile.exists()) + { + logger_.debug("Deleting output file on error."); + boolean deleted = outputFile.delete(); + if (!deleted) + { + logger_.error("Couldn't delete output file " + output); + } + } + if (e instanceof PresentableException) { + throw (PresentableException)e; + } else { + throw new PresentableException(ErrorCode.UNKNOWN_ERROR, e); + } + } // for performance measurement if (logger_.isInfoEnabled()) diff --git a/src/main/java/at/gv/egiz/pdfas/exceptions/ErrorCode.java b/src/main/java/at/gv/egiz/pdfas/exceptions/ErrorCode.java index f9616cf..c53151f 100644 --- a/src/main/java/at/gv/egiz/pdfas/exceptions/ErrorCode.java +++ b/src/main/java/at/gv/egiz/pdfas/exceptions/ErrorCode.java @@ -15,6 +15,7 @@ package at.gv.egiz.pdfas.exceptions; public final class ErrorCode { public static final int EXTERNAL_ERROR = 0; + public static final int UNKNOWN_ERROR = 6; public static final int SETTING_NOT_FOUND = 100; public static final int SETTINGS_EXCEPTION = 101; @@ -46,6 +47,7 @@ public final class ErrorCode public static final int NON_BINARY_SIGNATURES_PRESENT = 317; public static final int UNSUPPORTED_REPLACES_NAME = 318; + public static final int UNSUPPORTED_SIGNATURE_METHOD = 319; public static final int SIGNATURE_VERIFICATION_NOT_SUPPORTED = 371; public static final int INVALID_SIGNING_TIME = 372; -- cgit v1.2.3