/// <summary>Utility to find or create the array used by <code>SeparateArrayItems()</code>.</summary> /// <param name="schemaNS">a the namespace fo the array</param> /// <param name="arrayName">the name of the array</param> /// <param name="arrayOptions">the options for the array if newly created</param> /// <param name="xmp">the xmp object</param> /// <returns>Returns the array node.</returns> /// <exception cref="Com.Adobe.Xmp.XMPException">Forwards exceptions</exception> private static XMPNode SeparateFindCreateArray(string schemaNS, string arrayName, PropertyOptions arrayOptions, XMPMetaImpl xmp) { arrayOptions = XMPNodeUtils.VerifySetOptions(arrayOptions, null); if (!arrayOptions.IsOnlyArrayOptions()) { throw new XMPException("Options can only provide array form", XMPErrorConstants.Badoptions); } // Find the array node, make sure it is OK. Move the current children // aside, to be readded later if kept. XMPPath arrayPath = XMPPathParser.ExpandXPath(schemaNS, arrayName); XMPNode arrayNode = XMPNodeUtils.FindNode(xmp.GetRoot(), arrayPath, false, null); if (arrayNode != null) { // The array exists, make sure the form is compatible. Zero // arrayForm means take what exists. PropertyOptions arrayForm = arrayNode.GetOptions(); if (!arrayForm.IsArray() || arrayForm.IsArrayAlternate()) { throw new XMPException("Named property must be non-alternate array", XMPErrorConstants.Badxpath); } if (arrayOptions.EqualArrayTypes(arrayForm)) { throw new XMPException("Mismatch of specified and existing array form", XMPErrorConstants.Badxpath); } } else { // *** Right error? // The array does not exist, try to create it. // don't modify the options handed into the method arrayNode = XMPNodeUtils.FindNode(xmp.GetRoot(), arrayPath, true, arrayOptions.SetArray(true)); if (arrayNode == null) { throw new XMPException("Failed to create named array", XMPErrorConstants.Badxpath); } } return arrayNode; }
// Don't let failures (like a bad dc:rights form) stop other // cleanup. /// <summary> /// Initializes the map that contains the known arrays, that are fixed by /// <see cref="NormalizeDCArrays(XMPNode)"/> /// . /// </summary> private static void InitDCArrays() { dcArrayForms = new Hashtable(); // Properties supposed to be a "Bag". PropertyOptions bagForm = new PropertyOptions(); bagForm.SetArray(true); dcArrayForms.Put("dc:contributor", bagForm); dcArrayForms.Put("dc:language", bagForm); dcArrayForms.Put("dc:publisher", bagForm); dcArrayForms.Put("dc:relation", bagForm); dcArrayForms.Put("dc:subject", bagForm); dcArrayForms.Put("dc:type", bagForm); // Properties supposed to be a "Seq". PropertyOptions seqForm = new PropertyOptions(); seqForm.SetArray(true); seqForm.SetArrayOrdered(true); dcArrayForms.Put("dc:creator", seqForm); dcArrayForms.Put("dc:date", seqForm); // Properties supposed to be an "Alt" in alternative-text form. PropertyOptions altTextForm = new PropertyOptions(); altTextForm.SetArray(true); altTextForm.SetArrayOrdered(true); altTextForm.SetArrayAlternate(true); altTextForm.SetArrayAltText(true); dcArrayForms.Put("dc:description", altTextForm); dcArrayForms.Put("dc:rights", altTextForm); dcArrayForms.Put("dc:title", altTextForm); }