AddQualifier() public method

Adds a node as qualifier of the current instance
public AddQualifier ( XmpNode node ) : void
node XmpNode /// A to add as qualifier ///
return void
Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
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;
                }
                t.AddQualifier(new XmpNode(attr.NamespaceURI, attr.LocalName, attr.InnerText));
            }
            return(t);
        }
Exemplo n.º 4
0
        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;
            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;
            }
            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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
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);
		}
Exemplo n.º 7
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;
		}
Exemplo n.º 8
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);
		}
Exemplo n.º 9
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);
		}
Exemplo n.º 10
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);
		}
Exemplo n.º 11
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);
		}
Exemplo n.º 12
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);
        //}
        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);
        }
Exemplo n.º 13
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);
        //}
        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);
        }
Exemplo n.º 14
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;
		}