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); }
private void CleanupBrandingImages(XmlElement newPageDiv, string branding, string bookFolderPath, Layout layout) { if (branding == null) { return; // in testing. } if (BookStorage.IsStaticContent(bookFolderPath)) { return; } var prefix = BrandingApi.kApiBrandingImage + "?id="; foreach (XmlElement imageElt in newPageDiv.SafeSelectNodes("//img").Cast <XmlElement>().ToArray()) { var src = imageElt.Attributes["src"]?.Value; if (src == null || !src.StartsWith(prefix)) { continue; } var fileName = src.Substring(prefix.Length); var pathToRealImage = BrandingApi.FindBrandingImageFileIfPossible(branding, fileName, layout); if (string.IsNullOrEmpty(pathToRealImage)) { if (!TemporaryDom) { // If the book folder contains this file already, it's obsolete, from some previous branding choice. // Get rid of it to save space. We might also have an obsolete file with a png extension; get rid of // that too. Of course, if this is just for a temporary DOM, we don't want to mess with the real folder. var destFileName = Path.Combine(bookFolderPath, fileName); RobustFile.Delete(destFileName); RobustFile.Delete(Path.ChangeExtension(destFileName, ".png")); } // At this point the <img> element has src api/branding/something not in the current branding. // So it's not actually going to produce an image in Bloom itself. We could change it, as // in the following block, so that it points to a non-existent file in the book folder, // and do various tricks to try to prevent warnings about missing files. // But such an element does no good. Even if someone manually inserted the missing file // (presumably an attempt to circumvent the current branding?) the next bring-book-up-to-date // will remove it as not part of the current branding. // Meanwhile, we need tricks to prevent missing-image errors in Bloom itself, and more tricks // to prevent them in epubs, and .bloomd, and however else we might publish. // All this is made unnecessary by just deleting the <img> element if it's not used in the // current branding. // If we later switch to a different branding which does need it, // the next cycle of updating xmatter will start again with the original xmatter files // which contain all the api/branding urls, and this time we will find the file and not // delete the <img>. imageElt.ParentNode.RemoveChild(imageElt); } else { if (TemporaryDom) { // for a temporary DOM we don't care if the path is absolute and to something outside the book folder. // It just has to work. And we don't want to modify the book folder. It does need to go through the // image server, otherwise we'll get cross-domain problems. And we need the marker that prevents // creating screen-only quality images. imageElt.SetAttribute("src", (EnhancedImageServer.OriginalImageMarker + "/" + pathToRealImage).ToLocalhost()); } else { // We want to actually copy it into the book folder, where things will work right // even if someone just opens the HTML file in a context where our image server isn't // running at all. // We want to use the original name in the book folder...for one thing, works with // deletion code above...but the correct extension for the file we actually found. var destFileName = Path.ChangeExtension(Path.GetFileName(fileName), Path.GetExtension(pathToRealImage)); RobustFile.Copy(pathToRealImage, Path.Combine(bookFolderPath, destFileName), true); // Point the <img> element at the local file...which should be available since we // just copied it there. imageElt.SetAttribute("src", destFileName); } } } }