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); }
public XmpNode FindNodeTest([PexAssumeUnderTest] XmpTag target, string value) { PexAssume.IsNotNull(value); target.Copyright = value; XmpNode result = target.FindNode(XmpTag.DC_NS, "rights"); PexAssert.AreEqual(result.Value, target.Copyright); return(result); // TODO: add assertions to method XmpTagTest.FindNodeTest(XmpTag, String, String) }
/// <summary> /// Update the value of the specified node, or create it. /// Seems SetTextNode should work whether or not is already exists, but in some cases it doesn't. /// </summary> /// <param name="tag"></param> /// <param name="ns"></param> /// <param name="name"></param> /// <param name="val"></param> void AddOrModify(XmpTag tag, string ns, string name, string val) { var node = tag.FindNode(ns, name); if (node != null) { node.Value = val; } else { tag.SetTextNode(ns, name, val); } }
private void TestAltNode(XmpTag tag, string ns, string name, string[] values) { var node = tag.FindNode(ns, name); Assert.IsFalse(node == null); Assert.AreEqual(XmpNodeType.Alt, node.Type); Assert.AreEqual(values.Length, node.Children.Count); int i = 0; foreach (var childNode in node.Children) { Assert.AreEqual(values[i], childNode.Value); Assert.AreEqual(0, childNode.Children.Count); i++; } }
static string GetRights(XmpTag xmp) { var rightsNode = xmp.FindNode("http://purl.org/dc/elements/1.1/", "rights"); if (rightsNode == null) { return(null); } 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")) { return(child.Value); } } return(null); }