aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/gv')
-rw-r--r--src/main/java/at/gv/egiz/pdfas/commandline/CommandlineConnectorChooser.java3
-rw-r--r--src/main/java/at/gv/egiz/pdfas/commandline/Main.java23
-rw-r--r--src/main/java/at/gv/egiz/pdfas/exceptions/ErrorCode.java2
3 files changed, 25 insertions, 3 deletions
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;