You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2019/10/05 17:13:07 UTC
svn commit: r1868033 - in /pdfbox/branches/issue4569/preflight/src:
main/java/org/apache/pdfbox/preflight/parser/
test/java/org/apache/pdfbox/preflight/
test/java/org/apache/pdfbox/preflight/metadata/
Author: lehmi
Date: Sat Oct 5 17:13:07 2019
New Revision: 1868033
URL: http://svn.apache.org/viewvc?rev=1868033&view=rev
Log:
PDFBOX-4569: merge PDFParser#parse and PDFParser#getPDDocument
Modified:
pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java
pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java
pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/TestInvalidDirectory.java
pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartorBavaria.java
pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/TestValidDirectory.java
pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestMetadataFiles.java
pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestSynchronizedMetadataValidation.java
Modified: pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java?rev=1868033&r1=1868032&r2=1868033&view=diff
==============================================================================
--- pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java (original)
+++ pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java Sat Oct 5 17:13:07 2019
@@ -36,7 +36,6 @@ import org.apache.pdfbox.cos.COSDictiona
import org.apache.pdfbox.cos.COSDocument;
import org.apache.pdfbox.cos.COSFloat;
import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.cos.COSNull;
import org.apache.pdfbox.cos.COSNumber;
import org.apache.pdfbox.cos.COSObject;
import org.apache.pdfbox.cos.COSObjectKey;
@@ -44,7 +43,6 @@ import org.apache.pdfbox.cos.COSStream;
import org.apache.pdfbox.cos.COSString;
import org.apache.pdfbox.io.IOUtils;
import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream;
-import org.apache.pdfbox.io.RandomAccessRead;
import org.apache.pdfbox.io.ScratchFile;
import org.apache.pdfbox.pdfparser.PDFObjectStreamParser;
import org.apache.pdfbox.pdfparser.PDFParser;
@@ -103,9 +101,7 @@ public class PreflightParser extends PDF
*/
public PreflightParser(File file) throws IOException
{
- // TODO move file handling outside of the parser
super(new RandomAccessBufferedFileInputStream(file));
- this.setLenient(false);
}
/**
@@ -117,9 +113,7 @@ public class PreflightParser extends PDF
*/
public PreflightParser(File file, ScratchFile scratch) throws IOException
{
- // TODO move file handling outside of the parser
super(new RandomAccessBufferedFileInputStream(file), scratch);
- this.setLenient(false);
}
/**
@@ -130,7 +124,6 @@ public class PreflightParser extends PDF
*/
public PreflightParser(String filename) throws IOException
{
- // TODO move file handling outside of the parser
this(new File(filename));
}
@@ -143,40 +136,10 @@ public class PreflightParser extends PDF
*/
public PreflightParser(String filename, ScratchFile scratch) throws IOException
{
- // TODO move file handling outside of the parser
this(new File(filename), scratch);
}
/**
- * Constructor. This one is slower than the file and the filename constructors, because
- * a temporary file will be created.
- *
- * @param source
- * @throws IOException if there is a reading error.
- */
- public PreflightParser(RandomAccessRead source) throws IOException
- {
- // TODO move file handling outside of the parser
- super(source);
- this.setLenient(false);
- }
-
- /**
- * Constructor. This one is slower than the file and the filename constructors, because
- * a temporary file will be created.
- *
- * @param source
- * @param scratch
- * @throws IOException if there is a reading error.
- */
- public PreflightParser(RandomAccessRead source, ScratchFile scratch) throws IOException
- {
- // TODO move file handling outside of the parser
- super(source, scratch);
- this.setLenient(false);
- }
-
- /**
* Create an instance of ValidationResult with a ValidationError(UNKNOWN_ERROR)
*
* @return the ValidationError instance.
@@ -208,9 +171,9 @@ public class PreflightParser extends PDF
}
@Override
- public void parse() throws IOException
+ public PDDocument parse() throws IOException
{
- parse(Format.PDF_A1B);
+ return parse(Format.PDF_A1B);
}
/**
@@ -220,9 +183,9 @@ public class PreflightParser extends PDF
* format that the document should follow (default {@link Format#PDF_A1B})
* @throws IOException
*/
- public void parse(Format format) throws IOException
+ public PDDocument parse(Format format) throws IOException
{
- parse(format, null);
+ return parse(format, null);
}
/**
@@ -235,12 +198,14 @@ public class PreflightParser extends PDF
* the default configuration.
* @throws IOException
*/
- public void parse(Format format, PreflightConfiguration config) throws IOException
+ public PDDocument parse(Format format, PreflightConfiguration config) throws IOException
{
+ PDDocument pdDocument = null;
checkPdfHeader();
try
{
- super.parse();
+ // disable leniency
+ pdDocument = super.parse(false);
}
catch (IOException e)
{
@@ -255,6 +220,7 @@ public class PreflightParser extends PDF
Format formatToUse = (format == null ? Format.PDF_A1B : format);
createPdfADocument(formatToUse, config);
createContext();
+ return pdDocument;
}
protected void createPdfADocument(Format format, PreflightConfiguration config) throws IOException
@@ -275,19 +241,12 @@ public class PreflightParser extends PDF
ctx.setFileLen(this.fileLen);
}
- @Override
- public PDDocument getPDDocument() throws IOException
+ public PreflightDocument getPreflightDocument() throws IOException
{
preflightDocument.setResult(validationResult);
- // Add XMP MetaData
return preflightDocument;
}
- public PreflightDocument getPreflightDocument() throws IOException
- {
- return (PreflightDocument) getPDDocument();
- }
-
// --------------------------------------------------------
// - Below All methods that adds controls on the PDF syntax
// --------------------------------------------------------
Modified: pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java?rev=1868033&r1=1868032&r2=1868033&view=diff
==============================================================================
--- pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java (original)
+++ pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java Sat Oct 5 17:13:07 2019
@@ -32,8 +32,6 @@ import java.util.Map;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream;
-import org.apache.pdfbox.io.RandomAccessRead;
import org.apache.pdfbox.preflight.PreflightDocument;
import org.apache.pdfbox.preflight.ValidationResult;
import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
@@ -47,20 +45,20 @@ public class XmlResultParser
public Element validate(File file) throws IOException
{
- return validate(new RandomAccessBufferedFileInputStream(file), file.getName());
+ return validate(file, file.getName());
}
public Element validate(Document rdocument, File file) throws IOException
{
- return validate(rdocument, new RandomAccessBufferedFileInputStream(file), file.getName());
+ return validate(rdocument, file, file.getName());
}
- private Element validate(RandomAccessRead source, String name) throws IOException
+ private Element validate(File file, String name) throws IOException
{
try
{
Document rdocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
- return validate(rdocument, source, name);
+ return validate(rdocument, file, name);
}
catch (ParserConfigurationException e)
{
@@ -69,7 +67,7 @@ public class XmlResultParser
}
- private Element validate(Document rdocument, RandomAccessRead source, String name)
+ private Element validate(Document rdocument, File file, String name)
throws IOException
{
String pdfType = null;
@@ -77,7 +75,7 @@ public class XmlResultParser
long before = System.currentTimeMillis();
try
{
- PreflightParser parser = new PreflightParser(source);
+ PreflightParser parser = new PreflightParser(file);
try
{
parser.parse();
Modified: pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/TestInvalidDirectory.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/TestInvalidDirectory.java?rev=1868033&r1=1868032&r2=1868033&view=diff
==============================================================================
--- pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/TestInvalidDirectory.java (original)
+++ pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/TestInvalidDirectory.java Sat Oct 5 17:13:07 2019
@@ -58,7 +58,7 @@ public class TestInvalidDirectory
{
PreflightParser parser = new PreflightParser(target);
parser.parse();
- document = (PreflightDocument) parser.getPDDocument();
+ document = parser.getPreflightDocument();
document.validate();
result = document.getResult();
}
Modified: pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartorBavaria.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartorBavaria.java?rev=1868033&r1=1868032&r2=1868033&view=diff
==============================================================================
--- pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartorBavaria.java (original)
+++ pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartorBavaria.java Sat Oct 5 17:13:07 2019
@@ -183,7 +183,7 @@ public class TestIsartorBavaria
{
PreflightParser parser = new PreflightParser(file);
parser.parse();
- document = (PreflightDocument) parser.getPDDocument();
+ document = (PreflightDocument) parser.getPreflightDocument();
// to speeds up tests, skip validation of page count is over the limit
if (document.getNumberOfPages() < 8191)
{
Modified: pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/TestValidDirectory.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/TestValidDirectory.java?rev=1868033&r1=1868032&r2=1868033&view=diff
==============================================================================
--- pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/TestValidDirectory.java (original)
+++ pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/TestValidDirectory.java Sat Oct 5 17:13:07 2019
@@ -55,7 +55,7 @@ public class TestValidDirectory
{
PreflightParser parser = new PreflightParser(target);
parser.parse();
- document = (PreflightDocument) parser.getPDDocument();
+ document = (PreflightDocument) parser.getPreflightDocument();
document.validate();
result = document.getResult();
}
Modified: pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestMetadataFiles.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestMetadataFiles.java?rev=1868033&r1=1868032&r2=1868033&view=diff
==============================================================================
--- pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestMetadataFiles.java (original)
+++ pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestMetadataFiles.java Sat Oct 5 17:13:07 2019
@@ -76,7 +76,7 @@ public class TestMetadataFiles
{
PreflightParser parser = new PreflightParser(pdf);
parser.parse();
- document = (PreflightDocument) parser.getPDDocument();
+ document = parser.getPreflightDocument();
document.validate();
result = document.getResult();
}
Modified: pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestSynchronizedMetadataValidation.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestSynchronizedMetadataValidation.java?rev=1868033&r1=1868032&r2=1868033&view=diff
==============================================================================
--- pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestSynchronizedMetadataValidation.java (original)
+++ pdfbox/branches/issue4569/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestSynchronizedMetadataValidation.java Sat Oct 5 17:13:07 2019
@@ -27,7 +27,6 @@ import java.util.GregorianCalendar;
import java.util.List;
import org.junit.Assert;
-
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentInformation;
import org.apache.pdfbox.preflight.PreflightConstants;