You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2014/10/07 21:07:43 UTC

svn commit: r1629956 - in /pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight: ValidationResult.java content/PreflightContentStream.java content/PreflightStreamEngine.java font/descriptor/Type1DescriptorHelper.java font/util/Type1Parser.java

Author: tilman
Date: Tue Oct  7 19:07:42 2014
New Revision: 1629956

URL: http://svn.apache.org/r1629956
Log:
PDFBOX-2299, PDFBOX-2403: more error details, as suggested by Ralf Hauser; minor code + javadoc cleanup

Modified:
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/ValidationResult.java
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/descriptor/Type1DescriptorHelper.java
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/Type1Parser.java

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/ValidationResult.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/ValidationResult.java?rev=1629956&r1=1629955&r2=1629956&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/ValidationResult.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/ValidationResult.java Tue Oct  7 19:07:42 2014
@@ -182,12 +182,26 @@ public class ValidationResult
         private String details;
 
         /**
-         * false : this error can't be ignore true : this error can be ignore
+         * false: this error can't be ignored; true: this error can be ignored
          */
         private boolean isWarning = false;
 
         // TODO Add here COSObject or the PDObject that is linked to the error may a automatic fix can be done.
 
+        private Throwable t = null;
+
+        public Throwable getThrowable()
+        {
+            return t;
+        }
+
+        private Throwable cause = null;
+
+        public Throwable getCause()
+        {
+            return cause;
+        }
+
         /**
          * Create a validation error with the given error code
          * 
@@ -277,17 +291,18 @@ public class ValidationResult
                 // default Unkown error
                 this.details = "Unknown error";
             }
+            t = new Exception();
         }
 
         /**
-         * Create a validation error with the given error code and the error explanation.
-         * 
-         * @param errorCode
-         *            the error code
-         * @param details
-         *            the error explanation
+         * Create a validation error with the given error code and the error
+         * explanation.
+         *
+         * @param errorCode the error code
+         * @param details the error explanation
+         * @param cause the error cause
          */
-        public ValidationError(String errorCode, String details)
+        public ValidationError(String errorCode, String details, Throwable cause)
         {
             this(errorCode);
             if (details != null)
@@ -296,9 +311,24 @@ public class ValidationResult
                 sb.append(this.details).append(", ").append(details);
                 this.details = sb.toString();
             }
+            this.cause = cause;
+            t = new Exception();
         }
 
         /**
+         * Create a validation error with the given error code and the error explanation.
+         * 
+         * @param errorCode
+         *            the error code
+         * @param details
+         *            the error explanation
+         */
+        public ValidationError(String errorCode, String details)
+        {
+            this(errorCode, details, null);
+        }        
+
+        /**
          * @return the error code
          */
         public String getErrorCode()

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java?rev=1629956&r1=1629955&r2=1629956&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java Tue Oct  7 19:07:42 2014
@@ -235,7 +235,6 @@ public class PreflightContentStream exte
             {
                 registerError("Invalid argument for the operator : " + operator.getName(),
                         ERROR_SYNTAX_CONTENT_STREAM_INVALID_ARGUMENT);
-                return;
             }
         }
         else
@@ -249,7 +248,6 @@ public class PreflightContentStream exte
             {
                 registerError("Invalid argument for the operator : " + operator.getName(),
                         ERROR_SYNTAX_CONTENT_STREAM_INVALID_ARGUMENT);
-                return;
             }
         }
     }
@@ -345,14 +343,14 @@ public class PreflightContentStream exte
             }
             catch (IOException e)
             {
-                registerError("Encoding can't interpret the character code", ERROR_FONTS_ENCODING_ERROR);
+                registerError("Encoding can't interpret the character code", ERROR_FONTS_ENCODING_ERROR, e);
                 return;
             }
             catch (GlyphException e)
             {
                 if (renderingMode != RenderingMode.NEITHER)
                 {
-                    registerError(e.getMessage(), e.getErrorCode());
+                    registerError(e.getMessage(), e.getErrorCode(), e);
                     return;
                 }
             }

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java?rev=1629956&r1=1629955&r2=1629956&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java Tue Oct  7 19:07:42 2014
@@ -576,12 +576,23 @@ public abstract class PreflightStreamEng
      */
     protected void registerError(String msg, String errorCode)
     {
-        registerError(msg, errorCode, false);
+        registerError(msg, errorCode, null);
+    }
+
+    public void registerError(String msg, String errorCode, Throwable cause)
+    {
+        registerError(msg, errorCode, false, cause);
     }
     
     protected void registerError(String msg, String errorCode, boolean warning)
     {
-        ValidationError error = new ValidationError(errorCode, msg);
+        registerError(msg, errorCode, warning, null);
+    }
+
+    public void registerError(String msg, String errorCode, boolean warning,
+            Throwable cause)
+    {
+        ValidationError error = new ValidationError(errorCode, msg, cause);
         error.setWarning(warning);
         this.context.addValidationError(error);
     }

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/descriptor/Type1DescriptorHelper.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/descriptor/Type1DescriptorHelper.java?rev=1629956&r1=1629955&r2=1629956&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/descriptor/Type1DescriptorHelper.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/descriptor/Type1DescriptorHelper.java Tue Oct  7 19:07:42 2014
@@ -157,15 +157,16 @@ public class Type1DescriptorHelper exten
             Type1 parsedData = parserForMetrics.parse();
 
             this.fContainer.setType1Font(parsedData);
-
         }
         catch (IOException e)
         {
-            this.fContainer.push(new ValidationError(ERROR_FONTS_TYPE1_DAMAGED, "The FontFile can't be read"));
+            this.fContainer.push(new ValidationError(ERROR_FONTS_TYPE1_DAMAGED, 
+                    "The FontFile can't be read for " + font.getName() + ": " + e.getMessage()));
         }
         catch (FontFormatException e)
         {
-            this.fContainer.push(new ValidationError(ERROR_FONTS_TYPE1_DAMAGED, "The FontFile is damaged"));
+            this.fContainer.push(new ValidationError(ERROR_FONTS_TYPE1_DAMAGED, 
+                    "The FontFile is damaged for " + font.getName() + ": " + e.getMessage()));
         }
         finally
         {

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/Type1Parser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/Type1Parser.java?rev=1629956&r1=1629955&r2=1629956&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/Type1Parser.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/Type1Parser.java Tue Oct  7 19:07:42 2014
@@ -332,7 +332,7 @@ public final class Type1Parser
 
     private void goToBeginOfCharStringElements(PeekInputStream stream) throws IOException
     {
-        byte[] token = new byte[0];
+        byte[] token;
         do
         {
             token = readToken(stream);
@@ -373,7 +373,7 @@ public final class Type1Parser
         }
         catch (NumberFormatException e)
         {
-            throw new IOException("Number of CharStrings elements is expected.");
+            throw new IOException("Number of CharStrings elements was expected but we received " + word);
         }
     }
 
@@ -420,7 +420,7 @@ public final class Type1Parser
         int BUFFER_SIZE = 1024;
         byte[] buffer = new byte[BUFFER_SIZE];
         ByteArrayOutputStream eexecPart = new ByteArrayOutputStream();
-        int lr = 0;
+        int lr;
         int total = 0;
         do
         {
@@ -459,7 +459,8 @@ public final class Type1Parser
         {
             currentCharacter = readNextCharacter(stream);
             bytes.add((byte) (currentCharacter & 0xFF));
-        } while (!('\n' == currentCharacter || '\r' == currentCharacter));
+        }
+        while (!('\n' == currentCharacter || '\r' == currentCharacter));
 
         if ('\r' == currentCharacter && '\n' == stream.peek())
         {
@@ -477,7 +478,7 @@ public final class Type1Parser
 
     private byte[] readToken(PeekInputStream stream) throws IOException
     {
-        byte[] token = new byte[0];
+        byte[] token;
         skipBlankSeparators(stream);
 
         int nextByte = stream.peek();
@@ -511,7 +512,7 @@ public final class Type1Parser
         int opened = 0;
         List<Integer> buffer = new ArrayList<Integer>();
 
-        int currentByte = 0;
+        int currentByte;
         do
         {
             currentByte = readNextCharacter(stream);
@@ -530,7 +531,8 @@ public final class Type1Parser
             }
 
             buffer.add(currentByte);
-        } while (opened != 0);
+        } 
+        while (opened != 0);
 
         return convertListOfIntToByteArray(buffer);
     }
@@ -540,7 +542,7 @@ public final class Type1Parser
         int opened = 0;
         List<Integer> buffer = new ArrayList<Integer>();
 
-        int currentByte = 0;
+        int currentByte;
         do
         {
             currentByte = readNextCharacter(stream);
@@ -559,7 +561,8 @@ public final class Type1Parser
             }
 
             buffer.add(currentByte);
-        } while (opened != 0);
+        }
+        while (opened != 0);
 
         return convertListOfIntToByteArray(buffer);
     }
@@ -569,7 +572,7 @@ public final class Type1Parser
         int opened = 0;
         List<Integer> buffer = new ArrayList<Integer>();
 
-        int currentByte = 0;
+        int currentByte;
         do
         {
             currentByte = readNextCharacter(stream);
@@ -588,7 +591,8 @@ public final class Type1Parser
             }
 
             buffer.add(currentByte);
-        } while (opened != 0);
+        }
+        while (opened != 0);
 
         return convertListOfIntToByteArray(buffer);
     }
@@ -606,7 +610,8 @@ public final class Type1Parser
             }
             buffer.add(currentByte);
             nextByte = stream.peek();
-        } while (isNotBlankSperator(nextByte) && isNotBeginOfName(nextByte) && isNotSeparator(nextByte));
+        }
+        while (isNotBlankSperator(nextByte) && isNotBeginOfName(nextByte) && isNotSeparator(nextByte));
 
         return convertListOfIntToByteArray(buffer);
     }