pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msahy...@apache.org
Subject svn commit: r1656216 - /pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/metadata/SynchronizedMetaDataValidation.java
Date Sat, 31 Jan 2015 17:17:20 GMT
Author: msahyoun
Date: Sat Jan 31 17:17:20 2015
New Revision: 1656216

URL: http://svn.apache.org/r1656216
Log:
PDFBOX-2619 check for time zone information

Modified:
    pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/metadata/SynchronizedMetaDataValidation.java

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/metadata/SynchronizedMetaDataValidation.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/metadata/SynchronizedMetaDataValidation.java?rev=1656216&r1=1656215&r2=1656216&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/metadata/SynchronizedMetaDataValidation.java
(original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/metadata/SynchronizedMetaDataValidation.java
Sat Jan 31 17:17:20 2015
@@ -26,6 +26,7 @@ import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Iterator;
 import java.util.List;
+import java.util.regex.Pattern;
 
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDDocumentInformation;
@@ -379,6 +380,11 @@ public class SynchronizedMetaDataValidat
                     {
                         ve.add(unsynchronizedMetaDataError("CreationDate"));
                     }
+                    else if (hasTimeZone(xmp.getCreateDateProperty().getRawValue()) != 
+                            hasTimeZone(dico.getPropertyStringValue("CreationDate")))
+                    {
+                        ve.add(unsynchronizedMetaDataError("CreationDate"));
+                    }
                 }
 
             }
@@ -424,6 +430,11 @@ public class SynchronizedMetaDataValidat
 
                             ve.add(unsynchronizedMetaDataError("ModificationDate"));
                         }
+                        else if (hasTimeZone(xmp.getModifyDateProperty().getRawValue()) !=

+                                hasTimeZone(dico.getPropertyStringValue("ModDate")))
+                        {
+                            ve.add(unsynchronizedMetaDataError("ModificationDate"));
+                        }
                     }
 
                 }
@@ -600,4 +611,30 @@ public class SynchronizedMetaDataValidat
         }
         return string.substring(0, length);
     }
+    
+    /**
+     * Verify if the date string has time zone information.
+     * <p>
+     * <strong>This method doesn't do a complete parsing as
+     * this is a helper AFTER a date has proven to be valid
+     * </strong>
+     * </p>
+     * 
+     * @param date
+     * @return the validation result
+     */
+    private boolean hasTimeZone(Object date)
+    {
+        final String datePattern = "^D:.*[Z]$|^D:.*\\+.*|^\\d{4}.*T.*Z$|^\\d{4}.*T.*[\\+]\\d{2}.*$";
+        if (date instanceof Calendar)
+        {
+            // A Java Calendar object always has a time zone information
+            return true;
+        }
+        else if (date instanceof String)
+        {
+            return Pattern.matches(datePattern, (String) date);
+        }
+        return false;
+    }
 }



Mime
View raw message