diff options
author | netconomy <netconomy@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c> | 2007-12-17 15:43:39 +0000 |
---|---|---|
committer | netconomy <netconomy@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c> | 2007-12-17 15:43:39 +0000 |
commit | 9ef042419014ebe9ea3e6ce0af5568de2d933c7d (patch) | |
tree | a8284072aac2839b4d6ea0b1d39c4f82a93e5fb1 /src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java | |
parent | cd02a128515400fdb97c276e70631d5bdb5ff509 (diff) | |
download | pdf-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/wag/egov/egiz/PdfAS.java')
-rw-r--r-- | src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java | 39 |
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
|