pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1542735 [4/4] - in /pdfbox/branches/1.8: ./ fontbox/src/main/java/org/apache/fontbox/ttf/ pdfbox/src/main/java/org/apache/pdfbox/filter/ pdfbox/src/main/java/org/apache/pdfbox/io/ pdfbox/src/main/java/org/apache/pdfbox/pdfparser/ pdfbox/sr...
Date Sun, 17 Nov 2013 14:31:03 GMT
Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/AcroFormValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/AcroFormValidationProcess.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/AcroFormValidationProcess.java
(original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/AcroFormValidationProcess.java
Sun Nov 17 14:31:02 2013
@@ -26,6 +26,7 @@ import static org.apache.pdfbox.prefligh
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_ACTION_FORBIDDEN_ADDITIONAL_ACTIONS_FIELD;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_ACTION_FORBIDDEN_WIDGET_ACTION_FIELD;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_DICT_INVALID;
+import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_NOCATALOG;
 
 import java.io.IOException;
 import java.util.List;
@@ -37,6 +38,7 @@ import org.apache.pdfbox.pdmodel.interac
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
 import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
 import org.apache.pdfbox.pdmodel.interactive.form.PDField;
+import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 import org.apache.pdfbox.preflight.exception.ValidationException;
@@ -66,7 +68,7 @@ public class AcroFormValidationProcess e
         }
         else
         {
-            throw new ValidationException("There are no Catalog entry in the Document.");
+            ctx.addValidationError(new ValidationError(ERROR_SYNTAX_NOCATALOG, "There are
no Catalog entry in the Document."));
         }
     }
 

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/BookmarkValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/BookmarkValidationProcess.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/BookmarkValidationProcess.java
(original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/BookmarkValidationProcess.java
Sun Nov 17 14:31:02 2013
@@ -22,6 +22,7 @@
 package org.apache.pdfbox.preflight.process;
 
 import static org.apache.pdfbox.preflight.PreflightConfiguration.ACTIONS_PROCESS;
+import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_NOCATALOG;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_TRAILER_OUTLINES_INVALID;
 
 import org.apache.pdfbox.cos.COSBase;
@@ -31,6 +32,7 @@ import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
 import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDDocumentOutline;
 import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineItem;
+import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 import org.apache.pdfbox.preflight.exception.ValidationException;
@@ -69,7 +71,7 @@ public class BookmarkValidationProcess e
         }
         else
         {
-            throw new ValidationException("There are no Catalog entry in the Document.");
+            ctx.addValidationError(new ValidationError(ERROR_SYNTAX_NOCATALOG, "There are
no Catalog entry in the Document."));
         }
     }
 

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/CatalogValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/CatalogValidationProcess.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/CatalogValidationProcess.java
(original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/CatalogValidationProcess.java
Sun Nov 17 14:31:02 2013
@@ -202,15 +202,16 @@ public class CatalogValidationProcess ex
 
         if (this.catalog == null)
         {
-            new ValidationError(ERROR_SYNTAX_NOCATALOG, "There are no Catalog entry in the
Document.");
-            throw new ValidationException("There are no Catalog entry in the Document.");
+            ctx.addValidationError(new ValidationError(ERROR_SYNTAX_NOCATALOG, "There are
no Catalog entry in the Document."));
+        } 
+        else 
+        {
+            validateActions(ctx);
+            validateLang(ctx);
+            validateNames(ctx);
+            validateOCProperties(ctx);
+            validateOutputIntent(ctx);
         }
-
-        validateActions(ctx);
-        validateLang(ctx);
-        validateNames(ctx);
-        validateOCProperties(ctx);
-        validateOutputIntent(ctx);
     }
 
     /**
@@ -379,7 +380,7 @@ public class CatalogValidationProcess ex
      */
     protected void validateICCProfile(COSBase destOutputProfile, Map<COSObjectKey, Boolean>
mapDestOutputProfile,
             PreflightContext ctx) throws ValidationException
-    {
+            {
         try
         {
             if (destOutputProfile == null)
@@ -461,5 +462,5 @@ public class CatalogValidationProcess ex
         {
             throw new ValidationException("Unable to parse the ICC Profile", e);
         }
-    }
+            }
 }

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/PageTreeValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/PageTreeValidationProcess.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/PageTreeValidationProcess.java
(original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/PageTreeValidationProcess.java
Sun Nov 17 14:31:02 2013
@@ -22,12 +22,14 @@
 package org.apache.pdfbox.preflight.process;
 
 import static org.apache.pdfbox.preflight.PreflightConfiguration.PAGE_PROCESS;
+import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_NOCATALOG;
 
 import java.util.List;
 
 import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.preflight.PreflightContext;
+import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 import org.apache.pdfbox.preflight.exception.ValidationException;
 import org.apache.pdfbox.preflight.utils.ContextHelper;
 
@@ -47,7 +49,7 @@ public class PageTreeValidationProcess e
         }
         else
         {
-            throw new ValidationException("There are no Catalog entry in the Document.");
+            context.addValidationError(new ValidationError(ERROR_SYNTAX_NOCATALOG, "There
are no Catalog entry in the Document."));
         }
     }
 

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java
(original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java
Sun Nov 17 14:31:02 2013
@@ -21,6 +21,7 @@
 
 package org.apache.pdfbox.preflight.process;
 
+import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_STREAM_DAMAGED;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_STREAM_FX_KEYS;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_STREAM_INVALID_FILTER;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_STREAM_LENGTH_INVALID;
@@ -226,7 +227,9 @@ public class StreamValidationProcess ext
                     long curSkip = ra.skip(offset - skipped);
                     if (curSkip < 0)
                     {
-                        throw new ValidationException("Unable to skip bytes in the PDFFile
to check stream length");
+                        org.apache.pdfbox.io.IOUtils.closeQuietly(ra);
+                        addValidationError(context, new ValidationError(ERROR_SYNTAX_STREAM_DAMAGED,
"Unable to skip bytes in the PDFFile to check stream length"));
+                        return;
                     }
                     skipped += curSkip;
                 }
@@ -261,6 +264,7 @@ public class StreamValidationProcess ext
                         {
                             addValidationError(context, new ValidationError(ERROR_SYNTAX_STREAM_LENGTH_INVALID,
                                     "Stream length is invalide"));
+                            org.apache.pdfbox.io.IOUtils.closeQuietly(ra);
                             return;
                         }
                         else

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ActionsValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ActionsValidationProcess.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ActionsValidationProcess.java
(original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ActionsValidationProcess.java
Sun Nov 17 14:31:02 2013
@@ -26,12 +26,14 @@ import java.util.List;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.preflight.PreflightConfiguration;
+import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.PreflightPath;
 import org.apache.pdfbox.preflight.action.AbstractActionManager;
 import org.apache.pdfbox.preflight.action.ActionManagerFactory;
 import org.apache.pdfbox.preflight.exception.ValidationException;
 import org.apache.pdfbox.preflight.process.AbstractProcess;
+import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 
 public class ActionsValidationProcess extends AbstractProcess
 {
@@ -39,21 +41,26 @@ public class ActionsValidationProcess ex
     public void validate(PreflightContext context) throws ValidationException
     {
         PreflightPath vPath = context.getValidationPath();
-        if (vPath.isEmpty() || !vPath.isExpectedType(COSDictionary.class))
+        if (vPath.isEmpty()) {
+            return;
+        }
+        else if (!vPath.isExpectedType(COSDictionary.class))
         {
-            throw new ValidationException("Action validation process needs at least one COSDictionary
object");
+            context.addValidationError(new ValidationError(PreflightConstants.ERROR_ACTION_INVALID_TYPE,
"Action validation process needs at least one COSDictionary object"));
         }
-
-        COSDictionary actionsDict = (COSDictionary) vPath.peek();
-        // AA entry is authorized only for Page, in this case A Page is just before the Action
Dictionary in the path
-        boolean aaEntryAuth = ((vPath.size() - vPath.getClosestTypePosition(PDPage.class))
== 2);
-
-        PreflightConfiguration config = context.getConfig();
-        ActionManagerFactory factory = config.getActionFact();
-        List<AbstractActionManager> la = factory.getActionManagers(context, actionsDict);
-        for (AbstractActionManager aMng : la)
+        else 
         {
-            aMng.valid(aaEntryAuth);
+            COSDictionary actionsDict = (COSDictionary) vPath.peek();
+            // AA entry is authorized only for Page, in this case A Page is just before the
Action Dictionary in the path
+            boolean aaEntryAuth = ((vPath.size() - vPath.getClosestTypePosition(PDPage.class))
== 2);
+
+            PreflightConfiguration config = context.getConfig();
+            ActionManagerFactory factory = config.getActionFact();
+            List<AbstractActionManager> la = factory.getActionManagers(context, actionsDict);
+            for (AbstractActionManager aMng : la)
+            {
+                aMng.valid(aaEntryAuth);
+            }
         }
     }
 

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/AnnotationValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/AnnotationValidationProcess.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/AnnotationValidationProcess.java
(original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/AnnotationValidationProcess.java
Sun Nov 17 14:31:02 2013
@@ -21,8 +21,10 @@
 
 package org.apache.pdfbox.preflight.process.reflect;
 
+import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.preflight.PreflightConfiguration;
+import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.PreflightPath;
 import org.apache.pdfbox.preflight.annotation.AnnotationValidator;
@@ -36,19 +38,24 @@ public class AnnotationValidationProcess
     public void validate(PreflightContext context) throws ValidationException
     {
         PreflightPath vPath = context.getValidationPath();
-        if (vPath.isEmpty() || !vPath.isExpectedType(COSDictionary.class))
+        if (vPath.isEmpty()) {
+            return;
+        }
+        else if (!vPath.isExpectedType(COSDictionary.class))
         {
-            throw new ValidationException("Annotation validation process needs at least one
COSDictionary object");
+            context.addValidationError(new ValidationError(PreflightConstants.ERROR_ANNOT_INVALID_ELEMENT,
"Annotation validation process needs at least one COSDictionary object"));
         }
-
-        COSDictionary annotDict = (COSDictionary) vPath.peek();
-
-        PreflightConfiguration config = context.getConfig();
-        AnnotationValidatorFactory factory = config.getAnnotFact();
-        AnnotationValidator annotValidator = factory.getAnnotationValidator(context, annotDict);
-        if (annotValidator != null)
+        else
         {
-            annotValidator.validate();
+            COSDictionary annotDict = (COSDictionary) vPath.peek();
+
+            PreflightConfiguration config = context.getConfig();
+            AnnotationValidatorFactory factory = config.getAnnotFact();
+            AnnotationValidator annotValidator = factory.getAnnotationValidator(context,
annotDict);
+            if (annotValidator != null)
+            {
+                annotValidator.validate();
+            }
         }
     }
 

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ExtGStateValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ExtGStateValidationProcess.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ExtGStateValidationProcess.java
(original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ExtGStateValidationProcess.java
Sun Nov 17 14:31:02 2013
@@ -41,6 +41,7 @@ import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSDocument;
 import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.PreflightPath;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
@@ -54,14 +55,19 @@ public class ExtGStateValidationProcess 
     public void validate(PreflightContext context) throws ValidationException
     {
         PreflightPath vPath = context.getValidationPath();
-        if (vPath.isEmpty() || !vPath.isExpectedType(COSDictionary.class))
+        if (vPath.isEmpty()) {
+            return;
+        }
+        else if (!vPath.isExpectedType(COSDictionary.class)) 
         {
-            throw new ValidationException("ExtGState validation required at least a Resource
dictionary");
+            context.addValidationError(new ValidationError(PreflightConstants.ERROR_GRAPHIC_XOBJECT_INVALID_TYPE,
"ExtGState validation required at least a Resource dictionary"));
+        }
+        else
+        {
+            COSDictionary extGStatesDict = (COSDictionary) vPath.peek();
+            List<COSDictionary> listOfExtGState = extractExtGStateDictionaries(context,
extGStatesDict);
+            validateTransparencyRules(context, listOfExtGState);
         }
-
-        COSDictionary extGStatesDict = (COSDictionary) vPath.peek();
-        List<COSDictionary> listOfExtGState = extractExtGStateDictionaries(context,
extGStatesDict);
-        validateTransparencyRules(context, listOfExtGState);
     }
 
     /**
@@ -76,7 +82,7 @@ public class ExtGStateValidationProcess 
      */
     public List<COSDictionary> extractExtGStateDictionaries(PreflightContext context,
COSDictionary egsEntry)
             throws ValidationException
-    {
+            {
         List<COSDictionary> listOfExtGState = new ArrayList<COSDictionary>(0);
         COSDocument cosDocument = context.getDocument().getDocument();
         COSDictionary extGStates = COSUtils.getAsDictionary(egsEntry, cosDocument);
@@ -99,7 +105,7 @@ public class ExtGStateValidationProcess 
             }
         }
         return listOfExtGState;
-    }
+            }
 
     /**
      * Validate all ExtGState dictionaries of this container

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/FontValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/FontValidationProcess.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/FontValidationProcess.java
(original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/FontValidationProcess.java
Sun Nov 17 14:31:02 2013
@@ -32,6 +32,7 @@ import static org.apache.pdfbox.prefligh
 import static org.apache.pdfbox.preflight.PreflightConstants.FONT_DICTIONARY_VALUE_TYPE3;
 
 import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.PreflightPath;
 import org.apache.pdfbox.preflight.exception.ValidationException;
@@ -42,6 +43,8 @@ import org.apache.pdfbox.preflight.font.
 import org.apache.pdfbox.preflight.font.Type3FontValidator;
 import org.apache.pdfbox.preflight.font.container.FontContainer;
 import org.apache.pdfbox.preflight.process.AbstractProcess;
+import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
+
 
 public class FontValidationProcess extends AbstractProcess
 {
@@ -49,17 +52,22 @@ public class FontValidationProcess exten
     public void validate(PreflightContext context) throws ValidationException
     {
         PreflightPath vPath = context.getValidationPath();
-        if (vPath.isEmpty() || !vPath.isExpectedType(PDFont.class))
-        {
-            throw new ValidationException("Font validation process needs at least one PDFont
object");
+        if (vPath.isEmpty()) {
+            return;
         }
-
-        PDFont font = (PDFont) vPath.peek();
-        FontContainer fontContainer = context.getFontContainer(font.getCOSObject());
-        if (fontContainer == null)
-        { // if fontContainer isn't null the font is already checked
-            FontValidator<? extends FontContainer> validator = getFontValidator(context,
font);
-            validator.validate();
+        else if (!vPath.isExpectedType(PDFont.class)) 
+        {
+            context.addValidationError(new ValidationError(PreflightConstants.ERROR_FONTS_INVALID_DATA,
"Font validation process needs at least one PDFont object"));
+        } 
+        else
+        {
+            PDFont font = (PDFont) vPath.peek();
+            FontContainer fontContainer = context.getFontContainer(font.getCOSObject());
+            if (fontContainer == null)
+            { // if fontContainer isn't null the font is already checked
+                FontValidator<? extends FontContainer> validator = getFontValidator(context,
font);
+                if (validator != null) validator.validate();
+            }
         }
     }
 
@@ -70,7 +78,6 @@ public class FontValidationProcess exten
      * @return
      */
     protected FontValidator<? extends FontContainer> getFontValidator(PreflightContext
context, PDFont font)
-            throws ValidationException
     {
         String subtype = font.getSubType();
         if (FONT_DICTIONARY_VALUE_TRUETYPE.equals(subtype))
@@ -98,7 +105,8 @@ public class FontValidationProcess exten
         }
         else
         {
-            throw new ValidationException("Unknown font type : " + subtype);
+            context.addValidationError(new ValidationError(PreflightConstants.ERROR_FONTS_UNKNOWN_FONT_TYPE,
"Unknown font type : " + subtype));
+            return null;
         }
     }
 

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/GraphicObjectPageValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/GraphicObjectPageValidationProcess.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/GraphicObjectPageValidationProcess.java
(original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/GraphicObjectPageValidationProcess.java
Sun Nov 17 14:31:02 2013
@@ -27,6 +27,7 @@ import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectForm;
 import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage;
+import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.PreflightPath;
 import org.apache.pdfbox.preflight.exception.ValidationException;
@@ -36,6 +37,8 @@ import org.apache.pdfbox.preflight.xobje
 import org.apache.pdfbox.preflight.xobject.XObjPostscriptValidator;
 import org.apache.pdfbox.preflight.xobject.XObjectValidator;
 
+import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
+
 public class GraphicObjectPageValidationProcess extends AbstractProcess
 {
 
@@ -62,14 +65,16 @@ public class GraphicObjectPageValidation
             }
             else
             {
-                throw new ValidationException("Invalid XObject subtype");
+                context.addValidationError(new ValidationError(PreflightConstants.ERROR_GRAPHIC_XOBJECT_INVALID_TYPE,
"Invalid XObject subtype"));
             }
         }
         else
         {
-            throw new ValidationException("Graphic validation process needs at least one
PDFont object");
+            context.addValidationError(new ValidationError(PreflightConstants.ERROR_GRAPHIC_MISSING_OBJECT,
"Graphic validation process needs at least one PDXObject"));
         }
 
-        validator.validate();
+        if (validator != null) {
+            validator.validate();
+        }
     }
 }

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ResourcesValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ResourcesValidationProcess.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ResourcesValidationProcess.java
(original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ResourcesValidationProcess.java
Sun Nov 17 14:31:02 2013
@@ -44,6 +44,7 @@ import org.apache.pdfbox.pdmodel.graphic
 import org.apache.pdfbox.pdmodel.graphics.pattern.PDTilingPatternResources;
 import org.apache.pdfbox.pdmodel.graphics.shading.PDShadingResources;
 import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObject;
+import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.PreflightPath;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
@@ -58,18 +59,24 @@ public class ResourcesValidationProcess 
     public void validate(PreflightContext ctx) throws ValidationException
     {
         PreflightPath vPath = ctx.getValidationPath();
-        if (vPath.isEmpty() && !vPath.isExpectedType(PDResources.class))
-        {
-            throw new ValidationException("Resources validation process needs at least one
PDResources object");
+        if (vPath.isEmpty()) {
+            return;
         }
+        else if (!vPath.isExpectedType(PDResources.class))
+        {
+            addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_PDF_PROCESSING_MISSING,
"Resources validation process needs at least one PDResources object"));
+        } 
+        else
+        {
 
-        PDResources resources = (PDResources) vPath.peek();
+            PDResources resources = (PDResources) vPath.peek();
 
-        validateFonts(ctx, resources);
-        validateExtGStates(ctx, resources);
-        validateShadingPattern(ctx, resources);
-        validateTilingPattern(ctx, resources);
-        validateXObjects(ctx, resources);
+            validateFonts(ctx, resources);
+            validateExtGStates(ctx, resources);
+            validateShadingPattern(ctx, resources);
+            validateTilingPattern(ctx, resources);
+            validateXObjects(ctx, resources);
+        }
     }
 
     /**

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ShaddingPatternValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ShaddingPatternValidationProcess.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ShaddingPatternValidationProcess.java
(original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ShaddingPatternValidationProcess.java
Sun Nov 17 14:31:02 2013
@@ -29,10 +29,10 @@ import java.io.IOException;
 
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.pdmodel.PDPage;
-import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
 import org.apache.pdfbox.pdmodel.graphics.shading.PDShadingResources;
 import org.apache.pdfbox.preflight.PreflightConfiguration;
+import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.PreflightPath;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
@@ -49,15 +49,20 @@ public class ShaddingPatternValidationPr
     public void validate(PreflightContext context) throws ValidationException
     {
         PreflightPath vPath = context.getValidationPath();
-        if (vPath.isEmpty() && !vPath.isExpectedType(PDResources.class))
+        if (vPath.isEmpty()) {
+            return;
+        }
+        else if (!vPath.isExpectedType(PDShadingResources.class))
+        {
+            context.addValidationError(new ValidationError(PreflightConstants.ERROR_GRAPHIC_MISSING_OBJECT,
"ShadingPattern validation required at least a PDResources"));
+        } 
+        else 
         {
-            throw new ValidationException("ShadingPattern validation required at least a
PDResources");
+            PDShadingResources shaddingResource = (PDShadingResources) vPath.peek();
+            PDPage page = vPath.getClosestPathElement(PDPage.class);
+            checkColorSpace(context, page, shaddingResource);
+            checkGraphicState(context, page, shaddingResource);
         }
-
-        PDShadingResources shaddingResource = (PDShadingResources) vPath.peek();
-        PDPage page = vPath.getClosestPathElement(PDPage.class);
-        checkColorSpace(context, page, shaddingResource);
-        checkGraphicState(context, page, shaddingResource);
     }
 
     /**
@@ -73,7 +78,7 @@ public class ShaddingPatternValidationPr
      */
     protected void checkColorSpace(PreflightContext context, PDPage page, PDShadingResources
shadingRes)
             throws ValidationException
-    {
+            {
         try
         {
             PDColorSpace pColorSpace = shadingRes.getColorSpace();
@@ -86,7 +91,7 @@ public class ShaddingPatternValidationPr
         {
             context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_UNKNOWN_COLOR_SPACE,
e.getMessage()));
         }
-    }
+            }
 
     /**
      * Check the Extended Graphic State contains in the ShadingPattern dictionary if it is
present. To check this
@@ -97,12 +102,12 @@ public class ShaddingPatternValidationPr
      */
     protected void checkGraphicState(PreflightContext context, PDPage page, PDShadingResources
shadingRes)
             throws ValidationException
-    {
+            {
         COSDictionary resources = (COSDictionary) shadingRes.getCOSDictionary().getDictionaryObject(
                 TRANPARENCY_DICTIONARY_KEY_EXTGSTATE);
         if (resources != null)
         {
             ContextHelper.validateElement(context, resources, EXTGSTATE_PROCESS);
         }
-    }
+            }
 }

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/SinglePageValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/SinglePageValidationProcess.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/SinglePageValidationProcess.java
(original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/SinglePageValidationProcess.java
Sun Nov 17 14:31:02 2013
@@ -47,6 +47,7 @@ import org.apache.pdfbox.pdmodel.graphic
 import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
 import org.apache.pdfbox.preflight.PreflightConfiguration;
+import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.PreflightPath;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
@@ -65,22 +66,26 @@ public class SinglePageValidationProcess
     public void validate(PreflightContext context) throws ValidationException
     {
         PreflightPath vPath = context.getValidationPath();
-        if (vPath.isEmpty() && !vPath.isExpectedType(PDPage.class))
+        if (vPath.isEmpty()){
+            return;
+        }
+        else if (!vPath.isExpectedType(PDPage.class)) 
         {
-            throw new ValidationException("Page validation required at least a PDPage");
+            addValidationError(context, new ValidationError(PreflightConstants.ERROR_PDF_PROCESSING_MISSING,
"Page validation required at least a PDPage"));
+        } 
+        else 
+        {
+            PDPage page = (PDPage) vPath.peek();
+            validateActions(context, page);
+            validateAnnotation(context, page);
+            validateColorSpaces(context, page);
+            validateResources(context, page);
+            validateGraphicObjects(context, page);
+            validateGroupTransparency(context, page);
+            // TODO
+            // add MetaData validation ?
+            validateContent(context, page);
         }
-
-        PDPage page = (PDPage) vPath.peek();
-        validateActions(context, page);
-        validateAnnotation(context, page);
-        validateColorSpaces(context, page);
-        validateResources(context, page);
-        validateGraphicObjects(context, page);
-        validateGroupTransparency(context, page);
-        // TODO
-        // add MetaData validation ?
-
-        validateContent(context, page);
     }
 
     /**
@@ -142,7 +147,7 @@ public class SinglePageValidationProcess
                 {
                     thumbBase = ((COSObject) thumbBase).getObject();
                 }
-                PDXObject thumbImg = PDXObjectImage.createXObject(thumbBase);
+                PDXObject thumbImg = PDXObjectImage.createThumbnailXObject(thumbBase);
                 ContextHelper.validateElement(context, thumbImg, GRAPHIC_PROCESS);
             }
             catch (IOException e)

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/TilingPatternValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/TilingPatternValidationProcess.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/TilingPatternValidationProcess.java
(original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/TilingPatternValidationProcess.java
Sun Nov 17 14:31:02 2013
@@ -30,6 +30,7 @@ import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.graphics.pattern.PDTilingPatternResources;
+import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.PreflightPath;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
@@ -44,38 +45,43 @@ public class TilingPatternValidationProc
     public void validate(PreflightContext context) throws ValidationException
     {
         PreflightPath vPath = context.getValidationPath();
-        if (vPath.isEmpty() && !vPath.isExpectedType(PDPage.class))
+        if (vPath.isEmpty()) {
+            return;
+        }
+        else if (!vPath.isExpectedType(PDTilingPatternResources.class))
         {
-            throw new ValidationException("Tiling pattern validation required at least a
PDPage");
+            context.addValidationError(new ValidationError(PreflightConstants.ERROR_GRAPHIC_MISSING_OBJECT,
"Tiling pattern validation required at least a PDPage"));
         }
+        else
+        {
+            PDTilingPatternResources tilingPattern = (PDTilingPatternResources) vPath.peek();
+            PDPage page = vPath.getClosestPathElement(PDPage.class);
 
-        PDTilingPatternResources tilingPattern = (PDTilingPatternResources) vPath.peek();
-        PDPage page = vPath.getClosestPathElement(PDPage.class);
-
-        checkMandatoryFields(context, page, tilingPattern);
-        parseResources(context, page, tilingPattern);
-        parsePatternContent(context, page, tilingPattern);
+            checkMandatoryFields(context, page, tilingPattern);
+            parseResources(context, page, tilingPattern);
+            parsePatternContent(context, page, tilingPattern);
+        }
     }
 
     protected void parseResources(PreflightContext context, PDPage page, PDTilingPatternResources
pattern)
             throws ValidationException
-    {
+            {
         PDResources resources = pattern.getResources();
         if (resources != null)
         {
             ContextHelper.validateElement(context, resources, RESOURCES_PROCESS);
         }
-    }
+            }
 
     /**
      * Validate the Pattern content like Color and Show Text Operators using an instance
of ContentStreamWrapper.
      */
     protected void parsePatternContent(PreflightContext context, PDPage page, PDTilingPatternResources
pattern)
             throws ValidationException
-    {
+            {
         ContentStreamWrapper csWrapper = new ContentStreamWrapper(context, page);
         csWrapper.validPatternContentStream((COSStream) pattern.getCOSObject());
-    }
+            }
 
     /**
      * This method checks if required fields are present.

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/utils/ContextHelper.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/utils/ContextHelper.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/utils/ContextHelper.java
(original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/utils/ContextHelper.java
Sun Nov 17 14:31:02 2013
@@ -21,11 +21,13 @@
 
 package org.apache.pdfbox.preflight.utils;
 
+import static org.apache.pdfbox.preflight.PreflightConstants.*;
 import org.apache.pdfbox.preflight.PreflightConfiguration;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.PreflightPath;
 import org.apache.pdfbox.preflight.exception.ValidationException;
 import org.apache.pdfbox.preflight.process.ValidationProcess;
+import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 
 public class ContextHelper
 {
@@ -39,14 +41,16 @@ public class ContextHelper
      * @param processName
      * @throws ValidationException
      */
-    public static void validateElement(PreflightContext context, Object element, String processName)
-            throws ValidationException
+    public static void validateElement(PreflightContext context, Object element, String processName)
throws ValidationException
     {
         if (element == null)
         {
-            throw new ValidationException("Unable to process an element if it is null.");
+            context.addValidationError(new ValidationError(ERROR_PDF_PROCESSING_MISSING,
"Unable to process an element if it is null."));
+        } 
+        else 
+        {
+            callValidation(context, element, processName);
         }
-        callValidation(context, element, processName);
     }
 
     /**
@@ -60,20 +64,16 @@ public class ContextHelper
      * @throws ValidationException
      */
     private static void callValidation(PreflightContext context, Object element, String processName)
-            throws ValidationException
+    throws ValidationException
     {
-        if (context == null)
-        {
-            throw new ValidationException("Unable to process an element without context.");
-        }
-
         PreflightPath validationPath = context.getValidationPath();
         boolean needPop = validationPath.pushObject(element);
         PreflightConfiguration config = context.getConfig();
         ValidationProcess process = config.getInstanceOfProcess(processName);
         process.validate(context);
-        if (needPop)
+        if (needPop) {
             validationPath.pop();
+        }
     }
 
     /**

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjFormValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjFormValidator.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjFormValidator.java
(original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjFormValidator.java
Sun Nov 17 14:31:02 2013
@@ -36,6 +36,7 @@ import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectForm;
+import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.PreflightPath;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
@@ -116,9 +117,8 @@ public class XObjFormValidator extends A
      * A Form XObject may contain a Group object (Key =" Group"). If a Group object is present,
this method checks if
      * the S entry is present and if its value is different from "Transparency".
      * 
-     * @throws ValidationException
      */
-    protected void checkGroup() throws ValidationException
+    protected void checkGroup()
     {
         COSBase baseGroup = this.xobject.getItem(XOBJECT_DICTIONARY_KEY_GROUP);
         COSDictionary groupDictionary = COSUtils.getAsDictionary(baseGroup, cosDocument);
@@ -126,15 +126,16 @@ public class XObjFormValidator extends A
         {
             if (!XOBJECT_DICTIONARY_KEY_GROUP.equals(groupDictionary.getNameAsString(COSName.TYPE)))
             {
-                throw new ValidationException("The Group dictionary hasn't Group as Type
value");
-            }
-
-            String sVal = groupDictionary.getNameAsString(COSName.S);
-            if (sVal == null || XOBJECT_DICTIONARY_VALUE_S_TRANSPARENCY.equals(sVal))
+                context.addValidationError(new ValidationError(PreflightConstants.ERROR_GRAPHIC_MISSING_FIELD,
"The Group dictionary hasn't Group as Type value"));
+            } 
+            else 
             {
-                context.addValidationError(new ValidationError(ERROR_GRAPHIC_TRANSPARENCY_GROUP,
-                        "Group has a transparency S entry or the S entry is null."));
-                return;
+                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."));
+                    return;
+                }
             }
         }
     }



Mime
View raw message