You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by je...@apache.org on 2009/12/11 21:36:37 UTC
svn commit: r889803 - in /xmlgraphics/commons/trunk: examples/java/xmp/
src/java/org/apache/xmlgraphics/xmp/ test/java/org/apache/xmlgraphics/xmp/
Author: jeremias
Date: Fri Dec 11 20:36:36 2009
New Revision: 889803
URL: http://svn.apache.org/viewvc?rev=889803&view=rev
Log:
More test coverage.
Fixed a few smaller bugs.
Made null values and empty strings handling more uniform.
Removed XMPProperty.clear(). Was a bad idea.
Added:
xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/empty-values.xmp (with props)
Modified:
xmlgraphics/commons/trunk/examples/java/xmp/MetadataFromScratch.java
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPArray.java
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPProperty.java
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPSchemaAdapter.java
xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPParserTest.java
xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPPropertyTest.java
Modified: xmlgraphics/commons/trunk/examples/java/xmp/MetadataFromScratch.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/examples/java/xmp/MetadataFromScratch.java?rev=889803&r1=889802&r2=889803&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/examples/java/xmp/MetadataFromScratch.java (original)
+++ xmlgraphics/commons/trunk/examples/java/xmp/MetadataFromScratch.java Fri Dec 11 20:36:36 2009
@@ -24,10 +24,11 @@
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.stream.StreamResult;
+import org.xml.sax.SAXException;
+
import org.apache.xmlgraphics.xmp.Metadata;
import org.apache.xmlgraphics.xmp.XMPSerializer;
import org.apache.xmlgraphics.xmp.schemas.DublinCoreAdapter;
-import org.xml.sax.SAXException;
/**
* This example shows how to build an XMP metadata file from scratch in Java.
@@ -41,6 +42,8 @@
dc.setTitle("de", "Der Herr der Ringe");
dc.setTitle("en", "Lord of the Rings");
dc.addDate(new Date());
+ dc.setFormat("application/pdf");
+ dc.addCreator("J.R.R. Tolkien");
StreamResult res = new StreamResult(System.out);
XMPSerializer.writeXML(meta, res);
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=889803&r1=889802&r2=889803&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 Fri Dec 11 20:36:36 2009
@@ -189,6 +189,14 @@
}
/**
+ * Indicates whether the array is empty or not.
+ * @return true if the array is empty
+ */
+ public boolean isEmpty() {
+ return getSize() == 0;
+ }
+
+ /**
* Converts the array to an object array.
* @return an object array of all values in the array
*/
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPProperty.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPProperty.java?rev=889803&r1=889802&r2=889803&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPProperty.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPProperty.java Fri Dec 11 20:36:36 2009
@@ -76,14 +76,6 @@
}
/**
- * Resets this property to no value.
- */
- public void clear() {
- setValue(null);
- setXMLLang(null);
- }
-
- /**
* Sets the xml:lang value for this property
* @param lang the language ("x-default" for the default language, null to make the value
* language-independent)
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPSchemaAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPSchemaAdapter.java?rev=889803&r1=889802&r2=889803&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPSchemaAdapter.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPSchemaAdapter.java Fri Dec 11 20:36:36 2009
@@ -80,11 +80,8 @@
}
QName name = getQName(propName);
XMPProperty prop = meta.getProperty(name);
- XMPArray array;
if (prop == null) {
- array = new XMPArray(arrayType);
- array.add(value);
- prop = new XMPProperty(name, array);
+ prop = new XMPProperty(name, value);
meta.setProperty(prop);
} else {
prop.convertSimpleValueToArray(arrayType);
@@ -108,7 +105,7 @@
if (prop.isArray()) {
XMPArray arr = prop.getArrayValue();
boolean removed = arr.remove(value);
- if (arr.getSize() == 0) {
+ if (arr.isEmpty()) {
meta.removeProperty(name);
}
return removed;
@@ -287,14 +284,22 @@
XMPProperty prop = meta.getProperty(name);
XMPArray array;
if (prop == null) {
- array = new XMPArray(XMPArrayType.ALT);
- array.add(value, lang);
- prop = new XMPProperty(name, array);
- meta.setProperty(prop);
+ if (value != null && value.length() > 0) {
+ prop = new XMPProperty(name, value);
+ prop.setXMLLang(lang);
+ meta.setProperty(prop);
+ }
} else {
prop.convertSimpleValueToArray(XMPArrayType.ALT);
- removeLangAlt(lang, propName);
- prop.getArrayValue().add(value, lang);
+ array = prop.getArrayValue();
+ array.removeLangValue(lang);
+ if (value != null && value.length() > 0) {
+ array.add(value, lang);
+ } else {
+ if (array.isEmpty()) {
+ meta.removeProperty(name);
+ }
+ }
}
}
@@ -306,13 +311,17 @@
protected void setValue(String propName, String value) {
QName name = getQName(propName);
XMPProperty prop = meta.getProperty(name);
- if (prop == null && value != null && value.length() > 0) {
- prop = new XMPProperty(name, value);
- meta.setProperty(prop);
- } else if (value != null) {
- prop.setValue(value);
+ if (value != null && value.length() > 0) {
+ if (prop != null) {
+ prop.setValue(value);
+ } else {
+ prop = new XMPProperty(name, value);
+ meta.setProperty(prop);
+ }
} else {
- meta.removeProperty(name);
+ if (prop != null) {
+ meta.removeProperty(name);
+ }
}
}
@@ -345,14 +354,14 @@
array = prop.getArrayValue();
if (array != null) {
String removed = array.removeLangValue(lang);
- if (array.getSize() == 0) {
+ if (array.isEmpty()) {
meta.removeProperty(name);
}
return removed;
} else {
String removed = prop.getValue().toString();
if (lang.equals(prop.getXMLLang())) {
- prop.clear();
+ meta.removeProperty(name);
}
return removed;
}
Modified: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPParserTest.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPParserTest.java?rev=889803&r1=889802&r2=889803&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPParserTest.java (original)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPParserTest.java Fri Dec 11 20:36:36 2009
@@ -164,4 +164,19 @@
assertEquals(cal.getTime(), dcAdapter.getDate());
}
+ public void testParseEmptyValues() throws Exception {
+ URL url = getClass().getResource("empty-values.xmp");
+ Metadata meta = XMPParser.parseXMP(url);
+
+ DublinCoreAdapter dc = DublinCoreSchema.getAdapter(meta);
+ String title = dc.getTitle();
+ assertEquals("empty", title);
+
+ title = dc.getTitle("fr"); //Does not exist
+ assertNull(title);
+
+ title = dc.getTitle("de");
+ assertNull(title); //Empty value treated same as not existant
+ }
+
}
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=889803&r1=889802&r2=889803&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 Fri Dec 11 20:36:36 2009
@@ -19,10 +19,17 @@
package org.apache.xmlgraphics.xmp;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+
import junit.framework.TestCase;
import org.apache.xmlgraphics.xmp.schemas.DublinCoreAdapter;
import org.apache.xmlgraphics.xmp.schemas.DublinCoreSchema;
+import org.apache.xmlgraphics.xmp.schemas.XMPBasicAdapter;
+import org.apache.xmlgraphics.xmp.schemas.XMPBasicSchema;
/**
* Tests property access methods.
@@ -33,9 +40,15 @@
Metadata xmp = new Metadata();
DublinCoreAdapter dc = DublinCoreSchema.getAdapter(xmp);
assertNull(dc.getContributors());
+
dc.addContributor("Contributor1");
assertEquals(1, dc.getContributors().length);
assertEquals("Contributor1", dc.getContributors()[0]);
+ dc.removeContributor("Contributor1");
+ assertNull(dc.getContributors());
+
+ dc.addContributor("Contributor1");
+ assertEquals(1, dc.getContributors().length);
dc.addContributor("Contributor2");
assertEquals(2, dc.getContributors().length);
assertFalse(dc.removeContributor("DoesNotExist"));
@@ -45,23 +58,81 @@
assertFalse(dc.removeContributor("Contributor2"));
assertNull(dc.getContributors());
}
-
+
public void testPropertyRemovalLangAlt() throws Exception {
Metadata xmp = new Metadata();
DublinCoreAdapter dc = DublinCoreSchema.getAdapter(xmp);
//dc:title is a "Lang Alt"
dc.setTitle("en", "The title");
- dc.setTitle("de", "Der Titel");
String title = dc.removeTitle("en");
assertEquals("The title", title);
+ dc.setTitle("en", "The title");
+ dc.setTitle("de", "Der Titel");
+ title = dc.removeTitle("en");
+ assertEquals("The title", title);
title = dc.removeTitle("en");
assertNull(title);
-
+
title = dc.removeTitle("de");
assertEquals("Der Titel", title);
title = dc.removeTitle("de");
assertNull(title);
}
+ public void testPropertyValues() throws Exception {
+ Metadata xmp = new Metadata();
+ DublinCoreAdapter dc = DublinCoreSchema.getAdapter(xmp);
+
+ String format = dc.getFormat();
+ assertNull(format);
+
+ dc.setFormat("application/pdf");
+ format = dc.getFormat();
+ assertEquals("application/pdf", format);
+
+ dc.setFormat("image/jpeg");
+ format = dc.getFormat();
+ assertEquals("image/jpeg", format);
+
+ dc.setFormat(null);
+ format = dc.getFormat();
+ assertNull(format);
+
+ dc.setFormat(""); //Empty string same as null value
+ format = dc.getFormat();
+ assertNull(format);
+
+ dc.setTitle("title");
+ String title = dc.getTitle();
+ assertEquals("title", title);
+
+ dc.setTitle("Titel");
+ title = dc.getTitle();
+ assertEquals("Titel", title);
+
+ dc.setTitle(null);
+ title = dc.getTitle();
+ assertNull(title);
+
+ dc.setTitle("");
+ title = dc.getTitle();
+ assertNull(title);
+ }
+
+ public void testDates() throws Exception {
+ Metadata xmp = new Metadata();
+ XMPBasicAdapter basic = XMPBasicSchema.getAdapter(xmp);
+
+ Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.ENGLISH);
+ cal.set(2008, Calendar.FEBRUARY, 07, 15, 11, 07);
+ cal.set(Calendar.MILLISECOND, 0);
+ Date dt = cal.getTime();
+
+ assertNull(basic.getCreateDate());
+ basic.setCreateDate(dt);
+ Date dt2 = basic.getCreateDate();
+ assertEquals(dt2, dt);
+ }
+
}
Added: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/empty-values.xmp
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/empty-values.xmp?rev=889803&view=auto
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/empty-values.xmp (added)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/empty-values.xmp Fri Dec 11 20:36:36 2009
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<x:xmpmeta xmlns:x="adobe:ns:meta/">
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <rdf:Description xmlns:dc="http://purl.org/dc/elements/1.1/" rdf:about="">
+ <dc:title>
+ <rdf:Alt>
+ <rdf:li xml:lang="x-default">empty</rdf:li>
+ <rdf:li xml:lang="de"></rdf:li>
+ </rdf:Alt>
+ </dc:title>
+ </rdf:Description>
+ </rdf:RDF>
+</x:xmpmeta>
Propchange: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/empty-values.xmp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/empty-values.xmp
------------------------------------------------------------------------------
svn:keywords = Id
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org