/// <summary> /// The initial support for WAV files mapped a legacy ID3 audio copyright /// into a new xmpDM:copyright property. /// </summary> /// <remarks> /// The initial support for WAV files mapped a legacy ID3 audio copyright /// into a new xmpDM:copyright property. This is special case code to migrate /// that into dc:rights['x-default']. The rules: /// <pre> /// 1. If there is no dc:rights array, or an empty array - /// Create one with dc:rights['x-default'] set from double linefeed and xmpDM:copyright. /// 2. If there is a dc:rights array but it has no x-default item - /// Create an x-default item as a copy of the first item then apply rule #3. /// 3. If there is a dc:rights array with an x-default item, /// Look for a double linefeed in the value. /// A. If no double linefeed, compare the x-default value to the xmpDM:copyright value. /// A1. If they match then leave the x-default value alone. /// A2. Otherwise, append a double linefeed and /// the xmpDM:copyright value to the x-default value. /// B. If there is a double linefeed, compare the trailing text to the xmpDM:copyright value. /// B1. If they match then leave the x-default value alone. /// B2. Otherwise, replace the trailing x-default text with the xmpDM:copyright value. /// 4. In all cases, delete the xmpDM:copyright property. /// </pre> /// </remarks> /// <param name="xmp">the metadata object</param> /// <param name="dmCopyright">the "dm:copyright"-property</param> private static void MigrateAudioCopyright(IXmpMeta xmp, XmpNode dmCopyright) { try { var dcSchema = XmpNodeUtils.FindSchemaNode(((XmpMeta)xmp).GetRoot(), XmpConstants.NsDC, true); var dmValue = dmCopyright.Value; var doubleLf = "\n\n"; var dcRightsArray = XmpNodeUtils.FindChildNode(dcSchema, "dc:rights", false); if (dcRightsArray == null || !dcRightsArray.HasChildren) { // 1. No dc:rights array, create from double linefeed and xmpDM:copyright. dmValue = doubleLf + dmValue; xmp.SetLocalizedText(XmpConstants.NsDC, "rights", string.Empty, XmpConstants.XDefault, dmValue, null); } else { var xdIndex = XmpNodeUtils.LookupLanguageItem(dcRightsArray, XmpConstants.XDefault); if (xdIndex < 0) { // 2. No x-default item, create from the first item. var firstValue = dcRightsArray.GetChild(1).Value; xmp.SetLocalizedText(XmpConstants.NsDC, "rights", string.Empty, XmpConstants.XDefault, firstValue, null); xdIndex = XmpNodeUtils.LookupLanguageItem(dcRightsArray, XmpConstants.XDefault); } // 3. Look for a double linefeed in the x-default value. var defaultNode = dcRightsArray.GetChild(xdIndex); var defaultValue = defaultNode.Value; var lfPos = defaultValue.IndexOf(doubleLf); if (lfPos < 0) { // 3A. No double LF, compare whole values. if (!dmValue.Equals(defaultValue)) { // 3A2. Append the xmpDM:copyright to the x-default // item. defaultNode.Value = defaultValue + doubleLf + dmValue; } } else { // 3B. Has double LF, compare the tail. if (!defaultValue.Substring(lfPos + 2).Equals(dmValue)) { // 3B2. Replace the x-default tail. defaultNode.Value = defaultValue.Substring(0, lfPos + 2 - 0) + dmValue; } } } // 4. Get rid of the xmpDM:copyright. dmCopyright.Parent.RemoveChild(dmCopyright); } catch (XmpException) { } }
virtual public void AddDocInfoProperty(Object key, String value) { if (key is String) { key = new PdfName((String)key); } if (PdfName.TITLE.Equals(key)) { xmpMeta.SetLocalizedText(XmpConst.NS_DC, DublinCoreProperties.TITLE, XmpConst.X_DEFAULT, XmpConst.X_DEFAULT, value); } else if (PdfName.AUTHOR.Equals(key)) { xmpMeta.AppendArrayItem(XmpConst.NS_DC, DublinCoreProperties.CREATOR, new PropertyOptions(PropertyOptions.ARRAY_ORDERED), value, null); } else if (PdfName.SUBJECT.Equals(key)) { xmpMeta.SetLocalizedText(XmpConst.NS_DC, DublinCoreProperties.DESCRIPTION, XmpConst.X_DEFAULT, XmpConst.X_DEFAULT, value); } else if (PdfName.KEYWORDS.Equals(key)) { foreach (String v in value.Split(',', ';')) { if (v.Trim().Length > 0) { xmpMeta.AppendArrayItem(XmpConst.NS_DC, DublinCoreProperties.SUBJECT, new PropertyOptions(PropertyOptions.ARRAY), v.Trim(), null); } } xmpMeta.SetProperty(XmpConst.NS_PDF, PdfProperties.KEYWORDS, value); } else if (PdfName.PRODUCER.Equals(key)) { xmpMeta.SetProperty(XmpConst.NS_PDF, PdfProperties.PRODUCER, value); } else if (PdfName.CREATOR.Equals(key)) { xmpMeta.SetProperty(XmpConst.NS_XMP, XmpBasicProperties.CREATORTOOL, value); } else if (PdfName.CREATIONDATE.Equals(key)) { xmpMeta.SetProperty(XmpConst.NS_XMP, XmpBasicProperties.CREATEDATE, PdfDate.GetW3CDate(value)); } else if (PdfName.MODDATE.Equals(key)) { xmpMeta.SetProperty(XmpConst.NS_XMP, XmpBasicProperties.MODIFYDATE, PdfDate.GetW3CDate(value)); } }
/** * Sets a description. * * @param xmpMeta * @param desc * @param genericLang The name of the generic language * @param specificLang The name of the specific language */ public static void SetDescription(IXmpMeta xmpMeta, String desc, String genericLang, String specificLang) { xmpMeta.SetLocalizedText(XmpConst.NS_DC, DESCRIPTION, genericLang, specificLang, desc); }
/** * Sets a title. * * @param xmpMeta * @param title * @param genericLang The name of the generic language * @param specificLang The name of the specific language */ public static void SetTitle(IXmpMeta xmpMeta, String title, String genericLang, String specificLang) { xmpMeta.SetLocalizedText(XmpConst.NS_DC, TITLE, genericLang, specificLang, title); }
/// <summary> /// The initial support for WAV files mapped a legacy ID3 audio copyright /// into a new xmpDM:copyright property. /// </summary> /// <remarks> /// The initial support for WAV files mapped a legacy ID3 audio copyright /// into a new xmpDM:copyright property. This is special case code to migrate /// that into dc:rights['x-default']. The rules: /// <pre> /// 1. If there is no dc:rights array, or an empty array - /// Create one with dc:rights['x-default'] set from double linefeed and xmpDM:copyright. /// 2. If there is a dc:rights array but it has no x-default item - /// Create an x-default item as a copy of the first item then apply rule #3. /// 3. If there is a dc:rights array with an x-default item, /// Look for a double linefeed in the value. /// A. If no double linefeed, compare the x-default value to the xmpDM:copyright value. /// A1. If they match then leave the x-default value alone. /// A2. Otherwise, append a double linefeed and /// the xmpDM:copyright value to the x-default value. /// B. If there is a double linefeed, compare the trailing text to the xmpDM:copyright value. /// B1. If they match then leave the x-default value alone. /// B2. Otherwise, replace the trailing x-default text with the xmpDM:copyright value. /// 4. In all cases, delete the xmpDM:copyright property. /// </pre> /// </remarks> /// <param name="xmp">the metadata object</param> /// <param name="dmCopyright">the "dm:copyright"-property</param> private static void MigrateAudioCopyright(IXmpMeta xmp, XmpNode dmCopyright) { try { var dcSchema = XmpNodeUtils.FindSchemaNode(((XmpMeta)xmp).GetRoot(), XmpConstants.NsDC, true); var dmValue = dmCopyright.Value; var doubleLf = "\n\n"; var dcRightsArray = XmpNodeUtils.FindChildNode(dcSchema, "dc:rights", false); if (dcRightsArray == null || !dcRightsArray.HasChildren) { // 1. No dc:rights array, create from double linefeed and xmpDM:copyright. dmValue = doubleLf + dmValue; xmp.SetLocalizedText(XmpConstants.NsDC, "rights", string.Empty, XmpConstants.XDefault, dmValue, null); } else { var xdIndex = XmpNodeUtils.LookupLanguageItem(dcRightsArray, XmpConstants.XDefault); if (xdIndex < 0) { // 2. No x-default item, create from the first item. var firstValue = dcRightsArray.GetChild(1).Value; xmp.SetLocalizedText(XmpConstants.NsDC, "rights", string.Empty, XmpConstants.XDefault, firstValue, null); xdIndex = XmpNodeUtils.LookupLanguageItem(dcRightsArray, XmpConstants.XDefault); } // 3. Look for a double linefeed in the x-default value. var defaultNode = dcRightsArray.GetChild(xdIndex); var defaultValue = defaultNode.Value; var lfPos = defaultValue.IndexOf(doubleLf); if (lfPos < 0) { // 3A. No double LF, compare whole values. if (!dmValue.Equals(defaultValue)) { // 3A2. Append the xmpDM:copyright to the x-default // item. defaultNode.Value = defaultValue + doubleLf + dmValue; } } else { // 3B. Has double LF, compare the tail. if (!defaultValue.Substring (lfPos + 2).Equals(dmValue)) { // 3B2. Replace the x-default tail. defaultNode.Value = defaultValue.Substring (0, lfPos + 2 - 0) + dmValue; } } } // 4. Get rid of the xmpDM:copyright. dmCopyright.Parent.RemoveChild(dmCopyright); } catch (XmpException) { } }