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/21 22:08:43 UTC
svn commit: r892977 - in /xmlgraphics/commons/trunk:
src/java/org/apache/xmlgraphics/xmp/
src/java/org/apache/xmlgraphics/xmp/merge/
src/java/org/apache/xmlgraphics/xmp/schemas/
test/java/org/apache/xmlgraphics/xmp/
Author: jeremias
Date: Mon Dec 21 21:08:42 2009
New Revision: 892977
URL: http://svn.apache.org/viewvc?rev=892977&view=rev
Log:
Added support for XMP Basic's Identifier property (uses qualifiers).
Some simplifications.
Modified:
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPConstants.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/src/java/org/apache/xmlgraphics/xmp/merge/ArrayAddPropertyMerger.java
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/schemas/XMPBasicAdapter.java
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/schemas/XMPBasicSchema.java
xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPPropertyTest.java
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPConstants.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPConstants.java?rev=892977&r1=892976&r2=892977&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPConstants.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPConstants.java Mon Dec 21 21:08:42 2009
@@ -65,6 +65,6 @@
String DEFAULT_LANGUAGE = "x-default";
/** QName for rdf:value */
- QName RDF_VALUE = new QName(RDF_NAMESPACE, "value");
+ QName RDF_VALUE = new QName(RDF_NAMESPACE, "rdf", "value");
}
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=892977&r1=892976&r2=892977&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 Mon Dec 21 21:08:42 2009
@@ -107,8 +107,9 @@
/**
* Converts a simple value to an array of a given type if the value is not already an array.
* @param type the desired type of array
+ * @return the array value
*/
- public void convertSimpleValueToArray(XMPArrayType type) {
+ public XMPArray convertSimpleValueToArray(XMPArrayType type) {
if (getArrayValue() == null) {
XMPArray array = new XMPArray(type);
if (getXMLLang() != null) {
@@ -118,6 +119,9 @@
}
setValue(array);
setXMLLang(null);
+ return array;
+ } else {
+ return getArrayValue();
}
}
@@ -139,7 +143,7 @@
public boolean isQualifiedProperty() {
PropertyAccess props = getStructureValue();
if (props != null) {
- XMPProperty rdfValue = props.getProperty(XMPConstants.RDF_VALUE);
+ XMPProperty rdfValue = props.getValueProperty();
return (rdfValue != null);
} else {
return hasPropertyQualifiers();
@@ -149,14 +153,13 @@
public void simplify() {
PropertyAccess props = getStructureValue();
if (props != null) {
- XMPProperty rdfValue = props.getProperty(XMPConstants.RDF_VALUE);
+ XMPProperty rdfValue = props.getValueProperty();
if (rdfValue != null) {
if (hasPropertyQualifiers()) {
throw new IllegalStateException("Illegal internal state"
+ " (qualifiers present on non-simplified property)");
}
- Object value = props.getProperty(XMPConstants.RDF_VALUE);
- XMPProperty prop = new XMPProperty(getName(), value);
+ XMPProperty prop = new XMPProperty(getName(), rdfValue);
Iterator iter = props.iterator();
while (iter.hasNext()) {
QName name = (QName)iter.next();
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=892977&r1=892976&r2=892977&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 Mon Dec 21 21:08:42 2009
@@ -65,7 +65,7 @@
* @return the resulting QName
*/
protected QName getQName(String propName) {
- return new QName(getSchema().getNamespace(), propName);
+ return new QName(getSchema().getNamespace(), getSchema().getPreferredPrefix(), propName);
}
/**
@@ -78,6 +78,19 @@
if (value == null || value.length() == 0) {
throw new IllegalArgumentException("Value must not be empty");
}
+ addObjectToArray(propName, value, arrayType);
+ }
+
+ /**
+ * Adds a String value to an array.
+ * @param propName the property name
+ * @param value the String value
+ * @param arrayType the type of array to operate on
+ */
+ protected void addObjectToArray(String propName, Object value, XMPArrayType arrayType) {
+ if (value == null) {
+ throw new IllegalArgumentException("Value must not be null");
+ }
QName name = getQName(propName);
XMPProperty prop = meta.getProperty(name);
if (prop == null) {
@@ -392,6 +405,60 @@
}
/**
+ * Finds a structure that matches a given qualifier.
+ * @param propName the property name
+ * @param qualifier the qualifier
+ * @param qualifierValue the qualifier value
+ * @return the structure if a match was found (or null if no match was found)
+ */
+ protected PropertyAccess findQualifiedStructure(String propName,
+ QName qualifier, String qualifierValue) {
+ XMPProperty prop = meta.getProperty(getQName(propName));
+ XMPArray array;
+ if (prop != null) {
+ array = prop.getArrayValue();
+ if (array != null) {
+ for (int i = 0, c = array.getSize(); i < c; i++) {
+ Object value = array.getValue(i);
+ if (value instanceof PropertyAccess) {
+ PropertyAccess pa = (PropertyAccess)value;
+ XMPProperty q = pa.getProperty(qualifier);
+ if (q != null && q.getValue().equals(qualifierValue)) {
+ return pa;
+ }
+ }
+ }
+ } else if (prop.getStructureValue() != null) {
+ PropertyAccess pa = prop.getStructureValue();
+ XMPProperty q = pa.getProperty(qualifier);
+ if (q != null && q.getValue().equals(qualifierValue)) {
+ return pa;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Finds a value that matches a given qualifier.
+ * @param propName the property name
+ * @param qualifier the qualifier
+ * @param qualifierValue the qualifier value
+ * @return the value if a match was found (or null if no match was found)
+ */
+ protected Object findQualifiedValue(String propName,
+ QName qualifier, String qualifierValue) {
+ PropertyAccess pa = findQualifiedStructure(propName, qualifier, qualifierValue);
+ if (pa != null) {
+ XMPProperty rdfValue = pa.getValueProperty();
+ if (rdfValue != null) {
+ return rdfValue.getValue();
+ }
+ }
+ return null;
+ }
+
+ /**
* Returns an object array representation of the property's values.
* @param propName the property name
* @return the object array or null if the property isn't set
@@ -422,7 +489,13 @@
}
String[] res = new String[arr.length];
for (int i = 0, c = res.length; i < c; i++) {
- res[i] = arr[i].toString();
+ Object o = arr[i];
+ if (o instanceof PropertyAccess) {
+ XMPProperty prop = ((PropertyAccess)o).getValueProperty();
+ res[i] = prop.getValue().toString();
+ } else {
+ res[i] = o.toString();
+ }
}
return res;
}
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/merge/ArrayAddPropertyMerger.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/merge/ArrayAddPropertyMerger.java?rev=892977&r1=892976&r2=892977&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/merge/ArrayAddPropertyMerger.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/merge/ArrayAddPropertyMerger.java Mon Dec 21 21:08:42 2009
@@ -39,8 +39,7 @@
//simply copy over
target.setProperty(sourceProp);
} else {
- existing.convertSimpleValueToArray(XMPArrayType.SEQ);
- XMPArray array = existing.getArrayValue();
+ XMPArray array = existing.convertSimpleValueToArray(XMPArrayType.SEQ);
XMPArray otherArray = sourceProp.getArrayValue();
if (otherArray == null) {
if (sourceProp.getXMLLang() != null) {
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/schemas/XMPBasicAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/schemas/XMPBasicAdapter.java?rev=892977&r1=892976&r2=892977&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/schemas/XMPBasicAdapter.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/schemas/XMPBasicAdapter.java Mon Dec 21 21:08:42 2009
@@ -22,18 +22,29 @@
import java.util.Date;
import org.apache.xmlgraphics.xmp.Metadata;
+import org.apache.xmlgraphics.xmp.XMPArrayType;
+import org.apache.xmlgraphics.xmp.XMPConstants;
+import org.apache.xmlgraphics.xmp.XMPProperty;
import org.apache.xmlgraphics.xmp.XMPSchemaAdapter;
import org.apache.xmlgraphics.xmp.XMPSchemaRegistry;
+import org.apache.xmlgraphics.xmp.XMPStructure;
/**
* Schema adapter implementation for the XMP Basic schema.
*/
public class XMPBasicAdapter extends XMPSchemaAdapter {
- private static final String CREATOR_TOOL = "CreatorTool";
+ private static final String ADVISORY = "Advisory";
+ private static final String BASE_URL = "BaseURL";
private static final String CREATE_DATE = "CreateDate";
- private static final String MODIFY_DATE = "ModifyDate";
+ private static final String CREATOR_TOOL = "CreatorTool";
+ private static final String IDENTIFIER = "Identifier";
+ private static final String LABEL = "Label";
private static final String METADATA_DATE = "MetadataDate";
+ private static final String MODIFY_DATE = "ModifyDate";
+ private static final String NICKNAME = "Nickname";
+ private static final String RATING = "Rating";
+ private static final String THUMBNAILS = "Thumbnails";
/**
* Constructs a new adapter for XMP Basic around the given metadata object.
@@ -44,16 +55,19 @@
}
/**
- * Sets the first known tool used to create the resource.
- * @param value the creator tool
+ * Sets the base URL for relative URLs in the document content.
+ * @param value the base URL
*/
- public void setCreatorTool(String value) {
- setValue(CREATOR_TOOL, value);
+ public void setBaseUrl(String value) {
+ setValue(BASE_URL, value);
}
- /** @return the first known tool used to create the resource */
- public String getCreatorTool() {
- return getValue(CREATOR_TOOL);
+ /**
+ * Returns the base URL for relative URLs in the document content.
+ * @return the base URL
+ */
+ public String getBaseUrl() {
+ return getValue(BASE_URL);
}
/**
@@ -70,6 +84,59 @@
}
/**
+ * Sets the first known tool used to create the resource.
+ * @param value the creator tool
+ */
+ public void setCreatorTool(String value) {
+ setValue(CREATOR_TOOL, value);
+ }
+
+ /** @return the first known tool used to create the resource */
+ public String getCreatorTool() {
+ return getValue(CREATOR_TOOL);
+ }
+
+ /**
+ * Adds an identifier that unambiguously identify the resource within a given context.
+ * @param value the identifier value
+ */
+ public void addIdentifier(String value) {
+ addStringToBag(IDENTIFIER, value);
+ }
+
+ /**
+ * Adds a qualified identifier that unambiguously identify the resource within a given context.
+ * As qualifier, <code>xmpidq:Scheme</code> is used.
+ * @param value the identifier value
+ */
+ public void addIdentifier(String value, String qualifier) {
+ XMPStructure struct = new XMPStructure();
+ struct.setProperty(new XMPProperty(XMPConstants.RDF_VALUE, value));
+ struct.setProperty(new XMPProperty(XMPBasicSchema.SCHEME_QUALIFIER, qualifier));
+ addObjectToArray(IDENTIFIER, struct, XMPArrayType.BAG);
+ }
+
+ /**
+ * Returns an array of all identifiers that unambiguously identify the resource within a
+ * given context.
+ * @return a String array of all identifiers (or null if not set)
+ */
+ public String[] getIdentifiers() {
+ return getStringArray(IDENTIFIER);
+ }
+
+ /**
+ * Returns an identifier that matches a given qualifier.
+ * As qualifier, <code>xmpidq:Scheme</code> is used.
+ * @param qualifier the qualifier
+ * @return the identifier (or null if no matching value was found)
+ */
+ public String getIdentifier(String qualifier) {
+ Object value = findQualifiedValue(IDENTIFIER, XMPBasicSchema.SCHEME_QUALIFIER, qualifier);
+ return (value != null ? value.toString() : null);
+ }
+
+ /**
* Sets the date and time the resource was last modified.
* @param modifyDate the modification date
*/
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/schemas/XMPBasicSchema.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/schemas/XMPBasicSchema.java?rev=892977&r1=892976&r2=892977&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/schemas/XMPBasicSchema.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/schemas/XMPBasicSchema.java Mon Dec 21 21:08:42 2009
@@ -34,11 +34,20 @@
/** Namespace URI for XMP Basic */
public static final String NAMESPACE = XMPConstants.XMP_BASIC_NAMESPACE;
+ /** Preferred prefix for XMP Basic */
+ public static final String PREFERRED_PREFIX = "xmp";
+
+ /** Namespace URI for the qualifier for xmp:Identifier */
+ public static final String QUALIFIER_NAMESPACE = "http://ns.adobe.com/xmp/Identifier/qual/1.0/";
+
+ /** The qualified name for the qualifier for xmp:Identifier */
+ public static final QName SCHEME_QUALIFIER = new QName(QUALIFIER_NAMESPACE, "xmpidq:Scheme");
+
private static MergeRuleSet mergeRuleSet = new MergeRuleSet();
/** Creates a new schema instance for Dublin Core. */
public XMPBasicSchema() {
- super(NAMESPACE, "xmp");
+ super(NAMESPACE, PREFERRED_PREFIX);
}
static {
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=892977&r1=892976&r2=892977&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 Mon Dec 21 21:08:42 2009
@@ -19,9 +19,11 @@
package org.apache.xmlgraphics.xmp;
+import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
+import java.util.Set;
import java.util.TimeZone;
import junit.framework.TestCase;
@@ -135,4 +137,22 @@
assertEquals(dt2, dt);
}
+ public void testQualifiers() throws Exception {
+ Metadata xmp = new Metadata();
+ XMPBasicAdapter basic = XMPBasicSchema.getAdapter(xmp);
+
+ basic.addIdentifier("x123");
+ basic.addIdentifier("id1", "system1");
+ basic.addIdentifier("12345", "system2");
+
+ String[] ids = basic.getIdentifiers();
+ assertEquals(3, ids.length);
+ Set set = new java.util.HashSet(Arrays.asList(ids));
+ assertTrue(set.contains("x123"));
+ assertTrue(set.contains("id1"));
+ assertTrue(set.contains("12345"));
+
+ assertEquals("id1", basic.getIdentifier("system1"));
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org
Re: svn commit: r892977 - in /xmlgraphics/commons/trunk: src/java/org/apache/xmlgraphics/xmp/
src/java/org/apache/xmlgraphics/xmp/merge/ src/java/org/apache/xmlgraphics/xmp/schemas/
test/java/org/apache/xmlgraphics/xmp/
Posted by Vincent Hennebert <vh...@gmail.com>.
Hi,
> Author: jeremias
> Date: Mon Dec 21 21:08:42 2009
> New Revision: 892977
>
> URL: http://svn.apache.org/viewvc?rev=892977&view=rev
> Log:
> Added support for XMP Basic's Identifier property (uses qualifiers).
> Some simplifications.
<snip/>
> 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=892977&r1=892976&r2=892977&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 Mon Dec 21 21:08:42 2009
> @@ -78,6 +78,19 @@
> if (value == null || value.length() == 0) {
> throw new IllegalArgumentException("Value must not be empty");
> }
> + addObjectToArray(propName, value, arrayType);
> + }
> +
> + /**
> + * Adds a String value to an array.
> + * @param propName the property name
> + * @param value the String value
> + * @param arrayType the type of array to operate on
> + */
> + protected void addObjectToArray(String propName, Object value, XMPArrayType arrayType) {
> + if (value == null) {
> + throw new IllegalArgumentException("Value must not be null");
> + }
> QName name = getQName(propName);
> XMPProperty prop = meta.getProperty(name);
> if (prop == null) {
The javadoc says String, the method name and parameter type say Object??
<snip/>
Vincent
---------------------------------------------------------------------
To unsubscribe, e-mail: general-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: general-help@xmlgraphics.apache.org