private static Metadata GetMetadataWithDefaultCopyrightAndLicense(string brandingNameOrPath) { var metadata = new Metadata(); Logger.WriteEvent("For BL-3166 Investigation: GetMetadata() setting to default license"); metadata.License = new CreativeCommonsLicense(true, true, CreativeCommonsLicense.DerivativeRules.Derivatives); //OK, that's all we need, the rest is blank. That is, unless we are we are working with a brand //that has declared some defaults in a settings.json file: var settings = BrandingApi.GetSettings(brandingNameOrPath); if (settings != null) { if (!string.IsNullOrEmpty(settings.CopyrightNotice)) { metadata.CopyrightNotice = settings.CopyrightNotice; } if (!string.IsNullOrEmpty(settings.LicenseUrl)) { metadata.License = CreativeCommonsLicense.FromLicenseUrl(settings.LicenseUrl); } if (!string.IsNullOrEmpty(settings.LicenseUrl)) { metadata.License.RightsStatement = settings.LicenseRightsStatement; } } return(metadata); }
public void FromLicenseUrl_IGO_IGORead() { var license = CreativeCommonsLicense.FromLicenseUrl("http://creativecommons.org/licenses/by/3.0/"); Assert.IsFalse(license.IntergovernmentalOriganizationQualifier); license = CreativeCommonsLicense.FromLicenseUrl("http://creativecommons.org/licenses/by/3.0/IGO"); Assert.IsTrue(license.IntergovernmentalOriganizationQualifier); }
public void RoundTrip_BY_IGO() { var original = new CreativeCommonsLicense(true, true, CreativeCommonsLicense.DerivativeRules.DerivativesWithShareAndShareAlike); original.IntergovernmentalOriganizationQualifier = true; var copy = CreativeCommonsLicense.FromLicenseUrl(original.Url); Assert.IsTrue(copy.IntergovernmentalOriganizationQualifier); }
public void RoundTrip_BY_SA() { var original = new CreativeCommonsLicense(true, true, CreativeCommonsLicense.DerivativeRules.DerivativesWithShareAndShareAlike); var copy = CreativeCommonsLicense.FromLicenseUrl(original.Url); Assert.AreEqual(copy.AttributionRequired, true); Assert.AreEqual(copy.CommercialUseAllowed, true); Assert.AreEqual(copy.DerivativeRule, CreativeCommonsLicense.DerivativeRules.DerivativesWithShareAndShareAlike); }
public void RoundTrip_BY_NC_ND() { var original = new CreativeCommonsLicense(true, false, CreativeCommonsLicense.DerivativeRules.NoDerivatives); var copy = CreativeCommonsLicense.FromLicenseUrl(original.Url); Assert.AreEqual(copy.AttributionRequired, true); Assert.AreEqual(copy.CommercialUseAllowed, false); Assert.AreEqual(copy.DerivativeRule, CreativeCommonsLicense.DerivativeRules.NoDerivatives); }
public static Metadata CreateMetadata(MultiTextBase copyright, string licenseUrl, MultiTextBase licenseNotes, BookData bookData) { var metadata = new Metadata(); if (!copyright.Empty) { metadata.CopyrightNotice = GetBestMultiTextBaseValue(copyright, bookData); } if (string.IsNullOrWhiteSpace(licenseUrl)) { //NB: we are mapping "RightsStatement" (which comes from XMP-dc:Rights) to "LicenseNotes" in the html. //custom licenses live in this field, so if we have notes (and no URL) it is a custom one. if (!licenseNotes.Empty) { metadata.License = new CustomLicense { RightsStatement = GetBestMultiTextBaseValue(licenseNotes, bookData) }; } else { // The only remaining current option is a NullLicense metadata.License = new NullLicense(); //"contact the copyright owner } } else // there is a licenseUrl, which means it is a CC license { try { metadata.License = CreativeCommonsLicense.FromLicenseUrl(licenseUrl); } catch (IndexOutOfRangeException) { // Need to handle urls which do not end with the version number. // Simply set it to the default version. if (!licenseUrl.EndsWith("/")) { licenseUrl += "/"; } licenseUrl += CreativeCommonsLicense.kDefaultVersion; metadata.License = CreativeCommonsLicense.FromLicenseUrl(licenseUrl); } catch (Exception e) { throw new ApplicationException("Bloom had trouble parsing this license url: '" + licenseUrl + "'. (ref BL-4108)", e); } //are there notes that go along with that? if (!licenseNotes.Empty) { metadata.License.RightsStatement = GetBestMultiTextBaseValue(licenseNotes, bookData); } } return(metadata); }
public void RoundTrip_CC0() { // CC0 is essentially just "do what you want". So we don't have a particular property for it, we // just set all three aspects to be permissive. var original = new CreativeCommonsLicense(false, true, CreativeCommonsLicense.DerivativeRules.Derivatives); var copy = CreativeCommonsLicense.FromLicenseUrl(original.Url); Assert.IsFalse(copy.AttributionRequired); Assert.IsTrue(copy.CommercialUseAllowed); Assert.AreEqual(copy.DerivativeRule, CreativeCommonsLicense.DerivativeRules.Derivatives); }
public Metadata GetLicenseMetadata() { var data = new DataSet(); GatherDataItemsFromXElement(data, _dom.RawDom); var metadata = new Metadata(); NamedMutliLingualValue d; if (data.TextVariables.TryGetValue("copyright", out d)) { metadata.CopyrightNotice = d.TextAlternatives.GetFirstAlternative(); } string licenseUrl = ""; if (data.TextVariables.TryGetValue("licenseUrl", out d)) { licenseUrl = d.TextAlternatives.GetFirstAlternative(); } //Enhance: have a place for notes (amendments to license). It's already in the frontmatter, under "licenseNotes" if (licenseUrl == null || licenseUrl.Trim() == "") { //NB: we are mapping "RightsStatement" (which comes from XMP-dc:Rights) to "LicenseNotes" in the html. //custom licenses live in this field if (data.TextVariables.TryGetValue("licenseNotes", out d)) { string licenseNotes = d.TextAlternatives.GetFirstAlternative(); metadata.License = new CustomLicense { RightsStatement = licenseNotes }; } else { //how to detect a null license was chosen? We're using the fact that it has a description, but nothing else. if (data.TextVariables.TryGetValue("licenseDescription", out d)) { metadata.License = new NullLicense(); //"contact the copyright owner } else { //looks like the first time. Nudge them with a nice default metadata.License = new CreativeCommonsLicense(true, true, CreativeCommonsLicense.DerivativeRules.Derivatives); } } } else { metadata.License = CreativeCommonsLicense.FromLicenseUrl(licenseUrl); } return(metadata); }
public Metadata GetLicenseMetadata() { var data = new DataSet(); GatherDataItemsFromXElement(data, _dom.RawDom); var metadata = new Metadata(); NamedMutliLingualValue d; if (data.TextVariables.TryGetValue("copyright", out d)) { metadata.CopyrightNotice = WebUtility.HtmlDecode(d.TextAlternatives.GetFirstAlternative()); } string licenseUrl = ""; if (data.TextVariables.TryGetValue("licenseUrl", out d)) { licenseUrl = WebUtility.HtmlDecode(d.TextAlternatives.GetFirstAlternative()); } if (licenseUrl == null || licenseUrl.Trim() == "") { //NB: we are mapping "RightsStatement" (which comes from XMP-dc:Rights) to "LicenseNotes" in the html. //custom licenses live in this field, so if we have notes (and no URL) it is a custom one. if (data.TextVariables.TryGetValue("licenseNotes", out d)) { string licenseNotes = d.TextAlternatives.GetFirstAlternative(); metadata.License = new CustomLicense { RightsStatement = WebUtility.HtmlDecode(licenseNotes) }; } else { // The only remaining current option is a NullLicense metadata.License = new NullLicense(); //"contact the copyright owner } } else // there is a licenseUrl, which means it is a CC license { metadata.License = CreativeCommonsLicense.FromLicenseUrl(licenseUrl); if (data.TextVariables.TryGetValue("licenseNotes", out d)) { metadata.License.RightsStatement = WebUtility.HtmlDecode(d.TextAlternatives.GetFirstAlternative()); } } return(metadata); }
/// <summary> /// Create a Clearshare.Metadata object by reading values out of the dom's bloomDataDiv /// </summary> /// <param name="brandingNameOrFolderPath"> Normally, the branding is just a name, which we look up in the official branding folder //but unit tests can instead provide a path to the folder. /// </param> public static Metadata GetMetadata(HtmlDom dom, string brandingNameOrFolderPath = "") { if (ShouldSetToDefaultCopyrightAndLicense(dom)) { return(GetMetadataWithDefaultCopyrightAndLicense(brandingNameOrFolderPath)); } var metadata = new Metadata(); var copyright = dom.GetBookSetting("copyright"); if (!copyright.Empty) { metadata.CopyrightNotice = WebUtility.HtmlDecode(copyright.GetFirstAlternative()); } var licenseUrl = dom.GetBookSetting("licenseUrl").GetBestAlternativeString(new[] { "*", "en" }); if (string.IsNullOrWhiteSpace(licenseUrl)) { //NB: we are mapping "RightsStatement" (which comes from XMP-dc:Rights) to "LicenseNotes" in the html. //custom licenses live in this field, so if we have notes (and no URL) it is a custom one. var licenseNotes = dom.GetBookSetting("licenseNotes"); if (!licenseNotes.Empty) { metadata.License = new CustomLicense { RightsStatement = WebUtility.HtmlDecode(licenseNotes.GetFirstAlternative()) }; } else { // The only remaining current option is a NullLicense metadata.License = new NullLicense(); //"contact the copyright owner } } else // there is a licenseUrl, which means it is a CC license { try { metadata.License = CreativeCommonsLicense.FromLicenseUrl(licenseUrl); } catch (IndexOutOfRangeException) { // Need to handle urls which do not end with the version number. // Simply set it to the default version. if (!licenseUrl.EndsWith("/")) { licenseUrl += "/"; } licenseUrl += CreativeCommonsLicense.kDefaultVersion; metadata.License = CreativeCommonsLicense.FromLicenseUrl(licenseUrl); } catch (Exception e) { throw new ApplicationException("Bloom had trouble parsing this license url: '" + licenseUrl + "'. (ref BL-4108)", e); } //are there notes that go along with that? var licenseNotes = dom.GetBookSetting("licenseNotes"); if (!licenseNotes.Empty) { var s = WebUtility.HtmlDecode(licenseNotes.GetFirstAlternative()); metadata.License.RightsStatement = HtmlDom.ConvertHtmlBreaksToNewLines(s); } } return(metadata); }
public void FromLicenseUrl_VersionRead() { var original = CreativeCommonsLicense.FromLicenseUrl("http://creativecommons.org/licenses/by-nd/4.3/"); Assert.AreEqual("4.3", original.Version); }
public void FromLicenseUrl_EmtpyString_Throws() { Assert.Throws <ArgumentOutOfRangeException>(() => CreativeCommonsLicense.FromLicenseUrl("")); }
public void FromLicenseUrl_IGO_VersionRead() { var original = CreativeCommonsLicense.FromLicenseUrl("http://creativecommons.org/licenses/by/3.0/IGO"); Assert.AreEqual("3.0", original.Version); }