aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-lib/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-as-lib/src/main/java')
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/ByteArrayDataSink.java18
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/ByteArrayDataSource.java2
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/DataSink.java7
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/DataSource.java (renamed from pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IDataSource.java)2
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java7
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsParameter.java28
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/SignParameter.java34
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/SignResult.java35
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/verify/VerifyParameter.java9
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java14
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsParameterImpl.java33
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignParameterImpl.java45
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignResultImpl.java25
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/VerifyParameterImpl.java12
14 files changed, 211 insertions, 60 deletions
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/ByteArrayDataSink.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/ByteArrayDataSink.java
new file mode 100644
index 00000000..6cc63338
--- /dev/null
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/ByteArrayDataSink.java
@@ -0,0 +1,18 @@
+package at.gv.egiz.pdfas.lib.api;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+
+public class ByteArrayDataSink implements DataSink {
+
+ protected ByteArrayOutputStream bos = new ByteArrayOutputStream();
+
+ public OutputStream createOutputStream() {
+ bos = new ByteArrayOutputStream();
+ return bos;
+ }
+
+ public byte[] getData() {
+ return bos.toByteArray();
+ }
+}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/ByteArrayDataSource.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/ByteArrayDataSource.java
index 72c02b08..cd670cea 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/ByteArrayDataSource.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/ByteArrayDataSource.java
@@ -1,6 +1,6 @@
package at.gv.egiz.pdfas.lib.api;
-public class ByteArrayDataSource implements IDataSource {
+public class ByteArrayDataSource implements DataSource {
private byte[] byteData;
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/DataSink.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/DataSink.java
new file mode 100644
index 00000000..4a3fb52c
--- /dev/null
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/DataSink.java
@@ -0,0 +1,7 @@
+package at.gv.egiz.pdfas.lib.api;
+
+import java.io.OutputStream;
+
+public interface DataSink {
+ public OutputStream createOutputStream();
+}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IDataSource.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/DataSource.java
index 6fea788c..73487c7b 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IDataSource.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/DataSource.java
@@ -1,6 +1,6 @@
package at.gv.egiz.pdfas.lib.api;
-public interface IDataSource {
+public interface DataSource {
public String getMIMEType();
public byte[] getByteData();
}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java
index 444480cf..518f458d 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java
@@ -4,7 +4,9 @@ import java.io.File;
import org.apache.log4j.PropertyConfigurator;
+import at.gv.egiz.pdfas.lib.api.sign.SignParameter;
import at.gv.egiz.pdfas.lib.impl.PdfAsImpl;
+import at.gv.egiz.pdfas.lib.impl.SignParameterImpl;
public class PdfAsFactory {
@@ -15,4 +17,9 @@ public class PdfAsFactory {
public static PdfAs createPdfAs(File configuration) {
return new PdfAsImpl(configuration);
}
+
+ public static SignParameter createSignParameter(Configuration configuration, DataSource dataSource) {
+ SignParameter param = new SignParameterImpl(configuration, dataSource);
+ return param;
+ }
}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsParameter.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsParameter.java
index 999c91bc..8ffcf998 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsParameter.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsParameter.java
@@ -1,32 +1,14 @@
package at.gv.egiz.pdfas.lib.api;
-public abstract class PdfAsParameter {
+public interface PdfAsParameter {
- protected Configuration configuration;
-
- protected IDataSource dataSource;
-
- public PdfAsParameter(Configuration configuration,
- IDataSource dataSource) {
- this.configuration = configuration;
- this.dataSource = dataSource;
- }
-
- public Configuration getConfiguration() {
- return configuration;
- }
+ public Configuration getConfiguration() ;
- public void setConfiguration(Configuration configuration) {
- this.configuration = configuration;
- }
+ public void setConfiguration(Configuration configuration);
- public IDataSource getDataSource() {
- return dataSource;
- }
+ public DataSource getDataSource();
- public void setDataSource(IDataSource dataSource) {
- this.dataSource = dataSource;
- }
+ public void setDataSource(DataSource dataSource);
}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/SignParameter.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/SignParameter.java
index 1eee841a..0b4a076c 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/SignParameter.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/SignParameter.java
@@ -1,37 +1,19 @@
package at.gv.egiz.pdfas.lib.api.sign;
-import at.gv.egiz.pdfas.lib.api.Configuration;
-import at.gv.egiz.pdfas.lib.api.IDataSource;
+import at.gv.egiz.pdfas.lib.api.DataSink;
import at.gv.egiz.pdfas.lib.api.PdfAsParameter;
-public class SignParameter extends PdfAsParameter {
-
- protected String signatureProfileId = null;
- protected String signaturePosition = null;
+public interface SignParameter extends PdfAsParameter {
- public SignParameter(Configuration configuration,
- IDataSource dataSource) {
- super(configuration, dataSource);
- }
+ public String getSignatureProfileId();
- // ========================================================================
-
- public String getSignatureProfileId() {
- return signatureProfileId;
- }
+ public void setSignatureProfileId(String signatureProfileId);
- public void setSignatureProfileId(String signatureProfileId) {
- this.signatureProfileId = signatureProfileId;
- }
+ public String getSignaturePosition();
- public String getSignaturePosition() {
- return signaturePosition;
- }
+ public void setSignaturePosition(String signaturePosition);
- public void setSignaturePosition(String signaturePosition) {
- this.signaturePosition = signaturePosition;
- }
-
-
+ public void setOutput(DataSink output);
+ public DataSink getOutput();
}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/SignResult.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/SignResult.java
index 91da083e..03e48d73 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/SignResult.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/SignResult.java
@@ -1,5 +1,38 @@
package at.gv.egiz.pdfas.lib.api.sign;
-public class SignResult {
+import java.security.cert.X509Certificate;
+import at.gv.egiz.pdfas.lib.api.DataSink;
+
+public interface SignResult {
+ /**
+ * Returns the filled output data sink.
+ *
+ * @return Returns the filled output data sink.
+ */
+ public DataSink getOutputDocument();
+
+ /**
+ * Returns the certificate of the signer.
+ *
+ * @return Returns the certificate of the signer.
+ */
+ public X509Certificate getSignerCertificate();
+
+ /**
+ * Returns the position where the signature is finally placed.
+ *
+ * <p>
+ * This information can be useful for post-processing the document.
+ * </p>
+ *
+ * <p>
+ * Consult the PDF-AS documentation section Commandline for further
+ * information about positioning.
+ * </p>
+ *
+ * @return Returns the position where the signature is finally placed. May
+ * return null if no position information is available.
+ */
+ //public SignaturePosition getSignaturePosition();
}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/verify/VerifyParameter.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/verify/VerifyParameter.java
index 8c53ad47..914838ed 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/verify/VerifyParameter.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/verify/VerifyParameter.java
@@ -1,14 +1,9 @@
package at.gv.egiz.pdfas.lib.api.verify;
-import at.gv.egiz.pdfas.lib.api.Configuration;
-import at.gv.egiz.pdfas.lib.api.IDataSource;
import at.gv.egiz.pdfas.lib.api.PdfAsParameter;
-public class VerifyParameter extends PdfAsParameter {
+public interface VerifyParameter extends PdfAsParameter {
- public VerifyParameter(Configuration configuration,
- IDataSource dataSource) {
- super(configuration, dataSource);
- }
+
}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java
index e4132e91..adef37af 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java
@@ -2,6 +2,7 @@ package at.gv.egiz.pdfas.lib.impl;
import java.io.ByteArrayInputStream;
import java.io.File;
+import java.io.OutputStream;
import java.util.List;
import org.apache.pdfbox.pdmodel.PDDocument;
@@ -145,7 +146,18 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants {
// TODO: Create signature
- return null;
+ status.getPdfObject().setSignedDocument(status.getPdfObject().getStampedDocument());
+
+ // ================================================================
+ // Create SignResult
+ SignResultImpl result = new SignResultImpl(status.getSignParamter().getOutput());
+ OutputStream outputStream = result.getOutputDocument().createOutputStream();
+
+ outputStream.write(status.getPdfObject().getSignedDocument());
+
+ outputStream.close();
+
+ return result;
} catch (Throwable e) {
logger.error("sign failed " + e.getMessage(), e);
throw new PdfAsException("sign Failed", e);
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsParameterImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsParameterImpl.java
new file mode 100644
index 00000000..d4bb44e6
--- /dev/null
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsParameterImpl.java
@@ -0,0 +1,33 @@
+package at.gv.egiz.pdfas.lib.impl;
+
+import at.gv.egiz.pdfas.lib.api.Configuration;
+import at.gv.egiz.pdfas.lib.api.DataSource;
+import at.gv.egiz.pdfas.lib.api.PdfAsParameter;
+
+public class PdfAsParameterImpl implements PdfAsParameter {
+protected Configuration configuration;
+
+ protected DataSource dataSource;
+
+ public PdfAsParameterImpl(Configuration configuration,
+ DataSource dataSource) {
+ this.configuration = configuration;
+ this.dataSource = dataSource;
+ }
+
+ public Configuration getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(Configuration configuration) {
+ this.configuration = configuration;
+ }
+
+ public DataSource getDataSource() {
+ return dataSource;
+ }
+
+ public void setDataSource(DataSource dataSource) {
+ this.dataSource = dataSource;
+ }
+}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignParameterImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignParameterImpl.java
new file mode 100644
index 00000000..7989bca7
--- /dev/null
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignParameterImpl.java
@@ -0,0 +1,45 @@
+package at.gv.egiz.pdfas.lib.impl;
+
+import at.gv.egiz.pdfas.lib.api.Configuration;
+import at.gv.egiz.pdfas.lib.api.DataSink;
+import at.gv.egiz.pdfas.lib.api.DataSource;
+import at.gv.egiz.pdfas.lib.api.sign.SignParameter;
+
+public class SignParameterImpl extends PdfAsParameterImpl implements SignParameter {
+ protected String signatureProfileId = null;
+ protected String signaturePosition = null;
+ protected DataSink output = null;
+
+ public SignParameterImpl(Configuration configuration,
+ DataSource dataSource) {
+ super(configuration, dataSource);
+ }
+
+ // ========================================================================
+
+ public String getSignatureProfileId() {
+ return signatureProfileId;
+ }
+
+ public void setSignatureProfileId(String signatureProfileId) {
+ this.signatureProfileId = signatureProfileId;
+ }
+
+ public String getSignaturePosition() {
+ return signaturePosition;
+ }
+
+ public void setSignaturePosition(String signaturePosition) {
+ this.signaturePosition = signaturePosition;
+ }
+
+ public void setOutput(DataSink output) {
+ this.output = output;
+ }
+
+ public DataSink getOutput() {
+ return this.output;
+ }
+
+
+}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignResultImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignResultImpl.java
new file mode 100644
index 00000000..dcb27be9
--- /dev/null
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignResultImpl.java
@@ -0,0 +1,25 @@
+package at.gv.egiz.pdfas.lib.impl;
+
+import java.security.cert.X509Certificate;
+
+import at.gv.egiz.pdfas.lib.api.DataSink;
+import at.gv.egiz.pdfas.lib.api.sign.SignResult;
+
+public class SignResultImpl implements SignResult {
+
+ protected DataSink dataSink;
+
+ public SignResultImpl(DataSink dataSink) {
+ this.dataSink = dataSink;
+ }
+
+ public DataSink getOutputDocument() {
+ return this.dataSink;
+ }
+
+ public X509Certificate getSignerCertificate() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/VerifyParameterImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/VerifyParameterImpl.java
new file mode 100644
index 00000000..a82daba8
--- /dev/null
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/VerifyParameterImpl.java
@@ -0,0 +1,12 @@
+package at.gv.egiz.pdfas.lib.impl;
+
+import at.gv.egiz.pdfas.lib.api.Configuration;
+import at.gv.egiz.pdfas.lib.api.DataSource;
+import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter;
+
+public class VerifyParameterImpl extends PdfAsParameterImpl implements VerifyParameter {
+ public VerifyParameterImpl(Configuration configuration,
+ DataSource dataSource) {
+ super(configuration, dataSource);
+ }
+}