You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2014/11/18 16:01:59 UTC

svn commit: r1640358 - in /pdfbox/branches/1.8: ./ preflight/src/main/java/org/apache/pdfbox/preflight/metadata/ preflight/src/test/java/org/apache/pdfbox/preflight/metadata/ preflight/src/test/resources/org/apache/pdfbox/

Author: lehmi
Date: Tue Nov 18 15:01:58 2014
New Revision: 1640358

URL: http://svn.apache.org/r1640358
Log:
PDFBOX-2503: don't ignore all trailing space alike characters, but NUL; added some test cases for metadata validation based on Maruans testfiles

Added:
    pdfbox/branches/1.8/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestMetadataFiles.java
      - copied unchanged from r1640356, pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestMetadataFiles.java
    pdfbox/branches/1.8/preflight/src/test/resources/org/apache/pdfbox/
      - copied from r1640356, pdfbox/trunk/preflight/src/test/resources/org/apache/pdfbox/
Modified:
    pdfbox/branches/1.8/   (props changed)
    pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/metadata/SynchronizedMetaDataValidation.java

Propchange: pdfbox/branches/1.8/
------------------------------------------------------------------------------
  Merged /pdfbox/trunk:r1640355-1640356

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=1640358&r1=1640357&r2=1640358&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 Tue Nov 18 15:01:58 2014
@@ -64,8 +64,8 @@ public class SynchronizedMetaDataValidat
         String title = dico.getTitle();
         if (title != null)
         {
-            // automatically trim the provided string value
-            title = title.trim();
+            // automatically strip trailing Nul values
+            title = removeTrailingNul(title);
             if (dc != null)
             {
                 // Check the x-default value, if not found, check with the first value
@@ -135,8 +135,8 @@ public class SynchronizedMetaDataValidat
         String author = dico.getAuthor();
         if (author != null)
         {
-            // automatically trim the provided string value
-            author = author.trim();
+            // automatically strip trailing Nul values
+            author = removeTrailingNul(author);
             if (dc != null)
             {
                 if (dc.getCreatorsProperty() != null)
@@ -188,8 +188,8 @@ public class SynchronizedMetaDataValidat
         String subject = dico.getSubject();
         if (subject != null)
         {
-            // automatically trim the provided string value
-            subject = subject.trim();
+            // automatically strip trailing Nul values
+            subject = removeTrailingNul(subject);
             if (dc != null)
             {
                 // PDF/A Conformance Erratum (2007) specifies XMP Subject
@@ -237,8 +237,8 @@ public class SynchronizedMetaDataValidat
         String keyword = dico.getKeywords();
         if (keyword != null)
         {
-            // automatically trim the provided string value
-            keyword = keyword.trim();
+            // automatically strip trailing Nul values
+            keyword = removeTrailingNul(keyword);
             if (pdf != null)
             {
                 if (pdf.getKeywordsProperty() == null)
@@ -275,8 +275,8 @@ public class SynchronizedMetaDataValidat
         String producer = dico.getProducer();
         if (producer != null)
         {
-            // automatically trim the provided string value
-            producer = producer.trim();
+            // automatically strip trailing Nul values
+            producer = removeTrailingNul(producer);
             if (pdf != null)
             {
                 if (pdf.getProducerProperty() == null)
@@ -315,8 +315,8 @@ public class SynchronizedMetaDataValidat
         String creatorTool = dico.getCreator();
         if (creatorTool != null)
         {
-            // automatically trim the provided string value
-            creatorTool = creatorTool.trim();
+            // automatically strip trailing Nul values
+            creatorTool = removeTrailingNul(creatorTool);
             if (xmp != null)
             {
                 if (xmp.getCreatorToolProperty() == null)
@@ -582,4 +582,22 @@ public class SynchronizedMetaDataValidat
                 .append(details).append(")");
         return new ValidationError(PreflightConstants.ERROR_METADATA_MISMATCH, sb.toString());
     }
+    
+    /**
+     * A given string from the DocumentInformation dictionary may have some trailing Nul values 
+     * which have to be stripped.
+     *  
+     * @param string to be stripped
+     * @return the stripped string
+     */
+    private String removeTrailingNul(String string)
+    {
+        // remove trailing NUL values
+        int length = string.length();
+        while(length > 0 && (int)string.charAt(length-1) == 0)
+        {
+            length--;
+        }
+        return string.substring(0, length);
+    }
 }