예제 #1
0
		// 7.2.9 RDF
		//		start-element ( URI == rdf:RDF, attributes == set() )
		//		nodeElementList
		//		end-element()
		private XmpNode ParseRDF (XmlNode rdf_node, TagLib.File file)
		{
			XmpNode top = new XmpNode (String.Empty, String.Empty);
			foreach (XmlNode node in rdf_node.ChildNodes) {
				if (node is XmlWhitespace)
					continue;

				if (node.Is (RDF_NS, DESCRIPTION_URI)) {
					var attr = node.Attributes.GetNamedItem (RDF_NS, ABOUT_URI) as XmlAttribute;
					if (attr != null) {
						if (top.Name != String.Empty && top.Name != attr.InnerText)
							throw new CorruptFileException ("Multiple inconsistent rdf:about values!");
						top.Name = attr.InnerText;
					}
					continue;
				}

				file.MarkAsCorrupt ("Cannot have anything other than rdf:Description at the top level");
				return top;
			}
			ParseNodeElementList (top, rdf_node);
			return top;
		}
        /// <summary>
        ///    Construcor.
        /// </summary>
        /// <param name="tag">
        ///    A <see cref="System.UInt16"/> with the tag ID of the entry this instance
        ///    represents
        /// </param>
        /// <param name="data">
        ///    A <see cref="ByteVector"/> to be stored
        /// </param>
        /// <param name="file">
        ///    The file that's currently being parsed, used for reporting corruptions.
        /// </param>
        public UserCommentIFDEntry(ushort tag, ByteVector data, TagLib.File file)
        {
            Tag = tag;

            if (data.StartsWith (COMMENT_ASCII_CODE)) {
                Value = TrimNull (data.ToString (StringType.Latin1, COMMENT_ASCII_CODE.Count, data.Count - COMMENT_ASCII_CODE.Count));
                return;
            }

            if (data.StartsWith (COMMENT_UNICODE_CODE)) {
                Value = TrimNull (data.ToString (StringType.UTF8, COMMENT_UNICODE_CODE.Count, data.Count - COMMENT_UNICODE_CODE.Count));
                return;
            }

            var trimmed = data.ToString ().Trim ();
            if (trimmed.Length == 0 || trimmed == "\0") {
                Value = String.Empty;
                return;
            }

            // Some programs like e.g. CanonZoomBrowser inserts just the first 0x00-byte
            // followed by 7-bytes of trash.
            if (data.StartsWith ((byte) 0x00) && data.Count >= 8) {

                // And CanonZoomBrowser fills some trailing bytes of the comment field
                // with '\0'. So we return only the characters before the first '\0'.
                int term = data.Find ("\0", 8);
                if (term != -1) {
                    Value = data.ToString (StringType.Latin1, 8, term - 8);
                } else {
                    Value = data.ToString (StringType.Latin1, 8, data.Count - 8);
                }
                return;
            }

            if (data.Data.Length == 0) {
                Value = String.Empty;
                return;
            }

            // Try to parse anyway
            int offset = 0;
            int length = data.Count - offset;

            // Corruption that starts with a Unicode header and a count byte.
            if (data.StartsWith (COMMENT_BAD_UNICODE_CODE)) {
                offset = COMMENT_BAD_UNICODE_CODE.Count;
                length = data.Count - offset;
            }

            file.MarkAsCorrupt ("UserComment with other encoding than Latin1 or Unicode");
            Value = TrimNull (data.ToString (StringType.UTF8, offset, length));
        }