You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by gb...@apache.org on 2014/01/14 22:30:12 UTC

svn commit: r1558205 - in /pdfbox/trunk: pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java

Author: gbailleul
Date: Tue Jan 14 21:30:11 2014
New Revision: 1558205

URL: http://svn.apache.org/r1558205
Log:
PDFBOX-1840:
* add maven plugin to retrieve isartor test files
* modify test class

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java?rev=1558205&r1=1558204&r2=1558205&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java Tue Jan 14 21:30:11 2014
@@ -114,6 +114,11 @@ public class NonSequentialPDFParser exte
     private final RandomAccessBufferedFileInputStream raStream;
 
     /**
+     * is parser using auto healing capacity ?
+     */
+    private boolean isLenient = true;
+
+    /**
      * The security handler.
      */
     protected SecurityHandler securityHandler = null;
@@ -331,8 +336,10 @@ public class NonSequentialPDFParser exte
 
         long startXrefOffset = document.getStartXref();
         // check the startxref offset
-        startXrefOffset -= calculateFixingOffset(startXrefOffset);
-        document.setStartXref(startXrefOffset);
+        if (isLenient) {
+            startXrefOffset -= calculateFixingOffset(startXrefOffset);
+            document.setStartXref(startXrefOffset);
+        }
         long prev = startXrefOffset;
         // ---- parse whole chain of xref tables/object streams using PREV
         // reference
@@ -356,7 +363,7 @@ public class NonSequentialPDFParser exte
                 }
                 COSDictionary trailer = xrefTrailerResolver.getCurrentTrailer();
                 prev = trailer.getInt(COSName.PREV);
-                if (prev > -1)
+                if (isLenient && prev > -1)
                 {
                 	// check the xref table reference
                 	long fixingOffset = calculateFixingOffset(prev);
@@ -364,14 +371,14 @@ public class NonSequentialPDFParser exte
 	            	{
 	            		prev -= fixingOffset;
 	            		trailer.setLong(COSName.PREV, prev);
-	            	} 
-                }            	
+	            	}
+                }
             }
             else
             {
                 // parse xref stream
                 prev = parseXrefObjStream(prev);
-                if (prev > -1)
+                if (isLenient && prev > -1)
                 {
                 	// check the xref table reference
                 	long fixingOffset = calculateFixingOffset(prev);
@@ -380,8 +387,8 @@ public class NonSequentialPDFParser exte
 	            		prev -= fixingOffset;
 	                    COSDictionary trailer = xrefTrailerResolver.getCurrentTrailer();
 	            		trailer.setLong(COSName.PREV, prev);
-	            	} 
-                }            	
+	            	}
+                }
             }
         }
 
@@ -390,8 +397,10 @@ public class NonSequentialPDFParser exte
         COSDictionary trailer = xrefTrailerResolver.getTrailer();
         document.setTrailer(trailer);
 
-        // check the offsets of all referenced objects 
-        checkXrefOffsets();
+        // check the offsets of all referenced objects
+        if (isLenient) {
+            checkXrefOffsets();
+        }
         
         // ---- prepare encryption if necessary
         COSBase trailerEncryptItem = document.getTrailer().getItem(COSName.ENCRYPT);
@@ -782,6 +791,30 @@ public class NonSequentialPDFParser exte
     }
 
     /**
+     * Return true if parser is lenient. Meaning auto healing capacity of the parser are used.
+     *
+     * @return true if parser is lenient
+     */
+    public boolean isLenient () {
+        return isLenient;
+    }
+
+    /**
+     * Change the parser leniency flag.
+     *
+     * This method can only be called before the parsing of the file.
+     *
+     * @param lenient
+     *
+     * @throws IllegalArgumentException if the method is called after parsing.
+     */
+    public void setLenient (boolean lenient) throws IllegalArgumentException {
+        if (initialParseDone) {
+            throw new IllegalArgumentException("Cannot change leniency after parsing");
+        }
+        this.isLenient = lenient;
+    }
+    /**
      * Remove the temporary file. A temporary file is created if this class is
      * instantiated with an InputStream
      */

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=1558205&r1=1558204&r2=1558205&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 Jan 14 21:30:11 2014
@@ -106,6 +106,7 @@ public class PreflightParser extends Non
     public PreflightParser(File file, RandomAccess rafi) throws IOException
     {
         super(file, rafi);
+        this.setLenient(false);
         this.originalDocument = new FileDataSource(file);
     }
 
@@ -122,6 +123,7 @@ public class PreflightParser extends Non
     public PreflightParser(DataSource input) throws IOException
     {
         super(input.getInputStream());
+        this.setLenient(false);
         this.originalDocument = input;
     }