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 [14/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/reflect/TilingPatternValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/TilingPatternValidationProcess.java?rev=1453416&r1=1453415&r2=1453416&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/TilingPatternValidationProcess.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/TilingPatternValidationProcess.java Wed Mar  6 16:46:35 2013
@@ -38,53 +38,60 @@ import org.apache.pdfbox.preflight.excep
 import org.apache.pdfbox.preflight.process.AbstractProcess;
 import org.apache.pdfbox.preflight.utils.ContextHelper;
 
-public class TilingPatternValidationProcess extends AbstractProcess {
+public class TilingPatternValidationProcess extends AbstractProcess
+{
 
-
-	public void validate(PreflightContext context)  throws ValidationException {
-		PreflightPath vPath = context.getValidationPath();
-		if (vPath.isEmpty() && !vPath.isExpectedType(PDPage.class)) {
-			throw new ValidationException("Tiling pattern validation required at least a PDPage");
-		}
-
-		PDTilingPatternResources tilingPattern = (PDTilingPatternResources)vPath.peek();
-		PDPage page = vPath.getClosestPathElement(PDPage.class);
-
-		checkMandatoryFields(context, page, tilingPattern);
-		parseResources(context, page, tilingPattern);
-		parsePatternContent(context, page, tilingPattern);
-	}
-
-	protected void parseResources(PreflightContext context, PDPage page, PDTilingPatternResources pattern) throws ValidationException {
-		PDResources resources = pattern.getResources();
-		if (resources != null) {
-			ContextHelper.validateElement(context, resources, RESOURCES_PROCESS);
-		}
-	}
-
-	/**
-	 * Validate the Pattern content like Color and Show Text Operators using an
-	 * instance of ContentStreamWrapper.
-	 */
-	protected void parsePatternContent(PreflightContext context, PDPage page, PDTilingPatternResources pattern) 
-			throws ValidationException {
-		ContentStreamWrapper csWrapper = new ContentStreamWrapper(context, page);
-		csWrapper.validPatternContentStream((COSStream)pattern.getCOSObject());
-	}
-
-	/**
-	 * This method checks if required fields are present.
-	 */
-	protected void checkMandatoryFields(PreflightContext context, PDPage page, PDTilingPatternResources pattern) {
-		COSDictionary dictionary = pattern.getCOSDictionary();
-		boolean res = dictionary.getItem(COSName.RESOURCES) != null;
-		res = res && dictionary.getItem(COSName.BBOX) != null;
-		res = res && dictionary.getItem(COSName.PAINT_TYPE) != null;
-		res = res && dictionary.getItem(COSName.TILING_TYPE) != null;
-		res = res && dictionary.getItem(COSName.X_STEP) != null;
-		res = res && dictionary.getItem(COSName.Y_STEP) != null;
-		if (!res) {
-			context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_PATTERN_DEFINITION));
-		}
-	}
+    public void validate(PreflightContext context) throws ValidationException
+    {
+        PreflightPath vPath = context.getValidationPath();
+        if (vPath.isEmpty() && !vPath.isExpectedType(PDPage.class))
+        {
+            throw new ValidationException("Tiling pattern validation required at least a PDPage");
+        }
+
+        PDTilingPatternResources tilingPattern = (PDTilingPatternResources) vPath.peek();
+        PDPage page = vPath.getClosestPathElement(PDPage.class);
+
+        checkMandatoryFields(context, page, tilingPattern);
+        parseResources(context, page, tilingPattern);
+        parsePatternContent(context, page, tilingPattern);
+    }
+
+    protected void parseResources(PreflightContext context, PDPage page, PDTilingPatternResources pattern)
+            throws ValidationException
+    {
+        PDResources resources = pattern.getResources();
+        if (resources != null)
+        {
+            ContextHelper.validateElement(context, resources, RESOURCES_PROCESS);
+        }
+    }
+
+    /**
+     * Validate the Pattern content like Color and Show Text Operators using an instance of ContentStreamWrapper.
+     */
+    protected void parsePatternContent(PreflightContext context, PDPage page, PDTilingPatternResources pattern)
+            throws ValidationException
+    {
+        ContentStreamWrapper csWrapper = new ContentStreamWrapper(context, page);
+        csWrapper.validPatternContentStream((COSStream) pattern.getCOSObject());
+    }
+
+    /**
+     * This method checks if required fields are present.
+     */
+    protected void checkMandatoryFields(PreflightContext context, PDPage page, PDTilingPatternResources pattern)
+    {
+        COSDictionary dictionary = pattern.getCOSDictionary();
+        boolean res = dictionary.getItem(COSName.RESOURCES) != null;
+        res = res && dictionary.getItem(COSName.BBOX) != null;
+        res = res && dictionary.getItem(COSName.PAINT_TYPE) != null;
+        res = res && dictionary.getItem(COSName.TILING_TYPE) != null;
+        res = res && dictionary.getItem(COSName.X_STEP) != null;
+        res = res && dictionary.getItem(COSName.Y_STEP) != null;
+        if (!res)
+        {
+            context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_PATTERN_DEFINITION));
+        }
+    }
 }

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/ByteArrayDataSource.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/ByteArrayDataSource.java?rev=1453416&r1=1453415&r2=1453416&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/ByteArrayDataSource.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/ByteArrayDataSource.java Wed Mar  6 16:46:35 2013
@@ -31,47 +31,55 @@ import javax.activation.DataSource;
 
 import org.apache.commons.io.IOUtils;
 
-public class ByteArrayDataSource implements DataSource {
-  private ByteArrayOutputStream data;
-  private String type = null;
-  private String name = null;
-
-  public ByteArrayDataSource(InputStream is) throws IOException {
-    data = new ByteArrayOutputStream();
-    IOUtils.copyLarge(is, data);
-    IOUtils.closeQuietly(is);
-  }
-
-  public String getContentType() {
-    return this.type;
-  }
-
-  /**
-   * @param type
-   *          the type to set
-   */
-  public void setType(String type) {
-    this.type = type;
-  }
-
-  /**
-   * @param name
-   *          the name to set
-   */
-  public void setName(String name) {
-    this.name = name;
-  }
-
-  public InputStream getInputStream() throws IOException {
-    return new ByteArrayInputStream(data.toByteArray());
-  }
-
-  public String getName() {
-    return this.name;
-  }
-
-  public OutputStream getOutputStream() throws IOException {
-    this.data = new ByteArrayOutputStream();
-    return data;
-  }
+public class ByteArrayDataSource implements DataSource
+{
+    private ByteArrayOutputStream data;
+    private String type = null;
+    private String name = null;
+
+    public ByteArrayDataSource(InputStream is) throws IOException
+    {
+        data = new ByteArrayOutputStream();
+        IOUtils.copyLarge(is, data);
+        IOUtils.closeQuietly(is);
+    }
+
+    public String getContentType()
+    {
+        return this.type;
+    }
+
+    /**
+     * @param type
+     *            the type to set
+     */
+    public void setType(String type)
+    {
+        this.type = type;
+    }
+
+    /**
+     * @param name
+     *            the name to set
+     */
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+
+    public InputStream getInputStream() throws IOException
+    {
+        return new ByteArrayInputStream(data.toByteArray());
+    }
+
+    public String getName()
+    {
+        return this.name;
+    }
+
+    public OutputStream getOutputStream() throws IOException
+    {
+        this.data = new ByteArrayOutputStream();
+        return data;
+    }
 }

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/COSUtils.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/COSUtils.java?rev=1453416&r1=1453415&r2=1453416&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/COSUtils.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/COSUtils.java Wed Mar  6 16:46:35 2013
@@ -37,363 +37,482 @@ import org.apache.pdfbox.cos.COSString;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.persistence.util.COSObjectKey;
 
-public class COSUtils {
+public class COSUtils
+{
 
-	public static final Logger LOGGER = Logger.getLogger(COSUtils.class);
+    public static final Logger LOGGER = Logger.getLogger(COSUtils.class);
 
-	  /**
-	   * return true if the elt is a COSDictionary or a reference to a COSDictionary
-	   * 
-	   * @param elt
-	   * @param doc
-	   * @return
-	   */
-	  public static boolean isDictionary(COSBase elt, COSDocument doc) {
-	    if (elt instanceof COSObject) {
-	      try {
-	        COSObjectKey key = new COSObjectKey((COSObject) elt);
-	        COSObject obj = doc.getObjectFromPool(key);
-	        return (obj != null && obj.getObject() instanceof COSDictionary);
-	      } catch (IOException e) {
-	        return false;
-	      }
-	    }
-	    return (elt instanceof COSDictionary);
-	  }
-
-	  /**
-	   * return true if the elt is a COSString or a reference to a COSString
-	   * 
-	   * @param elt
-	   * @param doc
-	   * @return
-	   */
-	  public static boolean isString(COSBase elt, COSDocument doc) {
-	    if (elt instanceof COSObject) {
-	      try {
-	        COSObjectKey key = new COSObjectKey((COSObject) elt);
-	        COSObject obj = doc.getObjectFromPool(key);
-	        return (obj != null && (obj.getObject() instanceof COSString || obj
-	            .getObject() instanceof COSName));
-	      } catch (IOException e) {
-	        return false;
-	      }
-	    }
-
-	    return (elt instanceof COSString || elt instanceof COSName);
-	  }
-
-	  /**
-	   * return true if the elt is a COSStream or a reference to a COSStream
-	   * 
-	   * @param elt
-	   * @param doc
-	   * @return
-	   */
-	  public static boolean isStream(COSBase elt, COSDocument doc) {
-	    if (elt instanceof COSObject) {
-	      try {
-	        COSObjectKey key = new COSObjectKey((COSObject) elt);
-	        COSObject obj = doc.getObjectFromPool(key);
-	        return (obj != null && obj.getObject() instanceof COSStream);
-	      } catch (IOException e) {
-	        return false;
-	      }
-	    }
-
-	    return (elt instanceof COSStream);
-	  }
-
-	  /**
-	   * return true if the elt is a COSInteger or a reference to a COSInteger
-	   * 
-	   * @param elt
-	   * @param doc
-	   * @return
-	   */
-	  public static boolean isInteger(COSBase elt, COSDocument doc) {
-	    if (elt instanceof COSObject) {
-	      try {
-	        COSObjectKey key = new COSObjectKey((COSObject) elt);
-	        COSObject obj = doc.getObjectFromPool(key);
-	        return (obj != null && obj.getObject() instanceof COSInteger);
-	      } catch (IOException e) {
-	        return false;
-	      }
-	    }
-
-	    return (elt instanceof COSInteger);
-	  }
-
-	  /**
-	   * return true if elt is COSInteger or COSFloat
-	   *
-	   * @param elt
-	   * @param doc
-	   * @return boolean
-	   */
-	  public static boolean isNumeric (COSBase elt, COSDocument doc) {
-		  return isInteger(elt, doc) || isFloat(elt, doc);
-	  }
-	  
-	  /**
-	   * return true if the elt is a COSInteger or a reference to a COSInteger
-	   * 
-	   * @param elt
-	   * @param doc
-	   * @return
-	   */
-	  public static boolean isFloat(COSBase elt, COSDocument doc) {
-	    if (elt instanceof COSObject) {
-	      try {
-	        COSObjectKey key = new COSObjectKey((COSObject) elt);
-	        COSObject obj = doc.getObjectFromPool(key);
-	        return (obj != null && obj.getObject() instanceof COSFloat);
-	      } catch (IOException e) {
-	        return false;
-	      }
-	    }
-
-	    return (elt instanceof COSFloat);
-	  }
-
-	  /**
-	   * return true if the elt is a COSArray or a reference to a COSArray
-	   * 
-	   * @param elt
-	   * @param doc
-	   * @return
-	   */
-	  public static boolean isArray(COSBase elt, COSDocument doc) {
-	    if (elt instanceof COSObject) {
-	      try {
-	        COSObjectKey key = new COSObjectKey((COSObject) elt);
-	        COSObject obj = doc.getObjectFromPool(key);
-	        return (obj != null && obj.getObject() instanceof COSArray);
-	      } catch (IOException e) {
-	        return false;
-	      }
-	    }
-
-	    return (elt instanceof COSArray);
-	  }
-
-	  /**
-	   * Return the COSBase object as COSArray if the COSBase object is an instance
-	   * of COSArray or a reference to a COSArray object. In other cases, this
-	   * method returns null;
-	   * 
-	   * @param cbase
-	   * @param cDoc
-	   * @return
-	   */
-	  public static COSArray getAsArray(COSBase cbase, COSDocument cDoc) {
-	    if (cbase instanceof COSObject) {
-	      try {
-	        COSObjectKey key = new COSObjectKey((COSObject) cbase);
-	        COSObject obj = cDoc.getObjectFromPool(key);
-	        if (obj != null && obj.getObject() instanceof COSArray) {
-	          return (COSArray) obj.getObject();
-	        } else {
-	          return null;
-	        }
-	      } catch (IOException e) {
-	        return null;
-	      }
-	    } else if (cbase instanceof COSArray) {
-	      return (COSArray) cbase;
-	    } else {
-	      return null;
-	    }
-	  }
-
-	  /**
-	   * Return the COSBase object as COSString if the COSBase object is an instance
-	   * of COSString or a reference to a COSString object. In other cases, this
-	   * method returns null;
-	   * 
-	   * @param cbase
-	   * @param cDoc
-	   * @return
-	   */
-	  public static String getAsString(COSBase cbase, COSDocument cDoc) {
-	    if (cbase instanceof COSObject) {
-	      try {
-	        COSObjectKey key = new COSObjectKey((COSObject) cbase);
-	        COSObject obj = cDoc.getObjectFromPool(key);
-	        if (obj != null && obj.getObject() instanceof COSString) {
-	         return ((COSString) obj.getObject()).getString();
-	        } else if (obj != null && obj.getObject() instanceof COSName) {
-	          return ((COSName) obj.getObject()).getName();
-	        } else {
-	          return null;
-	        }
-	      } catch (IOException e) {
-	        return null;
-	      }
-	    } else if (cbase instanceof COSString) {
-	      return ((COSString) cbase).getString();
-	    } else if (cbase instanceof COSName) {
-	      return ((COSName) cbase).getName();
-	    } else { 
-	      return null;
-	    }
-	  }
-
-	  /**
-	   * Return the COSBase object as COSDictionary if the COSBase object is an
-	   * instance of COSDictionary or a reference to a COSDictionary object. In
-	   * other cases, this method returns null;
-	   * 
-	   * @param cbase
-	   * @param cDoc
-	   * @return
-	   */
-	  public static COSDictionary getAsDictionary(COSBase cbase, COSDocument cDoc) {
-	    if (cbase instanceof COSObject) {
-	      try {
-	        COSObjectKey key = new COSObjectKey((COSObject) cbase);
-	        COSObject obj = cDoc.getObjectFromPool(key);
-	        if (obj != null && obj.getObject() instanceof COSDictionary) {
-	          return (COSDictionary) obj.getObject();
-	        } else {
-	          return null;
-	        }
-	      } catch (IOException e) {
-	        return null;
-	      }
-	    } else if (cbase instanceof COSDictionary) {
-	      return (COSDictionary) cbase;
-	    } else {
-	      return null;
-	    }
-	  }
-
-	  /**
-	   * Return the COSBase object as COSStream if the COSBase object is an instance
-	   * of COSStream or a reference to a COSStream object. In other cases, this
-	   * method returns null;
-	   * 
-	   * @param cbase
-	   * @param cDoc
-	   * @return
-	   */
-	  public static COSStream getAsStream(COSBase cbase, COSDocument cDoc) {
-	    if (cbase instanceof COSObject) {
-	      try {
-	        COSObjectKey key = new COSObjectKey((COSObject) cbase);
-	        COSObject obj = cDoc.getObjectFromPool(key);
-	        if (obj != null && obj.getObject() instanceof COSStream) {
-	          return (COSStream) obj.getObject();
-	        } else {
-	          return null;
-	        }
-	      } catch (IOException e) {
-	        return null;
-	      }
-	    } else if (cbase instanceof COSStream) {
-	      return (COSStream) cbase;
-	    } else {
-	      return null;
-	    }
-	  }
-
-	  /**
-	   * Return the COSBase object as Float if the COSBase object is an instance of
-	   * COSFloat or a reference to a COSFloat object. In other cases, this method
-	   * returns null;
-	   * 
-	   * @param cbase
-	   * @param cDoc
-	   * @return
-	   */
-	  public static Float getAsFloat(COSBase cbase, COSDocument cDoc) {
-	    if (cbase instanceof COSObject) {
-	      try {
-	        COSObjectKey key = new COSObjectKey((COSObject) cbase);
-	        COSObject obj = cDoc.getObjectFromPool(key);
-	        if (obj ==null) {
-	        	return null;
-	        } else if (obj.getObject() instanceof COSFloat) {
-	          return ((COSFloat) obj.getObject()).floatValue();
-	        } else if (obj.getObject() instanceof COSInteger) {
-	        	return (float)((COSInteger)obj.getObject()).intValue();
-	        } else {
-	          return null;
-	        }
-	      } catch (IOException e) {
-	        return null;
-	      }
-	    } else if (cbase instanceof COSFloat) {
-	      return ((COSFloat) cbase).floatValue();
-	    } else if (cbase instanceof COSInteger) {
-	        return (float)((COSInteger) cbase).intValue();
-	    } else {
-	      return null;
-	    }
-	  }
-
-	  /**
-	   * Return the COSBase object as Integer if the COSBase object is an instance
-	   * of COSInteger or a reference to a COSInteger object. In other cases, this
-	   * method returns null;
-	   * 
-	   * @param cbase
-	   * @param cDoc
-	   * @return
-	   */
-	  public static Integer getAsInteger(COSBase cbase, COSDocument cDoc) {
-	    if (cbase instanceof COSObject) {
-	      try {
-	        COSObjectKey key = new COSObjectKey((COSObject) cbase);
-	        COSObject obj = cDoc.getObjectFromPool(key);
-	        if (obj == null) {
-	        	return null;
-	        } else if (obj.getObject() instanceof COSInteger) {
-	          return ((COSInteger) obj.getObject()).intValue();
-	        } else if (obj.getObject() instanceof COSFloat) {
-	          return ((COSFloat) obj.getObject()).intValue();
-	        } else {
-	          return null;
-	        }
-	      } catch (IOException e) {
-	        return null;
-	      }
-	    } else if (cbase instanceof COSInteger) {
-	      return ((COSInteger) cbase).intValue();
-	    } else if (cbase instanceof COSFloat) {
-	      return ((COSFloat) cbase).intValue();
-	    } else {
-	      return null;
-	    }
-	  }
-
-	  /**
-	   * Close the given Document. If the close method of the document throws an
-	   * exception, it is logged using a log4j logger (Level : WARN)
-	   * 
-	   * @param document
-	   */
-	  public static void closeDocumentQuietly(COSDocument document) {
-	    try {
-	      if (document != null) {
-	        document.close();
-	      }
-	    } catch (IOException e) {
-	      LOGGER.warn("Error occured during the close of a COSDocument : "
-	          + e.getMessage());
-	    }
-	  }
-
-	  /**
-	   * Close the given Document. If the close method of the document throws an
-	   * exception, it is logged using a log4j logger (Level : WARN)
-	   * 
-	   * @param document
-	   */
-	  public static void closeDocumentQuietly(PDDocument document) {
-	    if (document != null) {
-	      closeDocumentQuietly(document.getDocument());
-	    }
-	  }
+    /**
+     * return true if the elt is a COSDictionary or a reference to a COSDictionary
+     * 
+     * @param elt
+     * @param doc
+     * @return
+     */
+    public static boolean isDictionary(COSBase elt, COSDocument doc)
+    {
+        if (elt instanceof COSObject)
+        {
+            try
+            {
+                COSObjectKey key = new COSObjectKey((COSObject) elt);
+                COSObject obj = doc.getObjectFromPool(key);
+                return (obj != null && obj.getObject() instanceof COSDictionary);
+            }
+            catch (IOException e)
+            {
+                return false;
+            }
+        }
+        return (elt instanceof COSDictionary);
+    }
+
+    /**
+     * return true if the elt is a COSString or a reference to a COSString
+     * 
+     * @param elt
+     * @param doc
+     * @return
+     */
+    public static boolean isString(COSBase elt, COSDocument doc)
+    {
+        if (elt instanceof COSObject)
+        {
+            try
+            {
+                COSObjectKey key = new COSObjectKey((COSObject) elt);
+                COSObject obj = doc.getObjectFromPool(key);
+                return (obj != null && (obj.getObject() instanceof COSString || obj.getObject() instanceof COSName));
+            }
+            catch (IOException e)
+            {
+                return false;
+            }
+        }
+
+        return (elt instanceof COSString || elt instanceof COSName);
+    }
+
+    /**
+     * return true if the elt is a COSStream or a reference to a COSStream
+     * 
+     * @param elt
+     * @param doc
+     * @return
+     */
+    public static boolean isStream(COSBase elt, COSDocument doc)
+    {
+        if (elt instanceof COSObject)
+        {
+            try
+            {
+                COSObjectKey key = new COSObjectKey((COSObject) elt);
+                COSObject obj = doc.getObjectFromPool(key);
+                return (obj != null && obj.getObject() instanceof COSStream);
+            }
+            catch (IOException e)
+            {
+                return false;
+            }
+        }
+
+        return (elt instanceof COSStream);
+    }
+
+    /**
+     * return true if the elt is a COSInteger or a reference to a COSInteger
+     * 
+     * @param elt
+     * @param doc
+     * @return
+     */
+    public static boolean isInteger(COSBase elt, COSDocument doc)
+    {
+        if (elt instanceof COSObject)
+        {
+            try
+            {
+                COSObjectKey key = new COSObjectKey((COSObject) elt);
+                COSObject obj = doc.getObjectFromPool(key);
+                return (obj != null && obj.getObject() instanceof COSInteger);
+            }
+            catch (IOException e)
+            {
+                return false;
+            }
+        }
+
+        return (elt instanceof COSInteger);
+    }
+
+    /**
+     * return true if elt is COSInteger or COSFloat
+     * 
+     * @param elt
+     * @param doc
+     * @return boolean
+     */
+    public static boolean isNumeric(COSBase elt, COSDocument doc)
+    {
+        return isInteger(elt, doc) || isFloat(elt, doc);
+    }
+
+    /**
+     * return true if the elt is a COSInteger or a reference to a COSInteger
+     * 
+     * @param elt
+     * @param doc
+     * @return
+     */
+    public static boolean isFloat(COSBase elt, COSDocument doc)
+    {
+        if (elt instanceof COSObject)
+        {
+            try
+            {
+                COSObjectKey key = new COSObjectKey((COSObject) elt);
+                COSObject obj = doc.getObjectFromPool(key);
+                return (obj != null && obj.getObject() instanceof COSFloat);
+            }
+            catch (IOException e)
+            {
+                return false;
+            }
+        }
+
+        return (elt instanceof COSFloat);
+    }
+
+    /**
+     * return true if the elt is a COSArray or a reference to a COSArray
+     * 
+     * @param elt
+     * @param doc
+     * @return
+     */
+    public static boolean isArray(COSBase elt, COSDocument doc)
+    {
+        if (elt instanceof COSObject)
+        {
+            try
+            {
+                COSObjectKey key = new COSObjectKey((COSObject) elt);
+                COSObject obj = doc.getObjectFromPool(key);
+                return (obj != null && obj.getObject() instanceof COSArray);
+            }
+            catch (IOException e)
+            {
+                return false;
+            }
+        }
+
+        return (elt instanceof COSArray);
+    }
+
+    /**
+     * Return the COSBase object as COSArray if the COSBase object is an instance of COSArray or a reference to a
+     * COSArray object. In other cases, this method returns null;
+     * 
+     * @param cbase
+     * @param cDoc
+     * @return
+     */
+    public static COSArray getAsArray(COSBase cbase, COSDocument cDoc)
+    {
+        if (cbase instanceof COSObject)
+        {
+            try
+            {
+                COSObjectKey key = new COSObjectKey((COSObject) cbase);
+                COSObject obj = cDoc.getObjectFromPool(key);
+                if (obj != null && obj.getObject() instanceof COSArray)
+                {
+                    return (COSArray) obj.getObject();
+                }
+                else
+                {
+                    return null;
+                }
+            }
+            catch (IOException e)
+            {
+                return null;
+            }
+        }
+        else if (cbase instanceof COSArray)
+        {
+            return (COSArray) cbase;
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+    /**
+     * Return the COSBase object as COSString if the COSBase object is an instance of COSString or a reference to a
+     * COSString object. In other cases, this method returns null;
+     * 
+     * @param cbase
+     * @param cDoc
+     * @return
+     */
+    public static String getAsString(COSBase cbase, COSDocument cDoc)
+    {
+        if (cbase instanceof COSObject)
+        {
+            try
+            {
+                COSObjectKey key = new COSObjectKey((COSObject) cbase);
+                COSObject obj = cDoc.getObjectFromPool(key);
+                if (obj != null && obj.getObject() instanceof COSString)
+                {
+                    return ((COSString) obj.getObject()).getString();
+                }
+                else if (obj != null && obj.getObject() instanceof COSName)
+                {
+                    return ((COSName) obj.getObject()).getName();
+                }
+                else
+                {
+                    return null;
+                }
+            }
+            catch (IOException e)
+            {
+                return null;
+            }
+        }
+        else if (cbase instanceof COSString)
+        {
+            return ((COSString) cbase).getString();
+        }
+        else if (cbase instanceof COSName)
+        {
+            return ((COSName) cbase).getName();
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+    /**
+     * Return the COSBase object as COSDictionary if the COSBase object is an instance of COSDictionary or a reference
+     * to a COSDictionary object. In other cases, this method returns null;
+     * 
+     * @param cbase
+     * @param cDoc
+     * @return
+     */
+    public static COSDictionary getAsDictionary(COSBase cbase, COSDocument cDoc)
+    {
+        if (cbase instanceof COSObject)
+        {
+            try
+            {
+                COSObjectKey key = new COSObjectKey((COSObject) cbase);
+                COSObject obj = cDoc.getObjectFromPool(key);
+                if (obj != null && obj.getObject() instanceof COSDictionary)
+                {
+                    return (COSDictionary) obj.getObject();
+                }
+                else
+                {
+                    return null;
+                }
+            }
+            catch (IOException e)
+            {
+                return null;
+            }
+        }
+        else if (cbase instanceof COSDictionary)
+        {
+            return (COSDictionary) cbase;
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+    /**
+     * Return the COSBase object as COSStream if the COSBase object is an instance of COSStream or a reference to a
+     * COSStream object. In other cases, this method returns null;
+     * 
+     * @param cbase
+     * @param cDoc
+     * @return
+     */
+    public static COSStream getAsStream(COSBase cbase, COSDocument cDoc)
+    {
+        if (cbase instanceof COSObject)
+        {
+            try
+            {
+                COSObjectKey key = new COSObjectKey((COSObject) cbase);
+                COSObject obj = cDoc.getObjectFromPool(key);
+                if (obj != null && obj.getObject() instanceof COSStream)
+                {
+                    return (COSStream) obj.getObject();
+                }
+                else
+                {
+                    return null;
+                }
+            }
+            catch (IOException e)
+            {
+                return null;
+            }
+        }
+        else if (cbase instanceof COSStream)
+        {
+            return (COSStream) cbase;
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+    /**
+     * Return the COSBase object as Float if the COSBase object is an instance of COSFloat or a reference to a COSFloat
+     * object. In other cases, this method returns null;
+     * 
+     * @param cbase
+     * @param cDoc
+     * @return
+     */
+    public static Float getAsFloat(COSBase cbase, COSDocument cDoc)
+    {
+        if (cbase instanceof COSObject)
+        {
+            try
+            {
+                COSObjectKey key = new COSObjectKey((COSObject) cbase);
+                COSObject obj = cDoc.getObjectFromPool(key);
+                if (obj == null)
+                {
+                    return null;
+                }
+                else if (obj.getObject() instanceof COSFloat)
+                {
+                    return ((COSFloat) obj.getObject()).floatValue();
+                }
+                else if (obj.getObject() instanceof COSInteger)
+                {
+                    return (float) ((COSInteger) obj.getObject()).intValue();
+                }
+                else
+                {
+                    return null;
+                }
+            }
+            catch (IOException e)
+            {
+                return null;
+            }
+        }
+        else if (cbase instanceof COSFloat)
+        {
+            return ((COSFloat) cbase).floatValue();
+        }
+        else if (cbase instanceof COSInteger)
+        {
+            return (float) ((COSInteger) cbase).intValue();
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+    /**
+     * Return the COSBase object as Integer if the COSBase object is an instance of COSInteger or a reference to a
+     * COSInteger object. In other cases, this method returns null;
+     * 
+     * @param cbase
+     * @param cDoc
+     * @return
+     */
+    public static Integer getAsInteger(COSBase cbase, COSDocument cDoc)
+    {
+        if (cbase instanceof COSObject)
+        {
+            try
+            {
+                COSObjectKey key = new COSObjectKey((COSObject) cbase);
+                COSObject obj = cDoc.getObjectFromPool(key);
+                if (obj == null)
+                {
+                    return null;
+                }
+                else if (obj.getObject() instanceof COSInteger)
+                {
+                    return ((COSInteger) obj.getObject()).intValue();
+                }
+                else if (obj.getObject() instanceof COSFloat)
+                {
+                    return ((COSFloat) obj.getObject()).intValue();
+                }
+                else
+                {
+                    return null;
+                }
+            }
+            catch (IOException e)
+            {
+                return null;
+            }
+        }
+        else if (cbase instanceof COSInteger)
+        {
+            return ((COSInteger) cbase).intValue();
+        }
+        else if (cbase instanceof COSFloat)
+        {
+            return ((COSFloat) cbase).intValue();
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+    /**
+     * Close the given Document. If the close method of the document throws an exception, it is logged using a log4j
+     * logger (Level : WARN)
+     * 
+     * @param document
+     */
+    public static void closeDocumentQuietly(COSDocument document)
+    {
+        try
+        {
+            if (document != null)
+            {
+                document.close();
+            }
+        }
+        catch (IOException e)
+        {
+            LOGGER.warn("Error occured during the close of a COSDocument : " + e.getMessage());
+        }
+    }
+
+    /**
+     * Close the given Document. If the close method of the document throws an exception, it is logged using a log4j
+     * logger (Level : WARN)
+     * 
+     * @param document
+     */
+    public static void closeDocumentQuietly(PDDocument document)
+    {
+        if (document != null)
+        {
+            closeDocumentQuietly(document.getDocument());
+        }
+    }
 }

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/ContextHelper.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/ContextHelper.java?rev=1453416&r1=1453415&r2=1453416&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/ContextHelper.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/ContextHelper.java Wed Mar  6 16:46:35 2013
@@ -27,55 +27,64 @@ import org.apache.pdfbox.preflight.Prefl
 import org.apache.pdfbox.preflight.exception.ValidationException;
 import org.apache.pdfbox.preflight.process.ValidationProcess;
 
-public class ContextHelper {
+public class ContextHelper
+{
 
-	/**
-	 * Check that the element parameter isn't null before calling 
-	 * the {@link #callValidation(PreflightContext, Object, String)} method.
-	 * @param context
-	 * @param element
-	 * @param processName
-	 * @throws ValidationException
-	 */
-	public static void validateElement(PreflightContext context, Object element, String processName) 
-	throws ValidationException {
-		if (element == null) {
-			throw new ValidationException("Unable to process an element if it is null.");
-		}
-		callValidation(context, element, processName);
-	}
+    /**
+     * Check that the element parameter isn't null before calling the
+     * {@link #callValidation(PreflightContext, Object, String)} method.
+     * 
+     * @param context
+     * @param element
+     * @param processName
+     * @throws ValidationException
+     */
+    public static void validateElement(PreflightContext context, Object element, String processName)
+            throws ValidationException
+    {
+        if (element == null)
+        {
+            throw new ValidationException("Unable to process an element if it is null.");
+        }
+        callValidation(context, element, processName);
+    }
 
-	/**
-	 * Put the element to check on the top of the ValidationPath and call the validation 
-	 * method on the Process.
-	 * 
-	 * @param context (mandatory) the preflight context that contains all required information
-	 * @param element
-	 * @param processName the process to instantiate and to compute
-	 * @throws ValidationException
-	 */
-	private static void callValidation(PreflightContext context, Object element, String processName) 
-	throws ValidationException {
-		if (context == null) {
-			throw new ValidationException("Unable to process an element without context.");
-		}
+    /**
+     * Put the element to check on the top of the ValidationPath and call the validation method on the Process.
+     * 
+     * @param context
+     *            (mandatory) the preflight context that contains all required information
+     * @param element
+     * @param processName
+     *            the process to instantiate and to compute
+     * @throws ValidationException
+     */
+    private static void callValidation(PreflightContext context, Object element, String processName)
+            throws ValidationException
+    {
+        if (context == null)
+        {
+            throw new ValidationException("Unable to process an element without context.");
+        }
 
-		PreflightPath validationPath = context.getValidationPath(); 
-		boolean needPop = validationPath.pushObject(element);
-		PreflightConfiguration config = context.getConfig();
-		ValidationProcess process = config.getInstanceOfProcess(processName);
-		process.validate(context);
-		if ( needPop ) validationPath.pop();
-	}
+        PreflightPath validationPath = context.getValidationPath();
+        boolean needPop = validationPath.pushObject(element);
+        PreflightConfiguration config = context.getConfig();
+        ValidationProcess process = config.getInstanceOfProcess(processName);
+        process.validate(context);
+        if (needPop)
+            validationPath.pop();
+    }
 
-	/**
-	 * call directly the {@link #callValidation(PreflightContext, Object, String)}
-	 * @param context
-	 * @param processName
-	 * @throws ValidationException
-	 */
-	public static void validateElement(PreflightContext context, String processName) 
-	throws ValidationException {
-		callValidation(context, null, processName);
-	}
-}
\ No newline at end of file
+    /**
+     * call directly the {@link #callValidation(PreflightContext, Object, String)}
+     * 
+     * @param context
+     * @param processName
+     * @throws ValidationException
+     */
+    public static void validateElement(PreflightContext context, String processName) throws ValidationException
+    {
+        callValidation(context, null, processName);
+    }
+}

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/FilterHelper.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/FilterHelper.java?rev=1453416&r1=1453415&r2=1453416&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/FilterHelper.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/FilterHelper.java Wed Mar  6 16:46:35 2013
@@ -43,68 +43,77 @@ import org.apache.pdfbox.preflight.Prefl
 import org.apache.pdfbox.preflight.PreflightDocument;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 
+public class FilterHelper
+{
 
-public class FilterHelper {
-
-	/**
-	 * This method checks if the filter is authorized for the PDF file according to the preflight document specification attribute.
-	 * For example according to the PDF/A-1 specification, only the LZW filter is forbidden due to
-	 * Copyright compatibility. Because of the PDF/A is based on the PDF1.4 specification, 
-	 * all filters that aren't declared in the PDF Reference Third Edition are rejected. 
-	 * 
-	 * @param context the preflight context
-	 * @param filter the filter to checks
-	 */
-	public static void isAuthorizedFilter(PreflightContext context, String filter) {
-		PreflightDocument preflightDocument = context.getDocument();
-		switch (preflightDocument.getSpecification()) {
-		case PDF_A1A:
-			isAuthorizedFilterInPDFA(context, filter);		
-			break;
-
-		default:
-			// PDF/A-1b is the default format
-			isAuthorizedFilterInPDFA(context, filter);		
-			break;
-		}
-	}
-
-	/**
-	 * This method checks if the filter is authorized for a PDF/A file.
-	 * According to the PDF/A-1 specification, only the LZW filter is forbidden due to
-	 * Copyright compatibility. Because of the PDF/A is based on the PDF1.4 specification, 
-	 * all filters that aren't declared in the PDF Reference Third Edition are rejected. 
-	 * 
-	 * @param context
-	 * @param filter
-	 */
-	public static void isAuthorizedFilterInPDFA(PreflightContext context, String filter) {
-		if (filter != null) {
-			// --- LZW is forbidden.
-			if (STREAM_DICTIONARY_VALUE_FILTER_LZW.equals(filter) || INLINE_DICTIONARY_VALUE_FILTER_LZW.equals(filter) ) {
-				context.addValidationError(new ValidationError(ERROR_SYNTAX_STREAM_INVALID_FILTER, "LZWDecode is forbidden"));
-			}
-
-			// --- Filters declared in the PDF Reference for PDF 1.4
-			// --- Other Filters are considered as invalid to avoid not consistent behaviour
-			boolean definedFilter = STREAM_DICTIONARY_VALUE_FILTER_FLATE_DECODE.equals(filter);
-			definedFilter = definedFilter || STREAM_DICTIONARY_VALUE_FILTER_ASCII_HEX.equals(filter);
-			definedFilter = definedFilter || STREAM_DICTIONARY_VALUE_FILTER_ASCII_85.equals(filter);
-			definedFilter = definedFilter || STREAM_DICTIONARY_VALUE_FILTER_CCITTFF.equals(filter);
-			definedFilter = definedFilter || STREAM_DICTIONARY_VALUE_FILTER_DCT.equals(filter);
-			definedFilter = definedFilter || STREAM_DICTIONARY_VALUE_FILTER_JBIG.equals(filter);
-			definedFilter = definedFilter || STREAM_DICTIONARY_VALUE_FILTER_RUN.equals(filter);
-
-			definedFilter = definedFilter || INLINE_DICTIONARY_VALUE_FILTER_FLATE_DECODE.equals(filter);
-			definedFilter = definedFilter || INLINE_DICTIONARY_VALUE_FILTER_ASCII_HEX.equals(filter);
-			definedFilter = definedFilter || INLINE_DICTIONARY_VALUE_FILTER_ASCII_85.equals(filter);
-			definedFilter = definedFilter || INLINE_DICTIONARY_VALUE_FILTER_CCITTFF.equals(filter);
-			definedFilter = definedFilter || INLINE_DICTIONARY_VALUE_FILTER_DCT.equals(filter);
-			definedFilter = definedFilter || INLINE_DICTIONARY_VALUE_FILTER_RUN.equals(filter);
-
-			if (!definedFilter) {
-				context.addValidationError(new ValidationError(ERROR_SYNTAX_STREAM_UNDEFINED_FILTER, "This filter isn't defined in the PDF Reference Third Edition : "+filter));
-			}
-		}
-	}
+    /**
+     * This method checks if the filter is authorized for the PDF file according to the preflight document specification
+     * attribute. For example according to the PDF/A-1 specification, only the LZW filter is forbidden due to Copyright
+     * compatibility. Because of the PDF/A is based on the PDF1.4 specification, all filters that aren't declared in the
+     * PDF Reference Third Edition are rejected.
+     * 
+     * @param context
+     *            the preflight context
+     * @param filter
+     *            the filter to checks
+     */
+    public static void isAuthorizedFilter(PreflightContext context, String filter)
+    {
+        PreflightDocument preflightDocument = context.getDocument();
+        switch (preflightDocument.getSpecification())
+        {
+        case PDF_A1A:
+            isAuthorizedFilterInPDFA(context, filter);
+            break;
+
+        default:
+            // PDF/A-1b is the default format
+            isAuthorizedFilterInPDFA(context, filter);
+            break;
+        }
+    }
+
+    /**
+     * This method checks if the filter is authorized for a PDF/A file. According to the PDF/A-1 specification, only the
+     * LZW filter is forbidden due to Copyright compatibility. Because of the PDF/A is based on the PDF1.4
+     * specification, all filters that aren't declared in the PDF Reference Third Edition are rejected.
+     * 
+     * @param context
+     * @param filter
+     */
+    public static void isAuthorizedFilterInPDFA(PreflightContext context, String filter)
+    {
+        if (filter != null)
+        {
+            // --- LZW is forbidden.
+            if (STREAM_DICTIONARY_VALUE_FILTER_LZW.equals(filter) || INLINE_DICTIONARY_VALUE_FILTER_LZW.equals(filter))
+            {
+                context.addValidationError(new ValidationError(ERROR_SYNTAX_STREAM_INVALID_FILTER,
+                        "LZWDecode is forbidden"));
+            }
+
+            // --- Filters declared in the PDF Reference for PDF 1.4
+            // --- Other Filters are considered as invalid to avoid not consistent behaviour
+            boolean definedFilter = STREAM_DICTIONARY_VALUE_FILTER_FLATE_DECODE.equals(filter);
+            definedFilter = definedFilter || STREAM_DICTIONARY_VALUE_FILTER_ASCII_HEX.equals(filter);
+            definedFilter = definedFilter || STREAM_DICTIONARY_VALUE_FILTER_ASCII_85.equals(filter);
+            definedFilter = definedFilter || STREAM_DICTIONARY_VALUE_FILTER_CCITTFF.equals(filter);
+            definedFilter = definedFilter || STREAM_DICTIONARY_VALUE_FILTER_DCT.equals(filter);
+            definedFilter = definedFilter || STREAM_DICTIONARY_VALUE_FILTER_JBIG.equals(filter);
+            definedFilter = definedFilter || STREAM_DICTIONARY_VALUE_FILTER_RUN.equals(filter);
+
+            definedFilter = definedFilter || INLINE_DICTIONARY_VALUE_FILTER_FLATE_DECODE.equals(filter);
+            definedFilter = definedFilter || INLINE_DICTIONARY_VALUE_FILTER_ASCII_HEX.equals(filter);
+            definedFilter = definedFilter || INLINE_DICTIONARY_VALUE_FILTER_ASCII_85.equals(filter);
+            definedFilter = definedFilter || INLINE_DICTIONARY_VALUE_FILTER_CCITTFF.equals(filter);
+            definedFilter = definedFilter || INLINE_DICTIONARY_VALUE_FILTER_DCT.equals(filter);
+            definedFilter = definedFilter || INLINE_DICTIONARY_VALUE_FILTER_RUN.equals(filter);
+
+            if (!definedFilter)
+            {
+                context.addValidationError(new ValidationError(ERROR_SYNTAX_STREAM_UNDEFINED_FILTER,
+                        "This filter isn't defined in the PDF Reference Third Edition : " + filter));
+            }
+        }
+    }
 }

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/PdfElementParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/PdfElementParser.java?rev=1453416&r1=1453415&r2=1453416&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/PdfElementParser.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/PdfElementParser.java Wed Mar  6 16:46:35 2013
@@ -30,41 +30,44 @@ import org.apache.pdfbox.pdfparser.BaseP
 /**
  * This class is a tool to parse a byte array as a COS object (COSDIctionary)
  */
-public class PdfElementParser extends BaseParser {
+public class PdfElementParser extends BaseParser
+{
 
-  /**
-   * Create the PDFElementParser object.
-   * 
-   * @param cosDocument
-   *          a COSDocument which will be used to parse the byte array
-   * @param input
-   *          the byte array to parse
-   * @throws IOException
-   */
-  public PdfElementParser(COSDocument cosDocument, byte[] input) throws IOException {
-    super(input);
-    this.document = cosDocument;
-  }
+    /**
+     * Create the PDFElementParser object.
+     * 
+     * @param cosDocument
+     *            a COSDocument which will be used to parse the byte array
+     * @param input
+     *            the byte array to parse
+     * @throws IOException
+     */
+    public PdfElementParser(COSDocument cosDocument, byte[] input) throws IOException
+    {
+        super(input);
+        this.document = cosDocument;
+    }
 
-  /**
-   * Parse the input byte array of the constructor call as a COSDictionary.
-   * 
-   * @return a COSDictionary if the parsing succeed.
-   * @throws IOException
-   *           If the byte array isn't a COSDictionary or if there are an error
-   *           on the stream parsing
-   */
-  public COSDictionary parseAsDictionary() throws IOException {
-    return parseCOSDictionary();
-  }
+    /**
+     * Parse the input byte array of the constructor call as a COSDictionary.
+     * 
+     * @return a COSDictionary if the parsing succeed.
+     * @throws IOException
+     *             If the byte array isn't a COSDictionary or if there are an error on the stream parsing
+     */
+    public COSDictionary parseAsDictionary() throws IOException
+    {
+        return parseCOSDictionary();
+    }
 
-  /**
-   * Return the COSDocument used to create this object.
-   * 
-   * @return
-   */
-  public COSDocument getDocument() {
-    return this.document;
-  }
+    /**
+     * Return the COSDocument used to create this object.
+     * 
+     * @return
+     */
+    public COSDocument getDocument()
+    {
+        return this.document;
+    }
 
 }

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/RenderingIntents.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/RenderingIntents.java?rev=1453416&r1=1453415&r2=1453416&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/RenderingIntents.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/RenderingIntents.java Wed Mar  6 16:46:35 2013
@@ -31,9 +31,8 @@ import java.util.Collections;
 import java.util.List;
 
 /**
- * This class contains a static list of RenderingIntent values to allow an easy
- * RenderingIntent value validation. Here is the content of the RenderingIntent
- * list :
+ * This class contains a static list of RenderingIntent values to allow an easy RenderingIntent value validation. Here
+ * is the content of the RenderingIntent list :
  * <UL>
  * <li>Perceptual
  * <li>Saturation
@@ -41,19 +40,22 @@ import java.util.List;
  * <li>RelativeColorimetric
  * </UL>
  */
-public class RenderingIntents {
-  private static List<String> RENDERING_INTENTS;
+public class RenderingIntents
+{
+    private static List<String> RENDERING_INTENTS;
 
-  static {
-    ArrayList<String> al = new ArrayList<String>(4);
-    al.add(RENDERING_INTENT_REL_COLOR);
-    al.add(RENDERING_INTENT_ABS_COLOR);
-    al.add(RENDERING_INTENT_PERCEPTUAL);
-    al.add(RENDERING_INTENT_SATURATION);
-    RENDERING_INTENTS = Collections.unmodifiableList(al);
-  }
+    static
+    {
+        ArrayList<String> al = new ArrayList<String>(4);
+        al.add(RENDERING_INTENT_REL_COLOR);
+        al.add(RENDERING_INTENT_ABS_COLOR);
+        al.add(RENDERING_INTENT_PERCEPTUAL);
+        al.add(RENDERING_INTENT_SATURATION);
+        RENDERING_INTENTS = Collections.unmodifiableList(al);
+    }
 
-  public static boolean contains(Object riArg) {
-    return RENDERING_INTENTS.contains(riArg);
-  }
+    public static boolean contains(Object riArg)
+    {
+        return RENDERING_INTENTS.contains(riArg);
+    }
 }

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=1453416&r1=1453415&r2=1453416&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 Wed Mar  6 16:46:35 2013
@@ -39,113 +39,120 @@ import org.apache.pdfbox.preflight.utils
 /**
  * This class processes commons validations of XObjects.
  */
-public abstract class AbstractXObjValidator implements XObjectValidator {
-	/**
-	 * The XObject to validate as a COSStream.
-	 */
-	protected COSStream xobject = null;
-	/**
-	 * 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();
-	}
-
-	/**
-	 * This method checks the SMask entry in the XObject dictionary. According to
-	 * the PDF Reference, a SMask in a XObject is a Stream. So if it is not null,
-	 * it should be an error but a SMask with the name None is authorized in the
-	 * PDF/A Specification 6.4. If the validation fails (SMask not null and
-	 * different from None), the error list is updated with the error code
-	 * ERROR_GRAPHIC_TRANSPARENCY_SMASK (2.2.2).
-	 * 
-	 */
-	protected void checkSMask() {
-		COSBase smask = xobject.getItem(COSName.SMASK);
-		if (smask != null
-				&& !(COSUtils.isString(smask, cosDocument) && TRANSPARENCY_DICTIONARY_VALUE_SOFT_MASK_NONE
-						.equals(COSUtils.getAsString(smask, cosDocument)))) {
-			context.addValidationError(new ValidationError(ERROR_GRAPHIC_TRANSPARENCY_SMASK, "Soft Mask must be null or None"));
-		}
-	}
-
-	/**
-	 * According the ISO 190005:1-2005 specification, a XObject can't have an OPI
-	 * entry in its dictionary. If the XObject has a OPI entry, the error list is
-	 * updated with the error code ERROR_GRAPHIC_UNEXPECTED_KEY (2.3).
-	 * 
-	 * @param errors
-	 *          the list of error to update if the validation fails.
-	 * @return true if the OPI is missing, false otherwise.
-	 */
-	protected void checkOPI() {
-		// 6.2.4 and 6.2.5 no OPI
-		if (this.xobject.getItem(COSName.getPDFName("OPI")) != null) {
-			context.addValidationError(new ValidationError(
-					ERROR_GRAPHIC_UNEXPECTED_KEY,
-					"Unexpected 'OPI' Key"));
-		}
-	}
-
-	/**
-	 * According the ISO 190005:1-2005 specification, a XObject can't have an Ref
-	 * entry in its dictionary. If the XObject has a Ref entry, the error list is
-	 * updated with the error code ERROR_GRAPHIC_UNEXPECTED_KEY (2.3).
-	 * 
-	 */
-	protected void checkReferenceXObject() {
-		// 6.2.6 No reference xobject
-		if (this.xobject.getItem("Ref") != null) {
-			context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_KEY,
-					"No reference Xobject allowed in PDF/A"));
-		}
-	}
-
-	/**
-	 * According the ISO 190005:1-2005 specification, PostSCript XObject are
-	 * forbidden. If the XObject is a PostScript XObject, the error list is
-	 * updated with the error code ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY (2.3.2).
-	 * 
-	 * To know the if the object a Postscript XObject, "Subtype" and "Subtype2"
-	 * entries are checked.
-	 */
-	protected void checkPostscriptXObject() {
-		// 6.2.7 No PostScript XObjects
-		String subtype = this.xobject.getNameAsString(COSName.SUBTYPE);
-		if (subtype	!= null	&& XOBJECT_DICTIONARY_VALUE_SUBTYPE_POSTSCRIPT.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) {
-			context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY,"No Postscript Xobject allowed in PDF/A (Subtype2)"));
-			return;
-		}
-	}
-
-	/**
-	 * This method checks if required fields are present.
-	 * 
-	 */
-	protected abstract void checkMandatoryFields();
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see net.awl.edoc.pdfa.validation.graphics.XObjectValidator#validate()
-	 */
-	public void validate() throws ValidationException {
-		checkMandatoryFields();
-		checkOPI();
-		checkSMask();
-		checkReferenceXObject();
-		checkPostscriptXObject();
-	}
+public abstract class AbstractXObjValidator implements XObjectValidator
+{
+    /**
+     * The XObject to validate as a COSStream.
+     */
+    protected COSStream xobject = null;
+    /**
+     * 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();
+    }
+
+    /**
+     * This method checks the SMask entry in the XObject dictionary. According to the PDF Reference, a SMask in a
+     * XObject is a Stream. So if it is not null, it should be an error but a SMask with the name None is authorized in
+     * the PDF/A Specification 6.4. If the validation fails (SMask not null and different from None), the error list is
+     * updated with the error code ERROR_GRAPHIC_TRANSPARENCY_SMASK (2.2.2).
+     * 
+     */
+    protected void checkSMask()
+    {
+        COSBase smask = xobject.getItem(COSName.SMASK);
+        if (smask != null
+                && !(COSUtils.isString(smask, cosDocument) && TRANSPARENCY_DICTIONARY_VALUE_SOFT_MASK_NONE
+                        .equals(COSUtils.getAsString(smask, cosDocument))))
+        {
+            context.addValidationError(new ValidationError(ERROR_GRAPHIC_TRANSPARENCY_SMASK,
+                    "Soft Mask must be null or None"));
+        }
+    }
+
+    /**
+     * According the ISO 190005:1-2005 specification, a XObject can't have an OPI entry in its dictionary. If the
+     * XObject has a OPI entry, the error list is updated with the error code ERROR_GRAPHIC_UNEXPECTED_KEY (2.3).
+     * 
+     * @param errors
+     *            the list of error to update if the validation fails.
+     * @return true if the OPI is missing, false otherwise.
+     */
+    protected void checkOPI()
+    {
+        // 6.2.4 and 6.2.5 no OPI
+        if (this.xobject.getItem(COSName.getPDFName("OPI")) != null)
+        {
+            context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_KEY, "Unexpected 'OPI' Key"));
+        }
+    }
+
+    /**
+     * According the ISO 190005:1-2005 specification, a XObject can't have an Ref entry in its dictionary. If the
+     * XObject has a Ref entry, the error list is updated with the error code ERROR_GRAPHIC_UNEXPECTED_KEY (2.3).
+     * 
+     */
+    protected void checkReferenceXObject()
+    {
+        // 6.2.6 No reference xobject
+        if (this.xobject.getItem("Ref") != null)
+        {
+            context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_KEY,
+                    "No reference Xobject allowed in PDF/A"));
+        }
+    }
+
+    /**
+     * According the ISO 190005:1-2005 specification, PostSCript XObject are forbidden. If the XObject is a PostScript
+     * XObject, the error list is updated with the error code ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY (2.3.2).
+     * 
+     * To know the if the object a Postscript XObject, "Subtype" and "Subtype2" entries are checked.
+     */
+    protected void checkPostscriptXObject()
+    {
+        // 6.2.7 No PostScript XObjects
+        String subtype = this.xobject.getNameAsString(COSName.SUBTYPE);
+        if (subtype != null && XOBJECT_DICTIONARY_VALUE_SUBTYPE_POSTSCRIPT.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)
+        {
+            context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY,
+                    "No Postscript Xobject allowed in PDF/A (Subtype2)"));
+            return;
+        }
+    }
+
+    /**
+     * This method checks if required fields are present.
+     * 
+     */
+    protected abstract void checkMandatoryFields();
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see net.awl.edoc.pdfa.validation.graphics.XObjectValidator#validate()
+     */
+    public void validate() throws ValidationException
+    {
+        checkMandatoryFields();
+        checkOPI();
+        checkSMask();
+        checkReferenceXObject();
+        checkPostscriptXObject();
+    }
 }

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=1453416&r1=1453415&r2=1453416&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 Wed Mar  6 16:46:35 2013
@@ -47,118 +47,135 @@ import org.apache.pdfbox.preflight.utils
 /**
  * This class validates XObject with the Form subtype.
  */
-public class XObjFormValidator extends AbstractXObjValidator {
-	/**
-	 * High level object which represents the XObjectForm
-	 */
-	PDXObjectForm pdXObj = null;
-
-	public XObjFormValidator(PreflightContext context, PDXObjectForm xobj) {
-		super(context, xobj.getCOSStream());
-		this.pdXObj = xobj;
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see net.awl.edoc.pdfa.validation.graphics.AbstractXObjValidator#validate()
-	 */
-	@Override
-	public void validate() throws ValidationException {
-		super.validate();
-		checkGroup();
-		checkSubtype2Value();
-		validateXObjectResources();
-		validateXObjectContent();
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @seenet.awl.edoc.pdfa.validation.graphics.AbstractXObjValidator#
-	 * checkMandatoryFields(java.util.List)
-	 */
-	@Override
-	protected void checkMandatoryFields() {
-		boolean lastMod = this.xobject.getItem(COSName.LAST_MODIFIED) != null;
-		boolean pieceInfo = this.xobject.getItem("PieceInfo") != null;
-		// type and subtype checked before to create the Validator.
-		if (lastMod ^ pieceInfo) {
-			context.addValidationError(new ValidationError(ERROR_GRAPHIC_MISSING_FIELD));
-			return;
-		}
-
-		COSBase bbBase = this.xobject.getItem(COSName.BBOX);
-		// ---- BBox is an Array (Rectangle)
-		if (bbBase == null || !COSUtils.isArray(bbBase, cosDocument)) {
-			context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_BBOX));
-			return;
-		}
-	}
-
-	/**
-	 * An Form XObject is a ContentStream. This method method uses an instance of
-	 * ContentStreamWrapper to check the Stream of this Form XObject.
-	 */
-	protected void validateXObjectContent() throws ValidationException {
-		PreflightPath vPath = context.getValidationPath();
-		ContentStreamWrapper csWrapper = new ContentStreamWrapper(context, vPath.getClosestPathElement(PDPage.class));
-		csWrapper.validXObjContentStream(pdXObj);
-	}
-
-	/**
-	 * A Form XObject may contain a Group object (Key =" Group"). If a Group
-	 * object is present, this method checks if the S entry is present and if its
-	 * value is different from "Transparency".
-	 * 
-	 * @throws ValidationException
-	 */
-	protected void checkGroup() throws ValidationException {
-		COSBase baseGroup = this.xobject.getItem(XOBJECT_DICTIONARY_KEY_GROUP);
-		COSDictionary groupDictionary = COSUtils.getAsDictionary(baseGroup, cosDocument);
-		if (groupDictionary != null) {
-			if (!XOBJECT_DICTIONARY_KEY_GROUP.equals(groupDictionary.getNameAsString(COSName.TYPE))) {
-				throw new ValidationException("The Group dictionary hasn't Group as Type value");
-			}
-
-			String sVal = groupDictionary.getNameAsString(COSName.S);
-			if (sVal == null || XOBJECT_DICTIONARY_VALUE_S_TRANSPARENCY.equals(sVal)) {
-				context.addValidationError(new ValidationError(ERROR_GRAPHIC_TRANSPARENCY_GROUP , "Group has a transparency S entry or the S entry is null."));
-				return;
-			}
-		}
-	}
-
-	/**
-	 * Check if there are no PS entry in the Form XObject dictionary
-	 */
-	protected void checkPS() {
-		// 6.2.4 and 6.2.5 no PS
-		if (this.xobject.getItem(COSName.getPDFName("PS")) != null) {
-			context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_KEY, "Unexpected 'PS' Key"));
-			return;
-		}
-	}
-
-	/**
-	 * Check the SUbtype2 entry according to the §6.2.5 of the ISO 190005-1:2005
-	 * specification.
-	 */
-	protected void checkSubtype2Value() {
-		// 6.2.5 if Subtype2, value not PS
-		if (this.xobject.getItem(COSName.getPDFName("Subtype2")) != null) {
-			if ("PS".equals(this.xobject.getNameAsString("Subtype2"))) {
-				context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY,"Unexpected 'PS' value for 'Subtype2' Key"));
-				return ;
-			}
-		}
-	}
-	
-	protected void validateXObjectResources() throws ValidationException {
-		PDResources resources = this.pdXObj.getResources();
-		if (resources != null) {
-			ContextHelper.validateElement(context, resources, RESOURCES_PROCESS);
-		}
-	}
+public class XObjFormValidator extends AbstractXObjValidator
+{
+    /**
+     * High level object which represents the XObjectForm
+     */
+    PDXObjectForm pdXObj = null;
+
+    public XObjFormValidator(PreflightContext context, PDXObjectForm xobj)
+    {
+        super(context, xobj.getCOSStream());
+        this.pdXObj = xobj;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see net.awl.edoc.pdfa.validation.graphics.AbstractXObjValidator#validate()
+     */
+    @Override
+    public void validate() throws ValidationException
+    {
+        super.validate();
+        checkGroup();
+        checkSubtype2Value();
+        validateXObjectResources();
+        validateXObjectContent();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @seenet.awl.edoc.pdfa.validation.graphics.AbstractXObjValidator# checkMandatoryFields(java.util.List)
+     */
+    @Override
+    protected void checkMandatoryFields()
+    {
+        boolean lastMod = this.xobject.getItem(COSName.LAST_MODIFIED) != null;
+        boolean pieceInfo = this.xobject.getItem("PieceInfo") != null;
+        // type and subtype checked before to create the Validator.
+        if (lastMod ^ pieceInfo)
+        {
+            context.addValidationError(new ValidationError(ERROR_GRAPHIC_MISSING_FIELD));
+            return;
+        }
+
+        COSBase bbBase = this.xobject.getItem(COSName.BBOX);
+        // ---- BBox is an Array (Rectangle)
+        if (bbBase == null || !COSUtils.isArray(bbBase, cosDocument))
+        {
+            context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_BBOX));
+            return;
+        }
+    }
+
+    /**
+     * An Form XObject is a ContentStream. This method method uses an instance of ContentStreamWrapper to check the
+     * Stream of this Form XObject.
+     */
+    protected void validateXObjectContent() throws ValidationException
+    {
+        PreflightPath vPath = context.getValidationPath();
+        ContentStreamWrapper csWrapper = new ContentStreamWrapper(context, vPath.getClosestPathElement(PDPage.class));
+        csWrapper.validXObjContentStream(pdXObj);
+    }
+
+    /**
+     * A Form XObject may contain a Group object (Key =" Group"). If a Group object is present, this method checks if
+     * the S entry is present and if its value is different from "Transparency".
+     * 
+     * @throws ValidationException
+     */
+    protected void checkGroup() throws ValidationException
+    {
+        COSBase baseGroup = this.xobject.getItem(XOBJECT_DICTIONARY_KEY_GROUP);
+        COSDictionary groupDictionary = COSUtils.getAsDictionary(baseGroup, cosDocument);
+        if (groupDictionary != null)
+        {
+            if (!XOBJECT_DICTIONARY_KEY_GROUP.equals(groupDictionary.getNameAsString(COSName.TYPE)))
+            {
+                throw new ValidationException("The Group dictionary hasn't Group as Type value");
+            }
+
+            String sVal = groupDictionary.getNameAsString(COSName.S);
+            if (sVal == null || XOBJECT_DICTIONARY_VALUE_S_TRANSPARENCY.equals(sVal))
+            {
+                context.addValidationError(new ValidationError(ERROR_GRAPHIC_TRANSPARENCY_GROUP,
+                        "Group has a transparency S entry or the S entry is null."));
+                return;
+            }
+        }
+    }
+
+    /**
+     * Check if there are no PS entry in the Form XObject dictionary
+     */
+    protected void checkPS()
+    {
+        // 6.2.4 and 6.2.5 no PS
+        if (this.xobject.getItem(COSName.getPDFName("PS")) != null)
+        {
+            context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_KEY, "Unexpected 'PS' Key"));
+            return;
+        }
+    }
+
+    /**
+     * Check the SUbtype2 entry according to the §6.2.5 of the ISO 190005-1:2005 specification.
+     */
+    protected void checkSubtype2Value()
+    {
+        // 6.2.5 if Subtype2, value not PS
+        if (this.xobject.getItem(COSName.getPDFName("Subtype2")) != null)
+        {
+            if ("PS".equals(this.xobject.getNameAsString("Subtype2")))
+            {
+                context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY,
+                        "Unexpected 'PS' value for 'Subtype2' Key"));
+                return;
+            }
+        }
+    }
+
+    protected void validateXObjectResources() throws ValidationException
+    {
+        PDResources resources = this.pdXObj.getResources();
+        if (resources != null)
+        {
+            ContextHelper.validateElement(context, resources, RESOURCES_PROCESS);
+        }
+    }
 
 }

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=1453416&r1=1453415&r2=1453416&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 Wed Mar  6 16:46:35 2013
@@ -47,112 +47,140 @@ import org.apache.pdfbox.preflight.utils
 /**
  * This class validates XObject with the Image subtype.
  */
-public class XObjImageValidator extends AbstractXObjValidator {
-	protected PDXObjectImage xImage = null;
+public class XObjImageValidator extends AbstractXObjValidator
+{
+    protected PDXObjectImage xImage = null;
+
+    public XObjImageValidator(PreflightContext context, PDXObjectImage xobj)
+    {
+        super(context, xobj.getCOSStream());
+        this.xImage = xobj;
+    }
+
+    @Override
+    protected void checkMandatoryFields()
+    {
+        boolean res = this.xobject.getItem(COSName.WIDTH) != null;
+        res = res && this.xobject.getItem(COSName.HEIGHT) != null;
+        // type and subtype checked before to create the Validator.
+        if (!res)
+        {
+            context.addValidationError(new ValidationError(ERROR_GRAPHIC_MISSING_FIELD));
+        }
+    }
+
+    /*
+     * 6.2.4 no Alternates
+     */
+    protected void checkAlternates() throws ValidationException
+    {
+        if (this.xobject.getItem("Alternates") != null)
+        {
+            context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_KEY, "Unexpected 'Alternates' Key"));
+        }
+    }
+
+    /*
+     * 6.2.4 if interpolates, value = false
+     */
+    protected void checkInterpolate() throws ValidationException
+    {
+        if (this.xobject.getItem("Interpolate") != null)
+        {
+            if (this.xobject.getBoolean("Interpolate", true))
+            {
+                context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY,
+                        "Unexpected 'true' value for 'Interpolate' Key"));
+            }
+        }
+    }
+
+    /*
+     * 6.2.4 Intent has specific values
+     */
+    protected void checkIntent() throws ValidationException
+    {
+        if (this.xobject.getItem("Intent") != null)
+        {
+            String s = this.xobject.getNameAsString("Intent");
+            if (!RenderingIntents.contains(s))
+            {
+                context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY,
+                        "Unexpected value '" + s + "' for Intent key in image"));
+            }
+        }
+    }
+
+    /*
+     * According to the PDF Reference file, there are some specific rules on following fields ColorSpace, Mask,
+     * ImageMask and BitsPerComponent. If ImageMask is set to true, ColorSpace and Mask entries are forbidden.
+     */
+    protected void checkColorSpaceAndImageMask() throws ValidationException
+    {
+        COSBase csImg = this.xobject.getItem(COSName.COLORSPACE);
+        COSBase bitsPerComp = this.xobject.getItem("BitsPerComponent");
+        COSBase mask = this.xobject.getItem(COSName.MASK);
+
+        if (isImageMaskTrue())
+        {
+            if (csImg != null || mask != null)
+            {
+                context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_KEY,
+                        "ImageMask entry is true, ColorSpace and Mask are forbidden."));
+            }
+
+            Integer bitsPerCompValue = COSUtils.getAsInteger(bitsPerComp, cosDocument);
+            if (bitsPerCompValue != 1)
+            {
+                context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY,
+                        "ImageMask entry is true, BitsPerComponent must be 1."));
+            }
+
+        }
+        else
+        {
+            try
+            {
+                PreflightConfiguration config = context.getConfig();
+                ColorSpaceHelperFactory csFact = config.getColorSpaceHelperFact();
+                PDColorSpace pdCS = PDColorSpaceFactory.createColorSpace(csImg);
+                ColorSpaceHelper csh = csFact.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.NO_PATTERN);
+                csh.validate();
+            }
+            catch (IOException e)
+            {
+                context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_UNKNOWN_COLOR_SPACE));
+            }
+        }
+    }
+
+    private boolean isImageMaskTrue()
+    {
+        COSBase imgMask = this.xobject.getItem("ImageMask");
+        if (imgMask != null && imgMask instanceof COSBoolean)
+        {
+            return ((COSBoolean) imgMask).getValue();
+        }
+        else
+        {
+            return false;
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see net.awl.edoc.pdfa.validation.graphics.AbstractXObjValidator#validate()
+     */
+    @Override
+    public void validate() throws ValidationException
+    {
+        super.validate();
+
+        checkAlternates();
+        checkInterpolate();
+        checkIntent();
 
-	public XObjImageValidator(PreflightContext context, PDXObjectImage xobj) {
-		super(context, xobj.getCOSStream());
-		this.xImage = xobj;
-	}
-
-	@Override
-	protected void checkMandatoryFields() {
-		boolean res = this.xobject.getItem(COSName.WIDTH) != null;
-		res = res && this.xobject.getItem(COSName.HEIGHT) != null;
-		// type and subtype checked before to create the Validator.
-		if (!res) {
-			context.addValidationError(new ValidationError(ERROR_GRAPHIC_MISSING_FIELD));
-		}
-	}
-
-	/*
-	 * 6.2.4 no Alternates
-	 */
-	protected void checkAlternates() throws ValidationException {
-		if (this.xobject.getItem("Alternates") != null) {
-			context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_KEY, "Unexpected 'Alternates' Key"));
-		}
-	}
-
-	/*
-	 * 6.2.4 if interpolates, value = false
-	 */
-	protected void checkInterpolate() throws ValidationException {
-		if (this.xobject.getItem("Interpolate") != null) {
-			if (this.xobject.getBoolean("Interpolate", true)) {
-				context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY, "Unexpected 'true' value for 'Interpolate' Key"));
-			}
-		}
-	}
-
-	/*
-	 * 6.2.4 Intent has specific values
-	 */
-	protected void checkIntent() throws ValidationException {
-		if (this.xobject.getItem("Intent") != null) {
-			String s = this.xobject.getNameAsString("Intent");
-			if (!RenderingIntents.contains(s)) {
-				context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY,
-						"Unexpected value '" + s + "' for Intent key in image"));
-			}
-		}
-	}
-
-	/*
-	 * According to the PDF Reference file, there are some specific rules on following fields
-	 * ColorSpace, Mask, ImageMask and BitsPerComponent.
-	 * If ImageMask is set to true, ColorSpace and Mask entries are forbidden. 
-	 */
-	protected void checkColorSpaceAndImageMask() throws ValidationException {
-		COSBase csImg = this.xobject.getItem(COSName.COLORSPACE);
-		COSBase bitsPerComp = this.xobject.getItem("BitsPerComponent");
-		COSBase mask = this.xobject.getItem(COSName.MASK);
-
-		if (isImageMaskTrue()) {
-			if ( csImg != null || mask != null) {
-				context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_KEY, "ImageMask entry is true, ColorSpace and Mask are forbidden."));
-			}
-
-			Integer bitsPerCompValue = COSUtils.getAsInteger(bitsPerComp, cosDocument);
-			if (bitsPerCompValue != 1 ) {
-				context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY, "ImageMask entry is true, BitsPerComponent must be 1."));
-			}
-
-		} else {
-			try {
-				PreflightConfiguration config = context.getConfig();
-				ColorSpaceHelperFactory csFact = config.getColorSpaceHelperFact();
-				PDColorSpace pdCS = PDColorSpaceFactory.createColorSpace(csImg);
-				ColorSpaceHelper csh = csFact.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.NO_PATTERN);
-				csh.validate();
-			} catch (IOException e) {
-				context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_UNKNOWN_COLOR_SPACE));
-			}
-		}
-	}
-
-	private boolean isImageMaskTrue() {
-		COSBase imgMask = this.xobject.getItem("ImageMask");
-		if (imgMask != null && imgMask instanceof COSBoolean) {
-			return ((COSBoolean) imgMask).getValue();
-		} else {
-			return false;
-		}
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see net.awl.edoc.pdfa.validation.graphics.AbstractXObjValidator#validate()
-	 */
-	@Override
-	public void validate() throws ValidationException {
-		super.validate();
-
-		checkAlternates();
-		checkInterpolate();
-		checkIntent();
-
-		checkColorSpaceAndImageMask();
-	}
+        checkColorSpaceAndImageMask();
+    }
 }

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjPostscriptValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjPostscriptValidator.java?rev=1453416&r1=1453415&r2=1453416&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjPostscriptValidator.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjPostscriptValidator.java Wed Mar  6 16:46:35 2013
@@ -25,32 +25,35 @@ import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.exception.ValidationException;
 
-public class XObjPostscriptValidator extends AbstractXObjValidator {
+public class XObjPostscriptValidator extends AbstractXObjValidator
+{
 
-  public XObjPostscriptValidator(PreflightContext context, COSStream xobj) {
-    super(context, xobj);
-  }
+    public XObjPostscriptValidator(PreflightContext context, COSStream xobj)
+    {
+        super(context, xobj);
+    }
 
-  /*
-   * (non-Javadoc)
-   * 
-   * @see net.awl.edoc.pdfa.validation.graphics.AbstractXObjValidator#validate()
-   */
-  @Override
-  public void validate() throws ValidationException {
-    super.validate();
-  }
+    /*
+     * (non-Javadoc)
+     * 
+     * @see net.awl.edoc.pdfa.validation.graphics.AbstractXObjValidator#validate()
+     */
+    @Override
+    public void validate() throws ValidationException
+    {
+        super.validate();
+    }
 
-  /*
-   * (non-Javadoc)
-   * 
-   * @seenet.awl.edoc.pdfa.validation.graphics.AbstractXObjValidator#
-   * checkMandatoryFields(java.util.List)
-   */
-  @Override
-  protected void checkMandatoryFields() {
-    // PostScript XObjects are forbidden. Whatever the result of this function,
-    // the validation will fail
-  }
+    /*
+     * (non-Javadoc)
+     * 
+     * @seenet.awl.edoc.pdfa.validation.graphics.AbstractXObjValidator# checkMandatoryFields(java.util.List)
+     */
+    @Override
+    protected void checkMandatoryFields()
+    {
+        // PostScript XObjects are forbidden. Whatever the result of this function,
+        // the validation will fail
+    }
 
 }

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjectValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjectValidator.java?rev=1453416&r1=1453415&r2=1453416&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjectValidator.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjectValidator.java Wed Mar  6 16:46:35 2013
@@ -23,11 +23,12 @@ package org.apache.pdfbox.preflight.xobj
 
 import org.apache.pdfbox.preflight.exception.ValidationException;
 
-
-public interface XObjectValidator {
-  /**
-   * Process the validation of the XObject.
-   * @throws ValidationException
-   */
-  public abstract void validate() throws ValidationException;
+public interface XObjectValidator
+{
+    /**
+     * Process the validation of the XObject.
+     * 
+     * @throws ValidationException
+     */
+    public abstract void validate() throws ValidationException;
 }

Modified: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/Benchmark.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/Benchmark.java?rev=1453416&r1=1453415&r2=1453416&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/Benchmark.java (original)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/Benchmark.java Wed Mar  6 16:46:35 2013
@@ -36,68 +36,78 @@ import org.apache.commons.io.IOUtils;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 import org.apache.pdfbox.preflight.parser.PreflightParser;
 
-public class Benchmark {
+public class Benchmark
+{
 
-	/**
-	 * @param args
-	 */
-	public static void main(String[] args) throws Exception {
-		if ( args.length < 3 ) {
-			System.err.println("Usage : Benchmark loop resultFile <file1 ... filen|dir>");
-			System.exit(255);
-		}
-
-		Integer loop = Integer.parseInt(args[0]);
-		FileWriter resFile = new FileWriter(new File(args[1]));
-
-		List<File> lfd = new ArrayList<File>();
-		for (int i = 2; i < args.length ; ++i) {
-			File fi = new File(args[i]);
-			if (fi.isDirectory()) {
-				Collection<File> cf = FileUtils.listFiles(fi, null, true); // Get All files contained by the dir
-				lfd.addAll(cf);
-			} else {
-				lfd.add(fi);
-			}
-		}
-
-		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.Z");
-
-		long startGTime = System.currentTimeMillis();
-		
-		int size = lfd.size();
-		for (int i = 0 ; i < loop ; i++) {
-			File file = lfd.get(i%size);
-			long startLTime = System.currentTimeMillis();
-			PreflightParser parser = new PreflightParser(new FileDataSource(file));
-  		parser.parse();
-  		PreflightDocument document = parser.getPreflightDocument();
-  		document.validate();
-			ValidationResult result = document.getResult();
-			if (!result.isValid()) {
-				resFile.write(file.getAbsolutePath() + " isn't PDF/A\n");
-				for (ValidationError error : result.getErrorsList()) {
-					resFile.write(error.getErrorCode() + " : " + error.getDetails() +"\n");
-				}
-			}
-			document.close();
-			long endLTime = System.currentTimeMillis();
-			resFile.write(file.getName() + " (ms) : " + (endLTime - startLTime) + "\n");
-			resFile.flush();
-		}
-
-		long endGTime = System.currentTimeMillis();
-
-		resFile.write("Start : " + sdf.format(new Date(startGTime)) +"\n");
-		resFile.write("End : " + sdf.format(new Date(endGTime)) +"\n");
-		resFile.write("Duration (ms) : " + (endGTime - startGTime) +"\n");
-		resFile.write("Average (ms) : " + (int)((endGTime - startGTime)/loop) +"\n");
-		
-		System.out.println("Start : " + sdf.format(new Date(startGTime)));
-		System.out.println("End : " + sdf.format(new Date(endGTime)));
-		System.out.println("Duration (ms) : " + (endGTime - startGTime));
-		System.out.println("Average (ms) : " + (int)((endGTime - startGTime)/loop));
-		resFile.flush();
-		IOUtils.closeQuietly(resFile);
-	}
-}
\ No newline at end of file
+    /**
+     * @param args
+     */
+    public static void main(String[] args) throws Exception
+    {
+        if (args.length < 3)
+        {
+            System.err.println("Usage : Benchmark loop resultFile <file1 ... filen|dir>");
+            System.exit(255);
+        }
+
+        Integer loop = Integer.parseInt(args[0]);
+        FileWriter resFile = new FileWriter(new File(args[1]));
+
+        List<File> lfd = new ArrayList<File>();
+        for (int i = 2; i < args.length; ++i)
+        {
+            File fi = new File(args[i]);
+            if (fi.isDirectory())
+            {
+                Collection<File> cf = FileUtils.listFiles(fi, null, true); // Get All files contained by the dir
+                lfd.addAll(cf);
+            }
+            else
+            {
+                lfd.add(fi);
+            }
+        }
+
+        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.Z");
+
+        long startGTime = System.currentTimeMillis();
+
+        int size = lfd.size();
+        for (int i = 0; i < loop; i++)
+        {
+            File file = lfd.get(i % size);
+            long startLTime = System.currentTimeMillis();
+            PreflightParser parser = new PreflightParser(new FileDataSource(file));
+            parser.parse();
+            PreflightDocument document = parser.getPreflightDocument();
+            document.validate();
+            ValidationResult result = document.getResult();
+            if (!result.isValid())
+            {
+                resFile.write(file.getAbsolutePath() + " isn't PDF/A\n");
+                for (ValidationError error : result.getErrorsList())
+                {
+                    resFile.write(error.getErrorCode() + " : " + error.getDetails() + "\n");
+                }
+            }
+            document.close();
+            long endLTime = System.currentTimeMillis();
+            resFile.write(file.getName() + " (ms) : " + (endLTime - startLTime) + "\n");
+            resFile.flush();
+        }
+
+        long endGTime = System.currentTimeMillis();
+
+        resFile.write("Start : " + sdf.format(new Date(startGTime)) + "\n");
+        resFile.write("End : " + sdf.format(new Date(endGTime)) + "\n");
+        resFile.write("Duration (ms) : " + (endGTime - startGTime) + "\n");
+        resFile.write("Average (ms) : " + (int) ((endGTime - startGTime) / loop) + "\n");
+
+        System.out.println("Start : " + sdf.format(new Date(startGTime)));
+        System.out.println("End : " + sdf.format(new Date(endGTime)));
+        System.out.println("Duration (ms) : " + (endGTime - startGTime));
+        System.out.println("Average (ms) : " + (int) ((endGTime - startGTime) / loop));
+        resFile.flush();
+        IOUtils.closeQuietly(resFile);
+    }
+}