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/09/10 12:04:19 UTC
svn commit: r1866739 - in
/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight:
Validator_A1b.java parser/PreflightParser.java parser/XmlResultParser.java
utils/ByteArrayDataSource.java utils/DataSource.java
utils/FileDataSource.java
Author: lehmi
Date: Tue Sep 10 12:04:18 2019
New Revision: 1866739
URL: http://svn.apache.org/viewvc?rev=1866739&view=rev
Log:
PDFBOX-4340: remove usage of DataSource interface
Removed:
pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/ByteArrayDataSource.java
pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/DataSource.java
pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/FileDataSource.java
Modified:
pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/Validator_A1b.java
pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java
pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java
Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/Validator_A1b.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/Validator_A1b.java?rev=1866739&r1=1866738&r2=1866739&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/Validator_A1b.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/Validator_A1b.java Tue Sep 10 12:04:18 2019
@@ -43,7 +43,6 @@ import org.apache.pdfbox.preflight.Valid
import org.apache.pdfbox.preflight.exception.SyntaxValidationException;
import org.apache.pdfbox.preflight.parser.PreflightParser;
import org.apache.pdfbox.preflight.parser.XmlResultParser;
-import org.apache.pdfbox.preflight.utils.FileDataSource;
import org.apache.pdfbox.util.Version;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -107,7 +106,7 @@ public class Validator_A1b
root.setAttribute("count", String.format("%d", ftp.size()));
for (File file : ftp)
{
- Element result = xrp.validate(document,new FileDataSource(file));
+ Element result = xrp.validate(document, file);
root.appendChild(result);
}
transformer.transform(new DOMSource(document),
@@ -118,7 +117,7 @@ public class Validator_A1b
// isBatch
for (File file : ftp)
{
- Element result = xrp.validate(new FileDataSource(file));
+ Element result = xrp.validate(file);
Document document = result.getOwnerDocument();
document.appendChild(result);
transformer.transform(new DOMSource(document),
@@ -138,7 +137,7 @@ public class Validator_A1b
{
// generate xml output
XmlResultParser xrp = new XmlResultParser();
- Element result = xrp.validate(new FileDataSource(new File(args[posFile])));
+ Element result = xrp.validate(new File(args[posFile]));
Document document = result.getOwnerDocument();
document.appendChild(result);
Transformer transformer = TransformerFactory.newInstance().newTransformer();
Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java?rev=1866739&r1=1866738&r2=1866739&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java Tue Sep 10 12:04:18 2019
@@ -44,6 +44,7 @@ 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;
@@ -79,8 +80,6 @@ import static org.apache.pdfbox.prefligh
import static org.apache.pdfbox.preflight.PreflightConstants.MAX_NEGATIVE_FLOAT;
import static org.apache.pdfbox.preflight.PreflightConstants.MAX_POSITIVE_FLOAT;
import static org.apache.pdfbox.preflight.PreflightConstants.MAX_STRING_LENGTH;
-import org.apache.pdfbox.preflight.utils.DataSource;
-import org.apache.pdfbox.preflight.utils.FileDataSource;
public class PreflightParser extends PDFParser
{
@@ -90,8 +89,6 @@ public class PreflightParser extends PDF
*/
public static final Charset encoding = Charset.forName("ISO-8859-1");
- protected DataSource dataSource;
-
protected ValidationResult validationResult;
protected PreflightDocument preflightDocument;
@@ -109,7 +106,6 @@ public class PreflightParser extends PDF
// TODO move file handling outside of the parser
super(new RandomAccessBufferedFileInputStream(file));
this.setLenient(false);
- this.dataSource = new FileDataSource(file);
}
/**
@@ -124,7 +120,6 @@ public class PreflightParser extends PDF
// TODO move file handling outside of the parser
super(new RandomAccessBufferedFileInputStream(file), scratch);
this.setLenient(false);
- this.dataSource = new FileDataSource(file);
}
/**
@@ -159,12 +154,11 @@ public class PreflightParser extends PDF
* @param dataSource the datasource
* @throws IOException if there is a reading error.
*/
- public PreflightParser(DataSource dataSource) throws IOException
+ public PreflightParser(RandomAccessRead source) throws IOException
{
// TODO move file handling outside of the parser
- super(new RandomAccessBufferedFileInputStream(dataSource.getInputStream()));
+ super(source);
this.setLenient(false);
- this.dataSource = dataSource;
}
/**
@@ -175,12 +169,11 @@ public class PreflightParser extends PDF
* @param scratch
* @throws IOException if there is a reading error.
*/
- public PreflightParser(DataSource dataSource, ScratchFile scratch) throws IOException
+ public PreflightParser(RandomAccessRead source, ScratchFile scratch) throws IOException
{
// TODO move file handling outside of the parser
- super(new RandomAccessBufferedFileInputStream(dataSource.getInputStream()), scratch);
+ super(source, scratch);
this.setLenient(false);
- this.dataSource = dataSource;
}
/**
Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java?rev=1866739&r1=1866738&r2=1866739&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java Tue Sep 10 12:04:18 2019
@@ -21,6 +21,7 @@
package org.apache.pdfbox.preflight.parser;
+import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -31,11 +32,12 @@ 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;
import org.apache.pdfbox.preflight.exception.SyntaxValidationException;
-import org.apache.pdfbox.preflight.utils.DataSource;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -43,12 +45,22 @@ public class XmlResultParser
{
- public Element validate(DataSource dataSource) throws IOException
+ public Element validate(File file) throws IOException
+ {
+ return validate(new RandomAccessBufferedFileInputStream(file), file.getName());
+ }
+
+ public Element validate(Document rdocument, File file) throws IOException
+ {
+ return validate(rdocument, new RandomAccessBufferedFileInputStream(file), file.getName());
+ }
+
+ private Element validate(RandomAccessRead source, String name) throws IOException
{
try
{
Document rdocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
- return validate(rdocument,dataSource);
+ return validate(rdocument, source, name);
}
catch (ParserConfigurationException e)
{
@@ -57,14 +69,15 @@ public class XmlResultParser
}
- public Element validate(Document rdocument, DataSource dataSource) throws IOException
+ private Element validate(Document rdocument, RandomAccessRead source, String name)
+ throws IOException
{
String pdfType = null;
ValidationResult result;
long before = System.currentTimeMillis();
try
{
- PreflightParser parser = new PreflightParser(dataSource);
+ PreflightParser parser = new PreflightParser(source);
try
{
parser.parse();
@@ -83,13 +96,13 @@ public class XmlResultParser
catch(Exception e)
{
long after = System.currentTimeMillis();
- return generateFailureResponse(rdocument, dataSource.getName(), after-before, pdfType, e);
+ return generateFailureResponse(rdocument, name, after - before, pdfType, e);
}
long after = System.currentTimeMillis();
if (result.isValid())
{
- Element preflight = generateResponseSkeleton(rdocument, dataSource.getName(), after-before);
+ Element preflight = generateResponseSkeleton(rdocument, name, after - before);
// valid ?
Element valid = rdocument.createElement("isValid");
valid.setAttribute("type", pdfType);
@@ -99,7 +112,7 @@ public class XmlResultParser
}
else
{
- Element preflight = generateResponseSkeleton(rdocument, dataSource.getName(), after-before);
+ Element preflight = generateResponseSkeleton(rdocument, name, after - before);
// valid ?
createResponseWithError(rdocument, pdfType, result, preflight);
return preflight;