From fc44d4bcad00192f0df8f6086737b9b126094dcd Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Thu, 26 Sep 2013 15:48:43 +0200 Subject: initial code commit --- .../java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java | 69 ++++++ .../lib/impl/configuration/ConfigurationImpl.java | 110 +++++++++ .../impl/configuration/GlobalConfiguration.java | 21 ++ .../configuration/PlaceholderConfiguration.java | 23 ++ .../SignatureProfileConfiguration.java | 21 ++ .../configuration/SpecificBaseConfiguration.java | 13 ++ .../pdfas/lib/impl/configuration/package-info.java | 8 + .../at/gv/egiz/pdfas/lib/impl/package-info.java | 8 + .../pdfas/lib/impl/positioning/Positioning.java | 251 +++++++++++++++++++++ .../pdfas/lib/impl/positioning/package-info.java | 8 + .../egiz/pdfas/lib/impl/stamping/IPDFStamper.java | 12 + .../pdfas/lib/impl/stamping/IPDFVisualObject.java | 12 + .../pdfas/lib/impl/stamping/StamperFactory.java | 18 ++ .../egiz/pdfas/lib/impl/stamping/package-info.java | 8 + .../pdfas/lib/impl/status/OperationStatus.java | 76 +++++++ .../gv/egiz/pdfas/lib/impl/status/PDFObject.java | 31 +++ .../pdfas/lib/impl/status/RequestedSignature.java | 53 +++++ .../egiz/pdfas/lib/impl/status/package-info.java | 1 + 18 files changed, 743 insertions(+) create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/ConfigurationImpl.java create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/GlobalConfiguration.java create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/PlaceholderConfiguration.java create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/SignatureProfileConfiguration.java create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/SpecificBaseConfiguration.java create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/package-info.java create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/package-info.java create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/positioning/Positioning.java create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/positioning/package-info.java create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/IPDFStamper.java create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/IPDFVisualObject.java create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/StamperFactory.java create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/package-info.java create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/PDFObject.java create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/RequestedSignature.java create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/package-info.java (limited to 'pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl') 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 new file mode 100644 index 00000000..d7ed5f3a --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java @@ -0,0 +1,69 @@ +package at.gv.egiz.pdfas.lib.impl; + +import java.util.List; + +import at.gv.egiz.pdfas.common.exceptions.PdfAsException; +import at.gv.egiz.pdfas.common.settings.ISettings; +import at.gv.egiz.pdfas.lib.api.Configuration; +import at.gv.egiz.pdfas.lib.api.IConfigurationConstants; +import at.gv.egiz.pdfas.lib.api.PdfAs; +import at.gv.egiz.pdfas.lib.api.sign.SignParameter; +import at.gv.egiz.pdfas.lib.api.sign.SignResult; +import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter; +import at.gv.egiz.pdfas.lib.api.verify.VerifyResult; +import at.gv.egiz.pdfas.lib.impl.configuration.ConfigurationImpl; +import at.gv.egiz.pdfas.lib.impl.configuration.PlaceholderConfiguration; +import at.gv.egiz.pdfas.lib.impl.status.OperationStatus; +import at.gv.egiz.pdfas.lib.impl.status.RequestedSignature; + +public class PdfAsImpl implements PdfAs, IConfigurationConstants { + + public SignResult sign(SignParameter parameter) throws PdfAsException { + // TODO: verify signParameter + + // Status initialization + if(!(parameter.getConfiguration() instanceof ISettings)) { + + } + ISettings settings = (ISettings) parameter.getConfiguration(); + OperationStatus status = new OperationStatus(settings, parameter); + PlaceholderConfiguration placeholderConfiguration = status.getPlaceholderConfiguration(); + // set Original PDF Document Data + status.getPdfObject().setOriginalDocument(parameter.getDataSource().getByteData()); + + + // Placeholder search? + if(placeholderConfiguration.isGlobalPlaceholderEnabled()) { + // TODO: Do placeholder search + } + + RequestedSignature requestedSignature = new RequestedSignature(status); + + // TODO get Certificate + + if(requestedSignature.isVisual()) { + // TODO: SignBlockCreationStage (visual) -> create visual signature block (logicaly) + + // TODO: PositioningStage (visual) -> find position or use fixed position + + // TODO: StampingStage (visual) -> stamp logical signature block to location (itext) + } else { + // Stamped Object is equal to original + status.getPdfObject().setStampedDocument(status.getPdfObject().getOriginalDocument()); + } + + // TODO: Create signature + + return null; + } + + public List verify(VerifyParameter parameter) { + // TODO Auto-generated method stub + return null; + } + + public Configuration getConfiguration() { + return new ConfigurationImpl(); + } + +} diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/ConfigurationImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/ConfigurationImpl.java new file mode 100644 index 00000000..b901b597 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/ConfigurationImpl.java @@ -0,0 +1,110 @@ +package at.gv.egiz.pdfas.lib.impl.configuration; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; +import java.util.Vector; + +import at.gv.egiz.pdfas.common.settings.ISettings; +import at.gv.egiz.pdfas.common.settings.Settings; +import at.gv.egiz.pdfas.lib.api.Configuration; + +public class ConfigurationImpl implements ISettings, Configuration { + + protected Properties overwrittenProperties = new Properties(); + + public void setValue(String key, String value) { + overwrittenProperties.setProperty(key, value); + } + + public String getValue(String key) { + if(overwrittenProperties.containsKey(key)) { + return overwrittenProperties.getProperty(key); + } else { + return Settings.getInstance().getValue(key); + } + } + + public boolean hasValue(String key) { + if(overwrittenProperties.containsKey(key)) { + return true; + } else { + return Settings.getInstance().hasValue(key); + } + } + + public Map getValuesPrefix(String prefix) { + + Map valueMap = null; + valueMap = Settings.getInstance().getValuesPrefix(prefix); + if(valueMap == null) { + valueMap = new HashMap(); + } + + Iterator keyIterator = overwrittenProperties.keySet().iterator(); + + while(keyIterator.hasNext()) { + String key = keyIterator.next().toString(); + + if(key.startsWith(prefix)) { + valueMap.put(key, overwrittenProperties.getProperty(key)); + } + } + + if(valueMap.isEmpty()) { + return null; + } + + return valueMap; + } + + public Vector getFirstLevelKeys(String prefix) { + + Vector valueMap = Settings.getInstance().getFirstLevelKeys(prefix); + if(valueMap == null) { + valueMap = new Vector(); + } + + + String mPrefix = prefix.endsWith(".")?prefix:prefix+"."; + Iterator keyIterator = overwrittenProperties.keySet().iterator(); + + while(keyIterator.hasNext()) { + String key = keyIterator.next().toString(); + + if(key.startsWith(prefix)) { + int keyIdx = key.indexOf('.', mPrefix.length()) > 0 ? key.indexOf('.', mPrefix.length()) : key.length(); + String firstLevels = key.substring(0, keyIdx); + if(!valueMap.contains(firstLevels)) { + valueMap.add(firstLevels); + } + } + } + + if(valueMap.isEmpty()) { + return null; + } + + return valueMap; + } + + public boolean hasPrefix(String prefix) { + + if(Settings.getInstance().hasPrefix(prefix)) { + return true; + } + + Iterator keyIterator = overwrittenProperties.keySet().iterator(); + while(keyIterator.hasNext()) { + String key = keyIterator.next().toString(); + + if(key.startsWith(prefix)) { + return true; + } + } + return false; + } + + +} diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/GlobalConfiguration.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/GlobalConfiguration.java new file mode 100644 index 00000000..2124f63e --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/GlobalConfiguration.java @@ -0,0 +1,21 @@ +package at.gv.egiz.pdfas.lib.impl.configuration; + +import at.gv.egiz.pdfas.common.settings.ISettings; +import at.gv.egiz.pdfas.lib.api.Configuration; +import at.gv.egiz.pdfas.lib.api.IConfigurationConstants; + +public class GlobalConfiguration extends SpecificBaseConfiguration + implements IConfigurationConstants { + + public GlobalConfiguration(ISettings configuration) { + super(configuration); + } + + public String getDefaultSignatureProfile() { + if(this.configuration.hasValue(DEFAULT_SIGNATURE_PROFILE)) { + return this.configuration.getValue(DEFAULT_SIGNATURE_PROFILE); + } + return null; + } + +} diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/PlaceholderConfiguration.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/PlaceholderConfiguration.java new file mode 100644 index 00000000..7d3beb5c --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/PlaceholderConfiguration.java @@ -0,0 +1,23 @@ +package at.gv.egiz.pdfas.lib.impl.configuration; + +import at.gv.egiz.pdfas.common.settings.ISettings; +import at.gv.egiz.pdfas.lib.api.IConfigurationConstants; + +public class PlaceholderConfiguration extends SpecificBaseConfiguration + implements IConfigurationConstants { + + public PlaceholderConfiguration(ISettings configuration) { + super(configuration); + } + + public boolean isGlobalPlaceholderEnabled() { + if(configuration.hasValue(PLACEHOLDER_SEARCH_ENABLED)) { + String value = configuration.getValue(PLACEHOLDER_SEARCH_ENABLED); + if(value.equalsIgnoreCase(TRUE)) { + return true; + } + } + return false; + } + +} diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/SignatureProfileConfiguration.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/SignatureProfileConfiguration.java new file mode 100644 index 00000000..d7792dca --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/SignatureProfileConfiguration.java @@ -0,0 +1,21 @@ +package at.gv.egiz.pdfas.lib.impl.configuration; + +import at.gv.egiz.pdfas.common.settings.ISettings; +import at.gv.egiz.pdfas.lib.api.IConfigurationConstants; + +public class SignatureProfileConfiguration extends SpecificBaseConfiguration + implements IConfigurationConstants { + + protected String profileID; + + public SignatureProfileConfiguration(ISettings configuration, + String profileID) { + super(configuration); + this.profileID = profileID; + } + + public boolean isVisualSignature() { + String key = SIG_OBJECT + SEPERATOR + profileID + SEPERATOR + TABLE + SEPERATOR + MAIN; + return this.configuration.hasPrefix(key); + } +} diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/SpecificBaseConfiguration.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/SpecificBaseConfiguration.java new file mode 100644 index 00000000..88c7b3d7 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/SpecificBaseConfiguration.java @@ -0,0 +1,13 @@ +package at.gv.egiz.pdfas.lib.impl.configuration; + +import at.gv.egiz.pdfas.common.settings.ISettings; + +public abstract class SpecificBaseConfiguration { + + protected ISettings configuration; + + public SpecificBaseConfiguration(ISettings configuration) { + this.configuration = configuration; + } + +} diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/package-info.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/package-info.java new file mode 100644 index 00000000..d766824e --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/package-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * @author afitzek + * + */ +package at.gv.egiz.pdfas.lib.impl.configuration; \ No newline at end of file diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/package-info.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/package-info.java new file mode 100644 index 00000000..aba811aa --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/package-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * @author afitzek + * + */ +package at.gv.egiz.pdfas.lib.impl; \ No newline at end of file diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/positioning/Positioning.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/positioning/Positioning.java new file mode 100644 index 00000000..340ba0bb --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/positioning/Positioning.java @@ -0,0 +1,251 @@ +package at.gv.egiz.pdfas.lib.impl.positioning; + +import at.gv.egiz.pdfas.common.exceptions.PdfAsException; +import at.gv.egiz.pdfas.lib.impl.stamping.IPDFVisualObject; +import at.gv.egiz.pdfas.common.utils.PDFUtils; +import at.knowcenter.wag.egov.egiz.pdf.PDFUtilities; +import at.knowcenter.wag.egov.egiz.pdf.PositioningInstruction; +import at.knowcenter.wag.egov.egiz.pdf.TablePos; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDPage; +import org.apache.pdfbox.pdmodel.common.PDRectangle; + +/** + * Created with IntelliJ IDEA. + * User: afitzek + * Date: 8/29/13 + * Time: 4:30 PM + * To change this template use File | Settings | File Templates. + */ +public class Positioning { + + /** + * The left/right margin. + */ + public static final float SIGNATURE_MARGIN_HORIZONTAL = 50f; + + /** + * The top/bottom margin. + */ + public static final float SIGNATURE_MARGIN_VERTICAL = 20f; + + /** + * Evalutates absolute positioning and prepares the PositioningInstruction for + * placing the table. + * + * @param pos + * The absolute positioning parameter. If null it is sought in the + * profile definition. + * @param signature_type + * The profile definition of the table to be written. + * @param pdfDataSource + * The pdf. + * @param pdf_table + * The pdf table to be written. + * @return Returns the PositioningInformation. + * @throws PdfAsException + * F.e. + */ + public static PositioningInstruction determineTablePositioning(TablePos pos, String signature_type, + PDDocument pdfDataSource, IPDFVisualObject pdf_table) throws PdfAsException + { + boolean legacy32 = false; + + //TODO: settings reader ... + + /* + if (pos == null) + { + String pos_string = SettingsReader.getInstance().getSetting(SignatureTypes.SIG_OBJ + signature_type + ".pos", null); + if (pos_string != null) + { + pos = PdfAS.parsePositionFromPosString(pos_string); + } + } + if (pos == null) + { + // The default algorithm. x,y,w =auto ,p=lastpage, f:ignored because + // y:auto + pos = new TablePos(); + } + + // afitzek + // Allow legacy positioning (3.2) for BRZ Templates ... + boolean legacy32 = false; + String leg = SettingsReader.getInstance().getSetting(SignatureTypes.SIG_OBJ + signature_type + ".legacy.pos", "false"); + if (leg != null) { + if ("true".equals(leg.trim())) { + legacy32 = true; + } + } + */ + // System.out.println("Tablepos="+pos); + return adjustSignatureTableandCalculatePosition(pdfDataSource, pdf_table, pos, legacy32); + } + + /** + * Sets the width of the table according to the layout of the document and + * calculates the y position where the PDFPTable should be placed. + * + * @param pdfDataSource + * The PDF document. + * @param pdf_table + * The PDFPTable to be placed. + * @return Returns the position where the PDFPTable should be placed. + * @throws PdfAsException + * F.e. + */ + public static PositioningInstruction adjustSignatureTableandCalculatePosition(final PDDocument pdfDataSource, + IPDFVisualObject pdf_table, TablePos pos, boolean legacy32) throws PdfAsException + { + + try { + PDFUtils.checkPDFPermissions(pdfDataSource); + // get pages of currentdocument + + int doc_pages = pdfDataSource.getNumberOfPages(); + int page = doc_pages; + boolean make_new_page = pos.isNewPage(); + if (!(pos.isNewPage() || pos.isPauto())) + { + // we should posit signaturtable on this page + + page = pos.getPage(); + // System.out.println("XXXXPAGE="+page+" doc_pages="+doc_pages); + if (page > doc_pages) + { + make_new_page = true; + page = doc_pages; + // throw new PDFDocumentException(227, "Page number is to big(=" + page+ + // ") cannot be parsed."); + } + } + + PDPage pdPage = (PDPage)pdfDataSource.getDocumentCatalog().getAllPages().get(page - 1); + PDRectangle cropBox = pdPage.getCropBox(); + + if(cropBox == null) { + cropBox = pdPage.findCropBox(); + } + + + if(cropBox == null) { + cropBox = pdPage.findMediaBox(); + } + + //TODO: fallback to MediaBox if Cropbox not available! + + // getPagedimensions + //Rectangle psize = reader.getPageSizeWithRotation(page); + //int page_rotation = reader.getPageRotation(page); + + //Integer rotation = pdPage.getRotation(); + //int page_rotation = rotation.intValue(); + + float page_width = cropBox.getWidth(); + float page_height = cropBox.getHeight(); + + // now we can calculate x-position + float pre_pos_x = SIGNATURE_MARGIN_HORIZONTAL; + if (!pos.isXauto()) + { + // we do have absolute x + pre_pos_x = pos.getPosX(); + } + // calculate width + // center + float pre_width = page_width - 2*pre_pos_x; + if (!pos.isWauto()) + { + // we do have absolute width + pre_width = pos.getWidth(); + if (pos.isXauto()) + { // center x + pre_pos_x = (page_width - pre_width) / 2; + } + } + final float pos_x = pre_pos_x; + final float width = pre_width; + // Signatur table dimensions are complete + pdf_table.setWidth(width); + pdf_table.fixWidth(); + //pdf_table.setTotalWidth(width); + //pdf_table.setLockedWidth(true); + + final float table_height = pdf_table.getHeight(); + // now check pos_y + float pos_y = pos.getPosY(); + + // in case an absolute y position is already given OR + // if the table is related to an invisible signature + // there is no need for further calculations + // (fixed adding new page in case of invisible signatures) + if (!pos.isYauto() || table_height == 0) + { + // we do have y-position too --> all parameters but page ok + if (make_new_page) + { + page++; + } + return new PositioningInstruction(make_new_page, page, pos_x, pos_y); + } + // pos_y is auto + if (make_new_page) + { + // ignore footer in new page + page++; + pos_y = page_height - SIGNATURE_MARGIN_VERTICAL; + return new PositioningInstruction(make_new_page, page, pos_x, pos_y); + } + // up to here no checks have to be made if Tablesize and Pagesize are fit + // Now we have to getfreespace in page and reguard footerline + float footer_line = pos.getFooterLine(); + float pre_page_length = PDFUtilities.calculatePageLength(pdfDataSource, page - 1, page_height - footer_line, /*page_rotation,*/ legacy32); + if (pre_page_length == Float.NEGATIVE_INFINITY) + { + // we do have an empty page or nothing in area above footerline + pre_page_length = page_height; + // no text --> SIGNATURE_BORDER + pos_y = page_height - SIGNATURE_MARGIN_VERTICAL; + if (pos_y - footer_line <= table_height) + { + make_new_page = true; + if (!pos.isPauto()) + { + // we have to correct pagenumber + page = pdfDataSource.getNumberOfPages(); + } + page++; + // no text --> SIGNATURE_BORDER + pos_y = page_height - SIGNATURE_MARGIN_VERTICAL; + } + return new PositioningInstruction(make_new_page, page, pos_x, pos_y); + } + final float page_length = pre_page_length; + // we do have text take SIGNATURE_MARGIN + pos_y = page_height - page_length - SIGNATURE_MARGIN_VERTICAL; + if (pos_y - footer_line <= table_height) + { + make_new_page = true; + if (!pos.isPauto()) + { + // we have to correct pagenumber in case of absolute page and not enough + // space + page = pdfDataSource.getNumberOfPages(); + } + page++; + // no text --> SIGNATURE_BORDER + pos_y = page_height - SIGNATURE_MARGIN_VERTICAL; + } + return new PositioningInstruction(make_new_page, page, pos_x, pos_y); + } finally { + if (pdfDataSource != null) { + try { + pdfDataSource.close(); + } catch (Exception e) { + } + } + } + } + +} diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/positioning/package-info.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/positioning/package-info.java new file mode 100644 index 00000000..5b209e06 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/positioning/package-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * @author afitzek + * + */ +package at.gv.egiz.pdfas.lib.impl.positioning; \ No newline at end of file diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/IPDFStamper.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/IPDFStamper.java new file mode 100644 index 00000000..f1b59ceb --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/IPDFStamper.java @@ -0,0 +1,12 @@ +package at.gv.egiz.pdfas.lib.impl.stamping; + +import at.gv.egiz.pdfas.common.exceptions.PdfAsException; +import at.gv.egiz.pdfas.lib.impl.status.PDFObject; +import at.knowcenter.wag.egov.egiz.pdf.PositioningInstruction; +import at.knowcenter.wag.egov.egiz.table.Table; + +public interface IPDFStamper { + public IPDFVisualObject createVisualPDFObject(PDFObject pdf, Table table); + public byte[] writeVisualObject(IPDFVisualObject visualObject, PositioningInstruction positioningInstruction, + byte[] pdfData) throws PdfAsException; +} diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/IPDFVisualObject.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/IPDFVisualObject.java new file mode 100644 index 00000000..fd7cac5c --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/IPDFVisualObject.java @@ -0,0 +1,12 @@ +package at.gv.egiz.pdfas.lib.impl.stamping; + +public interface IPDFVisualObject { + public void setWidth(float width); + public void fixWidth(); + public float getHeight(); + public float getWidth(); + public void setXPos(float x); + public void setYPos(float x); + public int getPage(); + public void setPage(int page); +} diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/StamperFactory.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/StamperFactory.java new file mode 100644 index 00000000..1720057a --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/StamperFactory.java @@ -0,0 +1,18 @@ +package at.gv.egiz.pdfas.lib.impl.stamping; + +import at.gv.egiz.pdfas.common.exceptions.PdfAsException; + +public class StamperFactory { + + public static final String DEFAULT_STAMPER_CLASS = "at.gv.egiz.pdfas.stmp.itext.ITextStamper"; + + public static IPDFStamper createDefaultStamper() throws PdfAsException { + try { + Class cls = (Class) + Class.forName(DEFAULT_STAMPER_CLASS); + return cls.newInstance(); + } catch (Throwable e) { + throw new PdfAsException("NO STAMPER!", e); + } + } +} diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/package-info.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/package-info.java new file mode 100644 index 00000000..496f592f --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/package-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * @author afitzek + * + */ +package at.gv.egiz.pdfas.lib.impl.stamping; \ No newline at end of file diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java new file mode 100644 index 00000000..d7b956a7 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java @@ -0,0 +1,76 @@ +package at.gv.egiz.pdfas.lib.impl.status; + +import java.util.HashMap; +import java.util.Map; + +import at.gv.egiz.pdfas.common.settings.ISettings; +import at.gv.egiz.pdfas.lib.api.sign.SignParameter; +import at.gv.egiz.pdfas.lib.impl.configuration.GlobalConfiguration; +import at.gv.egiz.pdfas.lib.impl.configuration.PlaceholderConfiguration; +import at.gv.egiz.pdfas.lib.impl.configuration.SignatureProfileConfiguration; + +public class OperationStatus { + + private SignParameter signParamter; + private PDFObject pdfObject = new PDFObject(); + + + private ISettings configuration; + private PlaceholderConfiguration placeholderConfiguration = null; + private GlobalConfiguration gloablConfiguration = null; + private Map signatureProfiles = + new HashMap(); + + public OperationStatus(ISettings configuration, SignParameter signParameter) { + this.configuration = configuration; + this.signParamter = signParameter; + } + + // ======================================================================== + + public PlaceholderConfiguration getPlaceholderConfiguration() { + if(this.placeholderConfiguration == null) { + this.placeholderConfiguration = + new PlaceholderConfiguration(this.configuration); + } + return this.placeholderConfiguration; + } + + public GlobalConfiguration getGlobalConfiguration() { + if(this.gloablConfiguration == null) { + this.gloablConfiguration = + new GlobalConfiguration(this.configuration); + } + return this.gloablConfiguration; + } + + public SignatureProfileConfiguration getSignatureProfileConfiguration(String profileID) { + + SignatureProfileConfiguration signatureProfileConfiguration = signatureProfiles.get(profileID); + if(signatureProfileConfiguration == null) { + signatureProfileConfiguration = new SignatureProfileConfiguration(this.configuration, profileID); + signatureProfiles.put(profileID, signatureProfileConfiguration); + } + + return signatureProfileConfiguration; + } + + // ======================================================================== + + public PDFObject getPdfObject() { + return pdfObject; + } + + public void setPdfObject(PDFObject pdfObject) { + this.pdfObject = pdfObject; + } + + public SignParameter getSignParamter() { + return signParamter; + } + + public void setSignParamter(SignParameter signParamter) { + this.signParamter = signParamter; + } + +} diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/PDFObject.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/PDFObject.java new file mode 100644 index 00000000..1fe64bee --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/PDFObject.java @@ -0,0 +1,31 @@ +package at.gv.egiz.pdfas.lib.impl.status; + +public class PDFObject { + private byte[] originalDocument; + private byte[] stampedDocument; + private byte[] signedDocument; + + public byte[] getOriginalDocument() { + return originalDocument; + } + + public void setOriginalDocument(byte[] originalDocument) { + this.originalDocument = originalDocument; + } + + public byte[] getStampedDocument() { + return stampedDocument; + } + + public void setStampedDocument(byte[] stampedDocument) { + this.stampedDocument = stampedDocument; + } + + public byte[] getSignedDocument() { + return signedDocument; + } + + public void setSignedDocument(byte[] signedDocument) { + this.signedDocument = signedDocument; + } +} diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/RequestedSignature.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/RequestedSignature.java new file mode 100644 index 00000000..a78828f3 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/RequestedSignature.java @@ -0,0 +1,53 @@ +package at.gv.egiz.pdfas.lib.impl.status; + +import at.gv.egiz.pdfas.common.exceptions.PdfAsException; +import at.gv.egiz.pdfas.common.exceptions.PdfAsSettingsException; +import at.knowcenter.wag.egov.egiz.pdf.TablePos; + + +public class RequestedSignature { + private String signatureProfile; + private TablePos signaturePosition; + private OperationStatus status; + //private IPlainSigner signer = null; + + public RequestedSignature(OperationStatus status) throws PdfAsException { + + this.status = status; + + String profileID = status.getSignParamter().getSignatureProfileId(); + + if(profileID == null) { + profileID = status.getGlobalConfiguration().getDefaultSignatureProfile(); + + if(profileID == null) { + throw new PdfAsSettingsException("Failed to determine Signature Profile!"); + } + } + + this.signatureProfile = profileID; + + if(status.getSignParamter().getSignaturePosition() == null) { + this.signaturePosition = new TablePos(); + } else { + this.signaturePosition = new TablePos(status.getSignParamter().getSignaturePosition()); + } + } + + public boolean isVisual() { + return this.status.getSignatureProfileConfiguration(signatureProfile).isVisualSignature(); + } + + public TablePos getTablePos() { + return this.signaturePosition; + } + +/* + public IPlainSigner getSigner() { + return signer; + } + + public void setSigner(IPlainSigner signer) { + this.signer = signer; + }*/ +} diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/package-info.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/package-info.java new file mode 100644 index 00000000..4321a9b5 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/package-info.java @@ -0,0 +1 @@ +package at.gv.egiz.pdfas.lib.impl.status; \ No newline at end of file -- cgit v1.2.3