pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1838678 - in /pdfbox/trunk/preflight/src: main/java/org/apache/pdfbox/preflight/metadata/SynchronizedMetaDataValidation.java test/java/org/apache/pdfbox/preflight/metadata/TestSynchronizedMetadataValidation.java
Date Wed, 22 Aug 2018 19:32:04 GMT
Author: tilman
Date: Wed Aug 22 19:32:03 2018
New Revision: 1838678

URL: http://svn.apache.org/viewvc?rev=1838678&view=rev
Log:
PDFBOX-4292: compare calendar objects instead of ISO 8601 values to avoid false differences
when time zones are different, as suggested by Alonso Gonzalez; set milliseconds to 0 in test
for xmp values because these milliseconds are kept, but not in COS values; add a test

Modified:
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/metadata/SynchronizedMetaDataValidation.java
    pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestSynchronizedMetadataValidation.java

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/metadata/SynchronizedMetaDataValidation.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/metadata/SynchronizedMetaDataValidation.java?rev=1838678&r1=1838677&r2=1838678&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/metadata/SynchronizedMetaDataValidation.java
(original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/metadata/SynchronizedMetaDataValidation.java
Wed Aug 22 19:32:03 2018
@@ -35,7 +35,6 @@ import org.apache.pdfbox.pdmodel.PDDocum
 import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 import org.apache.pdfbox.preflight.exception.ValidationException;
-import org.apache.xmpbox.DateConverter;
 import org.apache.xmpbox.XMPMetadata;
 import org.apache.xmpbox.schema.AdobePDFSchema;
 import org.apache.xmpbox.schema.DublinCoreSchema;
@@ -352,7 +351,7 @@ public class SynchronizedMetaDataValidat
                 }
                 else
                 {
-                    if (!DateConverter.toISO8601(xmpCreationDate).equals(DateConverter.toISO8601(creationDate)))
+                    if (xmpCreationDate.compareTo(creationDate) != 0)
                     {
                         ve.add(unsynchronizedMetaDataError("CreationDate"));
                     }
@@ -395,7 +394,7 @@ public class SynchronizedMetaDataValidat
                 }
                 else
                 {
-                    if (!DateConverter.toISO8601(xmpModifyDate).equals(DateConverter.toISO8601(modifyDate)))
+                    if (xmpModifyDate.compareTo(modifyDate) != 0)
                     {
                         ve.add(unsynchronizedMetaDataError("ModificationDate"));
                     }

Modified: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestSynchronizedMetadataValidation.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestSynchronizedMetadataValidation.java?rev=1838678&r1=1838677&r2=1838678&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestSynchronizedMetadataValidation.java
(original)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestSynchronizedMetadataValidation.java
Wed Aug 22 19:32:03 2018
@@ -123,14 +123,7 @@ public class TestSynchronizedMetadataVal
     @Test
     public void testEmptyXMP() throws Exception
     {
-        title = "TITLE";
-        author = "AUTHOR(S)";
-        subject = "SUBJECTS";
-        keywords = "KEYWORD(S)";
-        creator = "CREATOR";
-        producer = "PRODUCER";
-        creationDate = Calendar.getInstance();
-        modifyDate = Calendar.getInstance();
+        initValues();
 
         // Writing info in Document Information dictionary
         // TITLE
@@ -173,14 +166,7 @@ public class TestSynchronizedMetadataVal
     @Test
     public void testEmptyXMPSchemas() throws Exception
     {
-        title = "TITLE";
-        author = "AUTHOR(S)";
-        subject = "SUBJECTS";
-        keywords = "KEYWORD(S)";
-        creator = "CREATOR";
-        producer = "PRODUCER";
-        creationDate = Calendar.getInstance();
-        modifyDate = Calendar.getInstance();
+        initValues();
 
         // building temporary XMP metadata (but empty)
         metadata.createAndAddDublinCoreSchema();
@@ -375,14 +361,7 @@ public class TestSynchronizedMetadataVal
     @Test
     public void testAllInfoSynhcronized() throws Exception
     {
-        title = "TITLE";
-        author = "AUTHOR(S)";
-        subject = "SUBJECTS";
-        keywords = "KEYWORD(S)";
-        creator = "CREATOR";
-        producer = "PRODUCER";
-        creationDate = Calendar.getInstance();
-        modifyDate = Calendar.getInstance();
+        initValues();
 
         // building temporary XMP metadata
         DublinCoreSchema dc = metadata.createAndAddDublinCoreSchema();
@@ -447,14 +426,7 @@ public class TestSynchronizedMetadataVal
     @Test
     public void testBadPrefixSchemas() throws Exception
     {
-        title = "TITLE";
-        author = "AUTHOR(S)";
-        subject = "SUBJECTS";
-        keywords = "KEYWORD(S)";
-        creator = "CREATOR";
-        producer = "PRODUCER";
-        creationDate = Calendar.getInstance();
-        modifyDate = Calendar.getInstance();
+        initValues();
 
         // building temporary XMP metadata
         DublinCoreSchema dc = new DublinCoreSchema(metadata, "dctest");
@@ -514,14 +486,7 @@ public class TestSynchronizedMetadataVal
     @Test
     public void testdoublePrefixSchemas() throws Exception
     {
-        title = "TITLE";
-        author = "AUTHOR(S)";
-        subject = "SUBJECTS";
-        keywords = "KEYWORD(S)";
-        creator = "CREATOR";
-        producer = "PRODUCER";
-        creationDate = Calendar.getInstance();
-        modifyDate = Calendar.getInstance();
+        initValues();
 
         // building temporary XMP metadata
         DublinCoreSchema dc = metadata.createAndAddDublinCoreSchema();
@@ -575,7 +540,40 @@ public class TestSynchronizedMetadataVal
         {
             throw new Exception(e.getMessage());
         }
+    }
+
+    /**
+     * Tests that two date values, which are from different time zones but
+     * really identical, are detected as such.
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testPDFBox4292() throws Exception
+    {
+        initValues();
+
+        Calendar cal1 = org.apache.pdfbox.util.DateConverter.toCalendar("20180817115837+02'00'");
+        Calendar cal2 = org.apache.xmpbox.DateConverter.toCalendar("2018-08-17T09:58:37Z");
+
+        XMPBasicSchema xmp = metadata.createAndAddXMPBasicSchema();
+
+        dico.setCreationDate(cal1);
+        xmp.setCreateDate(cal2);
+        dico.setModificationDate(cal1);
+        xmp.setModifyDate(cal2);
 
+        // Launching synchronization test
+        try
+        {
+            ve = sync.validateMetadataSynchronization(doc, metadata);
+            // Test unsychronized value
+            Assert.assertEquals(0, ve.size());
+        }
+        catch (ValidationException e)
+        {
+            throw new Exception(e.getMessage());
+        }
     }
 
     @After
@@ -595,4 +593,21 @@ public class TestSynchronizedMetadataVal
          */
     }
 
+    private void initValues()
+    {
+        title = "TITLE";
+        author = "AUTHOR(S)";
+        subject = "SUBJECTS";
+        keywords = "KEYWORD(S)";
+        creator = "CREATOR";
+        producer = "PRODUCER";
+        creationDate = Calendar.getInstance();
+        modifyDate = Calendar.getInstance();
+
+        // PDFBOX-4292: because xmp keeps the milliseconds before writing to XML,
+        // but COS doesn't, tests would fail when calendar values are compared
+        // so reset the milliseconds. 
+        creationDate.set(Calendar.MILLISECOND, 0);
+        modifyDate.set(Calendar.MILLISECOND, 0);
+    }
 }



Mime
View raw message