diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/XMPError.kt b/src/commonMain/kotlin/com/ashampoo/xmp/XMPError.kt index e61bfc3..c5a19ba 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/XMPError.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/XMPError.kt @@ -8,21 +8,22 @@ // ================================================================================================= 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 EMPTY_CONVERT_STRING_TEXT: String = "Empty convert-string" + + 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/XMPMetaFactory.kt b/src/commonMain/kotlin/com/ashampoo/xmp/XMPMetaFactory.kt index 690589f..528d305 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/XMPMetaFactory.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/XMPMetaFactory.kt @@ -28,23 +28,27 @@ object XMPMetaFactory { fun create(): XMPMeta = XMPMetaImpl() + @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/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() 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/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/XMPMetaParser.kt b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPMetaParser.kt index 3007b5f..16e8b4e 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 @@ -42,12 +42,14 @@ object XMPMetaParser { */ fun parse( input: String, - options: ParseOptions = ParseOptions() + options: ParseOptions? ): XMPMeta { - val document = XmlUtilDomParser.parseDocumentFromString(input) + val actualOptions = options ?: ParseOptions() - val xmpmetaRequired = options.getRequireXMPMeta() + val document = DomParser.parseDocumentFromString(input) + + val xmpmetaRequired = actualOptions.getRequireXMPMeta() var result: Array? = arrayOfNulls(3) @@ -55,13 +57,13 @@ 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 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..713a483 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt @@ -33,7 +33,8 @@ import nl.adaptivity.xmlutil.dom.value /** * Parser for "normal" XML serialisation of RDF. */ -internal object XMPRDFParser : XMPError { +@Suppress("TooManyFunctions") +internal object XMPRDFParser { const val RDFTERM_OTHER = 0 @@ -188,8 +189,8 @@ internal object XMPRDFParser : XMPError { * 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, @@ -520,7 +521,7 @@ internal object XMPRDFParser : XMPError { typeName += ":$localName" - addQualifierNode(newCompound, "rdf:type", typeName) + addQualifierNode(newCompound, XMPConst.RDF_TYPE, typeName) } } } @@ -850,10 +851,6 @@ internal object XMPRDFParser : XMPError { isTopLevel: Boolean ): XMPNode { - var actualXmpParent = xmpParent - - val registry = schemaRegistry - var namespace = when (xmlNode) { is Element -> xmlNode.namespaceURI is Attr -> xmlNode.namespaceURI @@ -870,7 +867,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 +882,7 @@ internal object XMPRDFParser : XMPError { else DEFAULT_PREFIX - prefix = registry.registerNamespace(namespace, prefix) + prefix = schemaRegistry.registerNamespace(namespace, prefix) } val xmlNodeLocalName = when (xmlNode) { @@ -901,6 +898,8 @@ internal object XMPRDFParser : XMPError { var isAlias = false + var actualXmpParent = xmpParent + if (isTopLevel) { // Lookup the schema node, adjust the XMP parent pointer. @@ -920,7 +919,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 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 diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPSchemaRegistryImpl.kt b/src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPSchemaRegistryImpl.kt index 83feb24..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 { /** @@ -66,7 +67,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) @@ -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, @@ -283,13 +285,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) @@ -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) 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) - } - } -} 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()) /**