Ejemplo n.º 1
0
        /// <summary>
        /// Parses XML from a byte buffer,
        /// fixing the encoding (Latin-1 to UTF-8) and illegal control character optionally.
        /// </summary>
        /// <param name="buffer">a byte buffer containing the XMP packet</param>
        /// <param name="options">the parsing options</param>
        /// <returns>Returns an XML DOM-Document.</returns>
        /// <exception cref="Com.Adobe.Xmp.XMPException">Thrown when the parsing fails.</exception>
        private static XmlDocument ParseXmlFromBytebuffer(ByteBuffer buffer, ParseOptions options)
        {
            InputSource source = new InputSource(buffer.GetByteStream());

            try
            {
                return(ParseInputSource(source));
            }
            catch (XMPException e)
            {
                if (e.GetErrorCode() == XMPErrorConstants.Badxml || e.GetErrorCode() == XMPErrorConstants.Badstream)
                {
                    if (options.GetAcceptLatin1())
                    {
                        buffer = Latin1Converter.Convert(buffer);
                    }
                    if (options.GetFixControlChars())
                    {
                        try
                        {
                            string encoding = buffer.GetEncoding();
                            System.IO.StreamReader fixReader = new FixASCIIControlsReader(new InputStreamReader(buffer.GetByteStream(), encoding));
                            return(ParseInputSource(new InputSource(fixReader)));
                        }
                        catch (UnsupportedEncodingException)
                        {
                            // can normally not happen as the encoding is provided by a util function
                            throw new XMPException("Unsupported Encoding", XMPErrorConstants.Internalfailure, e);
                        }
                    }
                    source = new InputSource(buffer.GetByteStream());
                    return(ParseInputSource(source));
                }
                else
                {
                    throw;
                }
            }
        }
Ejemplo n.º 2
0
		/// <summary>
		/// Parses XML from a byte buffer,
		/// fixing the encoding (Latin-1 to UTF-8) and illegal control character optionally.
		/// </summary>
		/// <param name="buffer">a byte buffer containing the XMP packet</param>
		/// <param name="options">the parsing options</param>
		/// <returns>Returns an XML DOM-Document.</returns>
		/// <exception cref="Com.Adobe.Xmp.XMPException">Thrown when the parsing fails.</exception>
		private static XmlDocument ParseXmlFromBytebuffer(ByteBuffer buffer, ParseOptions options)
		{
			InputSource source = new InputSource(buffer.GetByteStream());
			try
			{
				return ParseInputSource(source);
			}
			catch (XMPException e)
			{
				if (e.GetErrorCode() == XMPErrorConstants.Badxml || e.GetErrorCode() == XMPErrorConstants.Badstream)
				{
					if (options.GetAcceptLatin1())
					{
						buffer = Latin1Converter.Convert(buffer);
					}
					if (options.GetFixControlChars())
					{
						try
						{
							string encoding = buffer.GetEncoding();
							System.IO.StreamReader fixReader = new FixASCIIControlsReader(new InputStreamReader(buffer.GetByteStream(), encoding));
							return ParseInputSource(new InputSource(fixReader));
						}
						catch (UnsupportedEncodingException)
						{
							// can normally not happen as the encoding is provided by a util function
							throw new XMPException("Unsupported Encoding", XMPErrorConstants.Internalfailure, e);
						}
					}
					source = new InputSource(buffer.GetByteStream());
					return ParseInputSource(source);
				}
				else
				{
					throw;
				}
			}
		}