aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePositioning.java80
-rw-r--r--src/main/java/at/gv/egiz/pdfas/exceptions/ErrorCode.java3
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java124
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/signator/binary/BinarySignator_1_0_0.java5
-rw-r--r--src/main/java/at/gv/egiz/pdfas/itext/IText.java111
-rw-r--r--src/main/java/at/gv/egiz/pdfas/test/CreateFreeTextTest.java26
-rw-r--r--src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java55
-rw-r--r--src/main/java/at/gv/egiz/pdfas/utils/PDFASUtils.java30
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java2
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/exceptions/OutOfMemoryException.java19
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java4
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java12
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/FormFields.java10
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/ProvidePDFServlet.java2
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java102
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/UpdateFormServlet.java24
-rw-r--r--src/main/java/demo/SignatureCreationDemo.java3
17 files changed, 488 insertions, 124 deletions
diff --git a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePositioning.java b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePositioning.java
index b9e2c8a..42b02eb 100644
--- a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePositioning.java
+++ b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePositioning.java
@@ -3,6 +3,8 @@
*/
package at.gv.egiz.pdfas.api.sign.pos;
+import java.util.StringTokenizer;
+
import at.gv.egiz.pdfas.api.sign.pos.axis.AbsoluteAxisAlgorithm;
import at.gv.egiz.pdfas.api.sign.pos.axis.AutoAxisAlgorithm;
import at.gv.egiz.pdfas.api.sign.pos.axis.AxisAlgorithm;
@@ -10,6 +12,8 @@ import at.gv.egiz.pdfas.api.sign.pos.page.AbsolutePageAlgorithm;
import at.gv.egiz.pdfas.api.sign.pos.page.AutoPageAlgorithm;
import at.gv.egiz.pdfas.api.sign.pos.page.NewPageAlgorithm;
import at.gv.egiz.pdfas.api.sign.pos.page.PageAlgorithm;
+import at.gv.egiz.pdfas.exceptions.ErrorCode;
+import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
/**
* Defines how the signature positioning is to be performed.
@@ -186,4 +190,80 @@ public class SignaturePositioning
this.footerLine = footerLine;
}
+ public SignaturePositioning() {
+ }
+
+ public SignaturePositioning(String position) throws PDFDocumentException {
+ if (position != null) {
+ StringTokenizer tokenizer = new StringTokenizer(position, ";");
+ while (tokenizer.hasMoreTokens()) {
+ String token = tokenizer.nextToken().replaceAll(" ", "");
+ String[] sToken = token.split(":");
+ if (sToken == null || sToken.length != 2 || sToken[0].length() != 1) {
+ throw new PDFDocumentException(ErrorCode.INVALID_SIGNATURE_POSITION, "Invalid signature position element: " + token);
+ }
+ char cmd = sToken[0].toLowerCase().charAt(0);
+ String value = sToken[1];
+ switch (cmd) {
+ case 'x':
+ if ("auto".equalsIgnoreCase(value)) {
+ this.setXAlgorithm(new AutoAxisAlgorithm());
+ } else {
+ try {
+ this.setXAlgorithm(new AbsoluteAxisAlgorithm(Float.parseFloat(value)));
+ } catch (NumberFormatException e) {
+ throw new PDFDocumentException(ErrorCode.INVALID_SIGNATURE_POSITION, "Invalid signature position element: " + token);
+ }
+ }
+ break;
+ case 'y':
+ if ("auto".equalsIgnoreCase(value)) {
+ this.setYAlgorithm(new AutoAxisAlgorithm());
+ } else {
+ try {
+ this.setYAlgorithm(new AbsoluteAxisAlgorithm(Float.parseFloat(value)));
+ } catch (NumberFormatException e) {
+ throw new PDFDocumentException(ErrorCode.INVALID_SIGNATURE_POSITION, "Invalid signature position element: " + token);
+ }
+ }
+ break;
+ case 'w':
+ if ("auto".equalsIgnoreCase(value)) {
+ this.setWidthAlgorithm(new AutoAxisAlgorithm());
+ } else {
+ try {
+ this.setWidthAlgorithm(new AbsoluteAxisAlgorithm(Float.parseFloat(value)));
+ } catch (NumberFormatException e) {
+ throw new PDFDocumentException(ErrorCode.INVALID_SIGNATURE_POSITION, "Invalid signature position element: " + token);
+ }
+ }
+ break;
+ case 'p':
+ if ("auto".equalsIgnoreCase(value)) {
+ this.setPageAlgorithm(new AutoPageAlgorithm());
+ } else if ("new".equalsIgnoreCase(value)) {
+ this.setPageAlgorithm(new NewPageAlgorithm());
+ } else {
+ try {
+ this.setPageAlgorithm(new AbsolutePageAlgorithm(Integer.parseInt(value)));
+ } catch (NumberFormatException e) {
+ throw new PDFDocumentException(ErrorCode.INVALID_SIGNATURE_POSITION, "Invalid signature position element: " + token);
+ }
+ }
+ break;
+ case 'f':
+ try {
+ this.setFooterLine(Float.parseFloat(value));
+ } catch (NumberFormatException e) {
+ throw new PDFDocumentException(ErrorCode.INVALID_SIGNATURE_POSITION, "Invalid signature position element: " + token);
+ }
+ break;
+ default:
+ throw new PDFDocumentException(ErrorCode.INVALID_SIGNATURE_POSITION, "Invalid signature position element: " + token);
+ }
+ }
+ }
+ }
+
+
}
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 c53151f..9c2e440 100644
--- a/src/main/java/at/gv/egiz/pdfas/exceptions/ErrorCode.java
+++ b/src/main/java/at/gv/egiz/pdfas/exceptions/ErrorCode.java
@@ -16,6 +16,7 @@ public final class ErrorCode
{
public static final int EXTERNAL_ERROR = 0;
public static final int UNKNOWN_ERROR = 6;
+ public static final int OUT_OF_MEMORY_ERROR = 7;
public static final int SETTING_NOT_FOUND = 100;
public static final int SETTINGS_EXCEPTION = 101;
@@ -31,6 +32,8 @@ public final class ErrorCode
public static final int FONT_NOT_FOUND = 230;
public static final int DOCUMENT_IS_PROTECTED = 231;
+ public static final int INVALID_SIGNATURE_POSITION = 224;
+
public static final int SIGNATURE_COULDNT_BE_CREATED = 300;
public static final int SIGNED_TEXT_EMPTY = 301;
public static final int PROFILE_NOT_DEFINED = 302;
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java b/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java
index 824416f..2ccc1b7 100644
--- a/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java
+++ b/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java
@@ -50,6 +50,7 @@ import at.gv.egiz.pdfas.utils.ConfigUtils;
import at.knowcenter.wag.egov.egiz.PdfAS;
import at.knowcenter.wag.egov.egiz.PdfASID;
import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
+import at.knowcenter.wag.egov.egiz.exceptions.OutOfMemoryException;
import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
import at.knowcenter.wag.egov.egiz.exceptions.PresentableException;
import at.knowcenter.wag.egov.egiz.exceptions.SignatureException;
@@ -240,20 +241,24 @@ public class PdfAsObject implements PdfAs
TablePos pos = PosHelper.formTablePos(signParameters.getSignaturePositioning());
String connectorId = CommandlineConnectorChooser.chooseCommandlineConnectorForSign(signParameters.getSignatureDevice());
-
- SignatorInformation si = PdfAS.signCommandline(
- new PdfDataSourceAdapter(signParameters.getDocument()),
- new DataSinkAdapter(signParameters.getOutput()),
- signatorId,
- connectorId,
- signParameters.getSignatureProfileId(),
- signParameters.getSignatureKeyIdentifier(),
- pos,
- signParameters.getTimeStamperImpl()
- );
-
- return new SignResultImpl(signParameters.getOutput(), si.getSignSignatureObject().getX509Certificate(),
- new ActualSignaturePositionAdapter(si.getActualTablePos()), si.getNonTextualObjects());
+
+ try {
+ SignatorInformation si = PdfAS.signCommandline(
+ new PdfDataSourceAdapter(signParameters.getDocument()),
+ new DataSinkAdapter(signParameters.getOutput()),
+ signatorId,
+ connectorId,
+ signParameters.getSignatureProfileId(),
+ signParameters.getSignatureKeyIdentifier(),
+ pos,
+ signParameters.getTimeStamperImpl()
+ );
+ return new SignResultImpl(signParameters.getOutput(), si.getSignSignatureObject().getX509Certificate(),
+ new ActualSignaturePositionAdapter(si.getActualTablePos()), si.getNonTextualObjects());
+ } catch (java.lang.OutOfMemoryError e) {
+ throw new OutOfMemoryException(ErrorCode.OUT_OF_MEMORY_ERROR, "Insufficient memory allocated to virtual machine. Start Java with parameters \"-Xms128m -Xmx786m -XX:MaxPermSize=256m\".", e);
+ }
+
}
/**
@@ -364,31 +369,35 @@ public class PdfAsObject implements PdfAs
}
assert inputDataSource != null;
- ExtractionStage es = new ExtractionStage();
- List signature_holders = es.extractSignatureHolders(inputDataSource, parameters);
-
-// List sigInfs = new ArrayList(signature_holders.size());
- List sigInfs = new ArrayList();
- List noSigs = new ArrayList();
- Iterator it = signature_holders.iterator();
- while (it.hasNext())
- {
- SignatureHolder sh = (SignatureHolder)it.next();
-
- if(sh instanceof NoSignatureHolder) {
- noSigs.add(sh);
- } else {
-
- SignatureInformation si = new SignatureInformationAdapter(sh);
- sigInfs.add(si);
- if (analyzeParameters.isReturnNonTextualObjects()) {
- si.setNonTextualObjects(doExtractNonTexualObjects(sh, (PdfDataSource) inputDataSource));
- }
-
- }
+ try {
+ ExtractionStage es = new ExtractionStage();
+ List signature_holders = es.extractSignatureHolders(inputDataSource, parameters);
+
+ // List sigInfs = new ArrayList(signature_holders.size());
+ List sigInfs = new ArrayList();
+ List noSigs = new ArrayList();
+ Iterator it = signature_holders.iterator();
+ while (it.hasNext())
+ {
+ SignatureHolder sh = (SignatureHolder)it.next();
+
+ if(sh instanceof NoSignatureHolder) {
+ noSigs.add(sh);
+ } else {
+
+ SignatureInformation si = new SignatureInformationAdapter(sh);
+ sigInfs.add(si);
+ if (analyzeParameters.isReturnNonTextualObjects()) {
+ si.setNonTextualObjects(doExtractNonTexualObjects(sh, (PdfDataSource) inputDataSource));
+ }
+
+ }
+ }
+ return new AnalyzeResultImpl(sigInfs, noSigs);
+ } catch (java.lang.OutOfMemoryError e) {
+ throw new OutOfMemoryException(ErrorCode.OUT_OF_MEMORY_ERROR, "Insufficient memory allocated to virtual machine. Start Java with parameters \"-Xms128m -Xmx786m -XX:MaxPermSize=256m\".", e);
}
- return new AnalyzeResultImpl(sigInfs, noSigs);
}
private List doExtractNonTexualObjects(SignatureHolder sh, PdfDataSource pdfDataSource) {
@@ -433,25 +442,30 @@ public class PdfAsObject implements PdfAs
}
assert signature_holders.size() == signatures.size();
- List results = PdfAS.verifySignatureHolders(signature_holders, verifyAfterAnalysisParameters.getSignatureDevice(), verifyAfterAnalysisParameters.isReturnHashInputData(), verifyAfterAnalysisParameters.getVerificationTime());
-
- List vrs = new ArrayList(results.size());
-
- assert signature_holders.size() == results.size() : "Not all signatures were verified.";
-
- for (int i = 0; i < signature_holders.size(); i++)
- {
- SignatureResponse response = (SignatureResponse) results.get(i);
- SignatureHolder holder = (SignatureHolder) signature_holders.get(i);
-
- VerifyResult vr = new VerifyResultAdapter(response, holder, verifyAfterAnalysisParameters.getVerificationTime());
- vr.setNonTextualObjects( ((SignatureInformation) signatures.get(i)).getNonTextualObjects());
-
- vrs.add(vr);
+ try {
+ List results = PdfAS.verifySignatureHolders(signature_holders, verifyAfterAnalysisParameters.getSignatureDevice(), verifyAfterAnalysisParameters.isReturnHashInputData(), verifyAfterAnalysisParameters.getVerificationTime());
+
+ List vrs = new ArrayList(results.size());
+
+ assert signature_holders.size() == results.size() : "Not all signatures were verified.";
+
+ for (int i = 0; i < signature_holders.size(); i++)
+ {
+ SignatureResponse response = (SignatureResponse) results.get(i);
+ SignatureHolder holder = (SignatureHolder) signature_holders.get(i);
+
+ VerifyResult vr = new VerifyResultAdapter(response, holder, verifyAfterAnalysisParameters.getVerificationTime());
+ vr.setNonTextualObjects( ((SignatureInformation) signatures.get(i)).getNonTextualObjects());
+
+ vrs.add(vr);
+ }
+
+ VerifyResultsImpl verifyResults = new VerifyResultsImpl(vrs);
+ return verifyResults;
+ } catch (java.lang.OutOfMemoryError e) {
+ throw new OutOfMemoryException(ErrorCode.OUT_OF_MEMORY_ERROR, "Insufficient memory allocated to virtual machine. Start Java with parameters \"-Xms128m -Xmx786m -XX:MaxPermSize=256m\".", e);
}
-
- VerifyResultsImpl verifyResults = new VerifyResultsImpl(vrs);
- return verifyResults;
+
}
}
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/signator/binary/BinarySignator_1_0_0.java b/src/main/java/at/gv/egiz/pdfas/impl/signator/binary/BinarySignator_1_0_0.java
index 36d3764..bdb5fdb 100644
--- a/src/main/java/at/gv/egiz/pdfas/impl/signator/binary/BinarySignator_1_0_0.java
+++ b/src/main/java/at/gv/egiz/pdfas/impl/signator/binary/BinarySignator_1_0_0.java
@@ -17,6 +17,7 @@
*/
package at.gv.egiz.pdfas.impl.signator.binary;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -26,6 +27,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -40,6 +42,7 @@ import at.gv.egiz.pdfas.framework.signator.SignatorInformation;
import at.gv.egiz.pdfas.impl.input.CompoundPdfDataSourceImpl;
import at.gv.egiz.pdfas.impl.signator.IncrementalUpdateHelper;
import at.gv.egiz.pdfas.utils.OgnlUtil;
+import at.gv.egiz.pdfas.utils.PDFASUtils;
import at.knowcenter.wag.egov.egiz.PdfAS;
import at.knowcenter.wag.egov.egiz.PdfASID;
import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
@@ -199,7 +202,7 @@ public class BinarySignator_1_0_0 implements Signator
iui.invisibleKZString = invKZString;
String temp_string = iui.temp_ir_number + " " + iui.temp_ir_generation + " obj"; //$NON-NLS-1$//$NON-NLS-2$
- byte[] temp_bytes = temp_string.getBytes("US-ASCII"); //$NON-NLS-1$
+ byte[] temp_bytes = ArrayUtils.add(temp_string.getBytes("US-ASCII"), 0, (byte) 0x0A);
int temp_start = ByteArrayUtils.lastIndexOf(iui.signed_pdf, temp_bytes);
byte[] stream_bytes = new byte[] { '>', '>', 's', 't', 'r', 'e', 'a', 'm', 0x0A };
int stream_start = ByteArrayUtils.indexOf(iui.signed_pdf, temp_start, stream_bytes);
diff --git a/src/main/java/at/gv/egiz/pdfas/itext/IText.java b/src/main/java/at/gv/egiz/pdfas/itext/IText.java
new file mode 100644
index 0000000..767dbbc
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/itext/IText.java
@@ -0,0 +1,111 @@
+package at.gv.egiz.pdfas.itext;
+
+import java.awt.color.ICC_Profile;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.log4j.Logger;
+
+import com.lowagie.text.Document;
+import com.lowagie.text.DocumentException;
+import com.lowagie.text.Font;
+import com.lowagie.text.PageSize;
+import com.lowagie.text.Paragraph;
+import com.lowagie.text.Rectangle;
+import com.lowagie.text.pdf.BaseFont;
+import com.lowagie.text.pdf.PdfArray;
+import com.lowagie.text.pdf.PdfDictionary;
+import com.lowagie.text.pdf.PdfICCBased;
+import com.lowagie.text.pdf.PdfName;
+import com.lowagie.text.pdf.PdfString;
+import com.lowagie.text.pdf.PdfWriter;
+
+public final class IText {
+
+ private IText() {
+ }
+
+ private static final Logger LOG = Logger.getLogger(IText.class);
+
+ private static final Font DEFAULT_FONT = new Font(Font.HELVETICA, 12, Font.NORMAL);
+ private static final String DEFAULT_TTF_FONT_RESOURCE = "DejaVuSansCondensed.ttf";
+ private static final String DEFAULT_ICC_PROFILE_RESOURCE = "srgb.profile";
+ private static final Rectangle DEFAULT_PAGE_SIZE = PageSize.A4;
+ private static final int[] DEFAULT_MARGINS_MM = { 25, 25, 25, 25 }; // top, right, bottom, left
+ public static final String DEFAULT_FILENAME = "text";
+
+ private static Font DEFAULT_TTF_FONT;
+ private static PdfICCBased DEFAULT_ICC_COLOR_SPACE;
+
+ static {
+ try {
+ byte[] ttfFontData = IOUtils.toByteArray(IText.class.getResourceAsStream(DEFAULT_TTF_FONT_RESOURCE));
+ DEFAULT_TTF_FONT = new Font(BaseFont.createFont(DEFAULT_TTF_FONT_RESOURCE, BaseFont.WINANSI, true, true, ttfFontData, null));
+ } catch (Exception e) {
+ LOG.error(e);
+ DEFAULT_TTF_FONT = DEFAULT_FONT;
+ }
+ try {
+ byte[] iccData = IOUtils.toByteArray(IText.class.getResourceAsStream(DEFAULT_ICC_PROFILE_RESOURCE));
+ DEFAULT_ICC_COLOR_SPACE = new PdfICCBased(ICC_Profile.getInstance(iccData));
+ DEFAULT_ICC_COLOR_SPACE.remove(PdfName.ALTERNATE);
+ } catch (Exception e) {
+ LOG.error(e);
+ DEFAULT_ICC_COLOR_SPACE = null;
+ }
+ }
+
+ public static byte[] createPDF(String content, boolean pdfa) throws DocumentException, IOException {
+ ByteArrayOutputStream baOut = new ByteArrayOutputStream();
+ createPDF(content, pdfa, baOut);
+ return baOut.toByteArray();
+ }
+
+ public static byte[] createPDF(String content) throws DocumentException, IOException {
+ return createPDF(content, false);
+ }
+
+
+ private static void addContent(Document document, boolean pdfa, String content) throws DocumentException {
+ Paragraph p = new Paragraph(content, pdfa ? DEFAULT_TTF_FONT : DEFAULT_FONT);
+ document.add(p);
+ }
+ public static void createPDF(String content, OutputStream outputStream) throws DocumentException, IOException {
+ createPDF(content, false, outputStream);
+ }
+
+ public static void createPDF(String content, boolean pdfa, OutputStream outputStream) throws DocumentException, IOException {
+ final float factor = (float) 72 / (float) 25.4;
+ Document document = new Document(
+ DEFAULT_PAGE_SIZE,
+ (float) DEFAULT_MARGINS_MM[3] * factor, // left
+ (float) DEFAULT_MARGINS_MM[1] * factor, // right
+ (float) DEFAULT_MARGINS_MM[0] * factor, // top
+ (float) DEFAULT_MARGINS_MM[2] * factor // bottom
+ );
+
+ PdfWriter pdfWriter = PdfWriter.getInstance(document, outputStream);
+ if (pdfa) {
+ pdfWriter.setPDFXConformance(PdfWriter.PDFA1B);
+ }
+ document.open();
+ if (pdfa) {
+ PdfDictionary pdfOutputIntent = new PdfDictionary(PdfName.OUTPUTINTENT);
+ pdfOutputIntent.put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString("sRGB IEC61966-2.1"));
+ pdfOutputIntent.put(PdfName.INFO, new PdfString("sRGB IEC61966-2.1"));
+ pdfOutputIntent.put(PdfName.S, PdfName.GTS_PDFA1);
+ if (DEFAULT_ICC_COLOR_SPACE != null) {
+ pdfOutputIntent.put(PdfName.DESTOUTPUTPROFILE, pdfWriter.addToBody(DEFAULT_ICC_COLOR_SPACE).getIndirectReference());
+ }
+ pdfWriter.getExtraCatalog().put(PdfName.OUTPUTINTENTS, new PdfArray(pdfOutputIntent));
+ }
+ addContent(document, pdfa, content);
+ if (pdfa) {
+ pdfWriter.createXmpMetadata();
+ }
+ document.close();
+ }
+
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/test/CreateFreeTextTest.java b/src/main/java/at/gv/egiz/pdfas/test/CreateFreeTextTest.java
new file mode 100644
index 0000000..7665f33
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/test/CreateFreeTextTest.java
@@ -0,0 +1,26 @@
+package at.gv.egiz.pdfas.test;
+
+import java.io.File;
+
+import at.gv.egiz.pdfas.itext.IText;
+import at.gv.egiz.pdfas.utils.PDFASUtils;
+
+public class CreateFreeTextTest {
+
+ private CreateFreeTextTest() {
+ }
+
+ public static void main(String[] args) {
+
+ try {
+
+ byte[] pdf = IText.createPDF("Hello World", false);
+ PDFASUtils.toFile(pdf, new File("itext.pdf"));
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java b/src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java
index 88e597b..1862f20 100644
--- a/src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java
+++ b/src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java
@@ -1,8 +1,6 @@
package at.gv.egiz.pdfas.utils;
-import java.io.BufferedOutputStream;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -81,11 +79,37 @@ public final class ConfigUtils {
if (in == null) {
throw new ConfigUtilsException("Unable to find default configuration resource \"" + Constants.DEFAULT_CONFIGURATION_ZIP_RESOURCE + "\".");
}
- ZipInputStream zis = new ZipInputStream(in);
+ return deployFromZIP(in, destination, overwriteExisting);
+ } catch (IOException e) {
+ throw new ConfigUtilsException(e);
+ }
+ }
+
+ /**
+ * Deploys the contents of a ZIP file to a certain location.
+ *
+ * @param inputStream The inputStream of a ZIP container.
+ * @param destination The destination folder.
+ * @param overwriteExisting If set <code>true</code> an already existing configuration is overwritten. If <code>false</code> nothing is being copied if the destination folder already exists.
+ * @return <code>true</code> if the configuration has been deployed, <code>false</code> if not.
+ * @throws ConfigUtilsException Thrown if there was an error during the deployment of the configuration.
+ */
+ public static boolean deployFromZIP(InputStream inputStream, String destination, boolean overwriteExisting) throws ConfigUtilsException {
+ try {
+ if (!overwriteExisting) {
+ if (configurationAlreadyExists(destination)) {
+ logger_.debug("There is at least one file or folder that would be overwritten at destination path \"" + destination + "\". Skipping extraction.");
+ return false;
+ }
+ }
+ if (inputStream == null) {
+ throw new ConfigUtilsException("Unable to deploy ZIP file. InputStream is null.");
+ }
+ ZipInputStream zis = new ZipInputStream(inputStream);
ZipEntry ze;
File destinationFolder = new File(destination);
destinationFolder.mkdirs();
- logger_.debug("Extracting default configuration to folder \"" + destinationFolder.getCanonicalPath() + "\".");
+ logger_.debug("Extracting ZIP contents to folder \"" + destinationFolder.getCanonicalPath() + "\".");
while ((ze = zis.getNextEntry()) != null) {
if (ze.isDirectory()) {
File newFolder = new File(destinationFolder, ze.getName());
@@ -94,7 +118,7 @@ public final class ConfigUtils {
} else {
File destFile = new File(destinationFolder, ze.getName());
logger_.trace("Extracting file \"" + destFile.getName() + "\".");
- toFile(zis, destFile);
+ PDFASUtils.toFile(zis, destFile);
}
zis.closeEntry();
}
@@ -104,7 +128,7 @@ public final class ConfigUtils {
throw new ConfigUtilsException(e);
}
}
-
+
private static boolean configurationAlreadyExists(String destination) throws ConfigUtilsException, IOException {
logger_.debug("Checking configuration \"" + destination + "\" already exists (resp. if there are any directories or files that would be overwritten).");
File destinationFolder = new File(destination);
@@ -196,25 +220,6 @@ public final class ConfigUtils {
return deployDefaultConfiguration(false);
}
- public static boolean toFile(InputStream inputStream, File file) throws IOException {
- boolean result = false;
- BufferedOutputStream bufferedOutputStream = null;
- try {
- bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));
- writeInputStreamToOutputStream(inputStream, bufferedOutputStream);
- } finally {
- if (bufferedOutputStream != null) {
- try {
- bufferedOutputStream.close();
- result = true;
- } catch (IOException e) {
- result = false;
- }
- }
- }
- return result;
- }
-
public static void writeInputStreamToOutputStream(InputStream inputStream, OutputStream outputStream) throws IOException {
final int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
diff --git a/src/main/java/at/gv/egiz/pdfas/utils/PDFASUtils.java b/src/main/java/at/gv/egiz/pdfas/utils/PDFASUtils.java
index b26cc9b..9841779 100644
--- a/src/main/java/at/gv/egiz/pdfas/utils/PDFASUtils.java
+++ b/src/main/java/at/gv/egiz/pdfas/utils/PDFASUtils.java
@@ -1,5 +1,12 @@
package at.gv.egiz.pdfas.utils;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
import at.gv.egiz.pdfas.exceptions.ErrorCode;
import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
@@ -26,5 +33,28 @@ public class PDFASUtils {
throw new PDFDocumentException(ErrorCode.DOCUMENT_IS_PROTECTED, "Document is protected.");
}
}
+
+ public static boolean toFile(byte[] data, File file) throws IOException {
+ return PDFASUtils.toFile(new ByteArrayInputStream(data), file);
+ }
+
+ public static boolean toFile(InputStream inputStream, File file) throws IOException {
+ boolean result = false;
+ BufferedOutputStream bufferedOutputStream = null;
+ try {
+ bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));
+ ConfigUtils.writeInputStreamToOutputStream(inputStream, bufferedOutputStream);
+ } finally {
+ if (bufferedOutputStream != null) {
+ try {
+ bufferedOutputStream.close();
+ result = true;
+ } catch (IOException e) {
+ result = false;
+ }
+ }
+ }
+ return result;
+ }
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java
index 423c222..4b585fe 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java
@@ -100,7 +100,7 @@ public abstract class PdfAS
* The current version of the pdf-as library. This version string is logged on every invocation
* of the api or the web application.
*/
- public static final String PDFAS_VERSION = "3.1 (20100118)";
+ public static final String PDFAS_VERSION = "3.1.1-snapshot (20100316)";
/**
* The key of the strict mode setting.
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/exceptions/OutOfMemoryException.java b/src/main/java/at/knowcenter/wag/egov/egiz/exceptions/OutOfMemoryException.java
new file mode 100644
index 0000000..1b75e36
--- /dev/null
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/exceptions/OutOfMemoryException.java
@@ -0,0 +1,19 @@
+package at.knowcenter.wag.egov.egiz.exceptions;
+
+public class OutOfMemoryException extends PresentableException {
+
+ private static final long serialVersionUID = 1L;
+
+ public OutOfMemoryException(int errorCode, String message, Throwable cause) {
+ super(errorCode, message, cause);
+ }
+
+ public OutOfMemoryException(int errorCode, String message) {
+ super(errorCode, message);
+ }
+
+ public OutOfMemoryException(int errorCode, Throwable cause) {
+ super(errorCode, cause);
+ }
+
+}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java
index d1e227a..32871e8 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java
@@ -18,6 +18,7 @@
package at.knowcenter.wag.egov.egiz.pdf;
import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
@@ -32,6 +33,7 @@ import java.util.Iterator;
import java.util.List;
+import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -1213,7 +1215,7 @@ public abstract class BinarySignature
byte[] signed_pdf = iui.signed_pdf;
String str = iui.egiz_dict_ir_number + " " + iui.egiz_dict_ir_generation + " obj";
- byte[] obj_bytes = str.getBytes("US-ASCII");
+ byte[] obj_bytes = ArrayUtils.add(str.getBytes("US-ASCII"), 0, (byte) 0x0A);
int obj_index = ByteArrayUtils.lastIndexOf(signed_pdf, obj_bytes);
int obj_start = obj_index + obj_bytes.length;
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java
index 317e7a4..b343bc6 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java
@@ -18,6 +18,8 @@
package at.knowcenter.wag.egov.egiz.pdf;
import java.io.Serializable;
+
+import at.gv.egiz.pdfas.exceptions.ErrorCode;
import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
/**
@@ -153,12 +155,12 @@ public class TablePos implements Serializable
String[] cmd_kv = cmd_kvstring.split(":");
if (cmd_kv.length != 2)
{
- throw new PDFDocumentException(224, "Pos string (=" + pos_string + ") is invalid.");
+ throw new PDFDocumentException(ErrorCode.INVALID_SIGNATURE_POSITION, "Pos string (=" + pos_string + ") is invalid.");
}
String cmdstr = cmd_kv[0];
if (cmdstr.length() != 1)
{
- throw new PDFDocumentException(224, "Pos string (=" + pos_string + ") is invalid.");
+ throw new PDFDocumentException(ErrorCode.INVALID_SIGNATURE_POSITION, "Pos string (=" + pos_string + ") is invalid.");
}
char command = cmdstr.charAt(0);
String commandval= cmd_kv[1];
@@ -227,13 +229,13 @@ public class TablePos implements Serializable
float flval=Float.parseFloat(commandval);
if (flval<0)
{
- throw new PDFDocumentException(224, "Pos string (=" + pos_string + ") is invalid.");
+ throw new PDFDocumentException(ErrorCode.INVALID_SIGNATURE_POSITION, "Pos string (=" + pos_string + ") is invalid.");
}
this.footer_line = flval;
break;
}
default : {
- throw new PDFDocumentException(224, "Pos string (=" + pos_string + ") is invalid.");
+ throw new PDFDocumentException(ErrorCode.INVALID_SIGNATURE_POSITION, "Pos string (=" + pos_string + ") is invalid.");
}
}
}
@@ -241,7 +243,7 @@ public class TablePos implements Serializable
}
catch (NumberFormatException e)
{
- throw new PDFDocumentException(224, "Pos string (=" + pos_string + ") cannot be parsed.");
+ throw new PDFDocumentException(ErrorCode.INVALID_SIGNATURE_POSITION, "Pos string (=" + pos_string + ") cannot be parsed.");
}
}
public String toString()
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/FormFields.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/FormFields.java
index d455179..876413a 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/web/FormFields.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/FormFields.java
@@ -41,8 +41,6 @@ import at.knowcenter.wag.egov.egiz.sig.SignatureTypes;
*/
public abstract class FormFields
{
- public static final String PARAMETER_FREE_TEXT_ENTRY = "freetext";
-
public static final String FIELD_UPLOAD = "upload";
public static final String FIELD_CONNECTOR = "connector";
@@ -101,6 +99,14 @@ public abstract class FormFields
public static final String FIELD_SIGPOS_Y = "sig-pos-y";
public static final String FIELD_SIGPOS_P = "sig-pos-p";
+
+ public static final String FIELD_SOURCE = "source_filefreetext";
+
+ public static final String VALUE_SOURCE_FILE = "source-is-file";
+
+ public static final String VALUE_SOURCE_FREETEXT = "source-is-freetext";
+
+ public static final String FIELD_FREETEXT = "freetext";
// end add
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/ProvidePDFServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/ProvidePDFServlet.java
index 803dc59..0efed03 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/ProvidePDFServlet.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/ProvidePDFServlet.java
@@ -60,6 +60,8 @@ public class ProvidePDFServlet extends HttpServlet {
session.removeAttribute(SessionAttributes.SIGNED_PDF_DOCUMENT);
log.debug("Returning signed pdf to browser.");
SignServletHelper.returnSignResponse(si, request, response);
+ log.debug("Removing free text (if any) from session.");
+ session.removeAttribute(UpdateFormServlet.UPLOADFORM_FREETEXT_KEY);
return;
}
} else {
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java
index c946225..69b237f 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java
@@ -33,18 +33,26 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import com.lowagie.text.DocumentException;
+
import at.gv.egiz.pdfas.exceptions.ErrorCode;
import at.gv.egiz.pdfas.exceptions.ErrorCodeHelper;
import at.gv.egiz.pdfas.exceptions.external.ExternalErrorException;
import at.gv.egiz.pdfas.framework.input.PdfDataSource;
+import at.gv.egiz.pdfas.impl.input.ByteArrayPdfDataSourceImpl;
+import at.gv.egiz.pdfas.itext.IText;
+import at.gv.egiz.pdfas.utils.ConfigUtils;
+import at.gv.egiz.pdfas.utils.PDFASUtils;
import at.gv.egiz.pdfas.utils.WebUtils;
import at.gv.egiz.pdfas.web.SignSessionInformation;
import at.gv.egiz.pdfas.web.helper.SignServletHelper;
@@ -235,6 +243,7 @@ public class SignServlet extends HttpServlet
try
{
+
// tzefferer: modified
// UploadedData ud = retrieveUploadedDataFromRequest(request);
UploadedData ud_form = retrieveUploadedDataFromRequest(request);
@@ -244,9 +253,7 @@ public class SignServlet extends HttpServlet
}
catch (Exception e)
{
- // Error retrieving data
-// request.setAttribute("error", "Fehler beim Upload der Daten");
-// request.setAttribute("cause", "Beim Upload der Daten ist ein Fehler aufgetreten.");
+ log.error(e);
request.setAttribute("error", "signservlet.error");
request.setAttribute("cause", "signservlet.cause");
request.setAttribute("resourcebundle", Boolean.TRUE);
@@ -344,8 +351,11 @@ public class SignServlet extends HttpServlet
FileItem mode_fi = null;
FileItem file_upload_fi = null;
FileItem download_fi = null;
+ FileItem freeText = null;
+ FileItem pdfa = null;
Iterator it = items.iterator();
+ HttpSession session = request.getSession();
while (it.hasNext())
{
FileItem item = (FileItem) it.next();
@@ -374,18 +384,21 @@ public class SignServlet extends HttpServlet
if (item.getFieldName().equals(FormFields.FIELD_SIGNATURE_TYPE))
{
sig_type_fi = item;
+ session.setAttribute(UpdateFormServlet.UPLOADFORM_SIGNATURE_TYPE_KEY, sig_type_fi.getString("UTF-8"));
continue;
}
if (item.getFieldName().equals(FormFields.FIELD_CONNECTOR))
{
sig_app_fi = item;
+ session.setAttribute(UpdateFormServlet.UPLOADFORM_SIGNATURE_DEVICE_KEY, sig_app_fi.getString("UTF-8"));
continue;
}
if (item.getFieldName().equals(FormFields.FIELD_MODE))
{
mode_fi = item;
+ session.setAttribute(UpdateFormServlet.UPLOADFORM_SIGNATURE_MODE_KEY, mode_fi.getString("UTF-8"));
continue;
}
@@ -402,14 +415,30 @@ public class SignServlet extends HttpServlet
}
if (FormFields.FIELD_PDFA_ENABLED.equals(item.getFieldName())) {
+ pdfa = item;
+ session.setAttribute(UpdateFormServlet.UPLOADFORM_PDFA_KEY, pdfa.getString("UTF-8"));
+ continue;
+ }
+
+ if (FormFields.FIELD_FREETEXT.equals(item.getFieldName())) {
+ freeText = item;
+ String value = freeText.getString("UTF-8");
+ if (value != null) {
+ session.setAttribute(UpdateFormServlet.UPLOADFORM_FREETEXT_KEY, value);
+ }
+ continue;
+ }
+
+ if (FormFields.FIELD_SOURCE.equals(item.getFieldName())) {
+ session.setAttribute(UpdateFormServlet.UPLOADFORM_SOURCE_KEY, item.getString("UTF-8"));
continue;
}
- throw new ServletException("unrecognized POST data."); //$NON-NLS-1$
+ throw new ServletException("Unrecognized POST data."); //$NON-NLS-1$
}
- if (preview_fi == null || sig_type_fi == null || sig_app_fi == null || file_upload_fi == null || download_fi == null)
+ if (preview_fi == null || sig_type_fi == null || sig_app_fi == null || (file_upload_fi == null && freeText== null) || download_fi == null)
{
throw new ServletException("Insufficient data provided in request"); //$NON-NLS-1$
}
@@ -436,28 +465,47 @@ public class SignServlet extends HttpServlet
String sig_type = sig_type_fi.getString("UTF-8"); //$NON-NLS-1$
String sig_app = sig_app_fi.getString("UTF-8"); //$NON-NLS-1$
- String doc_file_name = TempDirHelper.extractFileNameSuffix(file_upload_fi.getName());
- log.debug("file content type =" + file_upload_fi.getContentType()); //$NON-NLS-1$
-
- String extension = VerifyServlet.extractExtension(doc_file_name);
- if (extension != null && !extension.equals("pdf")) //$NON-NLS-1$
- {
- throw new PDFDocumentException(201, "The provided file '" + doc_file_name + "' doesn't have the PDF extension (.pdf)."); //$NON-NLS-1$//$NON-NLS-2$
- }
-
- if (file_upload_fi.getSize() <= 0)
- {
- throw new PDFDocumentException(250, "The document is empty."); //$NON-NLS-1$
- }
-
- PdfDataSource pdfDataSource = null;
- try
- {
- pdfDataSource = TempDirHelper.placePdfIntoTempDir(file_upload_fi.getInputStream(), doc_file_name);
- }
- catch (IOException e)
- {
- throw new PDFDocumentException(201, "Couldn't store the file in the temp dir.", e);
+ PdfDataSource pdfDataSource;
+ String doc_file_name;
+ // distinguish between file and freetext
+ if (file_upload_fi != null) {
+ log.debug("Processing file.");
+ doc_file_name = TempDirHelper.extractFileNameSuffix(file_upload_fi.getName());
+ log.debug("file content type =" + file_upload_fi.getContentType()); //$NON-NLS-1$
+
+ String extension = VerifyServlet.extractExtension(doc_file_name);
+ if (extension != null && !extension.equals("pdf")) //$NON-NLS-1$
+ {
+ throw new PDFDocumentException(201, "The provided file '" + doc_file_name + "' doesn't have the PDF extension (.pdf)."); //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ if (file_upload_fi.getSize() <= 0)
+ {
+ throw new PDFDocumentException(250, "The document is empty."); //$NON-NLS-1$
+ }
+
+ try
+ {
+ pdfDataSource = TempDirHelper.placePdfIntoTempDir(file_upload_fi.getInputStream(), doc_file_name);
+ }
+ catch (IOException e)
+ {
+ throw new PDFDocumentException(201, "Couldn't store the file in the temp dir.", e);
+ }
+ } else {
+ log.debug("Processing free text.");
+ try {
+ boolean pdfaEnabled = pdfa != null && "true".equalsIgnoreCase(pdfa.getString());
+ byte[] freeTextPDF = IText.createPDF(freeText.getString("UTF-8"), pdfaEnabled);
+
+ pdfDataSource = new ByteArrayPdfDataSourceImpl(freeTextPDF);
+ doc_file_name = IText.DEFAULT_FILENAME;
+ } catch (DocumentException e) {
+ throw new PDFDocumentException(201, "Unable to create PDF document.", e);
+ } catch (IOException e) {
+ throw new PDFDocumentException(201, "Unable to create PDF document.", e);
+ }
+
}
// byte[] pdf = file_upload_fi.get();
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/UpdateFormServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/UpdateFormServlet.java
index 2d21545..f0d3d3d 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/UpdateFormServlet.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/UpdateFormServlet.java
@@ -19,22 +19,34 @@ public class UpdateFormServlet extends HttpServlet {
public static final String UPLOADFORM_SIGNATURE_MODE_KEY = "signupload.jsp:signatureMode";
public static final String UPLOADFORM_SIGNATURE_DEVICE_KEY = "signupload.jsp:signatureKey";
public static final String UPLOADFORM_PDFA_KEY = "signupload.jsp:pdfaKey";
+ public static final String UPLOADFORM_SOURCE_KEY = "signupload.jsp:sourceKey";
+ public static final String UPLOADFORM_FREETEXT_KEY = "signupload.jsp:freeTextKey";
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
-
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- String mode = request.getParameter(FormFields.FIELD_MODE);
- String device = request.getParameter(FormFields.FIELD_CONNECTOR);
- String type = request.getParameter(FormFields.FIELD_SIGNATURE_TYPE);
- String pdfa = request.getParameter(FormFields.FIELD_PDFA_ENABLED);
+
+ public static void updateSession(HttpServletRequest request) {
+ String mode = request.getParameter(FormFields.FIELD_MODE);
+ String device = request.getParameter(FormFields.FIELD_CONNECTOR);
+ String type = request.getParameter(FormFields.FIELD_SIGNATURE_TYPE);
+ String pdfa = request.getParameter(FormFields.FIELD_PDFA_ENABLED);
+ String source = request.getParameter(FormFields.FIELD_SOURCE);
+ String freeText = request.getParameter(FormFields.FIELD_FREETEXT);
HttpSession session = request.getSession();
session.setAttribute(UPLOADFORM_SIGNATURE_DEVICE_KEY, device);
session.setAttribute(UPLOADFORM_SIGNATURE_MODE_KEY, mode);
session.setAttribute(UPLOADFORM_SIGNATURE_TYPE_KEY, type);
session.setAttribute(UPLOADFORM_PDFA_KEY, pdfa);
+ session.setAttribute(UPLOADFORM_SOURCE_KEY, source);
+ if (freeText != null) {
+ session.setAttribute(UPLOADFORM_FREETEXT_KEY, freeText);
+ }
+ }
+
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ updateSession(request);
RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/signupload.jsp");
dispatcher.forward(request, response);
diff --git a/src/main/java/demo/SignatureCreationDemo.java b/src/main/java/demo/SignatureCreationDemo.java
index 1f6205d..dd7e36b 100644
--- a/src/main/java/demo/SignatureCreationDemo.java
+++ b/src/main/java/demo/SignatureCreationDemo.java
@@ -12,6 +12,7 @@ import at.gv.egiz.pdfas.api.exceptions.PdfAsException;
import at.gv.egiz.pdfas.api.io.DataSource;
import at.gv.egiz.pdfas.api.sign.SignParameters;
import at.gv.egiz.pdfas.api.sign.SignResult;
+import at.gv.egiz.pdfas.api.sign.pos.SignaturePositioning;
import at.gv.egiz.pdfas.api.timestamp.DummyTimeStamper;
import at.gv.egiz.pdfas.io.FileBasedDataSink;
import at.gv.egiz.pdfas.io.FileBasedDataSource;
@@ -57,7 +58,7 @@ public class SignatureCreationDemo {
signParameters.setDocument(dataSource);
signParameters.setOutput(dataSink);
signParameters.setSignatureDevice(Constants.SIGNATURE_DEVICE_MOA);
- signParameters.setSignaturePositioning(null);
+ signParameters.setSignaturePositioning(new SignaturePositioning("x:auto;y:auto;w:auto;p:auto;f:80"));
// standard signature
signParameters.setSignatureType(Constants.SIGNATURE_TYPE_TEXTUAL);
signParameters.setSignatureProfileId("SIGNATURBLOCK_DE");