Skip to content

Commit

Permalink
Fix for setLocation(null) + Kotlin update (#35)
Browse files Browse the repository at this point in the history
* Fix: setLocation(null) should delete all known fields. + Unit Test

* Removed debug println

* Dependency updates

* Target Android 35

* Bumped version
  • Loading branch information
StefanOltmann authored Jan 30, 2025
1 parent 2091090 commit ad05056
Show file tree
Hide file tree
Showing 225 changed files with 321 additions and 266 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# XMP Core for Kotlin Multiplatform

[![Kotlin](https://img.shields.io/badge/kotlin-2.1.0-blue.svg?logo=kotlin)](httpw://kotlinlang.org)
[![Kotlin](https://img.shields.io/badge/kotlin-2.1.10-blue.svg?logo=kotlin)](httpw://kotlinlang.org)
![JVM](https://img.shields.io/badge/-JVM-gray.svg?style=flat)
![Android](https://img.shields.io/badge/-Android-gray.svg?style=flat)
![iOS](https://img.shields.io/badge/-iOS-gray.svg?style=flat)
Expand All @@ -20,7 +20,7 @@ It's part of [Ashampoo Photo Organizer](https://ashampoo.com/photo-organizer).
## Installation

```
implementation("com.ashampoo:xmpcore:1.5.0")
implementation("com.ashampoo:xmpcore:1.5.1")
```

## How to use
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework

plugins {
kotlin("multiplatform") version "2.1.0"
kotlin("multiplatform") version "2.1.10"
id("com.android.library") version "8.5.0"
id("maven-publish")
id("signing")
Expand Down Expand Up @@ -295,7 +295,7 @@ android {

namespace = "com.ashampoo.xmpcore"

compileSdk = 34
compileSdk = 35

sourceSets["main"].res.srcDirs("src/commonMain/resources")

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
69 changes: 30 additions & 39 deletions src/commonMain/kotlin/com/ashampoo/xmp/XMPMeta.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,7 @@ public class XMPMeta internal constructor() {
}

/*
* For missing values fall back to the Photoshop namespace.
* For missing values fall back to older places.
*/

if (location.isNullOrBlank())
Expand Down Expand Up @@ -2062,21 +2062,28 @@ public class XMPMeta internal constructor() {
xmpLocation: XMPLocation?
) {

/* Delete existing entries, if any */
/* Delete existing entries */

deleteProperty(XMPConst.NS_IPTC_EXT, XMPConst.XMP_IPTC_EXT_LOCATION_SHOWN)
deleteProperty(XMPConst.NS_IPTC_CORE, "Location")
deleteProperty(XMPConst.NS_PHOTOSHOP, "City")
deleteProperty(XMPConst.NS_PHOTOSHOP, "State")
deleteProperty(XMPConst.NS_PHOTOSHOP, "Country")

if (xmpLocation == null)
return

/* Create a new array property. */
/*
* Write Iptc4xmpExt:LocationShown
*/

setProperty(
XMPConst.NS_IPTC_EXT,
XMPConst.XMP_IPTC_EXT_LOCATION_SHOWN,
null,
arrayOptions
)

/* Append empty entry */
appendArrayItem(
schemaNS = XMPConst.NS_IPTC_EXT,
arrayName = XMPConst.XMP_IPTC_EXT_LOCATION_SHOWN,
Expand Down Expand Up @@ -2112,8 +2119,7 @@ public class XMPMeta internal constructor() {
)
}

if (!xmpLocation.location.isNullOrBlank()) {

if (!xmpLocation.location.isNullOrBlank())
setStructField(
schemaNS = XMPConst.NS_IPTC_EXT,
structName = XMPConst.XMP_IPTC_EXT_LOCATION_SHOWN + "[1]",
Expand All @@ -2122,15 +2128,7 @@ public class XMPMeta internal constructor() {
fieldValue = xmpLocation.location
)

setProperty(
schemaNS = XMPConst.NS_IPTC_CORE,
propName = "Location",
propValue = xmpLocation.location
)
}

if (!xmpLocation.city.isNullOrBlank()) {

if (!xmpLocation.city.isNullOrBlank())
setStructField(
schemaNS = XMPConst.NS_IPTC_EXT,
structName = XMPConst.XMP_IPTC_EXT_LOCATION_SHOWN + "[1]",
Expand All @@ -2139,15 +2137,7 @@ public class XMPMeta internal constructor() {
fieldValue = xmpLocation.city
)

setProperty(
schemaNS = XMPConst.NS_PHOTOSHOP,
propName = "City",
propValue = xmpLocation.city
)
}

if (!xmpLocation.state.isNullOrBlank()) {

if (!xmpLocation.state.isNullOrBlank())
setStructField(
schemaNS = XMPConst.NS_IPTC_EXT,
structName = XMPConst.XMP_IPTC_EXT_LOCATION_SHOWN + "[1]",
Expand All @@ -2156,15 +2146,7 @@ public class XMPMeta internal constructor() {
fieldValue = xmpLocation.state
)

setProperty(
schemaNS = XMPConst.NS_PHOTOSHOP,
propName = "State",
propValue = xmpLocation.state
)
}

if (!xmpLocation.country.isNullOrBlank()) {

if (!xmpLocation.country.isNullOrBlank())
setStructField(
schemaNS = XMPConst.NS_IPTC_EXT,
structName = XMPConst.XMP_IPTC_EXT_LOCATION_SHOWN + "[1]",
Expand All @@ -2173,12 +2155,21 @@ public class XMPMeta internal constructor() {
fieldValue = xmpLocation.country
)

setProperty(
schemaNS = XMPConst.NS_PHOTOSHOP,
propName = "Country",
propValue = xmpLocation.country
)
}
/*
* Write older fields for completeness
*/

if (!xmpLocation.location.isNullOrBlank())
setProperty(XMPConst.NS_IPTC_CORE, "Location", xmpLocation.location)

if (!xmpLocation.city.isNullOrBlank())
setProperty(XMPConst.NS_PHOTOSHOP, "City", xmpLocation.city)

if (!xmpLocation.state.isNullOrBlank())
setProperty(XMPConst.NS_PHOTOSHOP, "State", xmpLocation.state)

if (!xmpLocation.country.isNullOrBlank())
setProperty(XMPConst.NS_PHOTOSHOP, "Country", xmpLocation.country)
}

public fun getTitle(): String? {
Expand Down
2 changes: 1 addition & 1 deletion src/commonMain/kotlin/com/ashampoo/xmp/XMPVersionInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public object XMPVersionInfo {

public const val MAJOR: Int = 1
public const val MINOR: Int = 5
public const val PATCH: Int = 0
public const val PATCH: Int = 1

public const val VERSION_MESSAGE: String =
"Ashampoo XMP Core $MAJOR.$MINOR.$PATCH"
Expand Down
2 changes: 0 additions & 2 deletions src/commonTest/kotlin/com/ashampoo/xmp/ReadXmpTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ class ReadXmpTest {
<?xpacket end="w"?>
""".trimIndent()

println(testXmp)

val xmpMeta = XMPMetaFactory.parseFromString(testXmp)

assertEquals(
Expand Down
68 changes: 67 additions & 1 deletion src/commonTest/kotlin/com/ashampoo/xmp/WriteXmpTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,72 @@ class WriteXmpTest {
)
}

/**
* Create an XMP only containing location info.
*/
@OptIn(ExperimentalStdlibApi::class)
@Test
fun testLocationRemovalXmp() {

/* language=XML */
val originalXmp = """
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="${XMPVersionInfo.VERSION_MESSAGE}">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:Iptc4xmpCore="http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/"
xmlns:Iptc4xmpExt="http://iptc.org/std/Iptc4xmpExt/2008-02-29/"
xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/"
Iptc4xmpCore:Location="Schafjückenweg 2"
photoshop:City="Rastede"
photoshop:Country="Deutschland"
photoshop:State="Niedersachsen">
<Iptc4xmpExt:LocationShown>
<rdf:Bag>
<rdf:li>
<rdf:Description
Iptc4xmpExt:City="Rastede"
Iptc4xmpExt:CountryName="Deutschland"
Iptc4xmpExt:ProvinceState="Niedersachsen"
Iptc4xmpExt:Sublocation="Schafjückenweg 2">
<Iptc4xmpExt:LocationName>
<rdf:Alt>
<rdf:li xml:lang="x-default">Ashampoo GmbH &amp; Co. KG</rdf:li>
</rdf:Alt>
</Iptc4xmpExt:LocationName>
</rdf:Description>
</rdf:li>
</rdf:Bag>
</Iptc4xmpExt:LocationShown>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>
""".trimIndent()

val xmpMeta = XMPMetaFactory.parseFromString(originalXmp)

xmpMeta.setLocation(null)

val actualXmp = XMPMetaFactory.serializeToString(xmpMeta, xmpSerializeOptionsCompact)

/* language=XML */
val expectedXmp = """
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="${XMPVersionInfo.VERSION_MESSAGE}">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""/>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>
""".trimIndent()

assertEquals(
expected = expectedXmp,
actual = actualXmp
)
}

/**
* Create an XMP only containing title & description.
*/
Expand All @@ -429,7 +495,7 @@ class WriteXmpTest {
/* language=XML */
val expectedXmp = """
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.0">
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="${XMPVersionInfo.VERSION_MESSAGE}">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:dc="http://purl.org/dc/elements/1.1/">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.0">
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.1">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:MicrosoftPhoto_1_="http://ns.microsoft.com/photo/1.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.0">
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.1">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:MicrosoftPhoto_1_="http://ns.microsoft.com/photo/1.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.0">
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.1">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:xmp="http://ns.adobe.com/xap/1.0/"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.0">
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.1">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:xmp="http://ns.adobe.com/xap/1.0/"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.0">
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.1">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:dc="http://purl.org/dc/elements/1.1/"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.0">
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.1">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:dc="http://purl.org/dc/elements/1.1/"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.0">
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.1">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:dc="http://purl.org/dc/elements/1.1/"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.0">
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.1">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:dc="http://purl.org/dc/elements/1.1/"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.0">
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.1">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:dc="http://purl.org/dc/elements/1.1/"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.0">
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.1">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:dc="http://purl.org/dc/elements/1.1/"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.0">
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.1">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:dc="http://purl.org/dc/elements/1.1/"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.0">
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.1">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:dc="http://purl.org/dc/elements/1.1/"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.0">
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.1">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:dc="http://purl.org/dc/elements/1.1/"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.0">
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.1">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:dc="http://purl.org/dc/elements/1.1/"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.0">
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.1">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:dc="http://purl.org/dc/elements/1.1/"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.0">
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.1">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:dc="http://purl.org/dc/elements/1.1/"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.0">
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.1">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:dc="http://purl.org/dc/elements/1.1/"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.0">
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Ashampoo XMP Core 1.5.1">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:dc="http://purl.org/dc/elements/1.1/"
Expand Down
Loading

0 comments on commit ad05056

Please sign in to comment.