pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1860965 [2/2] - in /pdfbox/trunk/preflight/src: main/java/org/apache/pdfbox/preflight/ main/java/org/apache/pdfbox/preflight/action/ main/java/org/apache/pdfbox/preflight/annotation/ main/java/org/apache/pdfbox/preflight/content/ main/java...
Date Mon, 10 Jun 2019 17:00:12 GMT
Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/TrailerValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/TrailerValidationProcess.java?rev=1860965&r1=1860964&r2=1860965&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/TrailerValidationProcess.java
(original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/TrailerValidationProcess.java
Mon Jun 10 17:00:11 2019
@@ -29,12 +29,6 @@ import static org.apache.pdfbox.prefligh
 import static org.apache.pdfbox.preflight.PreflightConstants.DICTIONARY_KEY_LINEARIZED_O;
 import static org.apache.pdfbox.preflight.PreflightConstants.DICTIONARY_KEY_LINEARIZED_T;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_TRAILER;
-import static org.apache.pdfbox.preflight.PreflightConstants.TRAILER_DICTIONARY_KEY_ENCRYPT;
-import static org.apache.pdfbox.preflight.PreflightConstants.TRAILER_DICTIONARY_KEY_ID;
-import static org.apache.pdfbox.preflight.PreflightConstants.TRAILER_DICTIONARY_KEY_INFO;
-import static org.apache.pdfbox.preflight.PreflightConstants.TRAILER_DICTIONARY_KEY_PREV;
-import static org.apache.pdfbox.preflight.PreflightConstants.TRAILER_DICTIONARY_KEY_ROOT;
-import static org.apache.pdfbox.preflight.PreflightConstants.TRAILER_DICTIONARY_KEY_SIZE;
 
 import java.util.List;
 
@@ -42,6 +36,7 @@ import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSDocument;
+import org.apache.pdfbox.cos.COSInteger;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSObject;
 import org.apache.pdfbox.cos.COSString;
@@ -51,7 +46,6 @@ import org.apache.pdfbox.preflight.Prefl
 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.COSUtils;
 
 public class TrailerValidationProcess extends AbstractProcess
 {
@@ -106,14 +100,12 @@ public class TrailerValidationProcess ex
         else
         {
             COSDictionary last = ctx.getXrefTrailerResolver().getLastTrailer();
-            COSDocument cosDoc = new COSDocument();
             checkMainTrailer(ctx, first);
-            if (!compareIds(first, last, cosDoc))
+            if (!compareIds(first, last))
             {
                 addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_ID_CONSISTENCY,
                         "ID is different in the first and the last trailer"));
             }
-            COSUtils.closeDocumentQuietly(cosDoc);
         }
     }
 
@@ -160,7 +152,7 @@ public class TrailerValidationProcess ex
             }
 
             checkMainTrailer(ctx, firstTrailer);
-            if (!compareIds(firstTrailer, lastTrailer, cosDocument))
+            if (!compareIds(firstTrailer, lastTrailer))
             {
                 addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_ID_CONSISTENCY,
                         "ID is different in the first and the last trailer"));
@@ -174,34 +166,27 @@ public class TrailerValidationProcess ex
      * 
      * @param first the first dictionary for comparison.
      * @param last the last dictionary for comparison.
-     * @param cosDocument the document.
      * @return true if the IDs of the first and last dictionary are the same.
      */
-    protected boolean compareIds(COSDictionary first, COSDictionary last, COSDocument cosDocument)
+    protected boolean compareIds(COSDictionary first, COSDictionary last)
     {
-        COSBase idFirst = first.getItem(COSName.getPDFName(TRAILER_DICTIONARY_KEY_ID));
-        COSBase idLast = last.getItem(COSName.getPDFName(TRAILER_DICTIONARY_KEY_ID));
+        COSBase idFirst = first.getDictionaryObject(COSName.ID);
+        COSBase idLast = last.getDictionaryObject(COSName.ID);
         // According to the revised PDF/A specification the IDs have to be identical
         // if both are present, otherwise everything is fine
         if (idFirst != null && idLast != null)
         {
-    
-            // ---- cast two COSBase to COSArray.
-            COSArray af = COSUtils.getAsArray(idFirst, cosDocument);
-            COSArray al = COSUtils.getAsArray(idLast, cosDocument);
-    
             // ---- if one COSArray is null, the PDF/A isn't valid
-            if ((af == null) || (al == null))
+            if (!(idFirst instanceof COSArray) || !(idLast instanceof COSArray))
             {
                 return false;
             }
-    
             // ---- compare both arrays
             boolean isEqual = true;
-            for (Object of : af.toList())
+            for (COSBase of : ((COSArray) idFirst).toList())
             {
                 boolean oneIsEquals = false;
-                for (Object ol : al.toList())
+                for (COSBase ol : ((COSArray) idLast).toList())
                 {
                     // ---- according to PDF Reference 1-4, ID is an array containing two
                     // strings
@@ -214,7 +199,7 @@ public class TrailerValidationProcess ex
                         break;
                     }
                 }
-                isEqual = isEqual && oneIsEquals;
+                isEqual &= oneIsEquals;
                 if (!isEqual)
                 {
                     break;
@@ -243,43 +228,34 @@ public class TrailerValidationProcess ex
         boolean info = false;
         boolean encrypt = false;
 
-        for (Object key : trailer.keySet())
+        for (COSName cosName : trailer.keySet())
         {
-            if (!(key instanceof COSName))
-            {
-                addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_DICTIONARY_KEY_INVALID,
-                        "Invalid key in The trailer dictionary"));
-                return;
-            }
-
-            String cosName = ((COSName) key).getName();
-            if (cosName.equals(TRAILER_DICTIONARY_KEY_ENCRYPT))
+            if (cosName.equals(COSName.ENCRYPT))
             {
                 encrypt = true;
             }
-            if (cosName.equals(TRAILER_DICTIONARY_KEY_SIZE))
+            if (cosName.equals(COSName.SIZE))
             {
                 size = true;
             }
-            if (cosName.equals(TRAILER_DICTIONARY_KEY_PREV))
+            if (cosName.equals(COSName.PREV))
             {
                 prev = true;
             }
-            if (cosName.equals(TRAILER_DICTIONARY_KEY_ROOT))
+            if (cosName.equals(COSName.ROOT))
             {
                 root = true;
             }
-            if (cosName.equals(TRAILER_DICTIONARY_KEY_INFO))
+            if (cosName.equals(COSName.INFO))
             {
                 info = true;
             }
-            if (cosName.equals(TRAILER_DICTIONARY_KEY_ID))
+            if (cosName.equals(COSName.ID))
             {
                 id = true;
             }
         }
 
-        COSDocument cosDocument = ctx.getDocument().getDocument();
         // PDF/A Trailer dictionary must contain the ID key
         if (!id)
         {
@@ -288,8 +264,8 @@ public class TrailerValidationProcess ex
         }
         else
         {
-            COSBase trailerId = trailer.getItem(TRAILER_DICTIONARY_KEY_ID);
-            if (!COSUtils.isArray(trailerId, cosDocument))
+            COSBase trailerId = trailer.getDictionaryObject(COSName.ID);
+            if (!(trailerId instanceof COSArray))
             {
                 addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID,
                         "The trailer dictionary contains an id but it isn't an array"));
@@ -309,8 +285,8 @@ public class TrailerValidationProcess ex
         }
         else
         {
-            COSBase trailerSize = trailer.getItem(TRAILER_DICTIONARY_KEY_SIZE);
-            if (!COSUtils.isInteger(trailerSize, cosDocument))
+            COSBase trailerSize = trailer.getDictionaryObject(COSName.SIZE);
+            if (!(trailerSize instanceof COSInteger))
             {
                 addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID,
                         "The trailer dictionary contains a size but it isn't an integer"));
@@ -325,8 +301,8 @@ public class TrailerValidationProcess ex
         }
         else
         {
-            COSBase trailerRoot = trailer.getItem(TRAILER_DICTIONARY_KEY_ROOT);
-            if (!COSUtils.isDictionary(trailerRoot, cosDocument))
+            COSBase trailerRoot = trailer.getDictionaryObject(COSName.ROOT);
+            if (!(trailerRoot instanceof COSDictionary))
             {
                 addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID,
                         "The trailer dictionary contains a root but it isn't a dictionary"));
@@ -335,8 +311,8 @@ public class TrailerValidationProcess ex
         // PDF Trailer dictionary may contain the Prev key
         if (prev)
         {
-            COSBase trailerPrev = trailer.getItem(TRAILER_DICTIONARY_KEY_PREV);
-            if (!COSUtils.isInteger(trailerPrev, cosDocument))
+            COSBase trailerPrev = trailer.getDictionaryObject(COSName.PREV);
+            if (!(trailerPrev instanceof COSInteger))
             {
                 addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID,
                         "The trailer dictionary contains a prev but it isn't an integer"));
@@ -345,8 +321,8 @@ public class TrailerValidationProcess ex
         // PDF Trailer dictionary may contain the Info key
         if (info)
         {
-            COSBase trailerInfo = trailer.getItem(TRAILER_DICTIONARY_KEY_INFO);
-            if (!COSUtils.isDictionary(trailerInfo, cosDocument))
+            COSBase trailerInfo = trailer.getDictionaryObject(COSName.INFO);
+            if (!(trailerInfo instanceof COSDictionary))
             {
                 addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID,
                         "The trailer dictionary contains an info but it isn't a dictionary"));
@@ -365,10 +341,10 @@ public class TrailerValidationProcess ex
     {
         // ---- Get Ref to obj
         COSDocument cDoc = document.getDocument();
-        List<?> lObj = cDoc.getObjects();
-        for (Object object : lObj)
+        List<COSObject> lObj = cDoc.getObjects();
+        for (COSObject object : lObj)
         {
-            COSBase curObj = ((COSObject) object).getObject();
+            COSBase curObj = object.getObject();
             if (curObj instanceof COSDictionary
                     && ((COSDictionary) curObj).keySet().contains(COSName.getPDFName(DICTIONARY_KEY_LINEARIZED)))
             {
@@ -395,16 +371,9 @@ public class TrailerValidationProcess ex
         boolean n = false;
         boolean t = false;
 
-        for (Object key : linearizedDict.keySet())
+        for (COSName key : linearizedDict.keySet())
         {
-            if (!(key instanceof COSName))
-            {
-                addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_DICTIONARY_KEY_INVALID,
-                        "Invalid key in The Linearized dictionary"));
-                return;
-            }
-
-            String cosName = ((COSName) key).getName();
+            String cosName = key.getName();
             if (cosName.equals(DICTIONARY_KEY_LINEARIZED_L))
             {
                 l = true;

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/DestinationValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/DestinationValidationProcess.java?rev=1860965&r1=1860964&r2=1860965&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/DestinationValidationProcess.java
(original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/DestinationValidationProcess.java
Mon Jun 10 17:00:11 2019
@@ -18,9 +18,9 @@ package org.apache.pdfbox.preflight.proc
 import java.io.IOException;
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
-import org.apache.pdfbox.cos.COSDocument;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSObject;
+import org.apache.pdfbox.cos.COSString;
 import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination;
 import org.apache.pdfbox.preflight.PreflightConstants;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_DICT_INVALID;
@@ -29,7 +29,6 @@ import org.apache.pdfbox.preflight.Prefl
 import org.apache.pdfbox.preflight.ValidationResult;
 import org.apache.pdfbox.preflight.exception.ValidationException;
 import org.apache.pdfbox.preflight.process.AbstractProcess;
-import org.apache.pdfbox.preflight.utils.COSUtils;
 
 /**
  *
@@ -57,8 +56,7 @@ public class DestinationValidationProces
         // "A destination may be specified either explicitly by 
         // an array of parameters defining its properties or indirectly by name."
 
-        COSDocument cosDocument = ctx.getDocument().getDocument();
-        if (!(dest instanceof COSName || COSUtils.isString(dest, cosDocument) || COSUtils.isArray(dest,
cosDocument)))
+        if (!(dest instanceof COSName || dest instanceof COSString || dest instanceof COSArray))
         {
             ctx.addValidationError(new ValidationResult.ValidationError(ERROR_SYNTAX_DICT_INVALID,

                     "Destination type entry " + dest.getClass().getSimpleName() + " is invalid"));

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ExtGStateValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ExtGStateValidationProcess.java?rev=1860965&r1=1860964&r2=1860965&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ExtGStateValidationProcess.java
(original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ExtGStateValidationProcess.java
Mon Jun 10 17:00:11 2019
@@ -31,12 +31,6 @@ import static org.apache.pdfbox.prefligh
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_TRANSPARENCY_EXT_GS_BLEND_MODE;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_TRANSPARENCY_EXT_GS_CA;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_TRANSPARENCY_EXT_GS_SOFT_MASK;
-import static org.apache.pdfbox.preflight.PreflightConstants.TRANSPARENCY_DICTIONARY_KEY_BLEND_MODE;
-import static org.apache.pdfbox.preflight.PreflightConstants.TRANSPARENCY_DICTIONARY_KEY_LOWER_CA;
-import static org.apache.pdfbox.preflight.PreflightConstants.TRANSPARENCY_DICTIONARY_KEY_UPPER_CA;
-import static org.apache.pdfbox.preflight.PreflightConstants.TRANSPARENCY_DICTIONARY_VALUE_BM_COMPATIBLE;
-import static org.apache.pdfbox.preflight.PreflightConstants.TRANSPARENCY_DICTIONARY_VALUE_BM_NORMAL;
-import static org.apache.pdfbox.preflight.PreflightConstants.TRANSPARENCY_DICTIONARY_VALUE_SOFT_MASK_NONE;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_COMMON;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_NUMERIC_RANGE;
 import static org.apache.pdfbox.preflight.PreflightConstants.MAX_NEGATIVE_FLOAT;
@@ -45,7 +39,8 @@ import static org.apache.pdfbox.prefligh
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
-import org.apache.pdfbox.cos.COSDocument;
+import org.apache.pdfbox.cos.COSFloat;
+import org.apache.pdfbox.cos.COSInteger;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSNumber;
 import org.apache.pdfbox.cos.COSObject;
@@ -58,7 +53,6 @@ import org.apache.pdfbox.preflight.Prefl
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 import org.apache.pdfbox.preflight.exception.ValidationException;
 import org.apache.pdfbox.preflight.process.AbstractProcess;
-import org.apache.pdfbox.preflight.utils.COSUtils;
 import org.apache.pdfbox.preflight.utils.ContextHelper;
 
 public class ExtGStateValidationProcess extends AbstractProcess
@@ -100,20 +94,16 @@ public class ExtGStateValidationProcess
      * @return the list of ExtGState dictionaries.
      * @throws ValidationException thrown if an Extended Graphic State isn't valid.
      */
-    public List<COSDictionary> extractExtGStateDictionaries(PreflightContext context,
COSDictionary egsEntry)
+    public List<COSDictionary> extractExtGStateDictionaries(PreflightContext context,
+            COSDictionary extGStates)
             throws ValidationException
     {
         List<COSDictionary> listOfExtGState = new ArrayList<>(0);
-        COSDocument cosDocument = context.getDocument().getDocument();
-        COSDictionary extGStates = COSUtils.getAsDictionary(egsEntry, cosDocument);
-
         if (extGStates != null)
         {
-            for (Object object : extGStates.keySet())
+            for (COSName key : extGStates.keySet())
             {
-                COSName key = (COSName) object;
-                COSBase gsBase = extGStates.getItem(key);
-                COSDictionary gsDict = COSUtils.getAsDictionary(gsBase, cosDocument);
+                COSDictionary gsDict = extGStates.getCOSDictionary(key);
                 if (gsDict == null)
                 {
                     throw new ValidationException("The Extended Graphics State dictionary
is invalid");
@@ -227,9 +217,9 @@ public class ExtGStateValidationProcess
      */
     private void checkSoftMask(PreflightContext context, COSDictionary egs)
     {
-        COSBase smVal = egs.getItem(COSName.SMASK);
+        COSBase smVal = egs.getDictionaryObject(COSName.SMASK);
         if (smVal != null && 
-                !(smVal instanceof COSName && TRANSPARENCY_DICTIONARY_VALUE_SOFT_MASK_NONE.equals(((COSName)
smVal).getName())))
+                !(smVal instanceof COSName && COSName.NONE.equals(smVal)))
         {
             // ---- Soft Mask is valid only if it is a COSName equals to None
             context.addValidationError(new ValidationError(ERROR_TRANSPARENCY_EXT_GS_SOFT_MASK,
@@ -245,16 +235,12 @@ public class ExtGStateValidationProcess
      */
     private void checkBlendMode(PreflightContext context, COSDictionary egs)
     {
-        COSBase bmVal = egs.getItem(TRANSPARENCY_DICTIONARY_KEY_BLEND_MODE);
-        if (bmVal != null)
+        COSName bmVal = egs.getCOSName(COSName.BM);
+        // ---- Blend Mode is valid only if it is equals to Normal or Compatible
+        if (bmVal != null && !(COSName.NORMAL.equals(bmVal) || COSName.COMPATIBLE.equals(bmVal)))
         {
-            // ---- Blend Mode is valid only if it is equals to Normal or Compatible
-            if (!(bmVal instanceof COSName && (TRANSPARENCY_DICTIONARY_VALUE_BM_NORMAL.equals(((COSName)
bmVal)
-                    .getName()) || TRANSPARENCY_DICTIONARY_VALUE_BM_COMPATIBLE.equals(((COSName)
bmVal).getName()))))
-            {
-                context.addValidationError(new ValidationError(ERROR_TRANSPARENCY_EXT_GS_BLEND_MODE,
-                        "BlendMode value isn't valid (only Normal and Compatible are authorized)"));
-            }
+            context.addValidationError(new ValidationError(ERROR_TRANSPARENCY_EXT_GS_BLEND_MODE,
+                    "BlendMode value isn't valid (only Normal and Compatible are authorized)"));
         }
     }
 
@@ -267,13 +253,12 @@ public class ExtGStateValidationProcess
      */
     private void checkUpperCA(PreflightContext context, COSDictionary egs)
     {
-        COSBase uCA = egs.getItem(TRANSPARENCY_DICTIONARY_KEY_UPPER_CA);
+        COSBase uCA = egs.getDictionaryObject(COSName.CA);
         if (uCA != null)
         {
             // ---- If CA is present only the value 1.0 is authorized
-            COSDocument cosDocument = context.getDocument().getDocument();
-            Float fca = COSUtils.getAsFloat(uCA, cosDocument);
-            Integer ica = COSUtils.getAsInteger(uCA, cosDocument);
+            Float fca = uCA instanceof COSFloat ? ((COSFloat) uCA).floatValue() : null;
+            Integer ica = uCA instanceof COSInteger ? ((COSInteger) uCA).intValue() : null;
             if (!(fca != null && Float.compare(fca, 1.0f) == 0) && !(ica
!= null && ica == 1))
             {
                 context.addValidationError(new ValidationError(ERROR_TRANSPARENCY_EXT_GS_CA,
@@ -291,13 +276,12 @@ public class ExtGStateValidationProcess
      */
     private void checkLowerCA(PreflightContext context, COSDictionary egs)
     {
-        COSBase lCA = egs.getItem(TRANSPARENCY_DICTIONARY_KEY_LOWER_CA);
+        COSBase lCA = egs.getDictionaryObject(COSName.CA_NS);
         if (lCA != null)
         {
             // ---- If ca is present only the value 1.0 is authorized
-            COSDocument cosDocument = context.getDocument().getDocument();
-            Float fca = COSUtils.getAsFloat(lCA, cosDocument);
-            Integer ica = COSUtils.getAsInteger(lCA, cosDocument);
+            Float fca = lCA instanceof COSFloat ? ((COSFloat) lCA).floatValue() : null;
+            Integer ica = lCA instanceof COSInteger ? ((COSInteger) lCA).intValue() : null;
             if (!(fca != null && Float.compare(fca, 1.0f) == 0) && !(ica
!= null && ica == 1))
             {
                 context.addValidationError(new ValidationError(ERROR_TRANSPARENCY_EXT_GS_CA,

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ResourcesValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ResourcesValidationProcess.java?rev=1860965&r1=1860964&r2=1860965&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ResourcesValidationProcess.java
(original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ResourcesValidationProcess.java
Mon Jun 10 17:00:11 2019
@@ -27,8 +27,8 @@ import java.util.Map;
 import java.util.Map.Entry;
 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.cos.COSObject;
 import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.font.PDFont;
@@ -43,7 +43,6 @@ import org.apache.pdfbox.preflight.Prefl
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 import org.apache.pdfbox.preflight.exception.ValidationException;
 import org.apache.pdfbox.preflight.process.AbstractProcess;
-import org.apache.pdfbox.preflight.utils.COSUtils;
 import org.apache.pdfbox.preflight.utils.ContextHelper;
 
 
@@ -54,7 +53,6 @@ import static org.apache.pdfbox.prefligh
 import static org.apache.pdfbox.preflight.PreflightConfiguration.TILING_PATTERN_PROCESS;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_INVALID_PATTERN_DEFINITION;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_MAIN;
-import static org.apache.pdfbox.preflight.PreflightConstants.TRANSPARENCY_DICTIONARY_KEY_EXTGSTATE;
 
 public class ResourcesValidationProcess extends AbstractProcess
 {
@@ -145,10 +143,8 @@ public class ResourcesValidationProcess
      */
     protected void validateExtGStates(PreflightContext context, PDResources resources) throws
ValidationException
     {
-        COSBase egsEntry = resources.getCOSObject().getItem(TRANSPARENCY_DICTIONARY_KEY_EXTGSTATE);
-        COSDocument cosDocument = context.getDocument().getDocument();
-        COSDictionary extGState = COSUtils.getAsDictionary(egsEntry, cosDocument);
-        if (egsEntry != null)
+        COSDictionary extGState = resources.getCOSObject().getCOSDictionary(COSName.EXT_G_STATE);
+        if (extGState != null)
         {
             ContextHelper.validateElement(context, extGState, EXTGSTATE_PROCESS);
         }
@@ -205,35 +201,40 @@ public class ResourcesValidationProcess
 
     protected void validateXObjects(PreflightContext context, PDResources resources) throws
ValidationException
     {
-        COSDocument cosDocument = context.getDocument().getDocument();
-        COSDictionary mapOfXObj = COSUtils.getAsDictionary(resources.getCOSObject().getItem(COSName.XOBJECT),
-                cosDocument);
+        COSDictionary mapOfXObj = resources.getCOSObject().getCOSDictionary(COSName.XOBJECT);
         if (mapOfXObj != null)
         {
             for (Entry<COSName, COSBase> entry : mapOfXObj.entrySet())
             {
                 COSBase xobj = entry.getValue();
-                if (xobj != null && COSUtils.isStream(xobj, cosDocument))
+                if (xobj != null)
                 {
-                    try
+                    if (xobj instanceof COSObject)
                     {
-                        COSStream stream = COSUtils.getAsStream(xobj, cosDocument);
-                        PDXObject pdXObject = PDXObject.createXObject(stream, resources);
-                        if (pdXObject != null)
+                        xobj = ((COSObject) xobj).getObject();
+                    }
+                    if (xobj instanceof COSStream) 
+                    {
+                        try
                         {
-                            ContextHelper.validateElement(context, pdXObject, GRAPHIC_PROCESS);
+                            COSStream stream = (COSStream) xobj;
+                            PDXObject pdXObject = PDXObject.createXObject(stream, resources);
+                            if (pdXObject != null)
+                            {
+                                ContextHelper.validateElement(context, pdXObject, GRAPHIC_PROCESS);
+                            }
+                            else
+                            {
+                                ContextHelper.validateElement(context, stream, GRAPHIC_PROCESS);
+                            }
                         }
-                        else
+                        catch (IOException e)
                         {
-                            ContextHelper.validateElement(context, stream, GRAPHIC_PROCESS);
+                            context.addValidationError(new ValidationError(ERROR_GRAPHIC_MAIN,
+                                    e.getMessage() + " for entry '"
+                                    + entry.getKey().getName() + "'", e));
                         }
                     }
-                    catch (IOException e)
-                    {
-                        context.addValidationError(new ValidationError(ERROR_GRAPHIC_MAIN,
-                                e.getMessage() + " for entry '"
-                                + entry.getKey().getName() + "'", e));
-                    }
                 }
             }
         }

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ShadingPatternValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ShadingPatternValidationProcess.java?rev=1860965&r1=1860964&r2=1860965&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ShadingPatternValidationProcess.java
(original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ShadingPatternValidationProcess.java
Mon Jun 10 17:00:11 2019
@@ -25,12 +25,12 @@ import java.io.IOException;
 
 import static org.apache.pdfbox.preflight.PreflightConfiguration.EXTGSTATE_PROCESS;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_INVALID_UNKNOWN_COLOR_SPACE;
-import static org.apache.pdfbox.preflight.PreflightConstants.TRANSPARENCY_DICTIONARY_KEY_EXTGSTATE;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
 import org.apache.pdfbox.pdmodel.graphics.shading.PDShading;
@@ -113,8 +113,8 @@ public class ShadingPatternValidationPro
     protected void checkGraphicState(PreflightContext context, PDPage page, PDShading shadingRes)
             throws ValidationException
     {
-        COSDictionary resources = (COSDictionary) shadingRes.getCOSObject().getDictionaryObject(
-                TRANSPARENCY_DICTIONARY_KEY_EXTGSTATE);
+        COSDictionary resources = (COSDictionary) shadingRes.getCOSObject()
+                .getDictionaryObject(COSName.EXT_G_STATE);
         if (resources != null)
         {
             ContextHelper.validateElement(context, resources, EXTGSTATE_PROCESS);

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/SinglePageValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/SinglePageValidationProcess.java?rev=1860965&r1=1860964&r2=1860965&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/SinglePageValidationProcess.java
(original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/SinglePageValidationProcess.java
Mon Jun 10 17:00:11 2019
@@ -28,9 +28,6 @@ import static org.apache.pdfbox.prefligh
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_INVALID;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_TRANSPARENCY_GROUP;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_UNKOWN_ERROR;
-import static org.apache.pdfbox.preflight.PreflightConstants.PAGE_DICTIONARY_VALUE_THUMB;
-import static org.apache.pdfbox.preflight.PreflightConstants.XOBJECT_DICTIONARY_KEY_GROUP;
-import static org.apache.pdfbox.preflight.PreflightConstants.XOBJECT_DICTIONARY_VALUE_S_TRANSPARENCY;
 
 import java.io.IOException;
 import java.util.List;
@@ -60,7 +57,6 @@ import org.apache.pdfbox.preflight.graph
 import org.apache.pdfbox.preflight.graphic.ColorSpaceHelperFactory;
 import org.apache.pdfbox.preflight.graphic.ColorSpaceHelperFactory.ColorSpaceRestriction;
 import org.apache.pdfbox.preflight.process.AbstractProcess;
-import org.apache.pdfbox.preflight.utils.COSUtils;
 import org.apache.pdfbox.preflight.utils.ContextHelper;
 
 public class SinglePageValidationProcess extends AbstractProcess
@@ -148,7 +144,7 @@ public class SinglePageValidationProcess
      */
     protected void validateGraphicObjects(PreflightContext context, PDPage page) throws ValidationException
     {
-        COSBase thumbBase = page.getCOSObject().getItem(PAGE_DICTIONARY_VALUE_THUMB);
+        COSBase thumbBase = page.getCOSObject().getItem(COSName.THUMB);
         if (thumbBase != null)
         {
             try
@@ -235,12 +231,11 @@ public class SinglePageValidationProcess
      */
     protected void validateGroupTransparency(PreflightContext context, PDPage page) throws
ValidationException
     {
-        COSBase baseGroup = page.getCOSObject().getItem(XOBJECT_DICTIONARY_KEY_GROUP);
-        COSDictionary groupDictionary = COSUtils.getAsDictionary(baseGroup, context.getDocument().getDocument());
+        COSDictionary groupDictionary = page.getCOSObject().getCOSDictionary(COSName.GROUP);
         if (groupDictionary != null)
         {
-            String sVal = groupDictionary.getNameAsString(COSName.S);
-            if (XOBJECT_DICTIONARY_VALUE_S_TRANSPARENCY.equals(sVal))
+            COSName sVal = groupDictionary.getCOSName(COSName.S);
+            if (COSName.S.equals(sVal))
             {
                 context.addValidationError(new ValidationError(ERROR_GRAPHIC_TRANSPARENCY_GROUP,
                         "Group has a transparency S entry or the S entry is null"));

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=1860965&r1=1860964&r2=1860965&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
Mon Jun 10 17:00:11 2019
@@ -24,17 +24,13 @@ package org.apache.pdfbox.preflight.xobj
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_TRANSPARENCY_SMASK;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_UNEXPECTED_KEY;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY;
-import static org.apache.pdfbox.preflight.PreflightConstants.TRANSPARENCY_DICTIONARY_VALUE_SOFT_MASK_NONE;
-import static org.apache.pdfbox.preflight.PreflightConstants.XOBJECT_DICTIONARY_VALUE_SUBTYPE_POSTSCRIPT;
 
 import org.apache.pdfbox.cos.COSBase;
-import org.apache.pdfbox.cos.COSDocument;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSStream;
 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.COSUtils;
 
 /**
  * This class processes commons validations of XObjects.
@@ -49,16 +45,11 @@ public abstract class AbstractXObjValida
      * The validation context which contains useful information to process validation.
      */
     protected PreflightContext context = null;
-    /**
-     * The PDF document as COSDocument.
-     */
-    protected COSDocument cosDocument = null;
 
     public AbstractXObjValidator(PreflightContext context, COSStream xobj)
     {
         this.xobject = xobj;
         this.context = context;
-        this.cosDocument = context.getDocument().getDocument();
     }
 
     /**
@@ -70,10 +61,9 @@ public abstract class AbstractXObjValida
      */
     protected void checkSMask()
     {
-        COSBase smask = xobject.getItem(COSName.SMASK);
+        COSBase smask = xobject.getCOSDictionary(COSName.SMASK);
         if (smask != null
-                && !(COSUtils.isString(smask, cosDocument) && TRANSPARENCY_DICTIONARY_VALUE_SOFT_MASK_NONE
-                        .equals(COSUtils.getAsString(smask, cosDocument))))
+                && !(smask instanceof COSName && COSName.NONE.equals(smask)))
         {
             context.addValidationError(new ValidationError(ERROR_GRAPHIC_TRANSPARENCY_SMASK,
                     "Soft Mask must be null or None ["+xobject.toString()+"]"));
@@ -118,18 +108,16 @@ public abstract class AbstractXObjValida
     protected void checkPostscriptXObject()
     {
         // 6.2.7 No PostScript XObjects
-        String subtype = this.xobject.getNameAsString(COSName.SUBTYPE);
-        if (XOBJECT_DICTIONARY_VALUE_SUBTYPE_POSTSCRIPT.equals(subtype))
+        COSName subtype = this.xobject.getCOSName(COSName.SUBTYPE);
+        if (COSName.PS.equals(subtype))
         {
             context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY,
                     "No Postscript XObject allowed in PDF/A"));
-            return;
         }
-        if (this.xobject.getItem(COSName.getPDFName("Subtype2")) != null)
+        else if (this.xobject.getItem(COSName.getPDFName("Subtype2")) != null)
         {
             context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY,
                     "No Postscript XObject allowed in PDF/A (Subtype2)"));
-            return;
         }
     }
 

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=1860965&r1=1860964&r2=1860965&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
Mon Jun 10 17:00:11 2019
@@ -27,10 +27,8 @@ import static org.apache.pdfbox.prefligh
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_TRANSPARENCY_GROUP;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_UNEXPECTED_KEY;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY;
-import static org.apache.pdfbox.preflight.PreflightConstants.XOBJECT_DICTIONARY_KEY_GROUP;
-import static org.apache.pdfbox.preflight.PreflightConstants.XOBJECT_DICTIONARY_VALUE_S_TRANSPARENCY;
 
-import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.PDPage;
@@ -42,7 +40,6 @@ import org.apache.pdfbox.preflight.Prefl
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 import org.apache.pdfbox.preflight.content.PreflightContentStream;
 import org.apache.pdfbox.preflight.exception.ValidationException;
-import org.apache.pdfbox.preflight.utils.COSUtils;
 import org.apache.pdfbox.preflight.utils.ContextHelper;
 
 /**
@@ -93,12 +90,11 @@ public class XObjFormValidator extends A
             return;
         }
 
-        COSBase bbBase = this.xobject.getItem(COSName.BBOX);
+        COSArray bbArray = this.xobject.getCOSArray(COSName.BBOX);
         // ---- BBox is an Array (Rectangle)
-        if (bbBase == null || !COSUtils.isArray(bbBase, cosDocument))
+        if (bbArray == null)
         {
             context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_BBOX));
-            return;
         }
     }
 
@@ -120,23 +116,21 @@ public class XObjFormValidator extends A
      */
     protected void checkGroup()
     {
-        COSBase baseGroup = this.xobject.getItem(XOBJECT_DICTIONARY_KEY_GROUP);
-        COSDictionary groupDictionary = COSUtils.getAsDictionary(baseGroup, cosDocument);
+        COSDictionary groupDictionary = this.xobject.getCOSDictionary(COSName.GROUP);
         if (groupDictionary != null)
         {
-            if (!XOBJECT_DICTIONARY_KEY_GROUP.equals(groupDictionary.getNameAsString(COSName.TYPE)))
+            if (!COSName.GROUP.equals(groupDictionary.getCOSName(COSName.TYPE)))
             {
                 context.addValidationError(new ValidationError(PreflightConstants.ERROR_GRAPHIC_MISSING_FIELD,

                         "The Group dictionary hasn't Group as Type value"));
             } 
             else 
             {
-                String sVal = groupDictionary.getNameAsString(COSName.S);
-                if (sVal == null || XOBJECT_DICTIONARY_VALUE_S_TRANSPARENCY.equals(sVal))
+                COSName sVal = groupDictionary.getCOSName(COSName.S);
+                if (sVal == null || COSName.TRANSPARENCY.equals(sVal))
                 {
                     context.addValidationError(new ValidationError(ERROR_GRAPHIC_TRANSPARENCY_GROUP,

                             "Group has a transparency S entry or the S entry is null ["+xobject.toString()+"]"));
-                    return;
                 }
             }
         }
@@ -148,11 +142,10 @@ public class XObjFormValidator extends A
     protected void checkPS()
     {
         // 6.2.4 and 6.2.5 no PS
-        if (this.xobject.getItem(COSName.getPDFName("PS")) != null)
+        if (this.xobject.getItem(COSName.PS) != null)
         {
             context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_KEY,

                     "Unexpected 'PS' Key"));
-            return;
         }
     }
 
@@ -167,7 +160,6 @@ public class XObjFormValidator extends A
         {
             context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY,
                     "Unexpected 'PS' value for 'Subtype2' Key"));
-            return;
         }
     }
 

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjImageValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjImageValidator.java?rev=1860965&r1=1860964&r2=1860965&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjImageValidator.java
(original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjImageValidator.java
Mon Jun 10 17:00:11 2019
@@ -32,6 +32,7 @@ import org.apache.commons.logging.LogFac
 
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSBoolean;
+import org.apache.pdfbox.cos.COSInteger;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
 import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
@@ -42,7 +43,6 @@ import org.apache.pdfbox.preflight.excep
 import org.apache.pdfbox.preflight.graphic.ColorSpaceHelper;
 import org.apache.pdfbox.preflight.graphic.ColorSpaceHelperFactory;
 import org.apache.pdfbox.preflight.graphic.ColorSpaceHelperFactory.ColorSpaceRestriction;
-import org.apache.pdfbox.preflight.utils.COSUtils;
 import org.apache.pdfbox.preflight.utils.RenderingIntents;
 
 /**
@@ -88,7 +88,8 @@ public class XObjImageValidator extends
      */
     protected void checkInterpolate() throws ValidationException
     {
-        if (this.xobject.getItem("Interpolate") != null && this.xobject.getBoolean("Interpolate",
true))
+        if (this.xobject.getItem(COSName.INTERPOLATE) != null
+                && this.xobject.getBoolean(COSName.INTERPOLATE, true))
         {
             context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY,
                     "Unexpected 'true' value for 'Interpolate' Key"));
@@ -118,7 +119,7 @@ public class XObjImageValidator extends
     protected void checkColorSpaceAndImageMask() throws ValidationException
     {
         COSBase csImg = this.xobject.getItem(COSName.COLORSPACE);
-        COSBase bitsPerComp = this.xobject.getItem("BitsPerComponent");
+        COSBase bitsPerComp = this.xobject.getDictionaryObject(COSName.BITS_PER_COMPONENT);
         COSBase mask = this.xobject.getItem(COSName.MASK);
 
         if (isImageMaskTrue())
@@ -129,8 +130,7 @@ public class XObjImageValidator extends
                         "ImageMask entry is true, ColorSpace and Mask are forbidden."));
             }
 
-            Integer bitsPerCompValue = COSUtils.getAsInteger(bitsPerComp, cosDocument);
-            if (bitsPerCompValue != null && bitsPerCompValue != 1)
+            if (bitsPerComp instanceof COSInteger && ((COSInteger) bitsPerComp).intValue()
!= 1)
             {
                 context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY,
                         "ImageMask entry is true, BitsPerComponent must be absent or 1."));



Mime
View raw message