xmlgraphics-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r893118 - in /xmlgraphics/commons/trunk: src/java/org/apache/xmlgraphics/xmp/XMPArray.java test/java/org/apache/xmlgraphics/xmp/XMPPropertyTest.java
Date Tue, 22 Dec 2009 09:14:05 GMT
Author: jeremias
Date: Tue Dec 22 09:14:05 2009
New Revision: 893118

URL: http://svn.apache.org/viewvc?rev=893118&view=rev
Log:
Bugfix: non-lang-qualified array value was not treated the same as one lang-qualified with
"x-default".

Modified:
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPArray.java
    xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPPropertyTest.java

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPArray.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPArray.java?rev=893118&r1=893117&r2=893118&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPArray.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPArray.java Tue Dec 22
09:14:05 2009
@@ -126,17 +126,17 @@
     }
 
     /**
-     * Removes a language-dependent value
+     * Removes a language-dependent value.
      * @param lang the language ("x-default" for the default value)
      * @return the removed value (or null if no value was set)
      */
     public String removeLangValue(String lang) {
         if (lang == null || "".equals(lang)) {
-            return null;
+            lang = XMPConstants.DEFAULT_LANGUAGE;
         }
         for (int i = 0, c = values.size(); i < c; i++) {
             String l = (String)xmllang.get(i);
-            if (lang.equals(l)) {
+            if ((XMPConstants.DEFAULT_LANGUAGE.equals(lang) && l == null) || lang.equals(l))
{
                 String value = (String)values.remove(i);
                 xmllang.remove(i);
                 return value;

Modified: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPPropertyTest.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPPropertyTest.java?rev=893118&r1=893117&r2=893118&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPPropertyTest.java (original)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPPropertyTest.java Tue
Dec 22 09:14:05 2009
@@ -19,6 +19,7 @@
 
 package org.apache.xmlgraphics.xmp;
 
+import java.io.StringWriter;
 import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Date;
@@ -26,8 +27,12 @@
 import java.util.Set;
 import java.util.TimeZone;
 
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
 import junit.framework.TestCase;
 
+import org.apache.xmlgraphics.util.QName;
 import org.apache.xmlgraphics.xmp.schemas.DublinCoreAdapter;
 import org.apache.xmlgraphics.xmp.schemas.DublinCoreSchema;
 import org.apache.xmlgraphics.xmp.schemas.XMPBasicAdapter;
@@ -82,6 +87,26 @@
         assertNull(title);
     }
 
+    public void testReplaceLangAlt() throws Exception {
+        Metadata xmp = new Metadata();
+        DublinCoreAdapter dc = DublinCoreSchema.getAdapter(xmp);
+        dc.setTitle("Default title");
+        StringWriter writer = new StringWriter();
+        XMPSerializer.writeXML(xmp, new StreamResult(writer));
+        String xmpString = writer.toString();
+        xmp = XMPParser.parseXMP(new StreamSource(new java.io.StringReader(xmpString)));
+        dc = DublinCoreSchema.getAdapter(xmp);
+        assertEquals("Default title", dc.getTitle());
+        dc.setTitle("Updated title");
+        XMPProperty prop = xmp.getProperty(new QName(DublinCoreSchema.NAMESPACE, "title"));
+        XMPArray array = prop.getArrayValue();
+        assertNotNull(array);
+        //Check that only one title is present. There used to be a bug that didn't set the
+        //non-qualified value equal to the value qualified with "x-default".
+        assertEquals(1, array.getSize());
+        assertEquals("Updated title", array.getValue(0));
+    }
+
     public void testPropertyValues() throws Exception {
         Metadata xmp = new Metadata();
         DublinCoreAdapter dc = DublinCoreSchema.getAdapter(xmp);



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org


Mime
View raw message