An XmpNode represents a node in the XMP document. This is any valid XMP element.
        /// <summary>
        ///    Adds a node as qualifier of the current instance
        /// </summary>
        /// <param name="node">
        ///    A <see cref="XmpNode"/> to add as qualifier
        /// </param>
        public void AddQualifier(XmpNode node)
        {
            if (node == null || node == this)
                throw new ArgumentException ("node");

            if (qualifiers == null)
                qualifiers = new Dictionary<string, Dictionary<string, XmpNode>> ();

            if (!qualifiers.ContainsKey (node.Namespace))
                qualifiers [node.Namespace] = new Dictionary<string, XmpNode> ();

            qualifiers [node.Namespace][node.Name] = node;
        }
Beispiel #2
0
        private void ParsePropertyElement(XmpNode parent, XmlNode node)
        {
            int  count     = 0;
            bool has_other = false;

            foreach (XmlAttribute attr in node.Attributes)
            {
                if (!attr.In(XMLNS_NS))
                {
                    count++;
                }
                if (!attr.Is(XML_NS, LANG_URI) && !attr.Is(RDF_NS, ID_URI) && !attr.In(XMLNS_NS))
                {
                    has_other = true;
                }
            }
            if (count > 3)
            {
                ParseEmptyPropertyElement(parent, node);
            }
            else
            {
                if (!has_other)
                {
                    if (!node.HasChildNodes)
                    {
                        ParseEmptyPropertyElement(parent, node);
                    }
                    else
                    {
                        bool only_text = true;
                        foreach (XmlNode child in node.ChildNodes)
                        {
                            if (!(child is XmlText))
                            {
                                only_text = false;
                            }
                        }
                        if (only_text)
                        {
                            ParseLiteralPropertyElement(parent, node);
                        }
                        else
                        {
                            ParseResourcePropertyElement(parent, node);
                        }
                    }
                }
                else
                {
                    foreach (XmlAttribute attr in node.Attributes)
                    {
                        if (attr.Is(XML_NS, LANG_URI) || attr.Is(RDF_NS, ID_URI) || attr.In(XMLNS_NS))
                        {
                            continue;
                        }
                        if (attr.Is(RDF_NS, DATA_TYPE_URI))
                        {
                            ParseLiteralPropertyElement(parent, node);
                        }
                        else if (!attr.Is(RDF_NS, PARSE_TYPE_URI))
                        {
                            ParseEmptyPropertyElement(parent, node);
                        }
                        else if (attr.InnerText.Equals("Resource"))
                        {
                            ParseTypeResourcePropertyElement(parent, node);
                        }
                        else
                        {
                            throw new CorruptFileException(String.Format("This is not allowed in XMP! Bad XMP: {0}", node.OuterXml));
                        }
                    }
                }
            }
        }
Beispiel #3
0
		private XmpNode NewNode (string ns, string name)
		{
			Dictionary <string, XmpNode> ns_nodes = null;

			if (!nodes.ContainsKey (ns)) {
				ns_nodes = new Dictionary <string, XmpNode> ();
				nodes.Add (ns, ns_nodes);

			} else
				ns_nodes = nodes [ns];

			if (ns_nodes.ContainsKey (name)) {
				foreach (XmpNode child_node in NodeTree.Children) {
					if (child_node.Namespace == ns && child_node.Name == name) {
						NodeTree.RemoveChild (child_node);
						break;
					}
				}

				ns_nodes.Remove (name);
			}

			XmpNode node = new XmpNode (ns, name);
			ns_nodes.Add (name, node);

			NodeTree.AddChild (node);

			return node;
		}
Beispiel #4
0
		/// <summary>
		///    Stores a the given <paramref name="value"/> as the default language
		///    value for the alt-node associated with the namespace
		///    <paramref name="ns"/> and the name <paramref name="name"/>.
		///    All other alternatives set, are deleted by this method.
		/// </summary>
		/// <param name="ns">
		///    A <see cref="System.String"/> with the namespace of the node.
		/// </param>
		/// <param name="name">
		///    A <see cref="System.String"/> with the name of the node.
		/// </param>
		/// <param name="value">
		///    A <see cref="System.String"/> with the value for the default language
		///    to set. If <see langword="null"/> is given, a possibly existing node
		///    will be deleted.
		/// </param>
		public void SetLangAltNode (string ns, string name, string value)
		{
			if (value == null) {
				RemoveNode (ns, name);
				return;
			}

			var node = NewNode (ns, name, XmpNodeType.Alt);

			var child_node = new XmpNode (RDF_NS, LI_URI, value);
			child_node.AddQualifier (new XmpNode (XML_NS, "lang", "x-default"));

			node.AddChild (child_node);
		}
Beispiel #5
0
		// 7.2.16 literalPropertyElt
		//		start-element ( URI == propertyElementURIs, attributes == set ( idAttr?, datatypeAttr?) )
		//		text()
		//		end-element()
		private void ParseLiteralPropertyElement (XmpNode parent, XmlNode node)
		{
			if (!node.IsPropertyElement ())
				throw new CorruptFileException ("Invalid property");
			parent.AddChild (CreateTextPropertyWithQualifiers (node, node.InnerText));
		}
Beispiel #6
0
		// 7.2.21 emptyPropertyElt
		//		start-element ( URI == propertyElementURIs,
		//						attributes == set ( idAttr?, ( resourceAttr | nodeIdAttr )?, propertyAttr* ) )
		//		end-element()
		private void ParseEmptyPropertyElement (XmpNode parent, XmlNode node)
		{
			if (!node.IsPropertyElement ())
				throw new CorruptFileException ("Invalid property");
			if (node.HasChildNodes)
				throw new CorruptFileException (String.Format ("Can't have content in this node! Node: {0}", node.OuterXml));

			var rdf_value = node.Attributes.GetNamedItem (VALUE_URI, RDF_NS) as XmlAttribute;
			var rdf_resource = node.Attributes.GetNamedItem (RESOURCE_URI, RDF_NS) as XmlAttribute;

			// Options 1 and 2
			var simple_prop_val = rdf_value ?? rdf_resource ?? null;
			if (simple_prop_val != null) {
				string value = simple_prop_val.InnerText;
				parent.AddChild (CreateTextPropertyWithQualifiers (node, value));
				return;
			}

			// Options 3 & 4
			var new_node = new XmpNode (node.NamespaceURI, node.LocalName);
			foreach (XmlAttribute a in node.Attributes) {
				if (a.Is(RDF_NS, ID_URI) || a.Is(RDF_NS, NODE_ID_URI)) {
					continue;
				} else if (a.In (XMLNS_NS)) {
					continue;
				} else if (a.Is (XML_NS, LANG_URI)) {
					new_node.AddQualifier (new XmpNode (XML_NS, LANG_URI, a.InnerText));
				}

				new_node.AddChild (new XmpNode (a.NamespaceURI, a.LocalName, a.InnerText));
			}
			parent.AddChild (new_node);
		}
        // 7.2.15 resourcePropertyElt
        //        start-element ( URI == propertyElementURIs, attributes == set ( idAttr? ) )
        //        ws* nodeElement ws*
        //        end-element()
        //private void ParseResourcePropertyElement (XmpNode parent, XmlNode node)
        //{
        //    if (!node.IsPropertyElement ())
        //        throw new CorruptFileException ("Invalid property");
        //    XmpNode new_node = new XmpNode (node.NamespaceURI, node.LocalName);
        //    foreach (XmlAttribute attr in node.Attributes) {
        //        if (attr.Is (XML_NS, LANG_URI)) {
        //            new_node.AddQualifier (new XmpNode (XML_NS, LANG_URI, attr.InnerText));
        //        } else if (attr.Is (RDF_NS, ID_URI) || attr.In (XMLNS_NS)) {
        //            continue;
        //        }
        //        throw new CorruptFileException (String.Format ("Invalid attribute: {0}", attr.OuterXml));
        //    }
        //    bool has_xml_children = false;
        //    foreach (XmlNode child in node.ChildNodes) {
        //        if (child is XmlWhitespace)
        //            continue;
        //        if (child is XmlText)
        //            throw new CorruptFileException ("Can't have text here!");
        //        has_xml_children = true;
        //        ParseNodeElement (new_node, child);
        //    }
        //    if (!has_xml_children)
        //        throw new CorruptFileException ("Missing children for resource property element");
        //    parent.AddChild (new_node);
        //}
        private void ParseResourcePropertyElement(XmpNode parent, XElement node)
        {
            // TODO: FIX
            //if (!node.IsPropertyElement())
            //    throw new CorruptFileException("Invalid property");

            XmpNode new_node = new XmpNode(node.Name.NamespaceName, node.Name.LocalName);
            foreach (XAttribute attr in node.Attributes())
            {
                if (attr.Is(XML_NS, LANG_URI))
                {
                    new_node.AddQualifier(new XmpNode(XML_NS, LANG_URI, attr.Value));
                }
                else if (attr.Is(RDF_NS, ID_URI) || attr.In(XMLNS_NS))
                {
                    continue;
                }

                throw new CorruptFileException(String.Format("Invalid attribute: {0}", attr.Parent.Name.LocalName));
            }

            bool has_xml_children = false;
            foreach (XElement child in node.Elements())
            {
                has_xml_children = true;

                ParseNodeElement(new_node, child);
            }

            if (!has_xml_children)
                throw new CorruptFileException("Missing children for resource property element");

            parent.AddChild(new_node);
        }
Beispiel #8
0
		// 7.2.14 propertyElt
		//		resourcePropertyElt | literalPropertyElt | parseTypeLiteralPropertyElt |
		//		parseTypeResourcePropertyElt | parseTypeCollectionPropertyElt |
		//		parseTypeOtherPropertyElt | emptyPropertyElt
		private void ParsePropertyElement (XmpNode parent, XmlNode node)
		{
			int count = 0;
			bool has_other = false;
			foreach (XmlAttribute attr in node.Attributes) {
				if (!attr.In (XMLNS_NS))
					count++;

				if (!attr.Is (XML_NS, LANG_URI) && !attr.Is (RDF_NS, ID_URI) && !attr.In (XMLNS_NS))
					has_other = true;
			}

			if (count > 3) {
				ParseEmptyPropertyElement (parent, node);
			} else {
				if (!has_other) {
					if (!node.HasChildNodes) {
						ParseEmptyPropertyElement (parent, node);
					} else {
						bool only_text = true;
						foreach (XmlNode child in node.ChildNodes) {
							if (!(child is XmlText))
								only_text = false;
						}

						if (only_text) {
							ParseLiteralPropertyElement (parent, node);
						} else {
							ParseResourcePropertyElement (parent, node);
						}
					}
				} else {
					foreach (XmlAttribute attr in node.Attributes) {
						if (attr.Is (XML_NS, LANG_URI) || attr.Is (RDF_NS, ID_URI) || attr.In (XMLNS_NS))
							continue;

						if (attr.Is (RDF_NS, DATA_TYPE_URI)) {
							ParseLiteralPropertyElement (parent, node);
						} else if (!attr.Is (RDF_NS, PARSE_TYPE_URI)) {
							ParseEmptyPropertyElement (parent, node);
						} else if (attr.InnerText.Equals ("Resource")) {
							ParseTypeResourcePropertyElement (parent, node);
						} else {
							// Neither Literal, Collection or anything else is allowed
							throw new CorruptFileException (String.Format ("This is not allowed in XMP! Bad XMP: {0}", node.OuterXml));
						}
					}
				}
			}
		}
        // 7.2.11 nodeElement
        //        start-element ( URI == nodeElementURIs,
        //                        attributes == set ( ( idAttr | nodeIdAttr | aboutAttr )?, propertyAttr* ) )
        //        propertyEltList
        //        end-element()
        //
        // 7.2.13 propertyEltList
        //        ws* ( propertyElt ws* )*
        //private void ParseNodeElement (XmpNode parent, XmlNode node)
        //{
        //    if (!node.IsNodeElement ())
        //        throw new CorruptFileException ("Unexpected node found, invalid RDF?");
        //    if (node.Is (RDF_NS, SEQ_URI)) {
        //        parent.Type = XmpNodeType.Seq;
        //    } else if (node.Is (RDF_NS, ALT_URI)) {
        //        parent.Type = XmpNodeType.Alt;
        //    } else if (node.Is (RDF_NS, BAG_URI)) {
        //        parent.Type = XmpNodeType.Bag;
        //    } else if (node.Is (RDF_NS, DESCRIPTION_URI)) {
        //        parent.Type = XmpNodeType.Struct;
        //    } else {
        //        throw new Exception ("Unknown nodeelement found! Perhaps an unimplemented collection?");
        //    }
        //    foreach (XmlAttribute attr in node.Attributes) {
        //        if (attr.In (XMLNS_NS))
        //            continue;
        //        if (attr.Is (RDF_NS, ID_URI) || attr.Is (RDF_NS, NODE_ID_URI) || attr.Is (RDF_NS, ABOUT_URI))
        //            continue;
        //        if (attr.Is (XML_NS, LANG_URI))
        //            throw new CorruptFileException ("xml:lang is not allowed here!");
        //        parent.AddChild (new XmpNode (attr.NamespaceURI, attr.LocalName, attr.InnerText));
        //    }
        //    foreach (XmlNode child in node.ChildNodes) {
        //        if (child is XmlWhitespace || child is XmlComment)
        //            continue;
        //        ParsePropertyElement (parent, child);
        //    }
        //}
        private void ParseNodeElement(XmpNode parent, XElement node)
        {
            if (node.Is(RDF_NS, SEQ_URI))
            {
                parent.Type = XmpNodeType.Seq;
            }
            else if (node.Is(RDF_NS, ALT_URI))
            {
                parent.Type = XmpNodeType.Alt;
            }
            else if (node.Is(RDF_NS, BAG_URI))
            {
                parent.Type = XmpNodeType.Bag;
            }
            else if (node.Is(RDF_NS, DESCRIPTION_URI))
            {
                parent.Type = XmpNodeType.Struct;
            }
            else
            {
                throw new Exception("Unknown nodeelement found! Perhaps an unimplemented collection?");
            }

            foreach (XAttribute attr in node.Attributes())
            {
                if (attr.In(XMLNS_NS))
                    continue;
                if (attr.Is(RDF_NS, ID_URI) || attr.Is(RDF_NS, NODE_ID_URI) || attr.Is(RDF_NS, ABOUT_URI))
                    continue;
                if (attr.Is(XML_NS, LANG_URI))
                    throw new CorruptFileException("xml:lang is not allowed here!");
                parent.AddChild(new XmpNode(attr.Name.NamespaceName, attr.Name.LocalName, attr.Value));
            }

            foreach (XElement child in node.Elements())
            {
                ParsePropertyElement(parent, child);
            }
        }
 //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;
 //}
 // 7.2.10 nodeElementList
 //        ws* ( nodeElement ws* )*
 //private void ParseNodeElementList (XmpNode parent, XmlNode xml_parent)
 //{
 //    foreach (XmlNode node in xml_parent.ChildNodes) {
 //        if (node is XmlWhitespace)
 //            continue;
 //        ParseNodeElement (parent, node);
 //    }
 //}
 private void ParseNodeElementList(XmpNode parent, XElement xml_parent)
 {
     foreach (XElement node in xml_parent.Elements())
     {
         ParseNodeElement(parent, node);
     }
 }
 // 7.2.16 literalPropertyElt
 //        start-element ( URI == propertyElementURIs, attributes == set ( idAttr?, datatypeAttr?) )
 //        text()
 //        end-element()
 //private void ParseLiteralPropertyElement (XmpNode parent, XmlNode node)
 //{
 //    if (!node.IsPropertyElement ())
 //        throw new CorruptFileException ("Invalid property");
 //    parent.AddChild (CreateTextPropertyWithQualifiers (node, node.InnerText));
 //}
 private void ParseLiteralPropertyElement(XmpNode parent, XElement node)
 {
     // TODO: FIX
     //if (!node.IsPropertyElement())
     //    throw new CorruptFileException("Invalid property");
     parent.AddChild(CreateTextPropertyWithQualifiers(node, node.Value));
 }
Beispiel #12
0
		private XmpNode CreateTextPropertyWithQualifiers (XmlNode node, string value)
		{
			XmpNode t = new XmpNode (node.NamespaceURI, node.LocalName, value);
			foreach (XmlAttribute attr in node.Attributes) {
				if (attr.In (XMLNS_NS))
					continue;
				t.AddQualifier (new XmpNode (attr.NamespaceURI, attr.LocalName, attr.InnerText));
			}
			return t;
		}
Beispiel #13
0
 public void ReplaceFrom(XmpTag tag)
 {
     NodeTree = tag.NodeTree;
     nodes    = new Dictionary <string, Dictionary <string, XmpNode> >();
     AcceptVisitors();
 }
Beispiel #14
0
		// 7.2.10 nodeElementList
		//		ws* ( nodeElement ws* )*
		private void ParseNodeElementList (XmpNode parent, XmlNode xml_parent)
		{
			foreach (XmlNode node in xml_parent.ChildNodes) {
				if (node is XmlWhitespace)
					continue;
				ParseNodeElement (parent, node);
			}
		}
        // 7.2.18 parseTypeResourcePropertyElt
        //        start-element ( URI == propertyElementURIs, attributes == set ( idAttr?, parseResource ) )
        //        propertyEltList
        //        end-element()
        //private void ParseTypeResourcePropertyElement (XmpNode parent, XmlNode node)
        //{
        //    if (!node.IsPropertyElement ())
        //        throw new CorruptFileException ("Invalid property");
        //    XmpNode new_node = new XmpNode (node.NamespaceURI, node.LocalName);
        //    new_node.Type = XmpNodeType.Struct;
        //    foreach (XmlNode attr in node.Attributes) {
        //        if (attr.Is (XML_NS, LANG_URI))
        //            new_node.AddQualifier (new XmpNode (XML_NS, LANG_URI, attr.InnerText));
        //    }
        //    foreach (XmlNode child in node.ChildNodes) {
        //        if (child is XmlWhitespace || child is XmlComment)
        //            continue;
        //        ParsePropertyElement (new_node, child);
        //    }
        //    parent.AddChild (new_node);
        //}
        private void ParseTypeResourcePropertyElement(XmpNode parent, XElement node)
        {
            // TODO: FIX
            //if (!node.IsPropertyElement())
            //    throw new CorruptFileException("Invalid property");

            XmpNode new_node = new XmpNode(node.Name.NamespaceName, node.Name.LocalName);
            new_node.Type = XmpNodeType.Struct;

            foreach (XAttribute attr in node.Attributes())
            {
                if (attr.Is(XML_NS, LANG_URI))
                    new_node.AddQualifier(new XmpNode(XML_NS, LANG_URI, attr.Value));
            }

            foreach (XElement child in node.Elements())
            {
                ParsePropertyElement(new_node, child);
            }

            parent.AddChild(new_node);
        }
Beispiel #16
0
		// 7.2.11 nodeElement
		//		start-element ( URI == nodeElementURIs,
		//						attributes == set ( ( idAttr | nodeIdAttr | aboutAttr )?, propertyAttr* ) )
		//		propertyEltList
		//		end-element()
		//
		// 7.2.13 propertyEltList
		//		ws* ( propertyElt ws* )*
		private void ParseNodeElement (XmpNode parent, XmlNode node)
		{
			if (!node.IsNodeElement ())
				throw new CorruptFileException ("Unexpected node found, invalid RDF?");

			if (node.Is (RDF_NS, SEQ_URI)) {
				parent.Type = XmpNodeType.Seq;
			} else if (node.Is (RDF_NS, ALT_URI)) {
				parent.Type = XmpNodeType.Alt;
			} else if (node.Is (RDF_NS, BAG_URI)) {
				parent.Type = XmpNodeType.Bag;
			} else if (node.Is (RDF_NS, DESCRIPTION_URI)) {
				parent.Type = XmpNodeType.Struct;
			} else {
				throw new Exception ("Unknown nodeelement found! Perhaps an unimplemented collection?");
			}

			foreach (XmlAttribute attr in node.Attributes) {
				if (attr.In (XMLNS_NS))
					continue;
				if (attr.Is (RDF_NS, ID_URI) || attr.Is (RDF_NS, NODE_ID_URI) || attr.Is (RDF_NS, ABOUT_URI))
					continue;
				if (attr.Is (XML_NS, LANG_URI))
					throw new CorruptFileException ("xml:lang is not allowed here!");
				parent.AddChild (new XmpNode (attr.NamespaceURI, attr.LocalName, attr.InnerText));
			}

			foreach (XmlNode child in node.ChildNodes) {
				if (child is XmlWhitespace || child is XmlComment)
					continue;
				ParsePropertyElement (parent, child);
			}
		}
Beispiel #17
0
		void SetRights(XmpTag xmp, string rights)
		{
			var rightsNode = xmp.FindNode("http://purl.org/dc/elements/1.1/", "rights");
			if (rightsNode == null)
			{
				if (string.IsNullOrEmpty(rights))
					return; // leave it missing.
				// No existing rights node, and we have some. We use (default lang) rights for copyright too, and there seems to be no way to
				// make the base node without setting that. So set it to something meaningless.
				// This will typically never happen, since our dialog requires a non-empty copyright.
				// I'm not entirely happy with it, but as far as I can discover the current version of taglib cannot
				// set the 'en' alternative of dc:rights without setting the  default alternative. In fact, I'm not sure the
				// result of doing so would technically be valid xmp; the standard calls for every langauge alternation
				// to have a default.
				xmp.SetLangAltNode("http://purl.org/dc/elements/1.1/", "rights", "Unknown");
				rightsNode = xmp.FindNode("http://purl.org/dc/elements/1.1/", "rights");
			}
			foreach (var child in rightsNode.Children)
			{
				if (child.Namespace == "http://www.w3.org/1999/02/22-rdf-syntax-ns#" && child.Name == "li" &&
					HasLangQualifier(child, "en"))
				{
					if (string.IsNullOrEmpty(rights))
					{
						rightsNode.RemoveChild(child);
						// enhance: possibly we should remove rightsNode, if it now has no children, and if taglib can.
						// However, we always require a copyright, so this will typically not happen.
					}
					else
						child.Value = rights;
					return;
				}
			}
			// Didn't find an existing rights:en node.
			if (string.IsNullOrEmpty(rights))
				return; // leave it missing.
			var childNode = new XmpNode(XmpTag.RDF_NS, "li", rights);
			childNode.AddQualifier(new XmpNode(XmpTag.XML_NS, "lang", "en"));

			rightsNode.AddChild(childNode);
		}
Beispiel #18
0
		// 7.2.15 resourcePropertyElt
		//		start-element ( URI == propertyElementURIs, attributes == set ( idAttr? ) )
		//		ws* nodeElement ws*
		//		end-element()
		private void ParseResourcePropertyElement (XmpNode parent, XmlNode node)
		{
			if (!node.IsPropertyElement ())
				throw new CorruptFileException ("Invalid property");

			XmpNode new_node = new XmpNode (node.NamespaceURI, node.LocalName);
			foreach (XmlAttribute attr in node.Attributes) {
				if (attr.Is (XML_NS, LANG_URI)) {
					new_node.AddQualifier (new XmpNode (XML_NS, LANG_URI, attr.InnerText));
				} else if (attr.Is (RDF_NS, ID_URI) || attr.In (XMLNS_NS)) {
					continue;
				}

				throw new CorruptFileException (String.Format ("Invalid attribute: {0}", attr.OuterXml));
			}

			bool has_xml_children = false;
			foreach (XmlNode child in node.ChildNodes) {
				if (child is XmlWhitespace)
					continue;
				if (child is XmlText)
					throw new CorruptFileException ("Can't have text here!");
				has_xml_children = true;

				ParseNodeElement (new_node, child);
			}

			if (!has_xml_children)
				throw new CorruptFileException ("Missing children for resource property element");

			parent.AddChild (new_node);
		}
Beispiel #19
0
		static bool HasLangQualifier(XmpNode node, string lang)
		{
			var qualifier = node.GetQualifier(XmpTag.XML_NS, "lang");
			return qualifier != null && qualifier.Value == lang;
		}
Beispiel #20
0
		// 7.2.18 parseTypeResourcePropertyElt
		//		start-element ( URI == propertyElementURIs, attributes == set ( idAttr?, parseResource ) )
		//		propertyEltList
		//		end-element()
		private void ParseTypeResourcePropertyElement (XmpNode parent, XmlNode node)
		{
			if (!node.IsPropertyElement ())
				throw new CorruptFileException ("Invalid property");

			XmpNode new_node = new XmpNode (node.NamespaceURI, node.LocalName);
			new_node.Type = XmpNodeType.Struct;

			foreach (XmlNode attr in node.Attributes) {
				if (attr.Is (XML_NS, LANG_URI))
					new_node.AddQualifier (new XmpNode (XML_NS, LANG_URI, attr.InnerText));
			}

			foreach (XmlNode child in node.ChildNodes) {
				if (child is XmlWhitespace || child is XmlComment)
					continue;
				ParsePropertyElement (new_node, child);
			}

			parent.AddChild (new_node);
		}
Beispiel #21
0
			public void Visit (XmpNode node)
			{
				// TODO: This should be a proper check to see if it is a nodeElement
				if (node.Namespace == XmpTag.RDF_NS && node.Name == XmpTag.LI_URI)
					return;

				AddNode (node);
			}
Beispiel #22
0
		private XmpNode CreateTextPropertyWithQualifiers (XmlNode node, string value)
		{
			XmpNode t = new XmpNode (node.NamespaceURI, node.LocalName, value);
			foreach (XmlAttribute attr in node.Attributes) {
				if (attr.In (XMLNS_NS))
					continue;
				if (attr.Is (RDF_NS, VALUE_URI) || attr.Is (RDF_NS, RESOURCE_URI))
					continue; // These aren't qualifiers
				t.AddQualifier (new XmpNode (attr.NamespaceURI, attr.LocalName, attr.InnerText));
			}
			return t;
		}
Beispiel #23
0
			void AddNode (XmpNode node)
			{
				if (tag.nodes == null)
					tag.nodes = new Dictionary<string, Dictionary<string, XmpNode>> ();
				if (!tag.nodes.ContainsKey (node.Namespace))
					tag.nodes [node.Namespace] = new Dictionary<string, XmpNode> ();

				tag.nodes [node.Namespace][node.Name] = node;
			}
Beispiel #24
0
		/// <summary>
		///	   Replace the current tag with the given one.
		///	</summary>
		/// <param name="tag">
		///    The tag from which the data should be copied.
		/// </param>
		public void ReplaceFrom (XmpTag tag)
		{
			NodeTree = tag.NodeTree;
			nodes = new Dictionary<string, Dictionary<string, XmpNode>> ();
			AcceptVisitors ();
		}
Beispiel #25
0
		/// <summary>
		///    Construct a new empty <see cref="XmpTag"/>.
		/// </summary>
		public XmpTag ()
		{
			NodeTree = new XmpNode (String.Empty, String.Empty);
			nodes = new Dictionary<string, Dictionary<string, XmpNode>> ();
		}
        /// <summary>
        ///    Adds a node as child of the current node
        /// </summary>
        /// <param name="node">
        ///    A <see cref="XmpNode"/> to be add as child
        /// </param>
        public void AddChild(XmpNode node)
        {
            if (node == null || node == this)
                throw new ArgumentException ("node");

            if (children == null)
                children = new List<XmpNode> ();

            children.Add (node);
        }
Beispiel #27
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>
        ///    Removes the given node as child of the current instance
        /// </summary>
        /// <param name="node">
        ///    A <see cref="XmpNode"/> to remove as child
        /// </param>
        public void RemoveChild(XmpNode node)
        {
            if (children == null)
                return;

            children.Remove (node);
        }
Beispiel #29
0
 public XmpTag()
 {
     NodeTree = new XmpNode(String.Empty, String.Empty);
     nodes    = new Dictionary <string, Dictionary <string, XmpNode> >();
 }