You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by gb...@apache.org on 2013/03/06 17:46:37 UTC

svn commit: r1453416 [13/16] - in /pdfbox/trunk/preflight: ./ src/main/java/org/apache/pdfbox/preflight/ src/main/java/org/apache/pdfbox/preflight/action/ src/main/java/org/apache/pdfbox/preflight/annotation/ src/main/java/org/apache/pdfbox/preflight/a...

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=1453416&r1=1453415&r2=1453416&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 Wed Mar  6 16:46:35 2013
@@ -54,346 +54,403 @@ import org.apache.pdfbox.preflight.Valid
 import org.apache.pdfbox.preflight.exception.ValidationException;
 import org.apache.pdfbox.preflight.utils.COSUtils;
 
-public class TrailerValidationProcess extends AbstractProcess {
+public class TrailerValidationProcess extends AbstractProcess
+{
 
-	public void validate(PreflightContext ctx) throws ValidationException {
-		PDDocument pdfDoc = ctx.getDocument();
+    public void validate(PreflightContext ctx) throws ValidationException
+    {
+        PDDocument pdfDoc = ctx.getDocument();
+
+        COSDictionary linearizedDict = getLinearizedDictionary(pdfDoc);
+        if (linearizedDict != null)
+        {
+            // it is a linearized PDF, check the linearized dictionary
+            checkLinearizedDictionnary(ctx, linearizedDict);
+
+            // if the pdf is a linearized pdf. the first trailer must be checked
+            // and it must have the same ID than the last trailer.
+            // According to the PDF version, trailers are available by the trailer key word (pdf <= 1.4)
+            // or in the dictionary of the XRef stream ( PDF >= 1.5)
+            String pdfVersion = pdfDoc.getDocument().getHeaderString();
+            if (pdfVersion != null && pdfVersion.matches("%PDF-1\\.[1-4]"))
+            {
+                checkTrailersForLinearizedPDF14(ctx);
+            }
+            else
+            {
+                checkTrailersForLinearizedPDF15(ctx);
+            }
+
+        }
+        else
+        {
+            // If the PDF isn't a linearized one, only the last trailer must be checked
+            checkMainTrailer(ctx, pdfDoc.getDocument().getTrailer());
+        }
+    }
+
+    /**
+     * Extracts and compares first and last trailers for PDF version between 1.1 and 1.4
+     * 
+     * @param ctx
+     * @param result
+     */
+    protected void checkTrailersForLinearizedPDF14(PreflightContext ctx)
+    {
+        COSDictionary first = ctx.getXrefTableResolver().getFirstTrailer();
+        if (first == null)
+        {
+            addValidationError(ctx, new ValidationError(ERROR_SYNTAX_TRAILER, "There are no trailer in the PDF file"));
+        }
+        else
+        {
+            COSDictionary last = ctx.getXrefTableResolver().getLastTrailer();
+            COSDocument cosDoc = null;
+            try
+            {
+                cosDoc = new COSDocument();
+                checkMainTrailer(ctx, first);
+                if (!compareIds(first, last, cosDoc))
+                {
+                    addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_ID_CONSISTENCY,
+                            "ID is different in the first and the last trailer"));
+                }
+
+            }
+            catch (IOException e)
+            {
+                addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER,
+                        "Unable to parse trailers of the linearized PDF"));
+            }
+            finally
+            {
+                COSUtils.closeDocumentQuietly(cosDoc);
+            }
+        }
+    }
+
+    /**
+     * Accesses and compares First and Last trailers for a PDF version higher than 1.4.
+     * 
+     * @param ctx
+     * @param result
+     */
+    protected void checkTrailersForLinearizedPDF15(PreflightContext ctx)
+    {
+        PDDocument pdfDoc = ctx.getDocument();
+        try
+        {
+            COSDocument cosDocument = pdfDoc.getDocument();
+            List<COSObject> xrefs = cosDocument.getObjectsByType(COSName.XREF);
+
+            if (xrefs.isEmpty())
+            {
+                // no XRef CosObject, may by this pdf file used the PDF 1.4 syntaxe
+                checkTrailersForLinearizedPDF14(ctx);
+
+            }
+            else
+            {
+
+                long min = Long.MAX_VALUE;
+                long max = Long.MIN_VALUE;
+                COSDictionary firstTrailer = null;
+                COSDictionary lastTrailer = null;
+
+                // Search First and Last trailers according to offset position.
+                for (COSObject co : xrefs)
+                {
+                    long offset = cosDocument.getXrefTable().get(new COSObjectKey(co));
+                    if (offset < min)
+                    {
+                        min = offset;
+                        firstTrailer = (COSDictionary) co.getObject();
+                    }
+
+                    if (offset > max)
+                    {
+                        max = offset;
+                        lastTrailer = (COSDictionary) co.getObject();
+                    }
+
+                }
+
+                checkMainTrailer(ctx, firstTrailer);
+                if (!compareIds(firstTrailer, lastTrailer, cosDocument))
+                {
+                    addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_ID_CONSISTENCY,
+                            "ID is different in the first and the last trailer"));
+                }
+            }
+        }
+        catch (IOException e)
+        {
+            addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER,
+                    "Unable to check PDF Trailers due to : " + e.getMessage()));
+        }
+    }
+
+    /**
+     * Return true if the ID of the first dictionary is the same as the id of the last dictionary Return false
+     * otherwise.
+     * 
+     * @param first
+     * @param last
+     * @return
+     */
+    protected boolean compareIds(COSDictionary first, COSDictionary last, COSDocument cosDocument)
+    {
+        COSBase idFirst = first.getItem(COSName.getPDFName(TRAILER_DICTIONARY_KEY_ID));
+        COSBase idLast = last.getItem(COSName.getPDFName(TRAILER_DICTIONARY_KEY_ID));
+
+        if (idFirst == null || idLast == null)
+        {
+            return false;
+        }
+
+        // ---- 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))
+        {
+            return false;
+        }
+
+        // ---- compare both arrays
+        boolean isEqual = true;
+        for (Object of : af.toList())
+        {
+            boolean oneIsEquals = false;
+            for (Object ol : al.toList())
+            {
+                // ---- according to PDF Reference 1-4, ID is an array containing two
+                // strings
+                if (!oneIsEquals)
+                    oneIsEquals = ((COSString) ol).getString().equals(((COSString) of).getString());
+                else
+                    break;
+            }
+            isEqual = isEqual && oneIsEquals;
+            if (!isEqual)
+            {
+                break;
+            }
+        }
+        return isEqual;
+    }
+
+    /**
+     * check if all keys are authorized in a trailer dictionary and if the type is valid.
+     * 
+     * @param ctx
+     * @param trailer
+     */
+    protected void checkMainTrailer(PreflightContext ctx, COSDictionary trailer)
+    {
+        boolean id = false;
+        boolean root = false;
+        boolean size = false;
+        boolean prev = false;
+        boolean info = false;
+        boolean encrypt = false;
+
+        for (Object key : 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))
+            {
+                encrypt = true;
+            }
+            if (cosName.equals(TRAILER_DICTIONARY_KEY_SIZE))
+            {
+                size = true;
+            }
+            if (cosName.equals(TRAILER_DICTIONARY_KEY_PREV))
+            {
+                prev = true;
+            }
+            if (cosName.equals(TRAILER_DICTIONARY_KEY_ROOT))
+            {
+                root = true;
+            }
+            if (cosName.equals(TRAILER_DICTIONARY_KEY_INFO))
+            {
+                info = true;
+            }
+            if (cosName.equals(TRAILER_DICTIONARY_KEY_ID))
+            {
+                id = true;
+            }
+        }
+
+        COSDocument cosDocument = ctx.getDocument().getDocument();
+        // PDF/A Trailer dictionary must contain the ID key
+        if (!id)
+        {
+            addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_MISSING_ID,
+                    "The trailer dictionary doesn't contain ID"));
+        }
+        else
+        {
+            COSBase trailerId = trailer.getItem(TRAILER_DICTIONARY_KEY_ID);
+            if (!COSUtils.isArray(trailerId, cosDocument))
+            {
+                addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID,
+                        "The trailer dictionary contains an id but it isn't an array"));
+            }
+        }
+        // PDF/A Trailer dictionary mustn't contain the Encrypt key
+        if (encrypt)
+        {
+            addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_ENCRYPT,
+                    "The trailer dictionary contains Encrypt"));
+        }
+        // PDF Trailer dictionary must contain the Size key
+        if (!size)
+        {
+            addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_MISSING_SIZE,
+                    "The trailer dictionary doesn't contain Size"));
+        }
+        else
+        {
+            COSBase trailerSize = trailer.getItem(TRAILER_DICTIONARY_KEY_SIZE);
+            if (!COSUtils.isInteger(trailerSize, cosDocument))
+            {
+                addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID,
+                        "The trailer dictionary contains a size but it isn't an integer"));
+            }
+        }
+
+        // PDF Trailer dictionary must contain the Root key
+        if (!root)
+        {
+            addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_MISSING_ROOT,
+                    "The trailer dictionary doesn't contain Root"));
+        }
+        else
+        {
+            COSBase trailerRoot = trailer.getItem(TRAILER_DICTIONARY_KEY_ROOT);
+            if (!COSUtils.isDictionary(trailerRoot, cosDocument))
+            {
+                addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID,
+                        "The trailer dictionary contains a root but it isn't a dictionary"));
+            }
+        }
+        // PDF Trailer dictionary may contain the Prev key
+        if (prev)
+        {
+            COSBase trailerPrev = trailer.getItem(TRAILER_DICTIONARY_KEY_PREV);
+            if (!COSUtils.isInteger(trailerPrev, cosDocument))
+            {
+                addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID,
+                        "The trailer dictionary contains a prev but it isn't an integer"));
+            }
+        }
+        // PDF Trailer dictionary may contain the Info key
+        if (info)
+        {
+            COSBase trailerInfo = trailer.getItem(TRAILER_DICTIONARY_KEY_INFO);
+            if (!COSUtils.isDictionary(trailerInfo, cosDocument))
+            {
+                addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID,
+                        "The trailer dictionary contains an info but it isn't a dictionary"));
+            }
+        }
+    }
+
+    /**
+     * According to the PDF Reference, A linearized PDF contain a dictionary as first object (linearized dictionary) and
+     * only this one in the first section.
+     * 
+     * @param document
+     * @return
+     */
+    protected COSDictionary getLinearizedDictionary(PDDocument document)
+    {
+        // ---- Get Ref to obj
+        COSDocument cDoc = document.getDocument();
+        List<?> lObj = cDoc.getObjects();
+        for (Object object : lObj)
+        {
+            COSBase curObj = ((COSObject) object).getObject();
+            if (curObj instanceof COSDictionary
+                    && ((COSDictionary) curObj).keySet().contains(COSName.getPDFName(DICTIONARY_KEY_LINEARIZED)))
+            {
+                return (COSDictionary) curObj;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Check if mandatory keys of linearized dictionary are present.
+     * 
+     * @param ctx
+     * @param linearizedDict
+     */
+    protected void checkLinearizedDictionnary(PreflightContext ctx, COSDictionary linearizedDict)
+    {
+        // ---- check if all keys are authorized in a linearized dictionary
+        // ---- Linearized dictionary must contain the lhoent keys
+        boolean l = false;
+        boolean h = false;
+        boolean o = false;
+        boolean e = false;
+        boolean n = false;
+        boolean t = false;
+
+        for (Object 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();
+            if (cosName.equals(DICTIONARY_KEY_LINEARIZED_L))
+            {
+                l = true;
+            }
+            if (cosName.equals(DICTIONARY_KEY_LINEARIZED_H))
+            {
+                h = true;
+            }
+            if (cosName.equals(DICTIONARY_KEY_LINEARIZED_O))
+            {
+                o = true;
+            }
+            if (cosName.equals(DICTIONARY_KEY_LINEARIZED_E))
+            {
+                e = true;
+            }
+            if (cosName.equals(DICTIONARY_KEY_LINEARIZED_N))
+            {
+                n = true;
+            }
+            if (cosName.equals(DICTIONARY_KEY_LINEARIZED_T))
+            {
+                t = true;
+            }
+        }
+
+        if (!(l && h && o && e && t && n))
+        {
+            addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_DICT_INVALID,
+                    "Invalid key in The Linearized dictionary"));
+        }
 
-		COSDictionary linearizedDict = getLinearizedDictionary(pdfDoc);
-		if (linearizedDict != null) {
-			// it is a linearized PDF, check the linearized dictionary
-			checkLinearizedDictionnary(ctx, linearizedDict);
-
-			// if the pdf is a linearized pdf. the first trailer must be checked
-			// and it must have the same ID than the last trailer.
-			// According to the PDF version, trailers are available by the trailer key word (pdf <= 1.4)
-			// or in the dictionary of the XRef stream ( PDF >= 1.5)
-			String pdfVersion = pdfDoc.getDocument().getHeaderString();
-			if ( pdfVersion != null && pdfVersion.matches("%PDF-1\\.[1-4]")) {
-				checkTrailersForLinearizedPDF14(ctx);
-			} else {
-				checkTrailersForLinearizedPDF15(ctx);
-			}
-
-		} else {
-			// If the PDF isn't a linearized one, only the last trailer must be checked
-			checkMainTrailer(ctx, pdfDoc.getDocument().getTrailer());
-		}
-	}
-
-
-	/**
-	 * Extracts and compares first and last trailers for PDF version between 1.1 and 1.4
-	 * @param ctx
-	 * @param result
-	 */
-	protected void checkTrailersForLinearizedPDF14(PreflightContext ctx) {
-		COSDictionary first = ctx.getXrefTableResolver().getFirstTrailer();
-		if (first == null) {
-			addValidationError(ctx, new ValidationError(ERROR_SYNTAX_TRAILER, "There are no trailer in the PDF file"));
-		} else {	
-			COSDictionary last = ctx.getXrefTableResolver().getLastTrailer();
-			COSDocument cosDoc = null;
-			try {
-				cosDoc = new COSDocument();
-				checkMainTrailer(ctx, first);
-				if (!compareIds(first, last, cosDoc)) {
-					addValidationError(ctx, new ValidationError(
-							PreflightConstants.ERROR_SYNTAX_TRAILER_ID_CONSISTENCY,
-							"ID is different in the first and the last trailer"));
-				}
-
-			} catch (IOException e) {
-				addValidationError(ctx, new ValidationError(
-						PreflightConstants.ERROR_SYNTAX_TRAILER,
-						"Unable to parse trailers of the linearized PDF"));
-			} finally {
-				COSUtils.closeDocumentQuietly(cosDoc);
-			}
-		}
-	}
-
-	/**
-	 * Accesses and compares First and Last trailers for a PDF version higher than 1.4.
-	 * 
-	 * @param ctx
-	 * @param result
-	 */
-	protected void checkTrailersForLinearizedPDF15(PreflightContext ctx) {
-		PDDocument pdfDoc = ctx.getDocument();
-		try {
-			COSDocument cosDocument = pdfDoc.getDocument();
-			List<COSObject> xrefs = cosDocument.getObjectsByType(COSName.XREF);
-
-			if (xrefs.isEmpty()) {
-				// no XRef CosObject, may by this pdf file used the PDF 1.4 syntaxe
-				checkTrailersForLinearizedPDF14(ctx);
-
-			} else {
-
-				long min = Long.MAX_VALUE;
-				long max = Long.MIN_VALUE;
-				COSDictionary firstTrailer = null;
-				COSDictionary lastTrailer = null;
-
-				// Search First and Last trailers according to offset position.
-				for(COSObject co : xrefs) {
-					long offset = cosDocument.getXrefTable().get(new COSObjectKey(co));
-					if (offset < min) {
-						min = offset;
-						firstTrailer = (COSDictionary)co.getObject();
-					}
-
-					if (offset > max) {
-						max = offset;
-						lastTrailer = (COSDictionary)co.getObject();
-					}
-
-				}
-
-				checkMainTrailer(ctx, firstTrailer);
-				if (!compareIds(firstTrailer, lastTrailer, cosDocument)) {
-					addValidationError(ctx, new ValidationError(
-							PreflightConstants.ERROR_SYNTAX_TRAILER_ID_CONSISTENCY,
-							"ID is different in the first and the last trailer"));
-				}
-			}
-		} catch (IOException e) {
-			addValidationError(ctx, new ValidationError(
-					PreflightConstants.ERROR_SYNTAX_TRAILER,
-					"Unable to check PDF Trailers due to : " + e.getMessage()));
-		}
-	}
-
-	/**
-	 * Return true if the ID of the first dictionary is the same as the id of the
-	 * last dictionary Return false otherwise.
-	 * 
-	 * @param first
-	 * @param last
-	 * @return
-	 */
-	protected boolean compareIds(COSDictionary first, COSDictionary last, COSDocument cosDocument) {
-		COSBase idFirst = first.getItem(COSName.getPDFName(TRAILER_DICTIONARY_KEY_ID));
-		COSBase idLast = last.getItem(COSName.getPDFName(TRAILER_DICTIONARY_KEY_ID));
-
-
-		if (idFirst == null || idLast == null) {
-			return false;
-		}
-
-		// ---- 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)) {
-			return false;
-		}
-
-		// ---- compare both arrays
-		boolean isEqual = true;
-		for (Object of : af.toList()) {
-			boolean oneIsEquals = false;
-			for (Object ol : al.toList()) {
-				// ---- according to PDF Reference 1-4, ID is an array containing two
-				// strings
-				if (!oneIsEquals)
-					oneIsEquals = ((COSString) ol).getString().equals(((COSString) of).getString());
-				else
-					break;
-			}
-			isEqual = isEqual && oneIsEquals;
-			if (!isEqual) {
-				break;
-			}
-		}
-		return isEqual;
-	}
-
-	/**
-	 * check if all keys are authorized in a trailer dictionary and if the type is valid.
-	 * @param ctx
-	 * @param trailer
-	 */
-	protected void checkMainTrailer(PreflightContext ctx, COSDictionary trailer) {
-		boolean id = false;
-		boolean root = false;
-		boolean size = false;
-		boolean prev = false;
-		boolean info = false;
-		boolean encrypt = false;
-
-		for (Object key : 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)) {
-				encrypt = true;
-			}
-			if (cosName.equals(TRAILER_DICTIONARY_KEY_SIZE)) {
-				size = true;
-			}
-			if (cosName.equals(TRAILER_DICTIONARY_KEY_PREV)) {
-				prev = true;
-			}
-			if (cosName.equals(TRAILER_DICTIONARY_KEY_ROOT)) {
-				root = true;
-			}
-			if (cosName.equals(TRAILER_DICTIONARY_KEY_INFO)) {
-				info = true;
-			}
-			if (cosName.equals(TRAILER_DICTIONARY_KEY_ID)) {
-				id = true;
-			}
-		}
-
-		COSDocument cosDocument = ctx.getDocument().getDocument();
-		// PDF/A Trailer dictionary must contain the ID key
-		if (!id) {
-			addValidationError(ctx, new ValidationError(
-					PreflightConstants.ERROR_SYNTAX_TRAILER_MISSING_ID,
-					"The trailer dictionary doesn't contain ID"));
-		} else {
-			COSBase trailerId = trailer.getItem(TRAILER_DICTIONARY_KEY_ID);
-			if (!COSUtils.isArray(trailerId, cosDocument)) {
-				addValidationError(ctx, new ValidationError(
-						PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID,
-						"The trailer dictionary contains an id but it isn't an array"));
-			}
-		}
-		// PDF/A Trailer dictionary mustn't contain the Encrypt key
-		if (encrypt) {
-			addValidationError(ctx, new ValidationError(
-					PreflightConstants.ERROR_SYNTAX_TRAILER_ENCRYPT,
-					"The trailer dictionary contains Encrypt"));
-		}
-		// PDF Trailer dictionary must contain the Size key
-		if (!size) {
-			addValidationError(ctx, new ValidationError(
-					PreflightConstants.ERROR_SYNTAX_TRAILER_MISSING_SIZE,
-					"The trailer dictionary doesn't contain Size"));
-		} else {
-			COSBase trailerSize = trailer.getItem(TRAILER_DICTIONARY_KEY_SIZE);
-			if (!COSUtils.isInteger(trailerSize, cosDocument)) {
-				addValidationError(ctx, new ValidationError(
-						PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID,
-						"The trailer dictionary contains a size but it isn't an integer"));
-			}
-		}
-
-		// PDF Trailer dictionary must contain the Root key
-		if (!root) {
-			addValidationError(ctx, new ValidationError(
-					PreflightConstants.ERROR_SYNTAX_TRAILER_MISSING_ROOT,
-					"The trailer dictionary doesn't contain Root"));
-		} else {
-			COSBase trailerRoot = trailer.getItem(TRAILER_DICTIONARY_KEY_ROOT);
-			if (!COSUtils.isDictionary(trailerRoot, cosDocument)) {
-				addValidationError(ctx, new ValidationError(
-						PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID,
-						"The trailer dictionary contains a root but it isn't a dictionary"));
-			}
-		}
-		// PDF Trailer dictionary may contain the Prev key
-		if (prev) {
-			COSBase trailerPrev = trailer.getItem(TRAILER_DICTIONARY_KEY_PREV);
-			if (!COSUtils.isInteger(trailerPrev, cosDocument)) {
-				addValidationError(ctx, new ValidationError(
-						PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID,
-						"The trailer dictionary contains a prev but it isn't an integer"));
-			}
-		}
-		// PDF Trailer dictionary may contain the Info key
-		if (info) {
-			COSBase trailerInfo = trailer.getItem(TRAILER_DICTIONARY_KEY_INFO);
-			if (!COSUtils.isDictionary(trailerInfo, cosDocument)) {
-				addValidationError(ctx, new ValidationError(
-						PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID,
-						"The trailer dictionary contains an info but it isn't a dictionary"));
-			}
-		}
-	}
-
-	/**
-	 * According to the PDF Reference, A linearized PDF contain a dictionary as
-	 * first object (linearized dictionary) and only this one in the first
-	 * section.
-	 * 
-	 * @param document
-	 * @return
-	 */
-	protected COSDictionary getLinearizedDictionary(PDDocument document) {
-		// ---- Get Ref to obj
-		COSDocument cDoc = document.getDocument();
-		List<?> lObj = cDoc.getObjects();
-		for (Object object : lObj) {
-			COSBase curObj = ((COSObject) object).getObject();
-			if (curObj instanceof COSDictionary
-					&& ((COSDictionary) curObj).keySet().contains(
-							COSName.getPDFName(DICTIONARY_KEY_LINEARIZED))) {
-				return (COSDictionary) curObj;
-			}
-		}
-		return null;
-	}
-
-	/**
-	 * Check if mandatory keys of linearized dictionary are present. 
-	 * @param ctx
-	 * @param linearizedDict
-	 */
-	protected void checkLinearizedDictionnary(PreflightContext ctx, COSDictionary linearizedDict) {
-		// ---- check if all keys are authorized in a linearized dictionary
-		// ---- Linearized dictionary must contain the lhoent keys
-		boolean l = false;
-		boolean h = false;
-		boolean o = false;
-		boolean e = false;
-		boolean n = false;
-		boolean t = false;
-
-		for (Object 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();
-			if (cosName.equals(DICTIONARY_KEY_LINEARIZED_L)) {
-				l = true;
-			}
-			if (cosName.equals(DICTIONARY_KEY_LINEARIZED_H)) {
-				h = true;
-			}
-			if (cosName.equals(DICTIONARY_KEY_LINEARIZED_O)) {
-				o = true;
-			}
-			if (cosName.equals(DICTIONARY_KEY_LINEARIZED_E)) {
-				e = true;
-			}
-			if (cosName.equals(DICTIONARY_KEY_LINEARIZED_N)) {
-				n = true;
-			}
-			if (cosName.equals(DICTIONARY_KEY_LINEARIZED_T)) {
-				t = true;
-			}
-		}
-
-		if (!(l && h && o && e && t && n)) {
-			addValidationError(ctx, new ValidationError(
-					PreflightConstants.ERROR_SYNTAX_DICT_INVALID,
-					"Invalid key in The Linearized dictionary"));
-		}
-
-		return;
-	}
+        return;
+    }
 
 }

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/ValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/ValidationProcess.java?rev=1453416&r1=1453415&r2=1453416&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/ValidationProcess.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/ValidationProcess.java Wed Mar  6 16:46:35 2013
@@ -24,11 +24,11 @@ package org.apache.pdfbox.preflight.proc
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.exception.ValidationException;
 
-public interface ValidationProcess {
+public interface ValidationProcess
+{
 
-	// TODO JavaDoc
-	void validate(PreflightContext ctx) 
-	throws ValidationException;
+    // TODO JavaDoc
+    void validate(PreflightContext ctx) throws ValidationException;
 
-	// TODO ? void validateAndFix(DocumentHandler documentHandler) throws ValidationException;
+    // TODO ? void validateAndFix(DocumentHandler documentHandler) throws ValidationException;
 }

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/XRefValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/XRefValidationProcess.java?rev=1453416&r1=1453415&r2=1453416&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/XRefValidationProcess.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/XRefValidationProcess.java Wed Mar  6 16:46:35 2013
@@ -29,14 +29,16 @@ import org.apache.pdfbox.preflight.Prefl
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 import org.apache.pdfbox.preflight.exception.ValidationException;
 
-public class XRefValidationProcess extends AbstractProcess {
-	
+public class XRefValidationProcess extends AbstractProcess
+{
 
-	public void validate(PreflightContext ctx) throws ValidationException {
-		COSDocument document = ctx.getDocument().getDocument();
-		if ( document.getObjects().size() > PreflightConstants.MAX_INDIRECT_OBJ ) {
-			addValidationError(ctx, new ValidationError(ERROR_SYNTAX_INDIRECT_OBJ_RANGE, "Too many indirect objects"));
-		}
-	}
+    public void validate(PreflightContext ctx) throws ValidationException
+    {
+        COSDocument document = ctx.getDocument().getDocument();
+        if (document.getObjects().size() > PreflightConstants.MAX_INDIRECT_OBJ)
+        {
+            addValidationError(ctx, new ValidationError(ERROR_SYNTAX_INDIRECT_OBJ_RANGE, "Too many indirect objects"));
+        }
+    }
 
 }

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ActionsValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ActionsValidationProcess.java?rev=1453416&r1=1453415&r2=1453416&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ActionsValidationProcess.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ActionsValidationProcess.java Wed Mar  6 16:46:35 2013
@@ -33,25 +33,28 @@ import org.apache.pdfbox.preflight.actio
 import org.apache.pdfbox.preflight.exception.ValidationException;
 import org.apache.pdfbox.preflight.process.AbstractProcess;
 
+public class ActionsValidationProcess extends AbstractProcess
+{
 
-public class ActionsValidationProcess extends AbstractProcess {
+    public void validate(PreflightContext context) throws ValidationException
+    {
+        PreflightPath vPath = context.getValidationPath();
+        if (vPath.isEmpty() || !vPath.isExpectedType(COSDictionary.class))
+        {
+            throw new ValidationException("Action validation process needs at least one COSDictionary object");
+        }
 
-	public void validate(PreflightContext context) throws ValidationException {
-		PreflightPath vPath = context.getValidationPath();
-		if (vPath.isEmpty() || !vPath.isExpectedType(COSDictionary.class)) {
-		 throw new ValidationException("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) {
-	      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/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/AnnotationValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/AnnotationValidationProcess.java?rev=1453416&r1=1453415&r2=1453416&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/AnnotationValidationProcess.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/AnnotationValidationProcess.java Wed Mar  6 16:46:35 2013
@@ -30,22 +30,26 @@ import org.apache.pdfbox.preflight.annot
 import org.apache.pdfbox.preflight.exception.ValidationException;
 import org.apache.pdfbox.preflight.process.AbstractProcess;
 
-public class AnnotationValidationProcess extends AbstractProcess {
+public class AnnotationValidationProcess extends AbstractProcess
+{
 
-	public void validate(PreflightContext context) throws ValidationException {
-		PreflightPath vPath = context.getValidationPath();
-		if (vPath.isEmpty() || !vPath.isExpectedType(COSDictionary.class)) {
-			throw new ValidationException("Annotation validation process needs at least one COSDictionary object");
-		}
+    public void validate(PreflightContext context) throws ValidationException
+    {
+        PreflightPath vPath = context.getValidationPath();
+        if (vPath.isEmpty() || !vPath.isExpectedType(COSDictionary.class))
+        {
+            throw new ValidationException("Annotation validation process needs at least one COSDictionary object");
+        }
 
-		COSDictionary annotDict = (COSDictionary)vPath.peek();
+        COSDictionary annotDict = (COSDictionary) vPath.peek();
 
-		PreflightConfiguration config = context.getConfig();
-		AnnotationValidatorFactory factory = config.getAnnotFact();
-		AnnotationValidator annotValidator = factory.getAnnotationValidator(context, annotDict);
-		if (annotValidator != null) {
-			annotValidator.validate();
-		}
-	}
+        PreflightConfiguration config = context.getConfig();
+        AnnotationValidatorFactory factory = config.getAnnotFact();
+        AnnotationValidator annotValidator = factory.getAnnotationValidator(context, annotDict);
+        if (annotValidator != null)
+        {
+            annotValidator.validate();
+        }
+    }
 
 }

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=1453416&r1=1453415&r2=1453416&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 Wed Mar  6 16:46:35 2013
@@ -48,182 +48,211 @@ import org.apache.pdfbox.preflight.excep
 import org.apache.pdfbox.preflight.process.AbstractProcess;
 import org.apache.pdfbox.preflight.utils.COSUtils;
 
-public class ExtGStateValidationProcess extends AbstractProcess {
+public class ExtGStateValidationProcess extends AbstractProcess
+{
 
-
-	public void validate(PreflightContext context)	throws ValidationException {
-		PreflightPath vPath = context.getValidationPath();
-		if (vPath.isEmpty() || !vPath.isExpectedType(COSDictionary.class)) {
-			throw new ValidationException("ExtGState validation required at least a Resource dictionary");
-		}
-
-		COSDictionary extGStatesDict = (COSDictionary)vPath.peek();
-		List<COSDictionary> listOfExtGState = extractExtGStateDictionaries(context, extGStatesDict);
-		validateTransparencyRules(context, listOfExtGState);
-	}
-
-	/**
-	 * Create  a list Of ExtGState dictionaries using the given Resource dictionary and the COSDocument.
-	 * 
-	 * @param context
-	 *          the context which contains the Resource dictionary
-	 * @param resources
-	 *          a resource COSDictionary
-	 * @throws ValidationException
-	 *           thrown if a the Extended Graphic State isn't valid
-	 */
-	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);
-
-		if (extGStates != null) {
-			for (Object object : extGStates.keySet()) {
-				COSName key = (COSName) object;
-				if (key.getName().matches(TRANPARENCY_DICTIONARY_KEY_EXTGSTATE_ENTRY_REGEX)) {
-					COSBase gsBase = extGStates.getItem(key);
-					COSDictionary gsDict = COSUtils.getAsDictionary(gsBase, cosDocument);
-					if (gsDict == null) {
-						throw new ValidationException("The Extended Graphics State dictionary is invalid");
-					}
-					listOfExtGState.add(gsDict);
-				}
-			}
-		} 
-		return listOfExtGState;
-	}
-
-	/**
-	 * Validate all ExtGState dictionaries of this container
-	 * 
-	 */
-	protected void validateTransparencyRules(PreflightContext context, List<COSDictionary> listOfExtGState) {
-		for (COSDictionary egs : listOfExtGState) {
-			checkSoftMask(context, egs);
-			checkCA(context, egs);
-			checkBlendMode(context, egs);
-			checkTRKey(context, egs);
-			checkTR2Key(context, egs);
-		}
-	}
-
-	/**
-	 * This method checks the SMask value of the ExtGState dictionary. The Soft
-	 * Mask is optional but must be "None" if it is present.
-	 * 
-	 * @param egs
-	 *          the Graphic state to check
-	 */
-	private void checkSoftMask(PreflightContext context, COSDictionary egs) {
-		COSBase smVal = egs.getItem(COSName.SMASK);
-		if (smVal != null) {
-			// ---- Soft Mask is valid only if it is a COSName equals to None
-			if (!(smVal instanceof COSName && TRANSPARENCY_DICTIONARY_VALUE_SOFT_MASK_NONE.equals(((COSName) smVal).getName()))) {
-				context.addValidationError(new ValidationError(ERROR_TRANSPARENCY_EXT_GS_SOFT_MASK, "SoftMask must be null or None"));
-			}
-		}
-	}
-
-	/**
-	 * This method checks the BM value of the ExtGState dictionary. The Blend Mode
-	 * is optional but must be "Normal" or "Compatible" if it is present.
-	 * 
-	 * @param egs
-	 *          the graphic state to check
-	 */
-	private void checkBlendMode(PreflightContext context, COSDictionary egs) {
-		COSBase bmVal = egs.getItem(TRANSPARENCY_DICTIONARY_KEY_BLEND_MODE);
-		if (bmVal != null) {
-			// ---- 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)"));
-			}
-		}
-	}
-
-	/**
-	 * This method checks the "CA" and "ca" values of the ExtGState dictionary.
-	 * They are optional but must be 1.0 if they are present.
-	 * 
-	 * @param egs
-	 *          the graphic state to check
-	 */
-	private void checkCA(PreflightContext context, COSDictionary egs) {
-		COSBase uCA = egs.getItem(TRANSPARENCY_DICTIONARY_KEY_UPPER_CA);
-		COSBase lCA = egs.getItem(TRANSPARENCY_DICTIONARY_KEY_LOWER_CA);
-		COSDocument cosDocument = context.getDocument().getDocument();
-		
-		if (uCA != null) {
-			// ---- If CA is present only the value 1.0 is authorized
-			Float fca = COSUtils.getAsFloat(uCA, cosDocument);
-			Integer ica = COSUtils.getAsInteger(uCA, cosDocument);
-			if (!(fca != null && fca == 1.0f) && !(ica != null && ica == 1)) {
-				context.addValidationError(new ValidationError(ERROR_TRANSPARENCY_EXT_GS_CA,"CA entry in a ExtGState is invalid"));
-			}
-		}
-
-		if (lCA != null) {
-			// ---- If ca is present only the value 1.0 is authorized
-			Float fca = COSUtils.getAsFloat(lCA, cosDocument);
-			Integer ica = COSUtils.getAsInteger(lCA, cosDocument);
-			if (!(fca != null && fca == 1.0f) && !(ica != null && ica == 1)) {
-				context.addValidationError(new ValidationError(ERROR_TRANSPARENCY_EXT_GS_CA,"ca entry in a ExtGState  is invalid."));
-			}
-		}
-	}
-
-	/**
-	 * Check the TR entry. A valid ExtGState hasn't TR entry.
-	 * 
-	 * @param egs
-	 *          the graphic state to check
-	 */
-	protected void checkTRKey(PreflightContext context, COSDictionary egs) {
-		if (egs.getItem("TR") != null) {
-			context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_KEY,
-					"No TR key expected in Extended graphics state"));
-		}
-	}
-
-	/**
-	 * Check the TR2 entry. A valid ExtGState hasn't TR2 entry or a TR2 entry
-	 * equals to "default".
-	 * 
-	 * @param egs
-	 *          the graphic state to check
-	 */
-	protected void checkTR2Key(PreflightContext context, COSDictionary egs) {
-		if (egs.getItem("TR2") != null) {
-			String s = egs.getNameAsString("TR2");
-			if (!"default".equals(s)) {
-				context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY,
-						"TR2 key only expect 'default' value, not '" + s + "'"));
-			}
-		}
-	}
-//
-//	/**
-//	 * Check the RI entry of the Graphic State. If the rendering intent entry is
-//	 * present, the value must be one of the four values defined in the PDF
-//	 * reference. (@see net.awl.edoc.pdfa.validation.utils.RenderingIntents)
-//	 * 
-//	 * @param egs
-//	 *          the graphic state to check
-//	 * @param error
-//	 *          the list of error to update if the validation fails.
-//	 * @return true if RI entry is valid, false otherwise.
-//	 */
-//	protected boolean checkRIKey(COSDictionary egs, List<ValidationError> error) {
-//		String rendenringIntent = egs.getNameAsString(COSName.getPDFName("RI"));
-//		if (rendenringIntent != null && !"".equals(rendenringIntent)
-//				&& !RenderingIntents.contains(rendenringIntent)) {
-//			error.add(new ValidationError(
-//					PreflightConstants.ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY,
-//					"Invalid rendering intent value in Extended graphics state"));
-//			return false;
-//		}
-//		return true;
-//	}
+    public void validate(PreflightContext context) throws ValidationException
+    {
+        PreflightPath vPath = context.getValidationPath();
+        if (vPath.isEmpty() || !vPath.isExpectedType(COSDictionary.class))
+        {
+            throw new ValidationException("ExtGState validation required at least a Resource dictionary");
+        }
+
+        COSDictionary extGStatesDict = (COSDictionary) vPath.peek();
+        List<COSDictionary> listOfExtGState = extractExtGStateDictionaries(context, extGStatesDict);
+        validateTransparencyRules(context, listOfExtGState);
+    }
+
+    /**
+     * Create a list Of ExtGState dictionaries using the given Resource dictionary and the COSDocument.
+     * 
+     * @param context
+     *            the context which contains the Resource dictionary
+     * @param resources
+     *            a resource COSDictionary
+     * @throws ValidationException
+     *             thrown if a the Extended Graphic State isn't valid
+     */
+    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);
+
+        if (extGStates != null)
+        {
+            for (Object object : extGStates.keySet())
+            {
+                COSName key = (COSName) object;
+                if (key.getName().matches(TRANPARENCY_DICTIONARY_KEY_EXTGSTATE_ENTRY_REGEX))
+                {
+                    COSBase gsBase = extGStates.getItem(key);
+                    COSDictionary gsDict = COSUtils.getAsDictionary(gsBase, cosDocument);
+                    if (gsDict == null)
+                    {
+                        throw new ValidationException("The Extended Graphics State dictionary is invalid");
+                    }
+                    listOfExtGState.add(gsDict);
+                }
+            }
+        }
+        return listOfExtGState;
+    }
+
+    /**
+     * Validate all ExtGState dictionaries of this container
+     * 
+     */
+    protected void validateTransparencyRules(PreflightContext context, List<COSDictionary> listOfExtGState)
+    {
+        for (COSDictionary egs : listOfExtGState)
+        {
+            checkSoftMask(context, egs);
+            checkCA(context, egs);
+            checkBlendMode(context, egs);
+            checkTRKey(context, egs);
+            checkTR2Key(context, egs);
+        }
+    }
+
+    /**
+     * This method checks the SMask value of the ExtGState dictionary. The Soft Mask is optional but must be "None" if
+     * it is present.
+     * 
+     * @param egs
+     *            the Graphic state to check
+     */
+    private void checkSoftMask(PreflightContext context, COSDictionary egs)
+    {
+        COSBase smVal = egs.getItem(COSName.SMASK);
+        if (smVal != null)
+        {
+            // ---- Soft Mask is valid only if it is a COSName equals to None
+            if (!(smVal instanceof COSName && TRANSPARENCY_DICTIONARY_VALUE_SOFT_MASK_NONE.equals(((COSName) smVal)
+                    .getName())))
+            {
+                context.addValidationError(new ValidationError(ERROR_TRANSPARENCY_EXT_GS_SOFT_MASK,
+                        "SoftMask must be null or None"));
+            }
+        }
+    }
+
+    /**
+     * This method checks the BM value of the ExtGState dictionary. The Blend Mode is optional but must be "Normal" or
+     * "Compatible" if it is present.
+     * 
+     * @param egs
+     *            the graphic state to check
+     */
+    private void checkBlendMode(PreflightContext context, COSDictionary egs)
+    {
+        COSBase bmVal = egs.getItem(TRANSPARENCY_DICTIONARY_KEY_BLEND_MODE);
+        if (bmVal != null)
+        {
+            // ---- 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)"));
+            }
+        }
+    }
+
+    /**
+     * This method checks the "CA" and "ca" values of the ExtGState dictionary. They are optional but must be 1.0 if
+     * they are present.
+     * 
+     * @param egs
+     *            the graphic state to check
+     */
+    private void checkCA(PreflightContext context, COSDictionary egs)
+    {
+        COSBase uCA = egs.getItem(TRANSPARENCY_DICTIONARY_KEY_UPPER_CA);
+        COSBase lCA = egs.getItem(TRANSPARENCY_DICTIONARY_KEY_LOWER_CA);
+        COSDocument cosDocument = context.getDocument().getDocument();
+
+        if (uCA != null)
+        {
+            // ---- If CA is present only the value 1.0 is authorized
+            Float fca = COSUtils.getAsFloat(uCA, cosDocument);
+            Integer ica = COSUtils.getAsInteger(uCA, cosDocument);
+            if (!(fca != null && fca == 1.0f) && !(ica != null && ica == 1))
+            {
+                context.addValidationError(new ValidationError(ERROR_TRANSPARENCY_EXT_GS_CA,
+                        "CA entry in a ExtGState is invalid"));
+            }
+        }
+
+        if (lCA != null)
+        {
+            // ---- If ca is present only the value 1.0 is authorized
+            Float fca = COSUtils.getAsFloat(lCA, cosDocument);
+            Integer ica = COSUtils.getAsInteger(lCA, cosDocument);
+            if (!(fca != null && fca == 1.0f) && !(ica != null && ica == 1))
+            {
+                context.addValidationError(new ValidationError(ERROR_TRANSPARENCY_EXT_GS_CA,
+                        "ca entry in a ExtGState  is invalid."));
+            }
+        }
+    }
+
+    /**
+     * Check the TR entry. A valid ExtGState hasn't TR entry.
+     * 
+     * @param egs
+     *            the graphic state to check
+     */
+    protected void checkTRKey(PreflightContext context, COSDictionary egs)
+    {
+        if (egs.getItem("TR") != null)
+        {
+            context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_KEY,
+                    "No TR key expected in Extended graphics state"));
+        }
+    }
+
+    /**
+     * Check the TR2 entry. A valid ExtGState hasn't TR2 entry or a TR2 entry equals to "default".
+     * 
+     * @param egs
+     *            the graphic state to check
+     */
+    protected void checkTR2Key(PreflightContext context, COSDictionary egs)
+    {
+        if (egs.getItem("TR2") != null)
+        {
+            String s = egs.getNameAsString("TR2");
+            if (!"default".equals(s))
+            {
+                context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY,
+                        "TR2 key only expect 'default' value, not '" + s + "'"));
+            }
+        }
+    }
+    //
+    // /**
+    // * Check the RI entry of the Graphic State. If the rendering intent entry is
+    // * present, the value must be one of the four values defined in the PDF
+    // * reference. (@see net.awl.edoc.pdfa.validation.utils.RenderingIntents)
+    // *
+    // * @param egs
+    // * the graphic state to check
+    // * @param error
+    // * the list of error to update if the validation fails.
+    // * @return true if RI entry is valid, false otherwise.
+    // */
+    // protected boolean checkRIKey(COSDictionary egs, List<ValidationError> error) {
+    // String rendenringIntent = egs.getNameAsString(COSName.getPDFName("RI"));
+    // if (rendenringIntent != null && !"".equals(rendenringIntent)
+    // && !RenderingIntents.contains(rendenringIntent)) {
+    // error.add(new ValidationError(
+    // PreflightConstants.ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY,
+    // "Invalid rendering intent value in Extended graphics state"));
+    // return false;
+    // }
+    // return true;
+    // }
 }

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/FontValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/FontValidationProcess.java?rev=1453416&r1=1453415&r2=1453416&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/FontValidationProcess.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/FontValidationProcess.java Wed Mar  6 16:46:35 2013
@@ -43,49 +43,63 @@ import org.apache.pdfbox.preflight.font.
 import org.apache.pdfbox.preflight.font.container.FontContainer;
 import org.apache.pdfbox.preflight.process.AbstractProcess;
 
-public class FontValidationProcess extends AbstractProcess {
+public class FontValidationProcess extends AbstractProcess
+{
 
-	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");
-		}
+    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");
+        }
 
-		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();
-		}
-	}
+        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();
+        }
+    }
 
-	/**
-	 * Create the right "Validator" object for the given font type
-	 * @param font
-	 * @return
-	 */
-	protected FontValidator<? extends FontContainer> getFontValidator(PreflightContext context, PDFont font)
-			throws ValidationException {
-		String subtype = font.getSubType();
-		if (FONT_DICTIONARY_VALUE_TRUETYPE.equals(subtype)) {
-			return new TrueTypeFontValidator(context, font);
-		} else if (FONT_DICTIONARY_VALUE_MMTYPE.equals(subtype)
-				|| FONT_DICTIONARY_VALUE_TYPE1.equals(subtype)) {
-			return new Type1FontValidator(context, font);
-		} else if (FONT_DICTIONARY_VALUE_TYPE3.equals(subtype)) {
-			return new Type3FontValidator(context, font);
-		} else if (FONT_DICTIONARY_VALUE_COMPOSITE.equals(subtype)) {
-			return new Type0FontValidator(context, font);
-		} else if (FONT_DICTIONARY_VALUE_TYPE2.equals(subtype)
-				|| FONT_DICTIONARY_VALUE_TYPE1C.equals(subtype)
-				|| FONT_DICTIONARY_VALUE_TYPE0C.equals(subtype)
-				|| FONT_DICTIONARY_VALUE_TYPE0.equals(subtype)) {
-			// ---- Font managed by a Composite font.
-			// this dictionary will be checked by a CompositeFontValidator
-			return null;
-		} else {
-			throw new ValidationException("Unknown font type : " + subtype);
-		}
-	}
+    /**
+     * Create the right "Validator" object for the given font type
+     * 
+     * @param font
+     * @return
+     */
+    protected FontValidator<? extends FontContainer> getFontValidator(PreflightContext context, PDFont font)
+            throws ValidationException
+    {
+        String subtype = font.getSubType();
+        if (FONT_DICTIONARY_VALUE_TRUETYPE.equals(subtype))
+        {
+            return new TrueTypeFontValidator(context, font);
+        }
+        else if (FONT_DICTIONARY_VALUE_MMTYPE.equals(subtype) || FONT_DICTIONARY_VALUE_TYPE1.equals(subtype))
+        {
+            return new Type1FontValidator(context, font);
+        }
+        else if (FONT_DICTIONARY_VALUE_TYPE3.equals(subtype))
+        {
+            return new Type3FontValidator(context, font);
+        }
+        else if (FONT_DICTIONARY_VALUE_COMPOSITE.equals(subtype))
+        {
+            return new Type0FontValidator(context, font);
+        }
+        else if (FONT_DICTIONARY_VALUE_TYPE2.equals(subtype) || FONT_DICTIONARY_VALUE_TYPE1C.equals(subtype)
+                || FONT_DICTIONARY_VALUE_TYPE0C.equals(subtype) || FONT_DICTIONARY_VALUE_TYPE0.equals(subtype))
+        {
+            // ---- Font managed by a Composite font.
+            // this dictionary will be checked by a CompositeFontValidator
+            return null;
+        }
+        else
+        {
+            throw new ValidationException("Unknown font type : " + subtype);
+        }
+    }
 
 }

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/GraphicObjectPageValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/GraphicObjectPageValidationProcess.java?rev=1453416&r1=1453415&r2=1453416&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/GraphicObjectPageValidationProcess.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/GraphicObjectPageValidationProcess.java Wed Mar  6 16:46:35 2013
@@ -21,7 +21,6 @@
 
 package org.apache.pdfbox.preflight.process.reflect;
 
-
 import static org.apache.pdfbox.preflight.PreflightConstants.XOBJECT_DICTIONARY_VALUE_SUBTYPE_POSTSCRIPT;
 
 import org.apache.pdfbox.cos.COSName;
@@ -37,29 +36,40 @@ import org.apache.pdfbox.preflight.xobje
 import org.apache.pdfbox.preflight.xobject.XObjPostscriptValidator;
 import org.apache.pdfbox.preflight.xobject.XObjectValidator;
 
-public class GraphicObjectPageValidationProcess extends AbstractProcess {
-
-
-	public void validate(PreflightContext context) throws ValidationException {
-		PreflightPath vPath = context.getValidationPath();
+public class GraphicObjectPageValidationProcess extends AbstractProcess
+{
 
-		XObjectValidator validator = null;
-		if (!vPath.isEmpty() && vPath.isExpectedType(PDXObjectImage.class)) {
-			validator = new XObjImageValidator(context, (PDXObjectImage)vPath.peek());
-		} else if (!vPath.isEmpty() && vPath.isExpectedType(PDXObjectForm.class)) {
-			validator = new XObjFormValidator(context, (PDXObjectForm)vPath.peek());
-		} else if (!vPath.isEmpty() && vPath.isExpectedType(COSStream.class)) {
-			COSStream stream = (COSStream)vPath.peek();
-			String subType = stream.getNameAsString(COSName.SUBTYPE);
-			if (XOBJECT_DICTIONARY_VALUE_SUBTYPE_POSTSCRIPT.equals(subType)) {
-				validator = new XObjPostscriptValidator(context, stream);
-			} else {
-				throw new ValidationException("Invalid XObject subtype");
-			}
-		} else {
-			throw new ValidationException("Graphic validation process needs at least one PDFont object");
-		}
+    public void validate(PreflightContext context) throws ValidationException
+    {
+        PreflightPath vPath = context.getValidationPath();
+
+        XObjectValidator validator = null;
+        if (!vPath.isEmpty() && vPath.isExpectedType(PDXObjectImage.class))
+        {
+            validator = new XObjImageValidator(context, (PDXObjectImage) vPath.peek());
+        }
+        else if (!vPath.isEmpty() && vPath.isExpectedType(PDXObjectForm.class))
+        {
+            validator = new XObjFormValidator(context, (PDXObjectForm) vPath.peek());
+        }
+        else if (!vPath.isEmpty() && vPath.isExpectedType(COSStream.class))
+        {
+            COSStream stream = (COSStream) vPath.peek();
+            String subType = stream.getNameAsString(COSName.SUBTYPE);
+            if (XOBJECT_DICTIONARY_VALUE_SUBTYPE_POSTSCRIPT.equals(subType))
+            {
+                validator = new XObjPostscriptValidator(context, stream);
+            }
+            else
+            {
+                throw new ValidationException("Invalid XObject subtype");
+            }
+        }
+        else
+        {
+            throw new ValidationException("Graphic validation process needs at least one PDFont object");
+        }
 
-		validator.validate();
-	}
+        validator.validate();
+    }
 }

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=1453416&r1=1453415&r2=1453416&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 Wed Mar  6 16:46:35 2013
@@ -52,113 +52,148 @@ import org.apache.pdfbox.preflight.proce
 import org.apache.pdfbox.preflight.utils.COSUtils;
 import org.apache.pdfbox.preflight.utils.ContextHelper;
 
-public class ResourcesValidationProcess extends AbstractProcess {
+public class ResourcesValidationProcess extends AbstractProcess
+{
 
-	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");
-		}
-
-		PDResources resources = (PDResources)vPath.peek();
-
-		validateFonts(ctx, resources);
-		validateExtGStates(ctx, resources);
-		validateShadingPattern(ctx, resources);
-		validateTilingPattern(ctx, resources);
-		validateXObjects(ctx, resources);	
-	}
-
-	/**
-	 * Check that fonts present in the Resources dictionary match with PDF/A-1 rules
-	 * @param context
-	 * @param resources
-	 * @throws ValidationException
-	 */
-	protected void validateFonts(PreflightContext context, PDResources resources) throws ValidationException {
-		Map<String, PDFont> mapOfFonts = resources.getFonts();
-		if (mapOfFonts != null) {
-			for (Entry<String, PDFont> entry : mapOfFonts.entrySet()) {
-				ContextHelper.validateElement(context, entry.getValue(), FONT_PROCESS);
-			}
-		}
-	}
-
-	/**
-	 * 
-	 * @param context
-	 * @param resources
-	 * @throws ValidationException
-	 */
-	protected void validateExtGStates(PreflightContext context, PDResources resources) throws ValidationException {
-		COSBase egsEntry = resources.getCOSDictionary().getItem(TRANPARENCY_DICTIONARY_KEY_EXTGSTATE);
-		COSDocument cosDocument = context.getDocument().getDocument();
-		COSDictionary extGState = COSUtils.getAsDictionary(egsEntry, cosDocument);
-		if (egsEntry != null) {
-			ContextHelper.validateElement(context, extGState, EXTGSTATE_PROCESS);
-		}
-	}
-
-	/**
-	 * This method check the Shading entry of the resource dictionary if exists.
-	 * @param context
-	 * @param resources
-	 * @throws ValidationException
-	 */
-	protected void validateShadingPattern(PreflightContext context, PDResources resources) throws ValidationException {
-		try {
-			Map<String , PDShadingResources> shadingResources = resources.getShadings();
-			if (shadingResources != null) {
-				for (Entry<String, PDShadingResources> entry : shadingResources.entrySet()) {
-					ContextHelper.validateElement(context, entry.getValue(), SHADDING_PATTERN_PROCESS);
-				}
-			}
-		} catch (IOException e) {
-			context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_PATTERN_DEFINITION, e.getMessage()));
-		}
-	}
-
-	/**
-	 * This method check the Shading entry of the resource dictionary if exists.
-	 * @param context
-	 * @param resources
-	 * @throws ValidationException
-	 */
-	protected void validateTilingPattern(PreflightContext context, PDResources resources) throws ValidationException {
-		try {
-			Map<String , PDPatternResources> patternResources = resources.getPatterns();
-			if (patternResources != null) {
-				for (Entry<String, PDPatternResources> entry : patternResources.entrySet()) {
-					if (entry.getValue() instanceof PDTilingPatternResources) {
-						ContextHelper.validateElement(context, entry.getValue(), TILING_PATTERN_PROCESS);
-					}
-				}
-			}
-		} catch (IOException e) {
-			context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_PATTERN_DEFINITION, e.getMessage()));
-		}
-	}
-
-	protected void validateXObjects(PreflightContext context, PDResources resources) throws ValidationException {
-		COSDocument cosDocument = context.getDocument().getDocument();
-		COSDictionary mapOfXObj = COSUtils.getAsDictionary(resources.getCOSDictionary().getItem(COSName.XOBJECT), cosDocument);
-		if (mapOfXObj != null) {
-			for ( Entry<COSName, COSBase> entry: mapOfXObj.entrySet()) {
-				COSBase xobj = entry.getValue();
-				if (xobj != null && COSUtils.isStream(xobj, cosDocument)) {
-					try {
-						COSStream stream = COSUtils.getAsStream(xobj, cosDocument);
-						PDXObject pdXObject= PDXObject.createXObject(stream);
-						if (pdXObject != null) {
-							ContextHelper.validateElement(context, pdXObject, GRAPHIC_PROCESS);
-						} else {
-							ContextHelper.validateElement(context, stream, GRAPHIC_PROCESS);
-						}
-					} catch (IOException e) {
-						throw new ValidationException(e.getMessage(), e);
-					}
-				}
-			}
-		}
-	}
+    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");
+        }
+
+        PDResources resources = (PDResources) vPath.peek();
+
+        validateFonts(ctx, resources);
+        validateExtGStates(ctx, resources);
+        validateShadingPattern(ctx, resources);
+        validateTilingPattern(ctx, resources);
+        validateXObjects(ctx, resources);
+    }
+
+    /**
+     * Check that fonts present in the Resources dictionary match with PDF/A-1 rules
+     * 
+     * @param context
+     * @param resources
+     * @throws ValidationException
+     */
+    protected void validateFonts(PreflightContext context, PDResources resources) throws ValidationException
+    {
+        Map<String, PDFont> mapOfFonts = resources.getFonts();
+        if (mapOfFonts != null)
+        {
+            for (Entry<String, PDFont> entry : mapOfFonts.entrySet())
+            {
+                ContextHelper.validateElement(context, entry.getValue(), FONT_PROCESS);
+            }
+        }
+    }
+
+    /**
+     * 
+     * @param context
+     * @param resources
+     * @throws ValidationException
+     */
+    protected void validateExtGStates(PreflightContext context, PDResources resources) throws ValidationException
+    {
+        COSBase egsEntry = resources.getCOSDictionary().getItem(TRANPARENCY_DICTIONARY_KEY_EXTGSTATE);
+        COSDocument cosDocument = context.getDocument().getDocument();
+        COSDictionary extGState = COSUtils.getAsDictionary(egsEntry, cosDocument);
+        if (egsEntry != null)
+        {
+            ContextHelper.validateElement(context, extGState, EXTGSTATE_PROCESS);
+        }
+    }
+
+    /**
+     * This method check the Shading entry of the resource dictionary if exists.
+     * 
+     * @param context
+     * @param resources
+     * @throws ValidationException
+     */
+    protected void validateShadingPattern(PreflightContext context, PDResources resources) throws ValidationException
+    {
+        try
+        {
+            Map<String, PDShadingResources> shadingResources = resources.getShadings();
+            if (shadingResources != null)
+            {
+                for (Entry<String, PDShadingResources> entry : shadingResources.entrySet())
+                {
+                    ContextHelper.validateElement(context, entry.getValue(), SHADDING_PATTERN_PROCESS);
+                }
+            }
+        }
+        catch (IOException e)
+        {
+            context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_PATTERN_DEFINITION, e.getMessage()));
+        }
+    }
+
+    /**
+     * This method check the Shading entry of the resource dictionary if exists.
+     * 
+     * @param context
+     * @param resources
+     * @throws ValidationException
+     */
+    protected void validateTilingPattern(PreflightContext context, PDResources resources) throws ValidationException
+    {
+        try
+        {
+            Map<String, PDPatternResources> patternResources = resources.getPatterns();
+            if (patternResources != null)
+            {
+                for (Entry<String, PDPatternResources> entry : patternResources.entrySet())
+                {
+                    if (entry.getValue() instanceof PDTilingPatternResources)
+                    {
+                        ContextHelper.validateElement(context, entry.getValue(), TILING_PATTERN_PROCESS);
+                    }
+                }
+            }
+        }
+        catch (IOException e)
+        {
+            context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_PATTERN_DEFINITION, e.getMessage()));
+        }
+    }
+
+    protected void validateXObjects(PreflightContext context, PDResources resources) throws ValidationException
+    {
+        COSDocument cosDocument = context.getDocument().getDocument();
+        COSDictionary mapOfXObj = COSUtils.getAsDictionary(resources.getCOSDictionary().getItem(COSName.XOBJECT),
+                cosDocument);
+        if (mapOfXObj != null)
+        {
+            for (Entry<COSName, COSBase> entry : mapOfXObj.entrySet())
+            {
+                COSBase xobj = entry.getValue();
+                if (xobj != null && COSUtils.isStream(xobj, cosDocument))
+                {
+                    try
+                    {
+                        COSStream stream = COSUtils.getAsStream(xobj, cosDocument);
+                        PDXObject pdXObject = PDXObject.createXObject(stream);
+                        if (pdXObject != null)
+                        {
+                            ContextHelper.validateElement(context, pdXObject, GRAPHIC_PROCESS);
+                        }
+                        else
+                        {
+                            ContextHelper.validateElement(context, stream, GRAPHIC_PROCESS);
+                        }
+                    }
+                    catch (IOException e)
+                    {
+                        throw new ValidationException(e.getMessage(), e);
+                    }
+                }
+            }
+        }
+    }
 }

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ShaddingPatternValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ShaddingPatternValidationProcess.java?rev=1453416&r1=1453415&r2=1453416&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ShaddingPatternValidationProcess.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ShaddingPatternValidationProcess.java Wed Mar  6 16:46:35 2013
@@ -43,58 +43,66 @@ import org.apache.pdfbox.preflight.graph
 import org.apache.pdfbox.preflight.process.AbstractProcess;
 import org.apache.pdfbox.preflight.utils.ContextHelper;
 
-public class ShaddingPatternValidationProcess extends AbstractProcess {
+public class ShaddingPatternValidationProcess extends AbstractProcess
+{
 
-
-	public void validate(PreflightContext context)  throws ValidationException {
-		PreflightPath vPath = context.getValidationPath();
-		if (vPath.isEmpty() && !vPath.isExpectedType(PDResources.class)) {
-			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);
-	}
-
-
-
-	/**
-	 * Checks if the ColorSapce entry is consistent which rules of the PDF Reference 
-	 * and the ISO 190005-1:2005 Specification.
-	 * 
-	 * This method is called by the validate method.
-	 * 
-	 * @param shadingRes
-	 *          the Shading pattern  to check
-	 * @return true if the Shading pattern is valid, false otherwise.
-	 * @throws ValidationException
-	 */
-	protected void checkColorSpace(PreflightContext context, PDPage page, PDShadingResources shadingRes) throws ValidationException {
-		try {
-			PDColorSpace pColorSpace = shadingRes.getColorSpace();
-			PreflightConfiguration config = context.getConfig();
-			ColorSpaceHelperFactory csFact = config.getColorSpaceHelperFact();
-			ColorSpaceHelper csh = csFact.getColorSpaceHelper(context, pColorSpace, ColorSpaceRestriction.NO_PATTERN);
-			csh.validate();
-		} catch (IOException e) {
-			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 ExtGState, this method uses the
-	 * net.awl.edoc.pdfa.validation.graphics.ExtGStateContainer object.
-	 * 
-	 * @return true is the ExtGState is missing or valid, false otherwise.
-	 * @throws ValidationException
-	 */
-	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);
-		}
-	}
+    public void validate(PreflightContext context) throws ValidationException
+    {
+        PreflightPath vPath = context.getValidationPath();
+        if (vPath.isEmpty() && !vPath.isExpectedType(PDResources.class))
+        {
+            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);
+    }
+
+    /**
+     * Checks if the ColorSapce entry is consistent which rules of the PDF Reference and the ISO 190005-1:2005
+     * Specification.
+     * 
+     * This method is called by the validate method.
+     * 
+     * @param shadingRes
+     *            the Shading pattern to check
+     * @return true if the Shading pattern is valid, false otherwise.
+     * @throws ValidationException
+     */
+    protected void checkColorSpace(PreflightContext context, PDPage page, PDShadingResources shadingRes)
+            throws ValidationException
+    {
+        try
+        {
+            PDColorSpace pColorSpace = shadingRes.getColorSpace();
+            PreflightConfiguration config = context.getConfig();
+            ColorSpaceHelperFactory csFact = config.getColorSpaceHelperFact();
+            ColorSpaceHelper csh = csFact.getColorSpaceHelper(context, pColorSpace, ColorSpaceRestriction.NO_PATTERN);
+            csh.validate();
+        }
+        catch (IOException e)
+        {
+            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
+     * ExtGState, this method uses the net.awl.edoc.pdfa.validation.graphics.ExtGStateContainer object.
+     * 
+     * @return true is the ExtGState is missing or valid, false otherwise.
+     * @throws ValidationException
+     */
+    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/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=1453416&r1=1453415&r2=1453416&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 Wed Mar  6 16:46:35 2013
@@ -21,7 +21,6 @@
 
 package org.apache.pdfbox.preflight.process.reflect;
 
-
 import static org.apache.pdfbox.preflight.PreflightConfiguration.ACTIONS_PROCESS;
 import static org.apache.pdfbox.preflight.PreflightConfiguration.ANNOTATIONS_PROCESS;
 import static org.apache.pdfbox.preflight.PreflightConfiguration.GRAPHIC_PROCESS;
@@ -60,146 +59,178 @@ import org.apache.pdfbox.preflight.proce
 import org.apache.pdfbox.preflight.utils.COSUtils;
 import org.apache.pdfbox.preflight.utils.ContextHelper;
 
-public class SinglePageValidationProcess extends AbstractProcess {
-
+public class SinglePageValidationProcess extends AbstractProcess
+{
 
-	public void validate(PreflightContext context) throws ValidationException {
-		PreflightPath vPath = context.getValidationPath();
-		if (vPath.isEmpty() && !vPath.isExpectedType(PDPage.class)) {
-			throw new ValidationException("Page validation required at least a PDPage");
-		}
-
-		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);
-	}
-
-	/**
-	 * This method checks additional actions contained in the given Page object.
-	 * 
-	 * @param context
-	 * @param page
-	 * @return
-	 * @throws ValidationException
-	 */
-	protected void validateActions(PreflightContext context, PDPage page) throws ValidationException {
-		ContextHelper.validateElement(context, page.getCOSDictionary(), ACTIONS_PROCESS);
-	}
-
-
-	/**
-	 * Check that all ColorSpace present in the Resource dictionary are conforming to the ISO 19005:2005-1 specification.
-	 * @param context
-	 * @param page
-	 */
-	protected void validateColorSpaces(PreflightContext context, PDPage page)
-			throws ValidationException {
-		PDResources resources = page.getResources();
-		if (resources != null) {
-			Map<String, PDColorSpace> colorSpaces = resources.getColorSpaces();
-			if (colorSpaces != null) {
-				PreflightConfiguration config = context.getConfig();
-				ColorSpaceHelperFactory colorSpaceFactory = config.getColorSpaceHelperFact();
-				for (PDColorSpace pdCS : colorSpaces.values()) {
-					ColorSpaceHelper csHelper = colorSpaceFactory.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.NO_RESTRICTION);
-					csHelper.validate();
-				}
-			}
-		}
-	}
-
-	/**
-	 * Check that all XObject references in the PDResource of the page and in the Thumb entry are confirming to 
-	 * the PDF/A specification.
-	 * @param context
-	 * @param page
-	 * @throws ValidationException
-	 */
-	protected void validateGraphicObjects(PreflightContext context, PDPage page) throws ValidationException {
-		COSBase thumbBase = page.getCOSDictionary().getItem(PAGE_DICTIONARY_VALUE_THUMB);
-		if (thumbBase != null) {
-			try {
-				if (thumbBase instanceof COSObject) {
-					thumbBase = ((COSObject)thumbBase).getObject();
-				}
-				PDXObject thumbImg = PDXObjectImage.createXObject(thumbBase);
-				ContextHelper.validateElement(context, thumbImg, GRAPHIC_PROCESS);
-			} catch (IOException e) {
-				context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID, "Unable to read Thumb image : " + e.getMessage()));
-			}
-		}
-	}
-
-	protected void validateResources(PreflightContext context, PDPage page) throws ValidationException {
-		ContextHelper.validateElement(context, page.getResources(), RESOURCES_PROCESS);
-	}
-
-	/**
-	 * 
-	 * @param page
-	 * @param context
-	 * @return
-	 * @throws ValidationException
-	 */
-	protected void validateContent(PreflightContext context, PDPage page) throws ValidationException {
-		// TODO add this wrapper in the config object ?
-		try {
-			ContentStreamWrapper csWrapper = new ContentStreamWrapper(context, page);
-			csWrapper.validPageContentStream();
-		} catch (IOException e) {
-			context.addValidationError(new ValidationError(ERROR_UNKOWN_ERROR, e.getMessage()));
-		}
-	}
-
-	/**
-	 * 
-	 * @param page
-	 * @return
-	 * @throws ValidationException
-	 */
-	protected void validateAnnotation(PreflightContext context, PDPage page) throws ValidationException {
-		try {
-			List<?> lAnnots = page.getAnnotations();
-			for (Object object : lAnnots) {
-				if (object instanceof PDAnnotation) {
-					COSDictionary cosAnnot = ((PDAnnotation) object).getDictionary();
-					ContextHelper.validateElement(context, cosAnnot, ANNOTATIONS_PROCESS);
-				}
-			}
-		} catch (IOException e) {
-			if (e instanceof ValidationException) {
-				throw (ValidationException)e;
-			}
-			// TODO IOException probably due to Encrypt
-			throw new ValidationException("Unable to access Annotation", e);
-		}
-	}
-	
-	/**
-	 * Check that the group dictionary doesn't have a Transparency attribute
-	 * 
-	 * @param context
-	 * @param page
-	 * @throws ValidationException
-	 */
-	protected void validateGroupTransparency(PreflightContext context, PDPage page) throws ValidationException {
-		COSBase baseGroup = page.getCOSDictionary().getItem(XOBJECT_DICTIONARY_KEY_GROUP);
-		COSDictionary groupDictionary = COSUtils.getAsDictionary(baseGroup, context.getDocument().getDocument());
-		if (groupDictionary != null) {
-			String sVal = groupDictionary.getNameAsString(COSName.S);
-			if (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;
-			}
-		}
-	}
+    public void validate(PreflightContext context) throws ValidationException
+    {
+        PreflightPath vPath = context.getValidationPath();
+        if (vPath.isEmpty() && !vPath.isExpectedType(PDPage.class))
+        {
+            throw new ValidationException("Page validation required at least a PDPage");
+        }
+
+        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);
+    }
+
+    /**
+     * This method checks additional actions contained in the given Page object.
+     * 
+     * @param context
+     * @param page
+     * @return
+     * @throws ValidationException
+     */
+    protected void validateActions(PreflightContext context, PDPage page) throws ValidationException
+    {
+        ContextHelper.validateElement(context, page.getCOSDictionary(), ACTIONS_PROCESS);
+    }
+
+    /**
+     * Check that all ColorSpace present in the Resource dictionary are conforming to the ISO 19005:2005-1
+     * specification.
+     * 
+     * @param context
+     * @param page
+     */
+    protected void validateColorSpaces(PreflightContext context, PDPage page) throws ValidationException
+    {
+        PDResources resources = page.getResources();
+        if (resources != null)
+        {
+            Map<String, PDColorSpace> colorSpaces = resources.getColorSpaces();
+            if (colorSpaces != null)
+            {
+                PreflightConfiguration config = context.getConfig();
+                ColorSpaceHelperFactory colorSpaceFactory = config.getColorSpaceHelperFact();
+                for (PDColorSpace pdCS : colorSpaces.values())
+                {
+                    ColorSpaceHelper csHelper = colorSpaceFactory.getColorSpaceHelper(context, pdCS,
+                            ColorSpaceRestriction.NO_RESTRICTION);
+                    csHelper.validate();
+                }
+            }
+        }
+    }
+
+    /**
+     * Check that all XObject references in the PDResource of the page and in the Thumb entry are confirming to the
+     * PDF/A specification.
+     * 
+     * @param context
+     * @param page
+     * @throws ValidationException
+     */
+    protected void validateGraphicObjects(PreflightContext context, PDPage page) throws ValidationException
+    {
+        COSBase thumbBase = page.getCOSDictionary().getItem(PAGE_DICTIONARY_VALUE_THUMB);
+        if (thumbBase != null)
+        {
+            try
+            {
+                if (thumbBase instanceof COSObject)
+                {
+                    thumbBase = ((COSObject) thumbBase).getObject();
+                }
+                PDXObject thumbImg = PDXObjectImage.createXObject(thumbBase);
+                ContextHelper.validateElement(context, thumbImg, GRAPHIC_PROCESS);
+            }
+            catch (IOException e)
+            {
+                context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID, "Unable to read Thumb image : "
+                        + e.getMessage()));
+            }
+        }
+    }
+
+    protected void validateResources(PreflightContext context, PDPage page) throws ValidationException
+    {
+        ContextHelper.validateElement(context, page.getResources(), RESOURCES_PROCESS);
+    }
+
+    /**
+     * 
+     * @param page
+     * @param context
+     * @return
+     * @throws ValidationException
+     */
+    protected void validateContent(PreflightContext context, PDPage page) throws ValidationException
+    {
+        // TODO add this wrapper in the config object ?
+        try
+        {
+            ContentStreamWrapper csWrapper = new ContentStreamWrapper(context, page);
+            csWrapper.validPageContentStream();
+        }
+        catch (IOException e)
+        {
+            context.addValidationError(new ValidationError(ERROR_UNKOWN_ERROR, e.getMessage()));
+        }
+    }
+
+    /**
+     * 
+     * @param page
+     * @return
+     * @throws ValidationException
+     */
+    protected void validateAnnotation(PreflightContext context, PDPage page) throws ValidationException
+    {
+        try
+        {
+            List<?> lAnnots = page.getAnnotations();
+            for (Object object : lAnnots)
+            {
+                if (object instanceof PDAnnotation)
+                {
+                    COSDictionary cosAnnot = ((PDAnnotation) object).getDictionary();
+                    ContextHelper.validateElement(context, cosAnnot, ANNOTATIONS_PROCESS);
+                }
+            }
+        }
+        catch (IOException e)
+        {
+            if (e instanceof ValidationException)
+            {
+                throw (ValidationException) e;
+            }
+            // TODO IOException probably due to Encrypt
+            throw new ValidationException("Unable to access Annotation", e);
+        }
+    }
+
+    /**
+     * Check that the group dictionary doesn't have a Transparency attribute
+     * 
+     * @param context
+     * @param page
+     * @throws ValidationException
+     */
+    protected void validateGroupTransparency(PreflightContext context, PDPage page) throws ValidationException
+    {
+        COSBase baseGroup = page.getCOSDictionary().getItem(XOBJECT_DICTIONARY_KEY_GROUP);
+        COSDictionary groupDictionary = COSUtils.getAsDictionary(baseGroup, context.getDocument().getDocument());
+        if (groupDictionary != null)
+        {
+            String sVal = groupDictionary.getNameAsString(COSName.S);
+            if (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;
+            }
+        }
+    }
 
 }