コード例 #1
0
        public void UpdateDomFromDataDiv_CopiesCopyrightAndOriginalCopyrightToMultipleDestinations()
        {
            // We could test other fields too, but these are enough to cover the two main methods that do the copying.
            var html    = @"<html><head><meta name='lockedDownAsShell' content='true'></meta></head><body>
							<div id='bloomDataDiv'>
								<div data-book='copyright' lang='*'>Copyright © 2008, Bar Publishers</div>
								<div data-book='originalLicenseUrl' lang='*'>http://creativecommons.org/licenses/by-nc/4.0/</div>
								<div data-book='originalLicenseNotes' lang='*'>You can do anything you want if your name is Fred.</div>
								<div data-book='originalCopyright' lang='*'>Copyright © 2007, Foo Publishers</div>
							</div>
							<div id='test' class='test'>
								<div data-derived='copyright' lang='*'>something obsolete</div>
								<div data-derived='originalCopyrightAndLicense' lang='en'>BoilerPlateDescription</div>
							</div>
							<div id='test2' class='test'>
								<div data-derived='copyright' lang='*'>something else obsolete to be overwritten</div>
								<div data-derived='originalCopyrightAndLicense' lang='en'>Some other place we show original copyright</div>
							</div>
						</body></html>"                        ;
            var bookDom = new HtmlDom(html);

            BookCopyrightAndLicense.UpdateDomFromDataDiv(bookDom, "", _collectionSettings, false);
            // This is an abbreviated version of the text we expect in originalCopyrightAndLicense. Now that we have an embedded <cite> element, matching the whole thing
            // is difficult. We have other tests that deal with exactly what goes in this field; here we're just concerned with getting the right number of copies.
            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='test']/*[@data-derived='originalCopyrightAndLicense' and @lang='*' and contains(text(),'Adapted from original')]", 2);
            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='test']/*[@data-derived='copyright' and @lang='*' and contains(text(),'Copyright © 2008, Bar Publishers')]", 2);

            // Changing the useOriginalCopyright flag should empty out the data-derived='originalCopyrightAndLicense' divs.
            // The #bloomDataDiv would have to change to change the data-derived='copyright' divs.
            BookCopyrightAndLicense.UpdateDomFromDataDiv(bookDom, "", _collectionSettings, true);
            Console.WriteLine("DEBUG bookDom =\n{0}", bookDom.RawDom.OuterXml);
            AssertThatXmlIn.Dom(bookDom.RawDom).HasNoMatchForXpath("//div[@class='test']/*[@data-derived='originalCopyrightAndLicense' and @lang='*']");
            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='test']/*[@data-derived='originalCopyrightAndLicense' and .='']", 2);
            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='test']/*[@data-derived='copyright' and @lang='*' and contains(text(),'Copyright © 2008, Bar Publishers')]", 2);
        }
コード例 #2
0
        private Metadata GetMetadata(string dataDivContent, CollectionSettings collectionSettings = null)
        {
            var dom      = MakeDom(dataDivContent);
            var bookData = new BookData(dom, collectionSettings ?? _collectionSettings, null);

            return(BookCopyrightAndLicense.GetMetadata(dom, bookData));
        }
コード例 #3
0
        public void UpdateDomFromDataDiv_CopiesCopyrightAndOriginalCopyrightToMultipleDestinations()
        {
            // We could test other fields too, but these are enough to cover the two main methods that do the copying.
            var html    = @"<html><head><meta name='lockedDownAsShell' content='true'></meta></head><body>
							<div id='bloomDataDiv'>
								<div data-book='copyright' lang='*'>Copyright © 2008, Bar Publishers</div>
								<div data-book='originalLicenseUrl' lang='*'>http://creativecommons.org/licenses/by-nc/4.0/</div>
								<div data-book='originalLicenseNotes' lang='*'>You can do anything you want if your name is Fred.</div>
								<div data-book='originalCopyright' lang='*'>Copyright © 2007, Foo Publishers</div>
							</div>
							<div id='test' class='test'>
								<div data-derived='copyright' lang='*'>something obsolete</div>
								<div data-derived='originalCopyrightAndLicense' lang='en'>BoilerPlateDescription</div>
							</div>
							<div id='test2' class='test'>
								<div data-derived='copyright' lang='*'>something else obsolete to be overwritten</div>
								<div data-derived='originalCopyrightAndLicense' lang='en'>Some other place we show original copyright</div>
							</div>
						</body></html>"                        ;
            var bookDom = new HtmlDom(html);

            BookCopyrightAndLicense.UpdateDomFromDataDiv(bookDom, "", _collectionSettings);
            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='test']/*[@data-derived='originalCopyrightAndLicense' and @lang='*' and contains(text(),'Adapted from original, Copyright © 2007, Foo Publishers. Licensed under CC-BY-NC 4.0. You can do anything you want if your name is Fred.')]", 2);
            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='test']/*[@data-derived='copyright' and @lang='*' and contains(text(),'Copyright © 2008, Bar Publishers')]", 2);
        }
コード例 #4
0
        public void SetOriginalCopyrightAndLicense_SourceIsAlsoAnAdaptation_OriginalCopyrightAndLicensePreserved()
        {
            var dom = SetOriginalCopyrightAndLicense(
                @" <div id='bloomDataDiv'>
					<div data-book='bookTitle' lang='en'>A really really empty book</div>
						<div data-book='copyright' lang='*'>
						Copyright © 2007, Foo Publishers
						</div>
					<div data-book='licenseUrl' lang='*'>
						http://creativecommons.org/licenses/by/4.0/
						</div>
						<div data-derived='licenseNotes' lang='*'>
							You can do anything you want if your name is Fred.
						</div>
					</div>"                    );
            // now do it again, simulating adaptation from the translation with different copyright etc.
            var dataDiv = dom.SelectSingleNode("//div[@id='bloomDataDiv']");

            AppendDataDivElement(dataDiv, "copyright", "*", "Copyright © 2008, Bar Translators");
            AppendDataDivElement(dataDiv, "licenseUrl", "*", "http://creativecommons.org/licenses/by-nc/4.0/");
            AppendDataDivElement(dataDiv, "licenseNotes", "*", "You can do almost anything if your name is John");
            var bookData = new BookData(dom, _collectionSettings, null);

            BookCopyrightAndLicense.SetOriginalCopyrightAndLicense(dom, bookData, _collectionSettings);
            Assert.AreEqual("Adapted from original, Copyright © 2007, Foo Publishers. Licensed under CC-BY 4.0. You can do anything you want if your name is Fred.", GetEnglishOriginalCopyrightAndLicense(dom));
            AssertOriginalCopyrightAndLicense(dom, "Copyright © 2007, Foo Publishers", "http://creativecommons.org/licenses/by/4.0/", "You can do anything you want if your name is Fred.");
        }
コード例 #5
0
        public void UpdateDomFromDataDiv_CCLicense_OnPageTheLicenseHasFrench()
        {
            _collectionSettings.Language1Iso639Code = "fr";
            _collectionSettings.Language2Iso639Code = "en";

            //NB: ideally, this test would just set the licenseUrl and then test the resulting description.
            //That is, the description would not even be in the datadiv, since all we need is the licenseURl
            //(at least for creative commons licenses). We would then just generate the description when we
            //update the page.
            //However, for backwards compatibility, we still (as of 3.6) determine the description when doing
            //a SetMetadata, put the description in the bloomdatadiv, and then it just flows down
            //to the page.
            var html     = @"<html><body>
							<div id='bloomDataDiv'>
								<div data-book='licenseDescription' lang='es'>Spanish Description</div>
								<div data-book='licenseDescription' lang='fr'>French Description</div>
								<div data-book='licenseDescription' lang='en'>English Description</div>
							</div>
							<div id='test'>
								<div data-derived='licenseDescription' lang='en'>BoilerPlateDescription</div>
							</div>
						</body></html>"                        ;
            var bookDom  = new HtmlDom(html);
            var bookData = new BookData(bookDom, _collectionSettings, null);

            BookCopyrightAndLicense.UpdateDomFromDataDiv(bookDom, "", bookData, false);
            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='test']/*[@data-derived='licenseDescription' and @lang='fr' and contains(text(),'French')]", 1);
        }
コード例 #6
0
        public object GetJsonFromMetadata(Metadata metadata, bool forBook)
        {
            dynamic derivativeInfo = null;

            if (forBook)
            {
                var originalMetadata            = BookCopyrightAndLicense.GetOriginalMetadata(Model.CurrentBook.Storage.Dom, Model.CurrentBook.BookData);
                var languagePriorityIdsNotLang1 = Model.CurrentBook.BookData.GetLanguagePrioritiesForLocalizedTextOnPage(false);
                var licenseText = BookCopyrightAndLicense.GetOriginalLicenseSentence(languagePriorityIdsNotLang1, originalMetadata.License, out string _);
                derivativeInfo = new
                {
                    isBookDerivative                = BookCopyrightAndLicense.IsDerivative(originalMetadata),
                    useOriginalCopyright            = Model.CurrentBook.BookInfo.MetaData.UseOriginalCopyright,
                    originalCopyrightAndLicenseText = $"{originalMetadata.CopyrightNotice}, {licenseText}",
                    originalCopyrightYear           = originalMetadata.GetCopyrightYear(),
                    originalCopyrightHolder         = originalMetadata.GetCopyrightBy(),
                    originalLicense = GetLicense(originalMetadata)
                };
            }

            var intellectualPropertyData = new
            {
                derivativeInfo = derivativeInfo,
                copyrightInfo  = new
                {
                    imageCreator    = metadata.Creator ?? string.Empty,
                    copyrightYear   = metadata.GetCopyrightYear() ?? string.Empty,
                    copyrightHolder = metadata.GetCopyrightBy() ?? string.Empty,
                },
                licenseInfo = GetLicense(metadata),
            };

            return(intellectualPropertyData);
        }
コード例 #7
0
        private HtmlDom SetOriginalCopyrightAndLicense(string dataDivString)
        {
            var dom      = new HtmlDom(dataDivString);
            var bookData = new BookData(dom, _collectionSettings, null);

            BookCopyrightAndLicense.SetOriginalCopyrightAndLicense(dom, bookData, _collectionSettings);
            return(dom);
        }
コード例 #8
0
        /// <summary>
        /// Start out with an html with a bloomDataDiv describe by the parameters, then run it through the derivation of
        /// elements, then check to see that we got the expected result
        /// </summary>
        /// <param name="key">the data key. E.g. 'licenseDescription'</param>
        /// <param name="dataDivValue">if null, then the element should not be present at all in the bloomDataDiv of the incoming html</param>
        /// <param name="tag">defaults to div, for img we pass in "img"</param>
        /// <param name="valueAttribute"></param>
        /// <param name="lang1"></param>
        /// <param name="lang2"></param>
        /// <param name="lang3"></param>
        /// <param name="description"></param>
        private void CheckUpdateDomFromDataDiv(string key, string dataDivValue, string lang1 = "en", string lang2 = "", string lang3 = "", string description = null, string customXPath = null)
        {
            if (description == null)
            {
                description = string.Format("{0} should be '{1}'", key, dataDivValue);
            }

            _collectionSettings.Language1Iso639Code = lang1;
            _collectionSettings.Language2Iso639Code = lang2;
            _collectionSettings.Language3Iso639Code = lang3;

            var existingLicenseBlockOnPage = @"<div id='test'>
						<div data-derived = 'copyright' lang='en'>Some Copyright</div>
						<img src='license.png' alt='blah blah' data-derived='licenseImage'/>
						<div data-derived = 'licenseUrl' lang='en'>Boilerplate.com</div>
						<div data-derived='licenseDescription' lang='en'>BoilerPlateDescription</div>
						<div data-derived='licenseNotes' lang='en'>BoilerPlateNotes</div>
					</div>"                    ;

            string html = "<html><body><div id='bloomDataDiv'>";

            if (dataDivValue != null)             //we want this even if it is empty, just not null
            {
                html += string.Format("<{0} data-book='{1}' lang='en'>{2}</{0}>", "div", key, dataDivValue);
            }
            html += "</div>";            //end of datadiv
            html += existingLicenseBlockOnPage;
            html += "</body></html>";
            var bookDom  = new HtmlDom(html);
            var bookData = new BookData(bookDom, _collectionSettings, null);

            BookCopyrightAndLicense.UpdateDomFromDataDiv(bookDom, "", bookData, false);
            string valuePredicate;

            if (key == "licenseImage")
            {
                valuePredicate = string.IsNullOrEmpty(dataDivValue) ? "@src=''" : "@src='" + dataDivValue + "'";
            }
            else
            {
                valuePredicate = string.IsNullOrEmpty(dataDivValue) ? "(text()='' or not(text()))" : "text()='" + dataDivValue + "'";
            }
            var xpath = "//div[@id='test']/*[@data-derived='" + key + "' and " + valuePredicate + "]";

            if (!string.IsNullOrEmpty(customXPath))
            {
                xpath = customXPath;
            }
            try
            {
                AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath(xpath, 1);
            }
            catch (AssertionException)
            {
                Console.WriteLine("xpath was:" + xpath);
                Assert.Fail(description);
            }
        }
コード例 #9
0
        private string GetFrenchOriginalCopyrightAndLicense(HtmlDom dom)
        {
            // Set these before making the bookData as it will cache during constructor.
            _collectionSettings.Language1.Iso639Code = "en";
            _collectionSettings.Language2.Iso639Code = "fr";
            var bookData = new BookData(dom, _collectionSettings, null);

            return(BookCopyrightAndLicense.GetOriginalCopyrightAndLicenseNotice(bookData, dom));
        }
コード例 #10
0
        private static Metadata GetMetadata(string dataDivContent)
        {
            var dom = MakeDom(dataDivContent);

            //normally, the branding is just a name, which we look up in the official branding folder
            //but in order to allow unit tests to test particular contents of it, we also allow
            //it to be a path to a constructed branding folder.
            //These unit tests can then write to a temp file and point to that.
            return(BookCopyrightAndLicense.GetMetadata(dom, _brandingFolder.Path));
        }
コード例 #11
0
        private HtmlDom SetOriginalCopyrightAndLicense(string dataDivString)
        {
            // All of the tests using this method require that the book is locked down (that is, a derivative that
            // is expected to have original copyright and license information).
            var html     = "<html><head><meta name='lockedDownAsShell' content='true'></meta></head><body>" + dataDivString + "</body></html>";
            var dom      = new HtmlDom(html);
            var bookData = new BookData(dom, _collectionSettings, null);

            BookCopyrightAndLicense.SetOriginalCopyrightAndLicense(dom, bookData, _collectionSettings);
            return(dom);
        }
コード例 #12
0
        public void AmpersandInOriginalCopyrightHandledProperly()
        {
            // See http://issues.bloomlibrary.org/youtrack/issue/BL-4585.
            var dom = new HtmlDom(
                @"<html>
				  <head><meta name='lockedDownAsShell' content='true'></meta></head>
				  <body>
				    <div id='bloomDataDiv'>
				      <div data-book='copyright' lang='*'>
				        Copyright © 2011, LASI &amp; SILA
				      </div>
				      <div data-book='licenseUrl' lang='en'>
				        http://creativecommons.org/licenses/by-nc-sa/4.0/
				      </div>
				    </div>
				    <div class='bloom-page cover frontCover outsideFrontCover coverColor bloom-frontMatter A4Landscape layout-style-Default' data-page='required singleton' data-export='front-matter-cover' id='2c97f5ad-24a1-47f0-8b5c-fa2181e1b129'>
				      <div class='bloom-page cover frontCover outsideFrontCover coverColor bloom-frontMatter verso A4Landscape layout-style-Default' data-page='required singleton' data-export='front-matter-credits' id='7a220c97-07e4-47c5-835a-e37dc921f98f'>
				        <div class='marginBox'>
				          <div data-functiononhintclick='bookMetadataEditor' data-hint='Click to Edit Copyright &amp; License' id='versoLicenseAndCopyright' class='bloom-metaData'>
				            <div data-derived='copyright' lang='*' class='copyright'></div>
				            <div data-derived='originalCopyrightAndLicense' lang='en' class='copyright'></div>
				          </div>
				        </div>
				      </div>
				    </div>
				  </body>
				</html>"                );
            var metadata         = BookCopyrightAndLicense.GetMetadata(dom);
            var initialCopyright = metadata.CopyrightNotice;

            Assert.AreEqual("Copyright © 2011, LASI & SILA", initialCopyright);

            var bookData = new BookData(dom, _collectionSettings, null);

            BookCopyrightAndLicense.SetOriginalCopyrightAndLicense(dom, bookData, _collectionSettings);
            var originalCopyright = GetEnglishOriginalCopyrightAndLicense(dom);

            Assert.AreEqual("Adapted from original, Copyright © 2011, LASI & SILA. Licensed under CC-BY-NC-SA 4.0.", originalCopyright);

            BookCopyrightAndLicense.UpdateDomFromDataDiv(dom, null, _collectionSettings);
            var nodes1 = dom.RawDom.SelectNodes("/html/body//div[@data-derived='originalCopyrightAndLicense']");

            Assert.AreEqual(1, nodes1.Count);
            Assert.AreEqual("Adapted from original, Copyright © 2011, LASI & SILA. Licensed under CC-BY-NC-SA 4.0.", nodes1.Item(0).InnerText);
            Assert.AreEqual("Adapted from original, Copyright © 2011, LASI &amp; SILA. Licensed under CC-BY-NC-SA 4.0.", nodes1.Item(0).InnerXml);
            var nodes2 = dom.RawDom.SelectNodes("/html/body//div[@data-derived='copyright']");

            Assert.AreEqual(1, nodes2.Count);
            Assert.AreEqual("", nodes2.Item(0).InnerText);
            Assert.AreEqual("", nodes2.Item(0).InnerXml);
            AssertOriginalCopyrightAndLicense(dom, "Copyright © 2011, LASI &amp; SILA", "http://creativecommons.org/licenses/by-nc-sa/4.0/");
        }
コード例 #13
0
        public void SetMetadata_CopiesCopyrightAndOriginalCopyrightToMultipleDestinations()
        {
            // We could test other fields too, but these are enough to cover the two main methods that do the copying.
            var html     = @"<html><head><meta name='lockedDownAsShell' content='true'></meta></head><body>
							<div id='bloomDataDiv'>
								<div data-book='copyright' lang='*'>Copyright © 2008, Bar Publishers</div>
								<div data-book='originalLicenseUrl' lang='*'>http://creativecommons.org/licenses/by-nc/4.0/</div>
								<div data-book='originalLicenseNotes' lang='*'>You can do anything you want if your name is Fred.</div>
								<div data-book='originalCopyright' lang='*'>Copyright © 2007, Foo Publishers</div>
							</div>
							<div id='test' class='test'>
								<div data-derived='copyright' lang='*'>something obsolete</div>
								<div data-derived='originalCopyrightAndLicense' lang='en'>BoilerPlateDescription</div>
							</div>
							<div id='test2' class='test'>
								<div data-derived='copyright' lang='*'>something else obsolete to be overwritten</div>
								<div data-derived='originalCopyrightAndLicense' lang='en'>Some other place we show original copyright</div>
							</div>
						</body></html>"                        ;
            var bookDom  = new HtmlDom(html);
            var bookData = new BookData(bookDom, _collectionSettings, null);
            var metadata = BookCopyrightAndLicense.GetMetadata(bookDom, bookData);

            metadata.CopyrightNotice = "Copyright © 2019, Foo-Bar Publishers";
            BookCopyrightAndLicense.SetMetadata(metadata, bookDom, "", bookData, false);
            // This is an abbreviated version of the text we expect in originalCopyrightAndLicense. Now that we have an embedded <cite> element, matching the whole thing
            // is difficult. We have other tests that deal with exactly what goes in this field; here we're just concerned with generating it or not.
            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='test']/*[@data-derived='originalCopyrightAndLicense' and @lang='*' and contains(text(),'This book is an adaptation of the original')]", 2);
            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='test']/*[@data-derived='copyright' and @lang='*' and contains(text(),'Copyright © 2019, Foo-Bar Publishers')]", 2);

            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='copyright' and contains(text(), 'Copyright © 2019, Foo-Bar Publishers')]", 1);
            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='originalCopyright' and contains(text(), 'Copyright © 2007, Foo Publishers')]", 1);
            AssertThatXmlIn.Dom(bookDom.RawDom).HasNoMatchForXpath("//div[@id='bloomDataDiv']/div[@data-book='licenseUrl']");
            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='originalLicenseUrl' and contains(text(), 'http://creativecommons.org/licenses/by-nc/4.0/')]", 1);

            // Change to use the original copyright and license.
            var originalMetadata = BookCopyrightAndLicense.GetOriginalMetadata(bookDom, bookData);

            BookCopyrightAndLicense.SetMetadata(originalMetadata, bookDom, "", bookData, true);
            AssertThatXmlIn.Dom(bookDom.RawDom).HasNoMatchForXpath("//div[@class='test']/*[@data-derived='originalCopyrightAndLicense' and @lang='*']");
            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='test']/*[@data-derived='originalCopyrightAndLicense' and .='']", 2);
            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='test']/*[@data-derived='copyright' and @lang='*' and contains(text(),'Copyright © 2007, Foo Publishers')]", 2);

            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='copyright' and contains(text(), 'Copyright © 2007, Foo Publishers')]", 1);
            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='originalCopyright' and contains(text(), 'Copyright © 2007, Foo Publishers')]", 1);
            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='licenseUrl' and contains(text(), 'http://creativecommons.org/licenses/by-nc/4.0/')]", 1);
            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='originalLicenseUrl' and contains(text(), 'http://creativecommons.org/licenses/by-nc/4.0/')]", 1);
        }
コード例 #14
0
        private Metadata GetMetadataFromJson(ApiRequest request, bool forBook)
        {
            var json     = request.RequiredPostJson();
            var settings = DynamicJson.Parse(json);

            if (forBook)
            {
                Model.CurrentBook.BookInfo.MetaData.UseOriginalCopyright = settings.derivativeInfo.useOriginalCopyright;

                if (settings.derivativeInfo.useOriginalCopyright)
                {
                    return(BookCopyrightAndLicense.GetOriginalMetadata(Model.CurrentBook.Storage.Dom, Model.CurrentBook.BookData));
                }
            }

            var metadata = new Metadata {
                Creator = settings.copyrightInfo.imageCreator
            };

            metadata.SetCopyrightNotice(settings.copyrightInfo.copyrightYear, settings.copyrightInfo.copyrightHolder);

            if (settings.licenseInfo.licenseType == "creativeCommons")
            {
                metadata.License = new CreativeCommonsLicense(
                    true,
                    settings.licenseInfo.creativeCommonsInfo.allowCommercial == "yes",
                    GetCcDerivativeRule(settings.licenseInfo.creativeCommonsInfo.allowDerivatives))
                {
                    IntergovernmentalOriganizationQualifier = settings.licenseInfo.creativeCommonsInfo.intergovernmentalVersion
                };
            }
            else if (settings.licenseInfo.licenseType == "publicDomain")
            {
                metadata.License = CreativeCommonsLicense.FromToken("cc0");
            }
            else if (settings.licenseInfo.licenseType == "contact")
            {
                metadata.License = new NullLicense();
            }
            else
            {
                metadata.License = new CustomLicense();
            }

            metadata.License.RightsStatement = settings.licenseInfo.rightsStatement;

            return(metadata);
        }
コード例 #15
0
        public void SetLicenseMetadata_ToNoLicenseUrl_OriginalHasLicenseUrlInEn_ClearsEn()
        {
            string dataDivContent         = @"<div lang='en' data-book='licenseUrl'>http://creativecommons.org/licenses/by-nc-sa/3.0/</div>";
            var    dom                    = MakeDom(dataDivContent);
            var    collectionSettings     = new CollectionSettings();
            var    bookData               = new BookData(dom, collectionSettings, null);
            var    creativeCommonsLicense = (CreativeCommonsLicense)(BookCopyrightAndLicense.GetMetadata(dom, bookData).License);

            Assert.IsTrue(creativeCommonsLicense.AttributionRequired);             // yes, we got a CC license from the 'en' licenseUrl
            var newLicense  = new CustomLicense();
            var newMetaData = new Metadata();

            newMetaData.License = newLicense;
            BookCopyrightAndLicense.SetMetadata(newMetaData, dom, null, bookData, false);
            AssertThatXmlIn.Dom(dom.RawDom).HasNoMatchForXpath("//div[@data-book='licenseUrl']");
        }
コード例 #16
0
        public void SetOriginalCopyrightAndLicense_SourceIsAlsoAnAdaptation_OriginalCopyrightAndLicensePreserved()
        {
            var dom = SetOriginalCopyrightAndLicense(
                @" <div id='bloomDataDiv'>
					<div data-book='bookTitle' lang='en'>A really really empty book</div>
						<div data-book='copyright' lang='*'>
						Copyright © 2007, Foo Publishers
						</div>
					<div data-book='licenseUrl' lang='*'>
						http://creativecommons.org/licenses/by/4.0/
						</div>
					</div>"                    );
            // now do it again, simulating adaptation from the translation
            var bookData = new BookData(dom, _collectionSettings, null);

            BookCopyrightAndLicense.SetOriginalCopyrightAndLicense(dom, bookData, _collectionSettings);
            Assert.AreEqual("Adapted from original, Copyright © 2007, Foo Publishers. Licensed under CC-BY 4.0.", GetEnglishOriginalCopyrightAndLicense(dom));
        }
コード例 #17
0
 private string GetEnglishOriginalCopyrightAndLicense(HtmlDom dom)
 {
     return(BookCopyrightAndLicense.GetOriginalCopyrightAndLicenseNotice(_collectionSettings, dom));
 }
コード例 #18
0
        private string GetEnglishOriginalCopyrightAndLicense(HtmlDom dom)
        {
            var bookData = new BookData(dom, _collectionSettings, null);

            return(BookCopyrightAndLicense.GetOriginalCopyrightAndLicenseNotice(bookData, dom));
        }
コード例 #19
0
        private static Metadata GetMetadata(string dataDivContent)
        {
            var dom = MakeDom(dataDivContent);

            return(BookCopyrightAndLicense.GetMetadata(dom));
        }