pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gbaill...@apache.org
Subject svn commit: r1604323 - in /pdfbox/trunk: preflight/src/main/java/org/apache/pdfbox/preflight/parser/ preflight/src/main/java/org/apache/pdfbox/preflight/process/ preflight/src/main/java/org/apache/pdfbox/preflight/xobject/ xmpbox/src/main/java/org/apac...
Date Sat, 21 Jun 2014 08:20:20 GMT
Author: gbailleul
Date: Sat Jun 21 08:20:20 2014
New Revision: 1604323

URL: http://svn.apache.org/r1604323
Log:
PDFBOX-1816: Added offset in error messages

Modified:
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/AbstractXObjValidator.java
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjFormValidator.java
    pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java

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=1604323&r1=1604322&r2=1604323&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
Sat Jun 21 08:20:20 2014
@@ -460,13 +460,13 @@ public class PreflightParser extends Non
         if (!streamV.equals("stream"))
         {
             addValidationError(new ValidationError(ERROR_SYNTAX_STREAM_DELIMITER,
-                    "Expected 'stream' keyword but found '" + streamV + "'"));
+                    "Expected 'stream' keyword but found '" + streamV + "' at offset "+pdfSource.getOffset()));
         }
         int nextChar = pdfSource.read();
         if (!((nextChar == 13 && pdfSource.peek() == 10) || nextChar == 10))
         {
             addValidationError(new ValidationError(ERROR_SYNTAX_STREAM_DELIMITER,
-                    "Expected 'EOL' after the stream keyword"));
+                    "Expected 'EOL' after the stream keyword at offset "+pdfSource.getOffset()));
         }
         // set the offset before stream
         pdfSource.seek(pdfSource.getOffset() - 7);
@@ -483,13 +483,13 @@ public class PreflightParser extends Non
         if (!nextIsEOL())
         {
             addValidationError(new ValidationError(ERROR_SYNTAX_STREAM_DELIMITER,
-                    "Expected 'EOL' before the endstream keyword"));
+                    "Expected 'EOL' before the endstream keyword at offset "+pdfSource.getOffset()+"
but found '"+pdfSource.peek()+"'"));
         }
         String endstreamV = readString();
         if (!endstreamV.equals("endstream"))
         {
             addValidationError(new ValidationError(ERROR_SYNTAX_STREAM_DELIMITER,
-                    "Expected 'endstream' keyword but found '" + endstreamV + "'"));
+                    "Expected 'endstream' keyword at offset "+pdfSource.getOffset()+" but
found '" + endstreamV + "'"));
         }
     }
 
@@ -583,7 +583,7 @@ public class PreflightParser extends Non
                     else
                     {
                         addValidationError(new ValidationError(ERROR_SYNTAX_HEXA_STRING_INVALID,
-                                "Hexa String must have only Hexadecimal Characters (found
'" + nextChar + "')"));
+                                "Hexa String must have only Hexadecimal Characters (found
'" + nextChar + "') at offset "+pdfSource.getOffset()));
                         break;
                     }
                 }
@@ -593,7 +593,7 @@ public class PreflightParser extends Non
         if (count % 2 != 0)
         {
             addValidationError(new ValidationError(ERROR_SYNTAX_HEXA_STRING_EVEN_NUMBER,
-                    "Hexa string shall contain even number of non white space char"));
+                    "Hexa string shall contain even number of non white space char at offset
"+pdfSource.getOffset()));
         }
 
         // reset the offset to parse the COSString
@@ -602,7 +602,7 @@ public class PreflightParser extends Non
 
         if (result.getString().length() > MAX_STRING_LENGTH)
         {
-            addValidationError(new ValidationError(ERROR_SYNTAX_HEXA_STRING_TOO_LONG, "Hexa
string is too long"));
+            addValidationError(new ValidationError(ERROR_SYNTAX_HEXA_STRING_TOO_LONG, "Hexa
string is too long at offset "+pdfSource.getOffset()));
         }
         return result;
     }
@@ -624,7 +624,7 @@ public class PreflightParser extends Non
                 if (real > MAX_POSITIVE_FLOAT || real < MAX_NEGATIVE_FLOAT)
                 {
                     addValidationError(new ValidationError(ERROR_SYNTAX_NUMERIC_RANGE,
-                            "Float is too long or too small: " + real));
+                            "Float is too long or too small: " + real+"  at offset "+pdfSource.getOffset()));
                 }
             }
             else
@@ -633,7 +633,7 @@ public class PreflightParser extends Non
                 if (numAsLong > Integer.MAX_VALUE || numAsLong < Integer.MIN_VALUE)
                 {
                     addValidationError(new ValidationError(ERROR_SYNTAX_NUMERIC_RANGE,
-                            "Numeric is too long or too small: " + numAsLong));
+                            "Numeric is too long or too small: " + numAsLong+"  at offset
"+pdfSource.getOffset()));
                 }
             }
         }
@@ -643,7 +643,7 @@ public class PreflightParser extends Non
             COSDictionary dic = (COSDictionary) result;
             if (dic.size() > MAX_DICT_ENTRIES)
             {
-                addValidationError(new ValidationError(ERROR_SYNTAX_TOO_MANY_ENTRIES, "Too
Many Entries In Dictionary"));
+                addValidationError(new ValidationError(ERROR_SYNTAX_TOO_MANY_ENTRIES, "Too
Many Entries In Dictionary at offset "+pdfSource.getOffset()));
             }
         }
         return result;
@@ -704,7 +704,7 @@ public class PreflightParser extends Non
                 else
                 {
 
-                    addValidationError(new ValidationError(ERROR_SYNTAX_OBJ_DELIMITER, "Single
space expected"));
+                    addValidationError(new ValidationError(ERROR_SYNTAX_OBJ_DELIMITER, "Single
space expected [offset="+offset+"; key="+offsetOrObjstmObNr.toString()+"; line="+line+"; object="+pdfObject.toString()+"]"));
 
                     // reset pdfSource cursor to read object information
                     pdfSource.seek(offset);
@@ -818,7 +818,7 @@ public class PreflightParser extends Non
                     if (!nextIsEOL())
                     {
                         addValidationError(new ValidationError(PreflightConstants.ERROR_SYNTAX_OBJ_DELIMITER,
-                                "EOL expected before the 'endobj' keyword"));
+                                "EOL expected before the 'endobj' keyword at offset "+pdfSource.getOffset()));
                     }
                     pdfSource.seek(offset);
                 }
@@ -826,7 +826,7 @@ public class PreflightParser extends Non
                 if (!nextIsEOL())
                 {
                     addValidationError(new ValidationError(PreflightConstants.ERROR_SYNTAX_OBJ_DELIMITER,
-                            "EOL expected after the 'endobj' keyword"));
+                            "EOL expected after the 'endobj' keyword at offset "+pdfSource.getOffset()));
                 }
 
                 releasePdfSourceInputStream();
@@ -879,7 +879,7 @@ public class PreflightParser extends Non
                         || !(buf[tmpOffset] == 10 || buf[tmpOffset] == 13 || buf[tmpOffset
+ 1] == 10))
                 {
                     addValidationError(new ValidationError(ERROR_SYNTAX_TRAILER_EOF,
-                            "File contains data after the last %%EOF sequence"));
+                            "File contains data after the last %%EOF sequence at offset "+pdfSource.getOffset()));
                 }
             }
         }

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java?rev=1604323&r1=1604322&r2=1604323&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java
(original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java
Sat Jun 21 08:20:20 2014
@@ -263,7 +263,7 @@ public class StreamValidationProcess ext
                         if (cr == -1)
                         {
                             addValidationError(context, new ValidationError(ERROR_SYNTAX_STREAM_LENGTH_INVALID,
-                                    "Stream length is invalide"));
+                                "Stream length is invalid [cObj="+cObj.toString()+"]"));
                             org.apache.pdfbox.io.IOUtils.closeQuietly(ra);
                             return;
                         }
@@ -287,7 +287,7 @@ public class StreamValidationProcess ext
                         if (!endStream.contains("endstream"))
                         {
                             addValidationError(context, new ValidationError(ERROR_SYNTAX_STREAM_LENGTH_INVALID,
-                                    "Stream length is invalide"));
+                                "Stream length is invalid [cObj="+cObj.toString()+"; defined
length="+length+"; buffer2="+endStream+"]"));
                         }
                     }
                     else if (buffer2[0] == '\r' && buffer2[1] == 'e')
@@ -295,7 +295,7 @@ public class StreamValidationProcess ext
                         if (!endStream.contains("endstream"))
                         {
                             addValidationError(context, new ValidationError(ERROR_SYNTAX_STREAM_LENGTH_INVALID,
-                                    "Stream length is invalide"));
+                                "Stream length is invalid [cObj="+cObj.toString()+"; defined
length="+length+"; buffer2="+endStream+"]"));
                         }
                     }
                     else if (buffer2[0] == '\n' && buffer2[1] == 'e')
@@ -303,20 +303,22 @@ public class StreamValidationProcess ext
                         if (!endStream.contains("endstream"))
                         {
                             addValidationError(context, new ValidationError(ERROR_SYNTAX_STREAM_LENGTH_INVALID,
-                                    "Stream length is invalide"));
+                                "Stream length is invalid [cObj="+cObj.toString()+"; defined
length="+length+"; buffer2="+endStream+"]"));
                         }
                     }
                     else
                     {
-                        addValidationError(context, new ValidationError(ERROR_SYNTAX_STREAM_LENGTH_INVALID,
-                                "Stream length is invalide"));
+                        if (!endStream.startsWith("endStream")) {
+                             addValidationError(context, new ValidationError(ERROR_SYNTAX_STREAM_LENGTH_INVALID,
+                                "Stream length is invalid [cObj="+cObj.toString()+"; defined
length="+length+"; buffer2="+endStream+"]"));
+                        }
                     }
 
                 }
                 else
                 {
                     addValidationError(context, new ValidationError(ERROR_SYNTAX_STREAM_LENGTH_INVALID,
-                            "Stream length is invalide"));
+                            "Stream length is invalid"));
                 }
             }
         }

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/AbstractXObjValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/AbstractXObjValidator.java?rev=1604323&r1=1604322&r2=1604323&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/AbstractXObjValidator.java
(original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/AbstractXObjValidator.java
Sat Jun 21 08:20:20 2014
@@ -76,7 +76,7 @@ public abstract class AbstractXObjValida
                         .equals(COSUtils.getAsString(smask, cosDocument))))
         {
             context.addValidationError(new ValidationError(ERROR_GRAPHIC_TRANSPARENCY_SMASK,
-                    "Soft Mask must be null or None"));
+                    "Soft Mask must be null or None ["+xobject.toString()+"]"));
         }
     }
 
@@ -84,9 +84,6 @@ public abstract class AbstractXObjValida
      * According the ISO 190005:1-2005 specification, a XObject can't have an OPI entry in
its dictionary. If the
      * XObject has a OPI entry, the error list is updated with the error code ERROR_GRAPHIC_UNEXPECTED_KEY
(2.3).
      * 
-     * @param errors
-     *            the list of error to update if the validation fails.
-     * @return true if the OPI is missing, false otherwise.
      */
     protected void checkOPI()
     {

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjFormValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjFormValidator.java?rev=1604323&r1=1604322&r2=1604323&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjFormValidator.java
(original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjFormValidator.java
Sat Jun 21 08:20:20 2014
@@ -133,7 +133,7 @@ public class XObjFormValidator extends A
                 String sVal = groupDictionary.getNameAsString(COSName.S);
                 if (sVal == null || XOBJECT_DICTIONARY_VALUE_S_TRANSPARENCY.equals(sVal))
                 {
-                    context.addValidationError(new ValidationError(ERROR_GRAPHIC_TRANSPARENCY_GROUP,
"Group has a transparency S entry or the S entry is null."));
+                    context.addValidationError(new ValidationError(ERROR_GRAPHIC_TRANSPARENCY_GROUP,
"Group has a transparency S entry or the S entry is null ["+xobject.toString()+"]"));
                     return;
                 }
             }

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java?rev=1604323&r1=1604322&r2=1604323&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java Sat Jun 21 08:20:20
2014
@@ -384,13 +384,13 @@ public class DomXmpParser
         {
             // not an array
             throw new XmpParsingException(ErrorType.Format, "Invalid array definition, expecting
" + type.card()
-                    + " and found nothing");
+                    + " and found nothing [prefix="+prefix+"; name="+name+"]");
         }
         if (!bagOrSeq.getLocalName().equals(type.card().name()))
         {
             // not the good array type
             throw new XmpParsingException(ErrorType.Format, "Invalid array type, expecting
" + type.card()
-                    + " and found " + bagOrSeq.getLocalName());
+                    + " and found " + bagOrSeq.getLocalName() + " [prefix="+prefix+"; name="+name+"]");
         }
         ArrayProperty array = tm.createArrayProperty(namespace, prefix, name, type.card());
         container.addProperty(array);
@@ -735,7 +735,7 @@ public class DomXmpParser
             }
             else if (node instanceof Text)
             {
-                if (((Text)node).getTextContent().trim().length() == 0)
+                if (node.getTextContent().trim().length() == 0)
                 {
                         root.removeChild(node);
                 }



Mime
View raw message