aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/input/IncrementalUpdateParser.java43
1 files changed, 33 insertions, 10 deletions
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/input/IncrementalUpdateParser.java b/src/main/java/at/gv/egiz/pdfas/impl/input/IncrementalUpdateParser.java
index b4c2bef..096bb0b 100644
--- a/src/main/java/at/gv/egiz/pdfas/impl/input/IncrementalUpdateParser.java
+++ b/src/main/java/at/gv/egiz/pdfas/impl/input/IncrementalUpdateParser.java
@@ -5,13 +5,16 @@ package at.gv.egiz.pdfas.impl.input;
import java.util.List;
-import at.gv.egiz.pdfas.impl.input.helper.DataSourceHelper;
-import at.gv.egiz.pdfas.exceptions.ErrorCode;
-import at.gv.egiz.pdfas.framework.input.PdfDataSource;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import at.gv.egiz.pdfas.exceptions.ErrorCode;
+import at.gv.egiz.pdfas.framework.input.PdfDataSource;
+import at.gv.egiz.pdfas.framework.input.PdfDataSourceHolder;
+import at.gv.egiz.pdfas.framework.input.correction.Corrector;
+import at.gv.egiz.pdfas.framework.input.correction.CorrectorFactory;
+import at.gv.egiz.pdfas.impl.input.helper.DataSourceHelper;
+import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
import at.knowcenter.wag.exactparser.ParseDocument;
@@ -26,24 +29,44 @@ public class IncrementalUpdateParser
*/
private static final Log log = LogFactory.getLog(IncrementalUpdateParser.class);
- public static List parsePdfIntoIUBlocks (PdfDataSource pdfDataSource) throws PDFDocumentException
+ public static List parsePdfIntoIUBlocks (PdfDataSourceHolder pdfDataSource) throws PDFDocumentException
{
log.trace("parsePdfIntoIUBlocks:");
List blocks = null;
try
{
- byte [] pdf = DataSourceHelper.convertDataSourceToByteArray(pdfDataSource);
+ byte [] pdf = DataSourceHelper.convertDataSourceToByteArray(pdfDataSource.getDataSource());
blocks = ParseDocument.parseDocument(pdf);
}
- catch (Exception e)
- {
- log.error("Error while parsing Document into IU blocks.", e);
- throw new PDFDocumentException(ErrorCode.DOCUMENT_CANNOT_BE_READ, e);
+ catch (Exception e) {
+ try {
+ log.debug("Error while parsing Document.", e);
+ boolean tryToCorrect = SettingsReader.getInstance().getSetting("correct_document_on_verify_if_necessary", "false").equals("true");
+ if (tryToCorrect) {
+ log.info("Correcting document...");
+ Corrector cor = CorrectorFactory.createCorrector();
+ PdfDataSource correctedDS = cor.correctDocument(pdfDataSource.getDataSource());
+ log.info("Correction finished.");
+ byte [] pdf = DataSourceHelper.convertDataSourceToByteArray(correctedDS);
+ blocks = ParseDocument.parseDocument(pdf);
+ pdfDataSource.setDataSource(correctedDS);
+ } else {
+ makeError(e);
+ }
+
+ } catch (Exception e1) {
+ makeError(e);
+ }
}
log.trace("parsePdfIntoIUBlocks finished.");
return blocks;
}
+ private static void makeError(Exception e) throws PDFDocumentException {
+ log.error("Error while parsing Document into IU blocks.", e);
+ throw new PDFDocumentException(ErrorCode.DOCUMENT_CANNOT_BE_READ, e);
+ }
+
}