From 61a2d23ef72630934c603fe9ffb96ebebff6ee09 Mon Sep 17 00:00:00 2001 From: netconomy Date: Thu, 29 Nov 2007 12:00:22 +0000 Subject: PDF-AS API git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@233 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../pdfas/impl/api/commons/DataSinkAdapter.java | 83 +++++++++++++++++++++ .../impl/api/commons/DataSourceApiAdapter.java | 85 +++++++++++++++++++++ .../impl/api/commons/PdfDataSourceAdapter.java | 52 +++++++++++++ .../api/commons/SignatureInformationAdapter.java | 87 ++++++++++++++++++++++ .../impl/api/commons/SignatureProfileImpl.java | 56 ++++++++++++++ .../impl/api/commons/TextDataSourceAdapter.java | 52 +++++++++++++ 6 files changed, 415 insertions(+) create mode 100644 src/main/java/at/gv/egiz/pdfas/impl/api/commons/DataSinkAdapter.java create mode 100644 src/main/java/at/gv/egiz/pdfas/impl/api/commons/DataSourceApiAdapter.java create mode 100644 src/main/java/at/gv/egiz/pdfas/impl/api/commons/PdfDataSourceAdapter.java create mode 100644 src/main/java/at/gv/egiz/pdfas/impl/api/commons/SignatureInformationAdapter.java create mode 100644 src/main/java/at/gv/egiz/pdfas/impl/api/commons/SignatureProfileImpl.java create mode 100644 src/main/java/at/gv/egiz/pdfas/impl/api/commons/TextDataSourceAdapter.java (limited to 'src/main/java/at/gv/egiz/pdfas/impl/api/commons') diff --git a/src/main/java/at/gv/egiz/pdfas/impl/api/commons/DataSinkAdapter.java b/src/main/java/at/gv/egiz/pdfas/impl/api/commons/DataSinkAdapter.java new file mode 100644 index 0000000..5744a21 --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/impl/api/commons/DataSinkAdapter.java @@ -0,0 +1,83 @@ +/** + * + */ +package at.gv.egiz.pdfas.impl.api.commons; + +import java.io.IOException; +import java.io.OutputStream; + +import at.gv.egiz.pdfas.api.io.DataSink; + +/** + * Adapter that converts an API DataSink to a framework DataSink. + * + * @author wprinz + */ +public class DataSinkAdapter implements at.gv.egiz.pdfas.framework.output.DataSink +{ + /** + * The API DataSink to be adapted to a framework DataSink. + */ + protected at.gv.egiz.pdfas.api.io.DataSink apiDataSink = null; + + /** + * Constructor. + * + * @param apiDataSink + * The API DataSink to be adapted to a framework DataSink. + */ + public DataSinkAdapter(DataSink apiDataSink) + { + this.apiDataSink = apiDataSink; + } + + /** + * @see at.gv.egiz.pdfas.framework.output.DataSink#createOutputStream(java.lang.String) + */ + public OutputStream createOutputStream(String mimeType) + { + try + { + return this.apiDataSink.createOutputStream(mimeType); + } + catch (IOException e) + { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + + /** + * @see at.gv.egiz.pdfas.framework.output.DataSink#createOutputStream(java.lang.String, + * java.lang.String) + */ + public OutputStream createOutputStream(String mimeType, String characterEncoding) + { + try + { + return this.apiDataSink.createOutputStream(mimeType, characterEncoding); + } + catch (IOException e) + { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + + /** + * @see at.gv.egiz.pdfas.framework.output.DataSink#getCharacterEncoding() + */ + public String getCharacterEncoding() + { + return this.apiDataSink.getCharacterEncoding(); + } + + /** + * @see at.gv.egiz.pdfas.framework.output.DataSink#getMimeType() + */ + public String getMimeType() + { + return this.apiDataSink.getMimeType(); + } + +} diff --git a/src/main/java/at/gv/egiz/pdfas/impl/api/commons/DataSourceApiAdapter.java b/src/main/java/at/gv/egiz/pdfas/impl/api/commons/DataSourceApiAdapter.java new file mode 100644 index 0000000..9e5495c --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/impl/api/commons/DataSourceApiAdapter.java @@ -0,0 +1,85 @@ +/** + * + */ +package at.gv.egiz.pdfas.impl.api.commons; + +import java.io.InputStream; + +import at.gv.egiz.pdfas.framework.input.PdfDataSource; +import at.gv.egiz.pdfas.framework.input.TextDataSource; + +/** + * Adapter that converts a framework DataSource to an API PdfDataSource. + * + * @author wprinz + */ +public class DataSourceApiAdapter implements at.gv.egiz.pdfas.api.io.DataSource +{ + /** + * The framework DataSource to be adapted to an API DataSource. + */ + protected at.gv.egiz.pdfas.framework.input.DataSource frameworkDataSource = null; + + /** + * Constructor. + * + * @param frameworkDataSource + * The framework DataSource to be adapted to an API DataSource. + */ + public DataSourceApiAdapter(at.gv.egiz.pdfas.framework.input.DataSource frameworkDataSource) + { + this.frameworkDataSource = frameworkDataSource; + } + + /** + * @see at.gv.egiz.pdfas.api.io.DataSource#createInputStream() + */ + public InputStream createInputStream() + { + return this.frameworkDataSource.createInputStream(); + } + + /** + * @see at.gv.egiz.pdfas.api.io.DataSource#getAsByteArray() + */ + public byte[] getAsByteArray() + { + return this.frameworkDataSource.getAsByteArray(); + } + + /** + * @see at.gv.egiz.pdfas.api.io.DataSource#getLength() + */ + public int getLength() + { + return this.frameworkDataSource.getLength(); + } + + public String getCharacterEncoding() + { + if (this.frameworkDataSource instanceof PdfDataSource) + { + return null; + } + if (this.frameworkDataSource instanceof TextDataSource) + { + return "UTF-8"; + } + return null; + } + + public String getMimeType() + { + if (this.frameworkDataSource instanceof PdfDataSource) + { + return "application/pdf"; + } + if (this.frameworkDataSource instanceof TextDataSource) + { + return "text/plain"; + } + + return null; + } + +} diff --git a/src/main/java/at/gv/egiz/pdfas/impl/api/commons/PdfDataSourceAdapter.java b/src/main/java/at/gv/egiz/pdfas/impl/api/commons/PdfDataSourceAdapter.java new file mode 100644 index 0000000..fbafafe --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/impl/api/commons/PdfDataSourceAdapter.java @@ -0,0 +1,52 @@ +/** + * + */ +package at.gv.egiz.pdfas.impl.api.commons; + +import java.io.InputStream; + +/** + * Adapter that converts an API DataSource to a framework PdfDataSource. + * + * @author wprinz + */ +public class PdfDataSourceAdapter implements at.gv.egiz.pdfas.framework.input.PdfDataSource +{ + /** + * The API DataSource to be adapted to a framework PdfDataSource. + */ + protected at.gv.egiz.pdfas.api.io.DataSource apiDataSource = null; + + /** + * Constructor. + * @param apiDataSource The API DataSource to be adapted to a framework PdfDataSource. + */ + public PdfDataSourceAdapter(at.gv.egiz.pdfas.api.io.DataSource apiDataSource) + { + this.apiDataSource = apiDataSource; + } + + /** + * @see at.gv.egiz.pdfas.framework.input.DataSource#createInputStream() + */ + public InputStream createInputStream() + { + return this.apiDataSource.createInputStream(); + } + + /** + * @see at.gv.egiz.pdfas.framework.input.DataSource#getAsByteArray() + */ + public byte[] getAsByteArray() + { + return this.apiDataSource.getAsByteArray(); + } + + /** + * @see at.gv.egiz.pdfas.framework.input.DataSource#getLength() + */ + public int getLength() + { + return this.apiDataSource.getLength(); + } +} diff --git a/src/main/java/at/gv/egiz/pdfas/impl/api/commons/SignatureInformationAdapter.java b/src/main/java/at/gv/egiz/pdfas/impl/api/commons/SignatureInformationAdapter.java new file mode 100644 index 0000000..875c3d9 --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/impl/api/commons/SignatureInformationAdapter.java @@ -0,0 +1,87 @@ +/** + * + */ +package at.gv.egiz.pdfas.impl.api.commons; + +import java.security.cert.X509Certificate; +import java.util.Date; + +import at.gv.egiz.pdfas.api.commons.Constants; +import at.gv.egiz.pdfas.api.commons.SignatureInformation; +import at.gv.egiz.pdfas.api.io.DataSource; +import at.knowcenter.wag.egov.egiz.pdf.EGIZDate; +import at.knowcenter.wag.egov.egiz.pdf.SignatureHolder; + +/** + * Adapter that converts a framework SignatureHolder to an API + * SignatureInformation. + * + * @author wprinz + */ +public class SignatureInformationAdapter implements SignatureInformation +{ + /** + * The framework SignatureHolder to be adapted to an API SignatureInformation. + */ + protected SignatureHolder signatureHolder = null; + + /** + * Constructor. + * + * @param signatureHolder + * The framework SignatureHolder to be adapted to an API + * SignatureInformation. + */ + public SignatureInformationAdapter(SignatureHolder signatureHolder) + { + this.signatureHolder = signatureHolder; + } + + /** + * @see at.gv.egiz.pdfas.api.commons.SignatureInformation#getSignedData() + */ + public DataSource getSignedData() + { + return new DataSourceApiAdapter(this.signatureHolder.getDataSource()); + } + + /** + * @see at.gv.egiz.pdfas.api.commons.SignatureInformation#getInternalSignatureInformation() + */ + public Object getInternalSignatureInformation() + { + return this.signatureHolder; + } + + /** + * @see at.gv.egiz.pdfas.api.commons.SignatureInformation#getSignatureType() + */ + public String getSignatureType() + { + if (this.signatureHolder.getSignatureObject().isBinary()) + { + return Constants.SIGNATURE_TYPE_BINARY; + } + return Constants.SIGNATURE_TYPE_TEXTUAL; + } + + + /** + * @see at.gv.egiz.pdfas.api.commons.SignatureInformation#getSignerCertificate() + */ + public X509Certificate getSignerCertificate() + { + return this.signatureHolder.getSignatureObject().getX509Cert().getX509Certificate(); + } + + /** + * @see at.gv.egiz.pdfas.api.commons.SignatureInformation#getSigningTime() + */ + public Date getSigningTime() + { + String date_value = this.signatureHolder.getSignatureObject().getSignationDate(); + Date date = EGIZDate.parseDateFromString(date_value); + return date; + } + +} diff --git a/src/main/java/at/gv/egiz/pdfas/impl/api/commons/SignatureProfileImpl.java b/src/main/java/at/gv/egiz/pdfas/impl/api/commons/SignatureProfileImpl.java new file mode 100644 index 0000000..0d2bfdd --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/impl/api/commons/SignatureProfileImpl.java @@ -0,0 +1,56 @@ +/** + * + */ +package at.gv.egiz.pdfas.impl.api.commons; + +import at.gv.egiz.pdfas.api.commons.SignatureProfile; + +/** + * Holds the data of a signature profile. + * + * @author wprinz + */ +public class SignatureProfileImpl implements SignatureProfile +{ + + /** + * The profile identifier. + */ + protected String profileId = null; + + /** + * The MOA key identifiert of this profile. + */ + protected String moaKeyIdentifier = null; + + /** + * Constructor. + * + * @param profileId + * The profile identifier. + * @param moaKeyIdentifier + * The MOA key identifiert of this profile. + */ + public SignatureProfileImpl(String profileId, String moaKeyIdentifier) + { + this.profileId = profileId; + this.moaKeyIdentifier = moaKeyIdentifier; + } + + /** + * @see at.gv.egiz.pdfas.api.commons.SignatureProfile#getProfileId() + */ + public String getProfileId() + { + return this.profileId; + } + + /** + * @see at.gv.egiz.pdfas.api.commons.SignatureProfile#getMOAKeyIdentifier() + */ + public String getMOAKeyIdentifier() + { + return this.moaKeyIdentifier; + } + +} diff --git a/src/main/java/at/gv/egiz/pdfas/impl/api/commons/TextDataSourceAdapter.java b/src/main/java/at/gv/egiz/pdfas/impl/api/commons/TextDataSourceAdapter.java new file mode 100644 index 0000000..4b34d6f --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/impl/api/commons/TextDataSourceAdapter.java @@ -0,0 +1,52 @@ +/** + * + */ +package at.gv.egiz.pdfas.impl.api.commons; + +import java.io.UnsupportedEncodingException; + +import at.gv.egiz.pdfas.api.io.TextBased; +import at.gv.egiz.pdfas.impl.input.TextDataSourceImpl; + +/** + * Adapter that converts an API DataSource to a framework TextDataSource. + * + * @author wprinz + */ +public class TextDataSourceAdapter extends TextDataSourceImpl +{ + /** + * The API DataSource to be adapted to a framework TextDataSource. + */ + protected at.gv.egiz.pdfas.api.io.DataSource apiDataSource = null; + + /** + * Constructor. + * + * @param apiDataSource + * The API DataSource to be adapted to a framework TextDataSource. + * @throws UnsupportedEncodingException + */ + public TextDataSourceAdapter(at.gv.egiz.pdfas.api.io.DataSource apiDataSource) throws UnsupportedEncodingException + { + super(null); + this.apiDataSource = apiDataSource; + + if (this.apiDataSource instanceof TextBased) + { + TextBased tb = (TextBased) this.apiDataSource; + this.text = tb.getText(); + } + else + { + byte[] data = this.apiDataSource.getAsByteArray(); + String characterEncoding = this.apiDataSource.getCharacterEncoding(); + if (characterEncoding == null) + { + throw new UnsupportedEncodingException("The characterEncoding must not be null. Specify a correct encoding."); + } + this.text = new String(data, characterEncoding); + } + assert this.text != null; + } +} -- cgit v1.2.3