From 25ae32fbccd6c5bd3bd0a6fa3342daf0f2153b92 Mon Sep 17 00:00:00 2001 From: Stefan Oltmann Date: Mon, 10 Jul 2023 10:10:25 +0200 Subject: [PATCH 01/12] Added @Throws for Swift code to propagate NSError --- src/commonMain/kotlin/com/ashampoo/xmp/XMPMetaFactory.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/XMPMetaFactory.kt b/src/commonMain/kotlin/com/ashampoo/xmp/XMPMetaFactory.kt index 690589f..e88a10b 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/XMPMetaFactory.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/XMPMetaFactory.kt @@ -28,12 +28,14 @@ object XMPMetaFactory { fun create(): XMPMeta = XMPMetaImpl() + @Throws(XMPException::class) fun parseFromString( packet: String, options: ParseOptions = ParseOptions() ): XMPMeta = XMPMetaParser.parse(packet, options) + @Throws(XMPException::class) fun serializeToString( xmp: XMPMeta, options: SerializeOptions = SerializeOptions() From 0034206a41bf1353b4b496020befe5c70e58f702 Mon Sep 17 00:00:00 2001 From: Stefan Oltmann Date: Mon, 10 Jul 2023 10:11:01 +0200 Subject: [PATCH 02/12] Internalized XMPMetaParser, so XMPMetaFactory must be used. --- src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPMetaParser.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPMetaParser.kt b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPMetaParser.kt index 3007b5f..7500c7c 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPMetaParser.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPMetaParser.kt @@ -28,7 +28,7 @@ import nl.adaptivity.xmlutil.dom.namespaceURI * XML-parsing and fixes the prefix. After the parsing several normalisations * are applied to the XMPTree. */ -object XMPMetaParser { +internal object XMPMetaParser { private val XMP_RDF = Any() // "new Object()" in Java From dba32357b88dc6f51d3896bd137bfa057d7dcf54 Mon Sep 17 00:00:00 2001 From: Stefan Oltmann Date: Mon, 10 Jul 2023 10:16:02 +0200 Subject: [PATCH 03/12] Made options optional --- .../kotlin/com/ashampoo/xmp/XMPMetaFactory.kt | 10 ++++++---- .../kotlin/com/ashampoo/xmp/impl/XMPMetaParser.kt | 12 +++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/XMPMetaFactory.kt b/src/commonMain/kotlin/com/ashampoo/xmp/XMPMetaFactory.kt index e88a10b..528d305 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/XMPMetaFactory.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/XMPMetaFactory.kt @@ -31,22 +31,24 @@ object XMPMetaFactory { @Throws(XMPException::class) fun parseFromString( packet: String, - options: ParseOptions = ParseOptions() + options: ParseOptions? = null ): XMPMeta = XMPMetaParser.parse(packet, options) @Throws(XMPException::class) fun serializeToString( xmp: XMPMeta, - options: SerializeOptions = SerializeOptions() + options: SerializeOptions? = null ): String { require(xmp is XMPMetaImpl) { "Serialization only works with XMPMetaImpl" } + val actualOptions = options ?: SerializeOptions() + /* sort the internal data model on demand */ - if (options.getSort()) + if (actualOptions.getSort()) xmp.sort() - return XMPRDFWriter(xmp, options).serialize() + return XMPRDFWriter(xmp, actualOptions).serialize() } } diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPMetaParser.kt b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPMetaParser.kt index 7500c7c..2b943a2 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPMetaParser.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPMetaParser.kt @@ -42,12 +42,14 @@ internal object XMPMetaParser { */ fun parse( input: String, - options: ParseOptions = ParseOptions() + options: ParseOptions? ): XMPMeta { + val actualOptions = options ?: ParseOptions() + val document = XmlUtilDomParser.parseDocumentFromString(input) - val xmpmetaRequired = options.getRequireXMPMeta() + val xmpmetaRequired = actualOptions.getRequireXMPMeta() var result: Array? = arrayOfNulls(3) @@ -55,13 +57,13 @@ internal object XMPMetaParser { return if (result != null && result[1] === XMP_RDF) { - val xmp = XMPRDFParser.parse(result[0] as Node, options) + val xmp = XMPRDFParser.parse(result[0] as Node, actualOptions) xmp.setPacketHeader(result[2] as? String) // Check if the XMP object shall be normalized - if (!options.getOmitNormalization()) - normalize(xmp, options) + if (!actualOptions.getOmitNormalization()) + normalize(xmp, actualOptions) else xmp From ea00517f9450e44c41760e7ecb938fec042b665c Mon Sep 17 00:00:00 2001 From: Stefan Oltmann Date: Mon, 10 Jul 2023 10:18:16 +0200 Subject: [PATCH 04/12] We only have one DomParser --- .../kotlin/com/ashampoo/xmp/impl/DomParser.kt | 27 ++++++++++++++-- .../com/ashampoo/xmp/impl/XMPMetaParser.kt | 2 +- .../com/ashampoo/xmp/impl/XmlUtilDomParser.kt | 32 ------------------- 3 files changed, 26 insertions(+), 35 deletions(-) delete mode 100644 src/commonMain/kotlin/com/ashampoo/xmp/impl/XmlUtilDomParser.kt diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/impl/DomParser.kt b/src/commonMain/kotlin/com/ashampoo/xmp/impl/DomParser.kt index e512338..2ea5ab2 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/impl/DomParser.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/impl/DomParser.kt @@ -1,9 +1,32 @@ package com.ashampoo.xmp.impl +import com.ashampoo.xmp.XMPError +import com.ashampoo.xmp.XMPException +import nl.adaptivity.xmlutil.DomWriter +import nl.adaptivity.xmlutil.EventType +import nl.adaptivity.xmlutil.XmlStreaming import nl.adaptivity.xmlutil.dom.Document +import nl.adaptivity.xmlutil.writeCurrent -fun interface DomParser { +object DomParser { - fun parseDocumentFromString(input: String): Document + fun parseDocumentFromString(input: String): Document { + try { + + val writer = DomWriter() + + val reader = XmlStreaming.newReader(input) + + do { + val event = reader.next() + reader.writeCurrent(writer) + } while (event != EventType.END_DOCUMENT) + + return writer.target + + } catch (ex: Exception) { + throw XMPException("Error reading the XML-file", XMPError.BADSTREAM, ex) + } + } } diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPMetaParser.kt b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPMetaParser.kt index 2b943a2..16e8b4e 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPMetaParser.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPMetaParser.kt @@ -47,7 +47,7 @@ internal object XMPMetaParser { val actualOptions = options ?: ParseOptions() - val document = XmlUtilDomParser.parseDocumentFromString(input) + val document = DomParser.parseDocumentFromString(input) val xmpmetaRequired = actualOptions.getRequireXMPMeta() diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XmlUtilDomParser.kt b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XmlUtilDomParser.kt deleted file mode 100644 index cf2ee0f..0000000 --- a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XmlUtilDomParser.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.ashampoo.xmp.impl - -import com.ashampoo.xmp.XMPError -import com.ashampoo.xmp.XMPException -import nl.adaptivity.xmlutil.DomWriter -import nl.adaptivity.xmlutil.EventType -import nl.adaptivity.xmlutil.XmlStreaming -import nl.adaptivity.xmlutil.dom.Document -import nl.adaptivity.xmlutil.writeCurrent - -object XmlUtilDomParser : DomParser { - - override fun parseDocumentFromString(input: String): Document { - - try { - - val writer = DomWriter() - - val reader = XmlStreaming.newReader(input) - - do { - val event = reader.next() - reader.writeCurrent(writer) - } while (event != EventType.END_DOCUMENT) - - return writer.target - - } catch (ex: Exception) { - throw XMPException("Error reading the XML-file", XMPError.BADSTREAM, ex) - } - } -} From 41044a3b15920e886ed08aab651c49e8e1f2bcb2 Mon Sep 17 00:00:00 2001 From: Stefan Oltmann Date: Mon, 10 Jul 2023 10:23:27 +0200 Subject: [PATCH 05/12] Use XMPConst.RDF_TYPE --- .../kotlin/com/ashampoo/xmp/impl/XMPNode.kt | 14 +++++++------- .../kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPNode.kt b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPNode.kt index 263cc1c..1b2afad 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPNode.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPNode.kt @@ -164,7 +164,7 @@ class XMPNode( getOrCreateQualifier().add(0, qualNode) - } else if ("rdf:type" == qualNode.name) { + } else if (XMPConst.RDF_TYPE == qualNode.name) { // "rdf:type" must be first or second after "xml:lang" and the option "hasType" is set options.setHasType(true) @@ -189,7 +189,7 @@ class XMPNode( if (XMPConst.XML_LANG == qualNode.name) { // if "xml:lang" is removed, remove hasLanguage-flag too options.setHasLanguage(false) - } else if ("rdf:type" == qualNode.name) { + } else if (XMPConst.RDF_TYPE == qualNode.name) { // if "rdf:type" is removed, remove hasType-flag too options.setHasType(false) } @@ -235,10 +235,10 @@ class XMPNode( override fun compareTo(other: XMPNode): Int { - return if (options.isSchemaNode()) - value!!.compareTo(other.value!!) - else - name!!.compareTo(other.name!!) + if (options.isSchemaNode()) + return value!!.compareTo(other.value!!) + + return name!!.compareTo(other.name!!) } /** @@ -260,7 +260,7 @@ class XMPNode( var sortFrom = 0 while (quals.size > sortFrom && - (XMPConst.XML_LANG == quals[sortFrom].name || "rdf:type" == quals[sortFrom].name) + (XMPConst.XML_LANG == quals[sortFrom].name || XMPConst.RDF_TYPE == quals[sortFrom].name) ) { quals[sortFrom].sort() sortFrom++ diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt index c929d55..38395fd 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt @@ -520,7 +520,7 @@ internal object XMPRDFParser : XMPError { typeName += ":$localName" - addQualifierNode(newCompound, "rdf:type", typeName) + addQualifierNode(newCompound, XMPConst.RDF_TYPE, typeName) } } } From 89edcf21150f343e6d76595173ccc14f80b75b09 Mon Sep 17 00:00:00 2001 From: Stefan Oltmann Date: Mon, 10 Jul 2023 10:24:38 +0200 Subject: [PATCH 06/12] Removed unused variable --- .../kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt index 38395fd..c532294 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt @@ -852,8 +852,6 @@ internal object XMPRDFParser : XMPError { var actualXmpParent = xmpParent - val registry = schemaRegistry - var namespace = when (xmlNode) { is Element -> xmlNode.namespaceURI is Attr -> xmlNode.namespaceURI @@ -870,7 +868,7 @@ internal object XMPRDFParser : XMPError { if (XMPConst.NS_DC_DEPRECATED == namespace) namespace = XMPConst.NS_DC - var prefix = registry.getNamespacePrefix(namespace) + var prefix = schemaRegistry.getNamespacePrefix(namespace) if (prefix == null) { @@ -885,7 +883,7 @@ internal object XMPRDFParser : XMPError { else DEFAULT_PREFIX - prefix = registry.registerNamespace(namespace, prefix) + prefix = schemaRegistry.registerNamespace(namespace, prefix) } val xmlNodeLocalName = when (xmlNode) { @@ -920,7 +918,7 @@ internal object XMPRDFParser : XMPError { // If this is an alias set the alias flag in the node // and the hasAliases flag in the tree. - if (registry.findAlias(childName) != null) { + if (schemaRegistry.findAlias(childName) != null) { isAlias = true xmp.root.hasAliases = true schemaNode.hasAliases = true From 18756d719ee2f4e8b8869f0428e4b2395c859557 Mon Sep 17 00:00:00 2001 From: Stefan Oltmann Date: Mon, 10 Jul 2023 10:25:25 +0200 Subject: [PATCH 07/12] Moved variable --- src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt index c532294..15b616c 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt @@ -850,8 +850,6 @@ internal object XMPRDFParser : XMPError { isTopLevel: Boolean ): XMPNode { - var actualXmpParent = xmpParent - var namespace = when (xmlNode) { is Element -> xmlNode.namespaceURI is Attr -> xmlNode.namespaceURI @@ -899,6 +897,8 @@ internal object XMPRDFParser : XMPError { var isAlias = false + var actualXmpParent = xmpParent + if (isTopLevel) { // Lookup the schema node, adjust the XMP parent pointer. From 4d159b4f42b9203fbe22da2ba06e152127ed8827 Mon Sep 17 00:00:00 2001 From: Stefan Oltmann Date: Mon, 10 Jul 2023 10:28:59 +0200 Subject: [PATCH 08/12] Avoided String duplication --- .../kotlin/com/ashampoo/xmp/XMPError.kt | 32 +++++++------- .../com/ashampoo/xmp/impl/XMPMetaImpl.kt | 44 +++++++++---------- .../com/ashampoo/xmp/impl/XMPRDFParser.kt | 2 +- .../xmp/impl/XMPSchemaRegistryImpl.kt | 6 +-- 4 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/XMPError.kt b/src/commonMain/kotlin/com/ashampoo/xmp/XMPError.kt index e61bfc3..7b87fd4 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/XMPError.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/XMPError.kt @@ -8,21 +8,21 @@ // ================================================================================================= package com.ashampoo.xmp -interface XMPError { +object XMPError { - companion object { - const val UNKNOWN: Int = 0 - const val BADPARAM: Int = 4 - const val BADVALUE: Int = 5 - const val INTERNALFAILURE: Int = 9 - const val BADSCHEMA: Int = 101 - const val BADXPATH: Int = 102 - const val BADOPTIONS: Int = 103 - const val BADINDEX: Int = 104 - const val BADSERIALIZE: Int = 107 - const val BADXML: Int = 201 - const val BADRDF: Int = 202 - const val BADXMP: Int = 203 - const val BADSTREAM: Int = 204 - } + const val EMPTY_SCHEMA_TEXT: String = "Empty schema namespace URI" + + const val UNKNOWN: Int = 0 + const val BADPARAM: Int = 4 + const val BADVALUE: Int = 5 + const val INTERNALFAILURE: Int = 9 + const val BADSCHEMA: Int = 101 + const val BADXPATH: Int = 102 + const val BADOPTIONS: Int = 103 + const val BADINDEX: Int = 104 + const val BADSERIALIZE: Int = 107 + const val BADXML: Int = 201 + const val BADRDF: Int = 202 + const val BADXMP: Int = 203 + const val BADSTREAM: Int = 204 } diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPMetaImpl.kt b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPMetaImpl.kt index b9a7707..7a1af52 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPMetaImpl.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPMetaImpl.kt @@ -73,7 +73,7 @@ class XMPMetaImpl : XMPMeta { ) { if (schemaNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (arrayName.isEmpty()) throw XMPException("Empty array name", XMPError.BADPARAM) @@ -120,7 +120,7 @@ class XMPMetaImpl : XMPMeta { override fun countArrayItems(schemaNS: String, arrayName: String): Int { if (schemaNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (arrayName.isEmpty()) throw XMPException("Empty array name", XMPError.BADPARAM) @@ -137,7 +137,7 @@ class XMPMetaImpl : XMPMeta { override fun deleteArrayItem(schemaNS: String, arrayName: String, itemIndex: Int) { if (schemaNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (arrayName.isEmpty()) throw XMPException("Empty array name", XMPError.BADPARAM) @@ -150,7 +150,7 @@ class XMPMetaImpl : XMPMeta { override fun deleteProperty(schemaNS: String, propName: String) { if (schemaNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (propName.isEmpty()) throw XMPException("Empty property name", XMPError.BADPARAM) @@ -169,7 +169,7 @@ class XMPMetaImpl : XMPMeta { // Note: qualNS and qualName are checked inside composeQualfierPath if (schemaNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (propName.isEmpty()) throw XMPException("Empty property name", XMPError.BADPARAM) @@ -189,7 +189,7 @@ class XMPMetaImpl : XMPMeta { // fieldNS and fieldName are checked inside composeStructFieldPath if (schemaNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (structName.isEmpty()) throw XMPException("Empty array name", XMPError.BADPARAM) @@ -202,7 +202,7 @@ class XMPMetaImpl : XMPMeta { override fun doesPropertyExist(schemaNS: String, propName: String): Boolean { if (schemaNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (propName.isEmpty()) throw XMPException("Empty property name", XMPError.BADPARAM) @@ -220,7 +220,7 @@ class XMPMetaImpl : XMPMeta { override fun doesArrayItemExist(schemaNS: String, arrayName: String, itemIndex: Int): Boolean { if (schemaNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (arrayName.isEmpty()) throw XMPException("Empty array name", XMPError.BADPARAM) @@ -240,7 +240,7 @@ class XMPMetaImpl : XMPMeta { // fieldNS and fieldName are checked inside composeStructFieldPath() if (schemaNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (structName.isEmpty()) throw XMPException("Empty array name", XMPError.BADPARAM) @@ -260,7 +260,7 @@ class XMPMetaImpl : XMPMeta { // qualNS and qualName are checked inside composeQualifierPath() if (schemaNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (propName.isEmpty()) throw XMPException("Empty property name", XMPError.BADPARAM) @@ -273,7 +273,7 @@ class XMPMetaImpl : XMPMeta { override fun getArrayItem(schemaNS: String, arrayName: String, itemIndex: Int): XMPProperty? { if (schemaNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (arrayName.isEmpty()) throw XMPException("Empty array name", XMPError.BADPARAM) @@ -291,7 +291,7 @@ class XMPMetaImpl : XMPMeta { ): XMPProperty? { if (schemaNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (altTextName.isEmpty()) throw XMPException("Empty array name", XMPError.BADPARAM) @@ -345,7 +345,7 @@ class XMPMetaImpl : XMPMeta { ) { if (schemaNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (altTextName.isEmpty()) throw XMPException("Empty array name", XMPError.BADPARAM) @@ -503,7 +503,7 @@ class XMPMetaImpl : XMPMeta { private fun getProperty(schemaNS: String, propName: String, valueType: Int): XMPProperty? { if (schemaNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (propName.isEmpty()) throw XMPException("Empty property name", XMPError.BADPARAM) @@ -546,7 +546,7 @@ class XMPMetaImpl : XMPMeta { private fun getPropertyObject(schemaNS: String, propName: String, valueType: Int): Any? { if (schemaNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (propName.isEmpty()) throw XMPException("Empty property name", XMPError.BADPARAM) @@ -641,7 +641,7 @@ class XMPMetaImpl : XMPMeta { // qualNS and qualName are checked inside composeQualfierPath if (schemaNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (propName.isEmpty()) throw XMPException("Empty property name", XMPError.BADPARAM) @@ -661,7 +661,7 @@ class XMPMetaImpl : XMPMeta { // fieldNS and fieldName are checked inside composeStructFieldPath if (schemaNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (structName.isEmpty()) throw XMPException("Empty array name", XMPError.BADPARAM) @@ -693,7 +693,7 @@ class XMPMetaImpl : XMPMeta { ) { if (schemaNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (arrayName.isEmpty()) throw XMPException("Empty array name", XMPError.BADPARAM) @@ -717,7 +717,7 @@ class XMPMetaImpl : XMPMeta { ) { if (schemaNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (arrayName.isEmpty()) throw XMPException("Empty array name", XMPError.BADPARAM) @@ -740,7 +740,7 @@ class XMPMetaImpl : XMPMeta { ) { if (schemaNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (propName.isEmpty()) throw XMPException("Empty property name", XMPError.BADPARAM) @@ -767,7 +767,7 @@ class XMPMetaImpl : XMPMeta { ) { if (schemaNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (propName.isEmpty()) throw XMPException("Empty property name", XMPError.BADPARAM) @@ -790,7 +790,7 @@ class XMPMetaImpl : XMPMeta { ) { if (schemaNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (structName.isEmpty()) throw XMPException("Empty array name", XMPError.BADPARAM) diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt index 15b616c..f0832aa 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt @@ -33,7 +33,7 @@ import nl.adaptivity.xmlutil.dom.value /** * Parser for "normal" XML serialisation of RDF. */ -internal object XMPRDFParser : XMPError { +internal object XMPRDFParser { const val RDFTERM_OTHER = 0 diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPSchemaRegistryImpl.kt b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPSchemaRegistryImpl.kt index 83feb24..dd28a84 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPSchemaRegistryImpl.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPSchemaRegistryImpl.kt @@ -66,7 +66,7 @@ object XMPSchemaRegistryImpl : XMPSchemaRegistry { var suggestedPrefix = suggestedPrefix if (namespaceURI.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (suggestedPrefix.isEmpty()) throw XMPException("Empty prefix", XMPError.BADPARAM) @@ -283,13 +283,13 @@ object XMPSchemaRegistryImpl : XMPSchemaRegistry { ) { if (aliasNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (aliasProp.isEmpty()) throw XMPException("Empty property name", XMPError.BADPARAM) if (actualNS.isEmpty()) - throw XMPException("Empty schema namespace URI", XMPError.BADPARAM) + throw XMPException(XMPError.EMPTY_SCHEMA_TEXT, XMPError.BADPARAM) if (actualProp.isEmpty()) throw XMPException("Empty property name", XMPError.BADPARAM) From 63c4c016e34a79840c49e261297b2e6c91e37584 Mon Sep 17 00:00:00 2001 From: Stefan Oltmann Date: Mon, 10 Jul 2023 10:31:25 +0200 Subject: [PATCH 09/12] Avoided String duplication --- src/commonMain/kotlin/com/ashampoo/xmp/XMPError.kt | 1 + src/commonMain/kotlin/com/ashampoo/xmp/XMPUtils.kt | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/XMPError.kt b/src/commonMain/kotlin/com/ashampoo/xmp/XMPError.kt index 7b87fd4..c5a19ba 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/XMPError.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/XMPError.kt @@ -11,6 +11,7 @@ package com.ashampoo.xmp object XMPError { const val EMPTY_SCHEMA_TEXT: String = "Empty schema namespace URI" + const val EMPTY_CONVERT_STRING_TEXT: String = "Empty convert-string" const val UNKNOWN: Int = 0 const val BADPARAM: Int = 4 diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/XMPUtils.kt b/src/commonMain/kotlin/com/ashampoo/xmp/XMPUtils.kt index 2e1f99a..4c4897d 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/XMPUtils.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/XMPUtils.kt @@ -33,7 +33,7 @@ object XMPUtils { fun convertToBoolean(value: String?): Boolean { if (value.isNullOrEmpty()) - throw XMPException("Empty convert-string", XMPError.BADVALUE) + throw XMPException(XMPError.EMPTY_CONVERT_STRING_TEXT, XMPError.BADVALUE) val valueLowercase = value.lowercase() @@ -55,7 +55,7 @@ object XMPUtils { try { if (rawValue.isNullOrEmpty()) - throw XMPException("Empty convert-string", XMPError.BADVALUE) + throw XMPException(XMPError.EMPTY_CONVERT_STRING_TEXT, XMPError.BADVALUE) return if (rawValue.startsWith("0x")) rawValue.substring(2).toInt(16) @@ -73,7 +73,7 @@ object XMPUtils { try { if (rawValue.isNullOrEmpty()) - throw XMPException("Empty convert-string", XMPError.BADVALUE) + throw XMPException(XMPError.EMPTY_CONVERT_STRING_TEXT, XMPError.BADVALUE) return if (rawValue.startsWith("0x")) rawValue.substring(2).toLong(16) @@ -91,7 +91,7 @@ object XMPUtils { try { if (rawValue.isNullOrEmpty()) - throw XMPException("Empty convert-string", XMPError.BADVALUE) + throw XMPException(XMPError.EMPTY_CONVERT_STRING_TEXT, XMPError.BADVALUE) return rawValue.toDouble() From 58b60e4b87abcceee9d7b3a027a1df1c0117ed01 Mon Sep 17 00:00:00 2001 From: Stefan Oltmann Date: Mon, 10 Jul 2023 10:34:10 +0200 Subject: [PATCH 10/12] Code Style: Removed unnecessary "public" --- .../kotlin/com/ashampoo/xmp/options/SerializeOptions.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/options/SerializeOptions.kt b/src/commonMain/kotlin/com/ashampoo/xmp/options/SerializeOptions.kt index d814657..18755f4 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/options/SerializeOptions.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/options/SerializeOptions.kt @@ -100,9 +100,8 @@ class SerializeOptions : Options { /** * @return Returns clone of this SerializeOptions-object with the same options set. - * */ - public fun clone(): SerializeOptions = + fun clone(): SerializeOptions = SerializeOptions(getOptions()) /** From 62d364163b4c81a55b1540d4887a2785ede6e85e Mon Sep 17 00:00:00 2001 From: Stefan Oltmann Date: Mon, 10 Jul 2023 10:35:25 +0200 Subject: [PATCH 11/12] Detekt: Added suppression --- src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt | 1 + src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFWriter.kt | 1 + 2 files changed, 2 insertions(+) diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt index f0832aa..da54eb4 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt @@ -33,6 +33,7 @@ import nl.adaptivity.xmlutil.dom.value /** * Parser for "normal" XML serialisation of RDF. */ +@Suppress("TooManyFunctions") internal object XMPRDFParser { const val RDFTERM_OTHER = 0 diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFWriter.kt b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFWriter.kt index 2212624..b47ab56 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFWriter.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFWriter.kt @@ -20,6 +20,7 @@ import com.ashampoo.xmp.options.SerializeOptions * Serializes the `XMPMeta`-object using the standard RDF serialization format. * The output is a XMP String according to the `SerializeOptions`. */ +@Suppress("TooManyFunctions") internal class XMPRDFWriter( val xmp: XMPMetaImpl, val options: SerializeOptions From 566b1eb09c7481e2fd81191dd2c4f22c669e671b Mon Sep 17 00:00:00 2001 From: Stefan Oltmann Date: Mon, 10 Jul 2023 10:38:09 +0200 Subject: [PATCH 12/12] Detekt: Added suppression --- src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt | 2 +- .../kotlin/com/ashampoo/xmp/impl/XMPSchemaRegistryImpl.kt | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt index da54eb4..713a483 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt @@ -189,8 +189,8 @@ internal object XMPRDFParser { * Process the attribute list for an RDF node element. A property attribute URI is * anything other than an RDF term. The rdf:ID and rdf:nodeID attributes are simply ignored, * as are rdf:about attributes on inner nodes. - * */ + @Suppress("ThrowsCount") private fun parseRdfNodeElementAttrs( xmp: XMPMetaImpl, xmpParent: XMPNode, diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPSchemaRegistryImpl.kt b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPSchemaRegistryImpl.kt index dd28a84..3a9b39a 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPSchemaRegistryImpl.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPSchemaRegistryImpl.kt @@ -20,6 +20,7 @@ import com.ashampoo.xmp.properties.XMPAliasInfo * The schema registry handles the namespaces, aliases and global options for the XMP Toolkit. * There is only one single instance used by the toolkit. */ +@Suppress("TooManyFunctions") object XMPSchemaRegistryImpl : XMPSchemaRegistry { /** @@ -274,6 +275,7 @@ object XMPSchemaRegistryImpl : XMPSchemaRegistry { * direct aliases regardless of whether the actual data type is * an array or not (see [AliasOptions]). */ + @Suppress("ThrowsCount") fun registerAlias( aliasNS: String, aliasProp: String, @@ -350,6 +352,7 @@ object XMPSchemaRegistryImpl : XMPSchemaRegistry { * Register the standard aliases. * Note: This method is not lock because only called by the constructor. */ + @Suppress("StringLiteralDuplication", "LongMethod") private fun registerStandardAliases() { val aliasToArrayOrdered = AliasOptions().setArrayOrdered(true)