aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java')
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java39
1 files changed, 37 insertions, 2 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