Reads and writes the aspects of the book related to copyright, license, license logo, etc. That involves three duties: 1) Serializing/Deserializing a libpalaso.ClearShare.Metadata to/from the bloomDataDiv of the html 2) Propagating that information into template fields found in the pages of the book (normally just the credits page) 3) Placing the correct license image into the folder
Example #1
0
        /// <summary>
        /// Copy the copyright & license info to the originalCopyrightAndLicense,
        /// then remove the copyright so the translator can put in their own if they
        /// want. We retain the license, but the translator is allowed to change that.
        /// </summary>
        public static void SetOriginalCopyrightAndLicense(HtmlDom dom, BookData bookData, CollectionSettings collectionSettings)
        {
            if (bookData.GetMultiTextVariableOrEmpty("originalCopyrightAndLicense").Count > 0)
            {
                return;                 //leave the original there.
            }
            var    metadata = BookCopyrightAndLicense.GetMetadata(dom);
            string idOfLanguageUsed;
            var    languagePriorityIds = collectionSettings.LicenseDescriptionLanguagePriorities;

            //TODO HOW DO I GET THESE IN THE NATIONAL LANGUAGE INSTEAD OF THE UI LANGUAGE?

            var    license = metadata.License.GetMinimalFormForCredits(languagePriorityIds, out idOfLanguageUsed);
            string originalLicenseSentence;
            var    preferredLanguageIds = new[] { collectionSettings.Language2Iso639Code, LocalizationManager.UILanguageId, "en" };

            if (metadata.License is CustomLicense)
            {
                // I can imagine being more fancy... something like "Licensed under custom license:", and get localizations
                // for that... but sheesh, these are even now very rare in Bloom-land and should become more rare.
                // So for now, let's just print the custom license contents.
                originalLicenseSentence = license;
            }
            else
            {
                var licenseSentenceTemplate = LocalizationManager.GetString("EditTab.FrontMatter.OriginalLicenseSentence",
                                                                            "Licensed under {0}.",
                                                                            "On the Credits page of a book being translated, Bloom puts texts like 'Licensed under CC-BY', so that we have a record of what the license was for the original book. Put {0} in the translation, where the license should go in the sentence.",
                                                                            preferredLanguageIds, out idOfLanguageUsed);
                originalLicenseSentence = string.IsNullOrWhiteSpace(license) ? "" : string.Format(licenseSentenceTemplate, license);
                originalLicenseSentence = originalLicenseSentence.Replace("..", ".");                  // in case had notes which also had a period.
            }

            Console.WriteLine(originalLicenseSentence);
            var copyrightNotice = "";

            if (string.IsNullOrWhiteSpace(metadata.CopyrightNotice))
            {
                var noCopyrightSentence = LocalizationManager.GetString("EditTab.FrontMatter.OriginalHadNoCopyrightSentence",
                                                                        "Adapted from original without a copyright notice.",
                                                                        "On the Credits page of a book being translated, Bloom shows this if the original book did not have a copyright notice.",
                                                                        preferredLanguageIds, out idOfLanguageUsed);

                copyrightNotice = noCopyrightSentence + " " + originalLicenseSentence;
            }
            else
            {
                var originalCopyrightSentence = LocalizationManager.GetString("EditTab.FrontMatter.OriginalCopyrightSentence",
                                                                              "Adapted from original, {0}.",
                                                                              "On the Credits page of a book being translated, Bloom shows the original copyright. Put {0} in the translation where the copyright notice should go. For example in English, 'Adapted from original, {0}.' comes out like 'Adapted from original, Copyright 2011 SIL'.",
                                                                              preferredLanguageIds, out idOfLanguageUsed);
                copyrightNotice = String.Format(originalCopyrightSentence, metadata.CopyrightNotice.Trim()) + " " + originalLicenseSentence;
            }
            Console.WriteLine(copyrightNotice);
            bookData.Set("originalCopyrightAndLicense", copyrightNotice, "*");
            bookData.RemoveAllForms("copyright");              // RemoveAllForms does modify the dom
        }
Example #2
0
        /// <summary>
        /// Copy the copyright & license info to the originalCopyrightAndLicense,
        /// then remove the copyright so the translator can put in their own if they
        /// want. We retain the license, but the translator is allowed to change that.
        /// If the source is already a translation (already has original copyright or license)
        /// we keep them unchanged.
        /// </summary>
        public static void SetOriginalCopyrightAndLicense(HtmlDom dom, BookData bookData, CollectionSettings collectionSettings)
        {
            // If it already has some of this information, just keep it.
            if (bookData.BookIsDerivative())
            {
                return;                 //leave the original there.
            }
            // If there's no copyright information in a source-collection book, we're presumably making
            // a new original book, and shouldn't try to record any original copyright and license information.
            // This is somewhat redundant with the check in BookStarter.SetupNewDocumentContents(), the one
            // non-unit-test current caller of this method, that doesn't call this at all if the source is
            // a template book. I was trying for a minimal reasonable change for BL-5131, and therefore
            // put in this extra check, since previously this method was simply NEVER called in a source
            // collection.
            var copyrightNotice = BookCopyrightAndLicense.GetMetadata(dom).CopyrightNotice;

            if (String.IsNullOrEmpty(copyrightNotice) && collectionSettings.IsSourceCollection)
            {
                return;
            }
            bookData.Set("originalLicenseUrl", BookCopyrightAndLicense.GetLicenseUrl(dom), "*");
            bookData.Set("originalCopyright", System.Web.HttpUtility.HtmlEncode(copyrightNotice), "*");
            bookData.Set("originalLicenseNotes", dom.GetBookSetting("licenseNotes").GetFirstAlternative(), "*");
        }
Example #3
0
        private string SetupNewDocumentContents(string sourceFolderPath, string initialPath)
        {
            var  storage        = _bookStorageFactory(initialPath);
            bool usingTemplate  = storage.BookInfo.IsSuitableForMakingShells;
            bool makingTemplate = storage.BookInfo.IsSuitableForMakingTemplates;
            // If we're not making it from a template or making a template, we're deriving a translation from an existing book
            var makingTranslation = !usingTemplate && !makingTemplate;

            var bookData = new BookData(storage.Dom, _collectionSettings, null);

            UpdateEditabilityMetadata(storage);            //Path.GetFileName(initialPath).ToLower().Contains("template"));
            // BL-7614 We don't want a derivative of a book downloaded from a "bookshelf" to have the same bookshelf
            storage.BookInfo.ClearBookshelf();

            // NB: For a new book based on a page template, I think this should remove *everything*,
            // because the rest is in the xmatter.
            // For shells, we'll still have pages.

            // BL-6108: But if this is a template and we remove all the pages and xmatter,
            // there won't be anything left to tell us what the template's preferred layout was,
            // so we'll save that first.
            Layout templateLayout = null;

            if (usingTemplate)
            {
                templateLayout = Layout.FromDom(storage.Dom, Layout.A5Portrait);
            }

            // Remove from the new book any pages labeled as "extra".
            // Typically pages in a template are marked "extra" to indicate that they are options to insert with "Add Page"
            // but not pages (which a few templates have) that should be automatically inserted into every book
            // made from the template.
            // Originally we removed 'extra' pages in all cases, but we haven't actually used the capability
            // of deleting 'extra' pages from translations of shell books, and on the other hand, we did briefly release
            // a version of Bloom that incorrectly left shell book pages so marked. Something like 73 books in our library
            // may have this problem (BL-6392). Since we don't actually need the capability for making translations
            // of shell books, we decided to simply disable it: all pages in a shell book, even those marked
            // 'extra', will be kept in the translation.
            if (!makingTranslation)
            {
                for (var initialPageDivs = storage.Dom.SafeSelectNodes("/html/body/div[contains(@data-page,'extra')]");
                     initialPageDivs.Count > 0;
                     initialPageDivs = storage.Dom.SafeSelectNodes("/html/body/div[contains(@data-page,'extra')]"))
                {
                    initialPageDivs[0].ParentNode.RemoveChild(initialPageDivs[0]);
                }
            }
            else
            {
                // When making a translation of an original move the 'publisher' (if there is one) to 'originalPublisher'.
                storage.BookInfo.MovePublisherToOriginalPublisher();
            }

            XMatterHelper.RemoveExistingXMatter(storage.Dom);

            // BL-4586 Some old books ended up with background-image urls containing XML img tags
            // in the HTML-encoded string. This happened because the coverImage data-book element
            // contained an img tag instead of a bare filename.
            // Normally such a thing would get fixed on loading the book, but if the "old book" in question
            // is a shell downloaded from BloomLibrary.org, Bloom is not allowed to modify the book,
            // so if such a thing exists in this copied book here we will strip it out and replace it with the
            // filename in the img src attribute.
            Book.RemoveImgTagInDataDiv(storage.Dom);

            bookData.RemoveAllForms("ISBN");            //ISBN number of the original doesn't apply to derivatives

            var sizeAndOrientation = Layout.FromDomAndChoices(storage.Dom, templateLayout ?? Layout.A5Portrait, _fileLocator);

            //Note that we do this *before* injecting frontmatter, which is more likely to have a good reason for having English
            //Useful for things like Primers. Note that Lorem Ipsum and prefixing all text with "_" also work.
            //			if ("true"==GetMetaValue(storage.Dom.RawDom, "removeTranslationsWhenMakingNewBook", "false"))
            //			{
            //				ClearAwayAllTranslations(storage.Dom.RawDom);
            //			}

            ProcessXMatterMetaTags(storage);
            // If we are making a shell (from a template, as opposed to making a translation of a shell),
            // it should not have a pre-determined license. A default will be filled in later.
            // (But, if we're MAKING a template, we want to keep the CC0 from Template Starter.)
            if (usingTemplate && !makingTemplate)
            {
                BookCopyrightAndLicense.RemoveLicense(storage);
            }

            InjectXMatter(initialPath, storage, sizeAndOrientation);

            SetLineageAndId(storage, sourceFolderPath);

            if (makingTranslation)
            {
                storage.EnsureOriginalTitle();                 // Before SetBookTitle, so we definitely won't use this book's new empty title
            }

            SetBookTitle(storage, bookData, usingTemplate);

            TransformCreditPageData(storage.Dom, bookData, _collectionSettings, storage, makingTranslation);

            //Few sources will have this set at all. A template picture dictionary is one place where we might expect it to call for, say, bilingual
            int multilingualLevel = int.Parse(GetMetaValue(storage.Dom.RawDom, "defaultMultilingualLevel", "1"));

            TranslationGroupManager.SetInitialMultilingualSetting(bookData, multilingualLevel, _collectionSettings);

            var sourceDom = XmlHtmlConverter.GetXmlDomFromHtmlFile(sourceFolderPath.CombineForPath(Path.GetFileName(GetPathToHtmlFile(sourceFolderPath))), false);

            //If this is a shell book, make elements to hold the vernacular
            foreach (XmlElement div in storage.Dom.RawDom.SafeSelectNodes("//div[contains(@class,'bloom-page')]"))
            {
                XmlElement sourceDiv = sourceDom.SelectSingleNode("//div[@id='" + div.GetAttribute("id") + "']") as XmlElement;
                SetupIdAndLineage(sourceDiv, div);
                SetupPage(div, _collectionSettings, null, null);
            }

            ClearAwayDraftText(storage.Dom.RawDom);

            storage.UpdateSupportFiles();               // Copy branding files etc.
            storage.Save();

            //REVIEW this actually undoes the setting of the initial files name:
            //      storage.UpdateBookFileAndFolderName(_librarySettings);
            return(storage.FolderPath);
        }
Example #4
0
        private string SetupNewDocumentContents(string sourceFolderPath, string initialPath)
        {
            var  storage        = _bookStorageFactory(initialPath);
            bool usingTemplate  = storage.MetaData.IsSuitableForMakingShells;
            bool makingTemplate = storage.MetaData.IsSuitableForMakingTemplates;

            var bookData = new BookData(storage.Dom, _collectionSettings, null);

            UpdateEditabilityMetadata(storage);            //Path.GetFileName(initialPath).ToLower().Contains("template"));

            // NB: For a new book based on a page template, I think this should remove *everything*,
            // because the rest is in the xmatter.
            // For shells, we'll still have pages.

            //Remove from the new book any div-pages labeled as "extraPage"
            for (var initialPageDivs = storage.Dom.SafeSelectNodes("/html/body/div[contains(@data-page,'extra')]");
                 initialPageDivs.Count > 0;
                 initialPageDivs = storage.Dom.SafeSelectNodes("/html/body/div[contains(@data-page,'extra')]"))
            {
                initialPageDivs[0].ParentNode.RemoveChild(initialPageDivs[0]);
            }

            XMatterHelper.RemoveExistingXMatter(storage.Dom);

            bookData.RemoveAllForms("ISBN");            //ISBN number of the original doesn't apply to derivatives

            var sizeAndOrientation = Layout.FromDomAndChoices(storage.Dom, Layout.A5Portrait, _fileLocator);

            //Note that we do this *before* injecting frontmatter, which is more likely to have a good reason for having English
            //Useful for things like Primers. Note that Lorem Ipsum and prefixing all text with "_" also work.
            //			if ("true"==GetMetaValue(storage.Dom.RawDom, "removeTranslationsWhenMakingNewBook", "false"))
            //			{
            //				ClearAwayAllTranslations(storage.Dom.RawDom);
            //			}

            ProcessXMatterMetaTags(storage);
            // If we are making a shell (from a template, as opposed to making a translation of a shell),
            // it should not have a pre-determined license. A default will be filled in later.
            // (But, if we're MAKING a template, we want to keep the CC0 from Template Starter.)
            if (usingTemplate && !makingTemplate)
            {
                BookCopyrightAndLicense.RemoveLicense(storage);
            }

            InjectXMatter(initialPath, storage, sizeAndOrientation);

            SetLineageAndId(storage, sourceFolderPath);

            SetBookTitle(storage, bookData, usingTemplate);

            if (!usingTemplate &&
                // when people add a book to a source collection, they are assumed *editing* the book, not making a derivative (BL-4497)
                !_collectionSettings.IsSourceCollection)
            {
                BookCopyrightAndLicense.SetOriginalCopyrightAndLicense(storage.Dom, bookData, _collectionSettings);
            }

            //Few sources will have this set at all. A template picture dictionary is one place where we might expect it to call for, say, bilingual
            int multilingualLevel = int.Parse(GetMetaValue(storage.Dom.RawDom, "defaultMultilingualLevel", "1"));

            TranslationGroupManager.SetInitialMultilingualSetting(bookData, multilingualLevel, _collectionSettings);

            var sourceDom = XmlHtmlConverter.GetXmlDomFromHtmlFile(sourceFolderPath.CombineForPath(Path.GetFileName(GetPathToHtmlFile(sourceFolderPath))), false);

            //If this is a shell book, make elements to hold the vernacular
            foreach (XmlElement div in storage.Dom.RawDom.SafeSelectNodes("//div[contains(@class,'bloom-page')]"))
            {
                XmlElement sourceDiv = sourceDom.SelectSingleNode("//div[@id='" + div.GetAttribute("id") + "']") as XmlElement;
                SetupIdAndLineage(sourceDiv, div);
                SetupPage(div, _collectionSettings, null, null);
            }

            ClearAwayDraftText(storage.Dom.RawDom);

            storage.Save();

            //REVIEW this actually undoes the setting of the initial files name:
            //      storage.UpdateBookFileAndFolderName(_librarySettings);
            return(storage.FolderPath);
        }