public SetBookSetting ( string key, string writingSystemId, string form ) : void | ||
key | string | |
writingSystemId | string | |
form | string | |
return | void |
/// <summary> /// Call this when we have a new set of metadata to use. It /// 1) sets the bloomDataDiv with the data, /// 2) causes any template fields in the book to get the new values /// 3) updates the license image on disk /// </summary> public static void SetMetadata(Metadata metadata, HtmlDom dom, string bookFolderPath, BookData bookData, bool useOriginalCopyright) { dom.SetBookSetting("copyright", "*", ConvertNewLinesToHtmlBreaks(metadata.CopyrightNotice)); dom.SetBookSetting("licenseUrl", "*", metadata.License.Url); // This is for backwards compatibility. The book may have licenseUrl in 'en' created by an earlier version of Bloom. // For backwards compatibility, GetMetaData will read that if it doesn't find a '*' license first. So now that we're // setting a licenseUrl for '*', we must make sure the 'en' one is gone, because if we're setting a non-CC license, // the new URL will be empty and the '*' one will go away, possibly exposing the 'en' one to be used by mistake. // See BL-3166. dom.SetBookSetting("licenseUrl", "en", null); string languageUsedForDescription; //This part is unfortunate... the license description, which is always localized, doesn't belong in the datadiv; it //could instead just be generated when we update the page. However, for backwards compatibility (prior to 3.6), //we localize it and place it in the datadiv. dom.RemoveBookSetting("licenseDescription"); var description = metadata.License.GetDescription(bookData.GetLanguagePrioritiesForLocalizedTextOnPage(), out languageUsedForDescription); dom.SetBookSetting("licenseDescription", languageUsedForDescription, ConvertNewLinesToHtmlBreaks(description)); // Book may have old licenseNotes, typically in 'en'. This can certainly show up again if licenseNotes in '*' is removed, // and maybe anyway. Safest to remove it altogether if we are setting it using the new scheme. dom.RemoveBookSetting("licenseNotes"); dom.SetBookSetting("licenseNotes", "*", ConvertNewLinesToHtmlBreaks(metadata.License.RightsStatement)); // we could do away with licenseImage in the bloomDataDiv, since the name is always the same, but we keep it for backward compatibility if (metadata.License is CreativeCommonsLicense) { dom.SetBookSetting("licenseImage", "*", "license.png"); } else { //CC licenses are the only ones we know how to show an image for dom.RemoveBookSetting("licenseImage"); } UpdateDomFromDataDiv(dom, bookFolderPath, bookData, useOriginalCopyright); }
public void SetBookSetting_WasMissingCompletely_DataDivHasNewString() { var bookDom = new HtmlDom(@"<html ><head></head><body> <div id='bloomDataDiv'> </div> </body></html>"); bookDom.SetBookSetting("foo","xyz","hello"); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@data-book='foo' and @lang='xyz' and text()='hello']", 1); }
public void SetBookSetting_NoDataDivYet_SettingAdded() { var bookDom = new HtmlDom(@"<html ><head></head><body> </body></html>"); bookDom.SetBookSetting("foo", "xyz", "hello"); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//body/div[@id='bloomDataDiv']/div[@data-book='foo' and @lang='xyz' and text()='hello']", 1); }
public void SetBookSetting_HadValueWithNoLanguage_RemovesItAndSavesNewValue() { var bookDom = new HtmlDom(@"<html ><head></head><body> <div id='bloomDataDiv'> <div data-book='foo'>blah</div> <div data-book='foo' lang='en'>blah</div> </div> </body></html>"); bookDom.SetBookSetting("foo", "xyz", "hello"); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@data-book='foo' and @lang='xyz' and text()='hello']", 1); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@data-book='foo' and @lang='en' and text()='blah']", 1); AssertThatXmlIn.Dom(bookDom.RawDom).HasNoMatchForXpath("//div[@data-book='foo' and not(@lang)]"); }
public void SetBookSetting_HadADifferentValueCompletely_NewValue() { var bookDom = new HtmlDom(@"<html ><head></head><body> <div id='bloomDataDiv'> <div data-book='foo' lang='en'>blah</div> <div data-book='foo' lang='xyz'>boo</div> </div> </body></html>"); bookDom.SetBookSetting("foo", "xyz", "hello"); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@data-book='foo' and @lang='xyz' and text()='hello']", 1); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@data-book='foo' and @lang='en' and text()='blah']", 1); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@data-book='foo']", 2); }
public void SetBookSetting_AddANewVariationToAnExistingKey_Added() { var bookDom = new HtmlDom(@"<html ><head></head><body> <div id='bloomDataDiv'> <div data-book='foo' lang='en'>English</div> <div data-book='foo' lang='id'>Indonesian</div> </div> </body></html>"); bookDom.SetBookSetting("foo", "fr", "French"); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@data-book='foo' and @lang='id' and text()='Indonesian']", 1); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@data-book='foo' and @lang='en' and text()='English']", 1); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@data-book='foo' and @lang='fr' and text()='French']", 1); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@data-book='foo']", 3); }
/// <summary> /// Call this when we have a new set of metadata to use. It /// 1) sets the bloomDataDiv with the data, /// 2) causes any template fields in the book to get the new values /// 3) updates the license image on disk /// </summary> public static void SetMetadata(Metadata metadata, HtmlDom dom, string bookFolderPath, CollectionSettings collectionSettings) { dom.SetBookSetting("copyright","*",metadata.CopyrightNotice); dom.SetBookSetting("licenseUrl","*",metadata.License.Url); // This is for backwards compatibility. The book may have licenseUrl in 'en' created by an earlier version of Bloom. // For backwards compatibiilty, GetMetaData will read that if it doesn't find a '*' license first. So now that we're // setting a licenseUrl for '*', we must make sure the 'en' one is gone, because if we're setting a non-CC license, // the new URL will be empty and the '*' one will go away, possibly exposing the 'en' one to be used by mistake. // See BL-3166. dom.SetBookSetting("licenseUrl", "en", null); string languageUsedForDescription; //This part is unfortunate... the license description, which is always localized, doesn't belong in the datadiv; it //could instead just be generated when we update the page. However, for backwards compatibility (prior to 3.6), //we localize it and place it in the datadiv. dom.RemoveBookSetting("licenseDescription"); var description = metadata.License.GetDescription(collectionSettings.LicenseDescriptionLanguagePriorities, out languageUsedForDescription); dom.SetBookSetting("licenseDescription", languageUsedForDescription, ConvertNewLinesToHtmlBreaks(description)); // Book may have old licenseNotes, typically in 'en'. This can certainly show up again if licenseNotes in '*' is removed, // and maybe anyway. Safest to remove it altogether if we are setting it using the new scheme. dom.RemoveBookSetting("licenseNotes"); dom.SetBookSetting("licenseNotes", "*", ConvertNewLinesToHtmlBreaks(metadata.License.RightsStatement)); // we could do away with licenseImage in the bloomDataDiv, since the name is always the same, but we keep it for backward compatibility if (metadata.License is CreativeCommonsLicense) { dom.SetBookSetting("licenseImage", "*", "license.png"); } else { //CC licenses are the only ones we know how to show an image for dom.RemoveBookSetting("licenseImage"); } UpdateDomFromDataDiv(dom, bookFolderPath, collectionSettings); }