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 2008/11/01 10:15:15 UTC
svn commit: r709661 - in /xmlgraphics/commons/trunk:
src/java/org/apache/xmlgraphics/xmp/
src/java/org/apache/xmlgraphics/xmp/schemas/
test/java/org/apache/xmlgraphics/xmp/
Author: jeremias
Date: Sat Nov 1 02:15:15 2008
New Revision: 709661
URL: http://svn.apache.org/viewvc?rev=709661&view=rev
Log:
XMP: Added support for dc:date.
Added:
xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/test-dates.xmp (with props)
Modified:
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPSchemaAdapter.java
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/schemas/DublinCoreAdapter.java
xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPParserTest.java
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=709661&r1=709660&r2=709661&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 Sat Nov 1 02:15:15 2008
@@ -37,7 +37,7 @@
/** the Metadata object this schema instance operates on */
protected Metadata meta;
private XMPSchema schema;
-
+
/**
* Main constructor.
* @param meta the Metadata object to wrao
@@ -53,12 +53,12 @@
this.meta = meta;
this.schema = schema;
}
-
+
/** @return the XMP schema associated with this adapter */
public XMPSchema getSchema() {
return this.schema;
}
-
+
/**
* Returns the QName for a given property
* @param propName the property name
@@ -122,7 +122,7 @@
df.setTimeZone(TimeZone.getTimeZone("GMT"));
return df;
}
-
+
/**
* Formats a Date using ISO 8601 format in the given time zone.
* @param dt the date
@@ -135,13 +135,13 @@
cal.setTime(dt);
int offset = cal.get(Calendar.ZONE_OFFSET);
offset += cal.get(Calendar.DST_OFFSET);
-
+
//DateFormat is operating on GMT so adjust for time zone offset
Date dt1 = new Date(dt.getTime() + offset);
StringBuffer sb = new StringBuffer(createPseudoISO8601DateFormat().format(dt1));
offset /= (1000 * 60); //Convert to minutes
-
+
if (offset == 0) {
sb.append('Z');
} else {
@@ -162,10 +162,10 @@
}
sb.append(zoneOffsetMinutes);
}
-
+
return sb.toString();
}
-
+
/**
* Parses an ISO 8601 date and time value.
* @param dt the date and time value as an ISO 8601 string
@@ -214,7 +214,7 @@
String dt = formatISO8601Date(value);
addStringToSeq(propName, dt);
}
-
+
/**
* Set a date value.
* @param propName the property name
@@ -238,7 +238,7 @@
return parseISO8601Date(dt);
}
}
-
+
/**
* Sets a language-dependent value.
* @param propName the property name
@@ -315,7 +315,7 @@
}
}
}
-
+
/**
* Returns a language-dependent value. If the value in the requested language is not available
* the value for the default language is returned.
@@ -374,5 +374,27 @@
return res;
}
-
+ /**
+ * Returns a Date array representation of the property's values.
+ * @param propName the property name
+ * @return the Date array or null if the property isn't set
+ */
+ protected Date[] getDateArray(String propName) {
+ Object[] arr = getObjectArray(propName);
+ if (arr == null) {
+ return null;
+ }
+ Date[] res = new Date[arr.length];
+ for (int i = 0, c = res.length; i < c; i++) {
+ Object obj = arr[i];
+ if (obj instanceof Date) {
+ res[i] = (Date)((Date)obj).clone();
+ } else {
+ res[i] = parseISO8601Date(obj.toString());
+ }
+ }
+ return res;
+ }
+
+
}
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/schemas/DublinCoreAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/schemas/DublinCoreAdapter.java?rev=709661&r1=709660&r2=709661&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/schemas/DublinCoreAdapter.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/schemas/DublinCoreAdapter.java Sat Nov 1 02:15:15 2008
@@ -29,7 +29,7 @@
* Schema adapter implementation for the Dublin Core schema.
* <p>
* Note: In Adobe's XMP specification dc:subject is defined as "bag Text", but in PDF/A-1 it is
- * defined as "Text". Here it is implemented as "bag Text".
+ * defined as "Text". Here it is implemented as "bag Text".
*/
public class DublinCoreAdapter extends XMPSchemaAdapter {
@@ -39,7 +39,7 @@
private static final String TITLE = "title";
private static final String DESCRIPTION = "description";
private static final String LANGUAGE = "language";
-
+
/**
* Constructs a new adapter for Dublin Core around the given metadata object.
* @param meta the underlying metadata
@@ -47,7 +47,7 @@
public DublinCoreAdapter(Metadata meta) {
super(meta, XMPSchemaRegistry.getInstance().getSchema(DublinCoreSchema.NAMESPACE));
}
-
+
/**
* Adds a new entry to the list of creators (authors of the resource).
* @param value the new value
@@ -55,21 +55,51 @@
public void addCreator(String value) {
addStringToSeq(CREATOR, value);
}
-
+
/** @return a String array of all creators */
public String[] getCreators() {
return getStringArray(CREATOR);
}
-
+
/**
* Adds a new entry to the list of dates indicating points in time something interesting
* happened to the resource.
- * @param value the date value
+ * @param value the date value
*/
public void addDate(Date value) {
addDateToSeq(DATE, value);
}
-
+
+ /**
+ * Returns a list of dates indicating point in time something interesting happened to the
+ * resource.
+ * @return the list of dates or null if no dates are set
+ */
+ public Date[] getDates() {
+ return getDateArray(DATE);
+ }
+
+ /**
+ * Returns a latest date indicating point in time something interesting happened to the
+ * resource.
+ * @return the last date or null
+ */
+ public Date getDate() {
+ Date[] dates = getDates();
+ if (dates != null) {
+ Date latest = null;
+ for (int i = 0, c = dates.length; i < c; i++) {
+ if (latest == null || dates[i].getTime() > latest.getTime()) {
+ latest = dates[i];
+ }
+ }
+ return latest;
+ } else {
+ return null;
+ }
+
+ }
+
/**
* Adds a new entry to the list of subjects (descriptive phrases or keywords that
* specify the topic of the content of the resource).
@@ -78,12 +108,12 @@
public void addSubject(String value) {
addStringToBag(SUBJECT, value);
}
-
+
/** @return a String array of all subjects */
public String[] getSubjects() {
return getStringArray(SUBJECT);
}
-
+
/**
* Sets the title of the resource (in the default language).
* @param value the new value
@@ -91,7 +121,7 @@
public void setTitle(String value) {
setTitle(null, value);
}
-
+
/**
* Sets the title of the resource.
* @param lang the language of the value ("x-default" or null for the default language)
@@ -100,12 +130,12 @@
public void setTitle(String lang, String value) {
setLangAlt(TITLE, lang, value);
}
-
+
/** @return the title of the resource (in the default language) */
public String getTitle() {
return getTitle(null);
}
-
+
/**
* Returns the title of the resource in a language-dependant way.
* @param lang the language ("x-default" or null for the default language)
@@ -114,7 +144,7 @@
public String getTitle(String lang) {
return getLangAlt(lang, TITLE);
}
-
+
/**
* Sets the description of the content of the resource.
* @param lang the language of the value ("x-default" or null for the default language)
@@ -123,12 +153,12 @@
public void setDescription(String lang, String value) {
setLangAlt(DESCRIPTION, lang, value);
}
-
+
/** @return the description of the content of the resource (in the default language) */
public String getDescription() {
return getDescription(null);
}
-
+
/**
* Returns the description of the content of the resource in a language-dependant way.
* @param lang the language ("x-default" or null for the default language)
@@ -137,7 +167,7 @@
public String getDescription(String lang) {
return getLangAlt(lang, DESCRIPTION);
}
-
+
/**
* Adds a new entry to the list of languages (RFC 3066).
* @param value the new value
@@ -145,10 +175,10 @@
public void addLanguage(String value) {
addStringToBag(LANGUAGE, value);
}
-
+
/** @return a String array of all language */
public String[] getLanguages() {
return getStringArray(LANGUAGE);
}
-
+
}
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=709661&r1=709660&r2=709661&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 Sat Nov 1 02:15:15 2008
@@ -20,6 +20,9 @@
package org.apache.xmlgraphics.xmp;
import java.net.URL;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
import junit.framework.TestCase;
@@ -129,4 +132,36 @@
assertEquals("Orson Scott Card", dcAdapter.getCreators()[0]);
}
+ public void testParseDates() throws Exception {
+ URL url = getClass().getResource("test-dates.xmp");
+ Metadata meta = XMPParser.parseXMP(url);
+ XMPProperty prop;
+
+ DublinCoreAdapter dcAdapter = DublinCoreSchema.getAdapter(meta);
+
+ //Simple adapter access
+ Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+2:00"));
+ cal.set(2006, Calendar.JUNE, 2, 10, 36, 40);
+ cal.set(Calendar.MILLISECOND, 0);
+ assertEquals(cal.getTime(), dcAdapter.getDate());
+ Date[] dates = dcAdapter.getDates();
+ assertEquals(2, dates.length);
+
+ //The second is the most recent and should match the simple value
+ assertEquals(dates[1], dcAdapter.getDate());
+
+ prop = meta.getProperty(XMPConstants.DUBLIN_CORE_NAMESPACE, "date");
+ assertNotNull(prop.getArrayValue());
+ assertEquals(2, prop.getArrayValue().getSize());
+
+ //Now add a new date and check if the adapter's getDate() method returns the new date.
+ cal.set(2008, Calendar.NOVEMBER, 1, 10, 10, 0);
+ dcAdapter.addDate(cal.getTime());
+ assertEquals(3, dcAdapter.getDates().length);
+ prop = meta.getProperty(XMPConstants.DUBLIN_CORE_NAMESPACE, "date");
+ assertNotNull(prop.getArrayValue());
+ assertEquals(3, prop.getArrayValue().getSize());
+ assertEquals(cal.getTime(), dcAdapter.getDate());
+ }
+
}
Added: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/test-dates.xmp
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/test-dates.xmp?rev=709661&view=auto
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/test-dates.xmp (added)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/test-dates.xmp Sat Nov 1 02:15:15 2008
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!-- $Id$ -->
+<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:date>
+ <rdf:Seq>
+ <rdf:li>2006-04-27T23:01:02+02:00</rdf:li>
+ <rdf:li>2006-06-02T10:36:40+02:00</rdf:li>
+ </rdf:Seq>
+ </dc:date>
+ </rdf:Description>
+ </rdf:RDF>
+</x:xmpmeta>
Propchange: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/test-dates.xmp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/test-dates.xmp
------------------------------------------------------------------------------
svn:keywords = Id
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org