当前位置: 首页>>代码示例>>C#>>正文


C# HtmlDom.GetBookSetting方法代码示例

本文整理汇总了C#中Bloom.Book.HtmlDom.GetBookSetting方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlDom.GetBookSetting方法的具体用法?C# HtmlDom.GetBookSetting怎么用?C# HtmlDom.GetBookSetting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Bloom.Book.HtmlDom的用法示例。


在下文中一共展示了HtmlDom.GetBookSetting方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetMetadata

        /// <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 (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;
        }
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:56,代码来源:BookCopyrightAndLicense.cs

示例2: GetBookSetting_TwoVariationsWereThere_ReturnsBoth

 public void GetBookSetting_TwoVariationsWereThere_ReturnsBoth()
 {
     var bookDom = new HtmlDom(@"<html ><head></head><body>
         <div id='bloomDataDiv'>
                 <div data-book='leaveMe' lang='en'>something unique</div>
                 <div data-book='getMe' lang='id'>Buku</div>
                 <div data-book='getMe' lang='tpi'>Buk</div>
         </div>
      </body></html>");
     var result = bookDom.GetBookSetting("getMe");
     Assert.AreEqual(2,result.Count);
     Assert.AreEqual("Buk", result["tpi"]);
     Assert.AreEqual("Buku", result["id"]);
 }
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:14,代码来源:HtmlDomTests.cs

示例3: GetBookSetting_NotThere_ReturnsEmptyMultistring

 public void GetBookSetting_NotThere_ReturnsEmptyMultistring()
 {
     var bookDom = new HtmlDom(@"<html ><head></head><body>
         <div id='bloomDataDiv'>
         </div>
      </body></html>");
     var result = bookDom.GetBookSetting("getMe");
     Assert.AreEqual(0, result.Count);
 }
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:9,代码来源:HtmlDomTests.cs

示例4: LogMetdata

 public static void LogMetdata(HtmlDom dom)
 {
     Logger.WriteEvent("LicenseUrl: " + dom.GetBookSetting("licenseUrl"));
     Logger.WriteEvent("LicenseNotes: " + dom.GetBookSetting("licenseNotes"));
     Logger.WriteEvent("");
 }
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:6,代码来源:BookCopyrightAndLicense.cs

示例5: ShouldSetToDefaultCopyrightAndLicense

        private static bool ShouldSetToDefaultCopyrightAndLicense(HtmlDom dom)
        {
            var hasCopyright = !dom.GetBookSetting("copyright").Empty;
            var hasLicenseUrl = !dom.GetBookSetting("licenseUrl").Empty;
            var hasLicenseNotes = !dom.GetBookSetting("licenseNotes").Empty;

            //Enhance: this logic is perhaps overly restrictive?
            return !hasCopyright && !hasLicenseUrl && !hasLicenseNotes;
        }
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:9,代码来源:BookCopyrightAndLicense.cs

示例6: CopyItemToFieldsInPages

        private static void CopyItemToFieldsInPages(HtmlDom dom, string key, string valueAttribute = null, string[] languagePreferences= null)
        {
            if (languagePreferences == null)
                languagePreferences = new[] {"*", "en"};

            MultiTextBase source = dom.GetBookSetting(key);

            var target = dom.SelectSingleNode("//*[@data-derived='" + key + "']");
            if (target == null)
            {
                return;
            }

            //just put value into the text of the element
            if (string.IsNullOrEmpty(valueAttribute))
            {
                //clear out what's there now
                target.RemoveAttribute("lang");
                target.InnerText = "";

                var form = source.GetBestAlternative(languagePreferences);
                if (form != null && !string.IsNullOrWhiteSpace(form.Form))
                {
                    HtmlDom.SetElementFromUserStringPreservingLineBreaks(target, form.Form);
                    target.SetAttribute("lang", form.WritingSystemId); //this allows us to set the font to suit the language
                }
            }
            else //Put the value into an attribute. The license image goes through this path.
            {
                target.SetAttribute(valueAttribute, source.GetBestAlternativeString(languagePreferences));
                if (source.Empty)
                {
                    //if the license image is empty, make sure we don't have some alternative text
                    //about the image being missing or slow to load
                    target.SetAttribute("alt", "");
                    //over in javascript land, @alt will get set appropriately when the image url is not empty.
                }
            }
        }
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:39,代码来源:BookCopyrightAndLicense.cs


注:本文中的Bloom.Book.HtmlDom.GetBookSetting方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。