aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/knowcenter
diff options
context:
space:
mode:
authornetconomy <netconomy@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2007-12-17 15:43:39 +0000
committernetconomy <netconomy@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2007-12-17 15:43:39 +0000
commit9ef042419014ebe9ea3e6ce0af5568de2d933c7d (patch)
treea8284072aac2839b4d6ea0b1d39c4f82a93e5fb1 /src/main/java/at/knowcenter
parentcd02a128515400fdb97c276e70631d5bdb5ff509 (diff)
downloadpdf-as-3-9ef042419014ebe9ea3e6ce0af5568de2d933c7d.tar.gz
pdf-as-3-9ef042419014ebe9ea3e6ce0af5568de2d933c7d.tar.bz2
pdf-as-3-9ef042419014ebe9ea3e6ce0af5568de2d933c7d.zip
Change Request "Document Correction"
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@239 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src/main/java/at/knowcenter')
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java39
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java7
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java2
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java2
4 files changed, 46 insertions, 4 deletions
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 9aef071..973b6f4 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java
@@ -31,10 +31,14 @@ import org.apache.commons.logging.LogFactory;
import at.gv.egiz.pdfas.commandline.CommandlineConnectorChooser;
import at.gv.egiz.pdfas.exceptions.ErrorCode;
+import at.gv.egiz.pdfas.exceptions.framework.CorrectorException;
import at.gv.egiz.pdfas.framework.ConnectorParameters;
import at.gv.egiz.pdfas.framework.input.PdfDataSource;
+import at.gv.egiz.pdfas.framework.input.correction.Corrector;
+import at.gv.egiz.pdfas.framework.input.correction.CorrectorFactory;
import at.gv.egiz.pdfas.framework.output.DataSink;
import at.gv.egiz.pdfas.framework.signator.SignatorInformation;
+import at.gv.egiz.pdfas.impl.api.commons.PdfDataSourceAdapter;
import at.gv.egiz.pdfas.impl.input.ByteArrayPdfDataSourceImpl;
import at.gv.egiz.pdfas.impl.input.helper.DataSourceHelper;
import at.gv.egiz.pdfas.web.VerifySessionInformation;
@@ -105,6 +109,8 @@ public abstract class PdfAS
* The Mime Type of a PDF document.
*/
public static final String PDF_MIME_TYPE = "application/pdf";
+
+ public static final String CORRECT_DOCUMENT_IF_NECESSARY_KEY = "correct_document_if_necessary";
/**
* The logger definition.
@@ -182,8 +188,10 @@ public abstract class PdfAS
* @param pdfDataSource
* The pdf to be checked against strict mode.
* @throws PDFDocumentException
+ * @throws SettingsException
+ * @throws CorrectorException
*/
- public static void applyStrictMode(PdfDataSource pdfDataSource) throws PDFDocumentException
+ public static PdfDataSource applyStrictMode(PdfDataSource pdfDataSource) throws PDFDocumentException, SettingsException, CorrectorException
{
if (isStrictPdfChecking())
{
@@ -200,8 +208,35 @@ public abstract class PdfAS
catch (Exception e)
{
log.debug("Error while parsing Document.", e);
- throw new PDFDocumentException(201, e);
+
+ boolean tryToCorrect = SettingsReader.getInstance().getSetting(CORRECT_DOCUMENT_IF_NECESSARY_KEY, "false").equals("true");
+ if (!tryToCorrect)
+ {
+ throw new PDFDocumentException(201, e);
+ }
+ log.debug("Correcting document...");
+ Corrector cor = CorrectorFactory.createCorrector();
+ PdfDataSource correctedDS = cor.correctDocument(pdfDataSource);
+ log.debug("Correction finished.");
+
+ return correctedDS;
+ }
+
+ return pdfDataSource;
+ }
+
+ public static at.gv.egiz.pdfas.api.io.DataSource applyStrictMode (at.gv.egiz.pdfas.api.io.DataSource dataSource) throws PDFDocumentException, SettingsException, CorrectorException
+ {
+ if (dataSource.getMimeType().equals("application/pdf"))
+ {
+ PdfDataSource pdfDS = new PdfDataSourceAdapter(dataSource);
+ PdfDataSource correctedDS = applyStrictMode(pdfDS);
+ if (correctedDS != pdfDS)
+ {
+ return new at.gv.egiz.pdfas.impl.api.commons.DataSourceApiAdapter(correctedDS);
+ }
}
+ return dataSource;
}
// TODO: unused method - remove
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java b/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java
index 054da24..c58da3f 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java
@@ -418,6 +418,13 @@ public class SettingsReader implements Serializable
// }
return result;
}
+
+ // TODO in the next change request, the Setting system will be refactored
+ // this is just for testing purposes.
+ public void setSetting(String key, String value)
+ {
+ properties_.setProperty(key, value);
+ }
/**
* Relocates the relative file.
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java b/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java
index 11bd0e0..76159ec 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java
@@ -565,7 +565,7 @@ public abstract class Main
public static void processSign(PdfDataSource pdfDataSource, String connector, String signature_mode, String signature_type, String pos_string, DataSink dataSink) throws PresentableException
{
- PdfAS.applyStrictMode(pdfDataSource);
+ pdfDataSource = PdfAS.applyStrictMode(pdfDataSource);
TablePos pos = null;
if (pos_string != null)
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 16b12e1..e2de8ae 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
@@ -254,7 +254,7 @@ public class SignServlet extends HttpServlet
try
{
- PdfAS.applyStrictMode(ud.pdfDataSource);
+ ud.pdfDataSource = PdfAS.applyStrictMode(ud.pdfDataSource);
SignSessionInformation si = new SignSessionInformation(); // SessionTable.generateSessionInformationObject();
si.connector = ud.sig_app;