Example #1
0
        private static IXmpMeta ParseXmlDoc(XDocument document, ParseOptions options)
        {
            // sort node Attributes to match Java DocumentBuilder (attribute order isn't supposed to matter but DocumentBuilder does some sorting)
            // namespace declarations come first, and then all are sorted in prefix:localname order
            foreach (var node in document.Descendants().Where(d => d.Attributes().Count() > 1))
            {
                var orderedattribs = node.Attributes()
                                     .OrderBy(n => !n.IsNamespaceDeclaration)
                                     .ThenBy(t => node.GetPrefixOfNamespace(t.Name.Namespace), StringComparer.Ordinal)
                                     .ThenBy(s => s.Name.LocalName, StringComparer.Ordinal);
                node.ReplaceAttributes(orderedattribs);
            }

            var result = FindRootNode(document.Nodes(), options.RequireXmpMeta, new object[3]);

            if (result == null || result[1] != XmpRdf)
            {
                // no appropriate root node found, return empty metadata object
                return(new XmpMeta());
            }

            var xmp = ParseRdf.Parse((XElement)result[0]);

            xmp.SetPacketHeader((string)result[2]);

            // Check if the XMP object shall be normalized
            return(!options.OmitNormalization
                ? XmpNormalizer.Process(xmp, options)
                : xmp);
        }
Example #2
0
        /// <summary>
        /// Parses the input source into an XMP metadata object, including
        /// de-aliasing and normalisation.
        /// </summary>
        /// <param name="input"> the input can be an <code>InputStream</code>, a <code>String</code> or
        ///             a byte buffer containing the XMP packet. </param>
        /// <param name="options"> the parse options </param>
        /// <returns> Returns the resulting XMP metadata object </returns>
        /// <exception cref="XmpException"> Thrown if parsing or normalisation fails. </exception>
        public static XMPMeta Parse(object input, ParseOptions options)
        {
            ParameterAsserts.AssertNotNull(input);
            options = options ?? new ParseOptions();

            XmlDocument document = ParseXml(input, options);

            bool xmpmetaRequired = options.RequireXmpMeta;

            object[] result = new object[3];
            result = FindRootNode(document, xmpmetaRequired, result);

            if (result != null && result[1] == XmpRdf)
            {
                XmpMetaImpl xmp = ParseRdf.Parse((XmlNode)result[0]);
                xmp.PacketHeader = (string)result[2];

                // Check if the XMP object shall be normalized
                if (!options.OmitNormalization)
                {
                    return(XmpNormalizer.Process(xmp, options));
                }
                return(xmp);
            }
            // no appropriate root node found, return empty metadata object
            return(new XmpMetaImpl());
        }
Example #3
0
 private static IXmpMeta ParseXmlDoc(XmlDocument document, ParseOptions options)
 {
     object[] result;
     if (FindRootNode(document, options.RequireXmpMeta, out result) && result[1] == XmpRdf)
     {
         var xmp = ParseRdf.Parse((XmlNode)result[0]);
         xmp.SetPacketHeader((string)result[2]);
         // Check if the XMP object shall be normalized
         if (!options.OmitNormalization)
         {
             return(XmpNormalizer.Process(xmp, options));
         }
         return(xmp);
     }
     // no appropriate root node found, return empty metadata object
     return(new XmpMeta());
 }