You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2016/03/04 20:00:29 UTC
svn commit: r1733636 - in
/pdfbox/branches/1.8/xmpbox/src/main/java/org/apache/xmpbox/type:
AbstractComplexProperty.java ComplexPropertyContainer.java
Author: tilman
Date: Fri Mar 4 19:00:28 2016
New Revision: 1733636
URL: http://svn.apache.org/viewvc?rev=1733636&view=rev
Log:
PDFBOX-3258: keep non-list properties unique
Modified:
pdfbox/branches/1.8/xmpbox/src/main/java/org/apache/xmpbox/type/AbstractComplexProperty.java
pdfbox/branches/1.8/xmpbox/src/main/java/org/apache/xmpbox/type/ComplexPropertyContainer.java
Modified: pdfbox/branches/1.8/xmpbox/src/main/java/org/apache/xmpbox/type/AbstractComplexProperty.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/xmpbox/src/main/java/org/apache/xmpbox/type/AbstractComplexProperty.java?rev=1733636&r1=1733635&r2=1733636&view=diff
==============================================================================
--- pdfbox/branches/1.8/xmpbox/src/main/java/org/apache/xmpbox/type/AbstractComplexProperty.java (original)
+++ pdfbox/branches/1.8/xmpbox/src/main/java/org/apache/xmpbox/type/AbstractComplexProperty.java Fri Mar 4 19:00:28 2016
@@ -64,6 +64,16 @@ public abstract class AbstractComplexPro
*/
public final void addProperty(AbstractField obj)
{
+ // https://www.adobe.com/content/dam/Adobe/en/devnet/xmp/pdfs/cs6/XMPSpecificationPart1.pdf
+ // "Each property name in an XMP packet shall be unique within that packet"
+ // "Multiple values are represented using an XMP array value"
+ // "The nested element's element content shall consist of zero or more rdf:li elements,
+ // one for each item in the array"
+ // thus delete existing elements of a property, except for arrays ("li")
+ if (!(this instanceof ArrayProperty))
+ {
+ container.removePropertiesByName(obj.getPropertyName());
+ }
container.addProperty(obj);
}
Modified: pdfbox/branches/1.8/xmpbox/src/main/java/org/apache/xmpbox/type/ComplexPropertyContainer.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/xmpbox/src/main/java/org/apache/xmpbox/type/ComplexPropertyContainer.java?rev=1733636&r1=1733635&r2=1733636&view=diff
==============================================================================
--- pdfbox/branches/1.8/xmpbox/src/main/java/org/apache/xmpbox/type/ComplexPropertyContainer.java (original)
+++ pdfbox/branches/1.8/xmpbox/src/main/java/org/apache/xmpbox/type/ComplexPropertyContainer.java Fri Mar 4 19:00:28 2016
@@ -161,11 +161,11 @@ public class ComplexPropertyContainer /*
}
/**
- * Return all properties with this specified localName
+ * Return all properties with this specified localName.
*
* @param localName
* the local name wanted
- * @return All properties with local name which match with localName given
+ * @return All properties with local name which match with localName given, or null if there are none.
*/
public List<AbstractField> getPropertiesByLocalName(String localName)
{
@@ -190,17 +190,16 @@ public class ComplexPropertyContainer /*
}
}
return null;
-
}
/**
- * Check if two property are similar
+ * Check if two properties are equal.
*
* @param prop1
* First property
* @param prop2
* Second property
- * @return True if these properties are equals
+ * @return True if these properties are equal.
*/
public boolean isSameProperty(AbstractField prop1, AbstractField prop2)
{
@@ -260,4 +259,25 @@ public class ComplexPropertyContainer /*
}
}
+ /**
+ * Remove all properties with a specified LocalName.
+ *
+ * @param localName The name for which to remove all.
+ */
+ public void removePropertiesByName(String localName)
+ {
+ if (properties.isEmpty())
+ {
+ return;
+ }
+ List<AbstractField> propList = getPropertiesByLocalName(localName);
+ if (propList == null)
+ {
+ return;
+ }
+ for (AbstractField field : propList)
+ {
+ properties.remove(field);
+ }
+ }
}