Class XMPUtils
Utility methods for XMP.
public sealed class XMPUtils
- Inheritance
-
XMPUtils
- Inherited Members
Remarks
Utility methods for XMP. I included only those that are different from the Java default conversion utilities.
Methods
AppendProperties(XMPMeta, XMPMeta, bool, bool)
Alias without the new option deleteEmptyValues
.
public static void AppendProperties(XMPMeta source, XMPMeta dest, bool doAllProperties, bool replaceOldValues)
Parameters
source
XMPMetaThe source XMP object.
dest
XMPMetaThe destination XMP object.
doAllProperties
boolDo internal properties in addition to external properties.
replaceOldValues
boolReplace the values of existing properties.
AppendProperties(XMPMeta, XMPMeta, bool, bool, bool)
Append properties from one XMP object to another.
public static void AppendProperties(XMPMeta source, XMPMeta dest, bool doAllProperties, bool replaceOldValues, bool deleteEmptyValues)
Parameters
source
XMPMetaThe source XMP object.
dest
XMPMetaThe destination XMP object.
doAllProperties
boolDo internal properties in addition to external properties.
replaceOldValues
boolReplace the values of existing properties.
deleteEmptyValues
boolDelete destination values if source property is empty.
Remarks
Append properties from one XMP object to another.
XMPUtils#appendProperties was created to support the File Info dialog's Append button, and has been been generalized somewhat from those specific needs. It appends information from one XMP object (source) to another (dest). The default operation is to append only external properties that do not already exist in the destination. The flagdoAllProperties
can be used to operate on all properties, external and internal.
The flag replaceOldValues
option can be used to replace the values
of existing properties. The notion of external
versus internal applies only to top level properties. The keep-or-replace-old notion applies
within structs and arrays as described below.
- If
replaceOldValues
is true then the processing is restricted to the top level properties. The processed properties from the source (according todoAllProperties
) are propagated to the destination, replacing any existing values.Properties in the destination that are not in the source are left alone. - If
replaceOldValues
is not passed then the processing is more complicated. Top level properties are added to the destination if they do not already exist. If they do exist but differ in form (simple/struct/array) then the destination is left alone. If the forms match, simple properties are left unchanged while structs and arrays are merged. - If
deleteEmptyValues
is passed then an empty value in the source XMP causes the corresponding destination XMP property to be deleted. The default is to treat empty values the same as non-empty values. An empty value is any of a simple empty string, an array with no items, or a struct with no fields. Qualifiers are ignored.
Note: appendProperties can be expensive if replaceOldValues is not passed and the XMP contains large arrays. The array item checking described above is n-squared. Each source item is checked to see if it already exists in the destination, without regard to order or duplicates. Simple items are compared by value and "xml:lang" qualifier, other qualifiers are ignored. Structs are recursively compared by field names, without regard to field order. Arrays are compared by recursively comparing all items.appendProperties ( sourceXMP, destXMP, doAllProperties, replaceOldValues, deleteEmptyValues ): for all source schema (top level namespaces): for all top level properties in sourceSchema: if doAllProperties or prop is external: appendSubtree ( sourceNode, destSchema, replaceOldValues, deleteEmptyValues ) appendSubtree ( sourceNode, destParent, replaceOldValues, deleteEmptyValues ): if deleteEmptyValues and source value is empty: delete the corresponding child from destParent else if sourceNode not in destParent (by name): copy sourceNode's subtree to destParent else if replaceOld: delete subtree from destParent copy sourceNode's subtree to destParent else: // Already exists in dest and not replacing, merge structs and arrays if sourceNode and destNode forms differ: return, leave the destNode alone else if form is a struct: for each field in sourceNode: AppendSubtree ( sourceNode.field, destNode, replaceOldValues ) else if form is an alt-text array: copy new items by "xml:lang" value into the destination else if form is an array: copy new items by value into the destination, ignoring order and duplicates
CatenateArrayItems(XMPMeta, string, string, string, string, bool)
Create a single edit string from an array of strings.
public static string CatenateArrayItems(XMPMeta xmp, string schemaNS, string arrayName, string separator, string quotes, bool allowCommas)
Parameters
xmp
XMPMetaThe XMP object containing the array to be catenated.
schemaNS
stringThe schema namespace URI for the array. Must not be null or the empty string.
arrayName
stringThe name of the array. May be a general path expression, must not be null or the empty string. Each item in the array must be a simple string value.
separator
stringThe string to be used to separate the items in the catenated string. Defaults to "; ", ASCII semicolon and space (U+003B, U+0020).
quotes
stringThe characters to be used as quotes around array items that contain a separator. Defaults to '"'
allowCommas
boolOption flag to control the catenation.
Returns
- string
Returns the string containing the catenated array items.
ConvertFromBoolean(bool)
Convert from boolean to string.
public static string ConvertFromBoolean(bool value)
Parameters
value
boola boolean value
Returns
- string
The XMP string representation of the boolean. The values used are given by the constnts TRUESTR and FALSESTR.
ConvertFromDate(XMPDateTime)
Convert from XMPDateTime
to string.
public static string ConvertFromDate(XMPDateTime value)
Parameters
value
XMPDateTimean
XMPDateTime
Returns
- string
The string representation of the long.
ConvertFromDouble(double)
Convert from long to string.
public static string ConvertFromDouble(double value)
Parameters
value
doublea long value
Returns
- string
The string representation of the long.
ConvertFromInteger(int)
Convert from int to string.
public static string ConvertFromInteger(int value)
Parameters
value
intan int value
Returns
- string
The string representation of the int.
ConvertFromLong(long)
Convert from long to string.
public static string ConvertFromLong(long value)
Parameters
value
longa long value
Returns
- string
The string representation of the long.
ConvertToBoolean(string)
Convert from string to Boolean.
public static bool ConvertToBoolean(string value)
Parameters
value
stringThe string representation of the Boolean.
Returns
- bool
The appropriate boolean value for the string. The checked values for
true
andfalse
are:
ConvertToDate(string)
Converts a string value to an XMPDateTime
.
public static XMPDateTime ConvertToDate(string rawValue)
Parameters
rawValue
stringthe string value
Returns
- XMPDateTime
Returns an
XMPDateTime
-object.
ConvertToDouble(string)
Converts a string value to a double
.
public static double ConvertToDouble(string rawValue)
Parameters
rawValue
stringthe string value
Returns
- double
Returns a double.
ConvertToInteger(string)
Converts a string value to an int
.
public static int ConvertToInteger(string rawValue)
Parameters
rawValue
stringthe string value
Returns
- int
Returns an int.
ConvertToLong(string)
Converts a string value to a long
.
public static long ConvertToLong(string rawValue)
Parameters
rawValue
stringthe string value
Returns
- long
Returns a long.
DecodeBase64(string)
Decode from Base64 encoded string to raw data.
public static byte[] DecodeBase64(string base64String)
Parameters
base64String
stringa base64 encoded string
Returns
- byte[]
Returns a byte array containg the decoded string.
EncodeBase64(byte[])
Convert from a byte array to a base64 encoded string.
public static string EncodeBase64(byte[] buffer)
Parameters
buffer
byte[]the byte array to be converted
Returns
- string
Returns the base64 string.
RemoveProperties(XMPMeta, string, string, bool, bool)
Remove multiple properties from an XMP object.
public static void RemoveProperties(XMPMeta xmp, string schemaNS, string propName, bool doAllProperties, bool includeAliases)
Parameters
xmp
XMPMetaThe XMP object containing the properties to be removed.
schemaNS
stringOptional schema namespace URI for the properties to be removed.
propName
stringOptional path expression for the property to be removed.
doAllProperties
boolOption flag to control the deletion: do internal properties in addition to external properties.
includeAliases
boolOption flag to control the deletion: Include aliases in the "named schema" case above. Note: Currently not supported.
Remarks
Remove multiple properties from an XMP object. RemoveProperties was created to support the File Info dialog's Delete button, and has been been generalized somewhat from those specific needs. It operates in one of three main modes depending on the schemaNS and propName parameters:
- Non-empty
schemaNS
andpropName
- The named property is removed if it is an external property, or if the flagdoAllProperties
option is true. It does not matter whether the named property is an actual property or an alias. - Non-empty
schemaNS
and emptypropName
- The all external properties in the named schema are removed. Internal properties are also removed if the flagdoAllProperties
option is set. In addition, aliases from the named schema will be removed if the flagincludeAliases
option is set. - Empty
schemaNS
and emptypropName
- All external properties in all schema are removed. Internal properties are also removed if the flagdoAllProperties
option is passed. Aliases are implicitly handled because the associated actuals are internal if the alias is.
schemaNS
and non-empty propName
.
SeparateArrayItems(XMPMeta, string, string, string, PropertyOptions, bool)
Separate a single edit string into an array of strings.
public static void SeparateArrayItems(XMPMeta xmp, string schemaNS, string arrayName, string catedStr, PropertyOptions arrayOptions, bool preserveCommas)
Parameters
xmp
XMPMetaThe XMP object containing the array to be updated.
schemaNS
stringThe schema namespace URI for the array. Must not be null or the empty string.
arrayName
stringThe name of the array. May be a general path expression, must not be null or the empty string. Each item in the array must be a simple string value.
catedStr
stringThe string to be separated into the array items.
arrayOptions
PropertyOptionsOption flags to control the separation.
preserveCommas
boolFlag if commas shall be preserved