You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ju...@apache.org on 2012/11/19 16:14:50 UTC

svn commit: r1411237 - /tika/trunk/tika-core/src/main/java/org/apache/tika/metadata/Metadata.java

Author: jukka
Date: Mon Nov 19 15:14:50 2012
New Revision: 1411237

URL: http://svn.apache.org/viewvc?rev=1411237&view=rev
Log:
TIKA-1027: Allow null values when setting metadata

Modified:
    tika/trunk/tika-core/src/main/java/org/apache/tika/metadata/Metadata.java

Modified: tika/trunk/tika-core/src/main/java/org/apache/tika/metadata/Metadata.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-core/src/main/java/org/apache/tika/metadata/Metadata.java?rev=1411237&r1=1411236&r2=1411237&view=diff
==============================================================================
--- tika/trunk/tika-core/src/main/java/org/apache/tika/metadata/Metadata.java (original)
+++ tika/trunk/tika-core/src/main/java/org/apache/tika/metadata/Metadata.java Mon Nov 19 15:14:50 2012
@@ -378,16 +378,19 @@ public class Metadata implements Creativ
 
     /**
      * Set metadata name/value. Associate the specified value to the specified
-     * metadata name. If some previous values were associated to this name, they
-     * are removed.
-     * 
-     * @param name
-     *          the metadata name.
-     * @param value
-     *          the metadata value.
+     * metadata name. If some previous values were associated to this name,
+     * they are removed. If the given value is <code>null</code>, then the
+     * metadata entry is removed.
+     *
+     * @param name the metadata name.
+     * @param value  the metadata value, or <code>null</code>
      */
     public void set(String name, String value) {
-        metadata.put(name, new String[] { value });
+        if (value != null) {
+            metadata.put(name, new String[] { value });
+        } else {
+            metadata.remove(name);
+        }
     }
 
     /**
@@ -485,7 +488,11 @@ public class Metadata implements Creativ
         if(property.getPrimaryProperty().getValueType() != Property.ValueType.DATE) {
             throw new PropertyTypeException(Property.ValueType.DATE, property.getPrimaryProperty().getValueType());
         }
-        set(property, formatDate(date));
+        String dateString = null;
+        if (date != null) {
+            dateString = formatDate(date);
+        }
+        set(property, dateString);
     }
 
     /**