/// <exception cref="iText.Kernel.XMP.XMPException"/>
        private static void AppendArrayItemIfDoesNotExist(XMPMeta meta, String ns, String arrayName, String value)
        {
            int currentCnt = meta.CountArrayItems(ns, arrayName);

            for (int i = 0; i < currentCnt; i++)
            {
                XMPProperty item = meta.GetArrayItem(ns, arrayName, i + 1);
                if (value.Equals(item.GetValue()))
                {
                    return;
                }
            }
            meta.AppendArrayItem(ns, arrayName, new PropertyOptions(PropertyOptions.ARRAY_ORDERED), value, null);
        }
Example #2
0
        /// <exception cref="iText.Kernel.XMP.XMPException"/>
        private static String FetchArrayIntoString(XMPMeta meta, String ns, String arrayName)
        {
            int           keywordsCnt = meta.CountArrayItems(ns, arrayName);
            StringBuilder sb          = null;

            for (int i = 0; i < keywordsCnt; i++)
            {
                XMPProperty curKeyword = meta.GetArrayItem(ns, arrayName, i + 1);
                if (sb == null)
                {
                    sb = new StringBuilder();
                }
                else
                {
                    if (sb.Length > 0)
                    {
                        sb.Append("; ");
                    }
                }
                sb.Append(curKeyword.GetValue());
            }
            return(sb != null?sb.ToString() : null);
        }
Example #3
0
        /// <summary>Reads an property value with given namespace URI and property name.</summary>
        /// <remarks>Reads an property value with given namespace URI and property name. Add property value to directory if exists</remarks>
        /// <exception cref="Com.Adobe.Xmp.XMPException"/>
        private static void ProcessXmpTag([NotNull] XMPMeta meta, [NotNull] XmpDirectory directory, int tagType, int formatCode)
        {
            string schemaNS = XmpDirectory._tagSchemaMap.Get(tagType);
            string propName = XmpDirectory._tagPropNameMap.Get(tagType);
            string property = meta.GetPropertyString(schemaNS, propName);

            if (property == null)
            {
                return;
            }
            switch (formatCode)
            {
            case FmtRational:
            {
                string[] rationalParts = property.Split("/", 2);
                if (rationalParts.Length == 2)
                {
                    try
                    {
                        Rational rational = new Rational((long)float.Parse(rationalParts[0]), (long)float.Parse(rationalParts[1]));
                        directory.SetRational(tagType, rational);
                    }
                    catch (FormatException)
                    {
                        directory.AddError(Sharpen.Extensions.StringFormat("Unable to parse XMP property %s as a Rational.", propName));
                    }
                }
                else
                {
                    directory.AddError("Error in rational format for tag " + tagType);
                }
                break;
            }

            case FmtInt:
            {
                try
                {
                    directory.SetInt(tagType, (int)Sharpen.Extensions.ValueOf(property));
                }
                catch (FormatException)
                {
                    directory.AddError(Sharpen.Extensions.StringFormat("Unable to parse XMP property %s as an int.", propName));
                }
                break;
            }

            case FmtDouble:
            {
                try
                {
                    directory.SetDouble(tagType, (double)double.Parse(property));
                }
                catch (FormatException)
                {
                    directory.AddError(Sharpen.Extensions.StringFormat("Unable to parse XMP property %s as an double.", propName));
                }
                break;
            }

            case FmtString:
            {
                directory.SetString(tagType, property);
                break;
            }

            case FmtStringArray:
            {
                //XMP iterators are 1-based
                int      count = meta.CountArrayItems(schemaNS, propName);
                string[] array = new string[count];
                for (int i = 1; i <= count; ++i)
                {
                    array[i - 1] = meta.GetArrayItem(schemaNS, propName, i).GetValue();
                }
                directory.SetStringArray(tagType, array);
                break;
            }

            default:
            {
                directory.AddError(Sharpen.Extensions.StringFormat("Unknown format code %d for tag %d", formatCode, tagType));
                break;
            }
            }
        }