ConvertHtmlBreaksToNewLines() public static method

public static ConvertHtmlBreaksToNewLines ( string html ) : string
html string
return string
Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
 private static string DecodeAlternative(string alternative)
 {
     return(HtmlDom.ConvertHtmlBreaksToNewLines(WebUtility.HtmlDecode(alternative)));
 }
Ejemplo n.º 3
0
 private static string DecodeMultiTextBase(MultiTextBase multistring)
 {
     return(HtmlDom.ConvertHtmlBreaksToNewLines(WebUtility.HtmlDecode(multistring.GetFirstAlternative())));
 }