From 25f5495b60fb0fb089c7af216986d2f3abf92375 Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Thu, 26 Sep 2013 16:09:12 +0200 Subject: first version of API IO implemented --- .../gv/egiz/pdfas/lib/api/ByteArrayDataSink.java | 18 +++++++++++ .../gv/egiz/pdfas/lib/api/ByteArrayDataSource.java | 2 +- .../java/at/gv/egiz/pdfas/lib/api/DataSink.java | 7 +++++ .../java/at/gv/egiz/pdfas/lib/api/DataSource.java | 6 ++++ .../java/at/gv/egiz/pdfas/lib/api/IDataSource.java | 6 ---- .../at/gv/egiz/pdfas/lib/api/PdfAsFactory.java | 7 +++++ .../at/gv/egiz/pdfas/lib/api/PdfAsParameter.java | 28 ++++------------- .../gv/egiz/pdfas/lib/api/sign/SignParameter.java | 34 +++++---------------- .../at/gv/egiz/pdfas/lib/api/sign/SignResult.java | 35 +++++++++++++++++++++- .../egiz/pdfas/lib/api/verify/VerifyParameter.java | 9 ++---- 10 files changed, 88 insertions(+), 64 deletions(-) create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/ByteArrayDataSink.java create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/DataSink.java create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/DataSource.java delete mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IDataSource.java (limited to 'pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api') 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/DataSource.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/DataSource.java new file mode 100644 index 00000000..73487c7b --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/DataSource.java @@ -0,0 +1,6 @@ +package at.gv.egiz.pdfas.lib.api; + +public interface DataSource { + public String getMIMEType(); + public byte[] getByteData(); +} 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/IDataSource.java deleted file mode 100644 index 6fea788c..00000000 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IDataSource.java +++ /dev/null @@ -1,6 +0,0 @@ -package at.gv.egiz.pdfas.lib.api; - -public interface IDataSource { - 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. + * + *

+ * This information can be useful for post-processing the document. + *

+ * + *

+ * Consult the PDF-AS documentation section Commandline for further + * information about positioning. + *

+ * + * @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); - } + } -- cgit v1.2.3