RemoveAllForms() public method

public RemoveAllForms ( string key ) : void
key string
return void
        /// <summary>
        /// This is used when a book is first created from a source; without it, if the shell maker left the book as trilingual when working on it,
        /// then every time someone created a new book based on it, it too would be trilingual.
        /// </summary>
        /// <remarks>
        /// This method explicitly used the CollectionSettings languages in creating a new book.
        /// </remarks>
        public static void SetInitialMultilingualSetting(BookData bookData, int oneTwoOrThreeContentLanguages)
        {
            //var multilingualClass =  new string[]{"bloom-monolingual", "bloom-bilingual","bloom-trilingual"}[oneTwoOrThreeContentLanguages-1];

            if (oneTwoOrThreeContentLanguages < 3)
            {
                bookData.RemoveAllForms("contentLanguage3");
            }
            if (oneTwoOrThreeContentLanguages < 2)
            {
                bookData.RemoveAllForms("contentLanguage2");
            }

            var language1 = bookData.CollectionSettings.Language1;

            bookData.Set("contentLanguage1", XmlString.FromUnencoded(language1.Iso639Code), false);
            bookData.Set("contentLanguage1Rtl", XmlString.FromUnencoded(language1.IsRightToLeft.ToString()), false);
            if (oneTwoOrThreeContentLanguages > 1)
            {
                var language2 = bookData.CollectionSettings.Language2;
                bookData.Set("contentLanguage2", XmlString.FromUnencoded(language2.Iso639Code), false);
                bookData.Set("contentLanguage2Rtl", XmlString.FromUnencoded(language2.IsRightToLeft.ToString()), false);
            }
            var language3 = bookData.CollectionSettings.Language3;

            if (oneTwoOrThreeContentLanguages > 2 && !String.IsNullOrEmpty(language3.Iso639Code))
            {
                bookData.Set("contentLanguage3", XmlString.FromUnencoded(language3.Iso639Code), false);
                bookData.Set("contentLanguage3Rtl", XmlString.FromUnencoded(language3.IsRightToLeft.ToString()), false);
            }
        }
Example #2
0
        /// <summary>
        /// This is used when a book is first created from a source; without it, if the shell maker left the book as trilingual when working on it,
        /// then everytime someone created a new book based on it, it too would be trilingual.
        /// </summary>
        public static void SetInitialMultilingualSetting(BookData bookData, int oneTwoOrThreeContentLanguages, CollectionSettings collectionSettings)
        {
            //var multilingualClass =  new string[]{"bloom-monolingual", "bloom-bilingual","bloom-trilingual"}[oneTwoOrThreeContentLanguages-1];

            if (oneTwoOrThreeContentLanguages < 3)
            {
                bookData.RemoveAllForms("contentLanguage3");
            }
            if (oneTwoOrThreeContentLanguages < 2)
            {
                bookData.RemoveAllForms("contentLanguage2");
            }

            bookData.Set("contentLanguage1", collectionSettings.Language1Iso639Code, false);
            bookData.Set("contentLanguage1Rtl", collectionSettings.IsLanguage1Rtl.ToString(), false);
            if (oneTwoOrThreeContentLanguages > 1)
            {
                bookData.Set("contentLanguage2", collectionSettings.Language2Iso639Code, false);
                bookData.Set("contentLanguage2Rtl", collectionSettings.IsLanguage2Rtl.ToString(), false);
            }
            if (oneTwoOrThreeContentLanguages > 2 && !string.IsNullOrEmpty(collectionSettings.Language3Iso639Code))
            {
                bookData.Set("contentLanguage3", collectionSettings.Language3Iso639Code, false);
                bookData.Set("contentLanguage3Rtl", collectionSettings.IsLanguage3Rtl.ToString(), false);
            }
        }
        /// <summary>
        /// This is used when a book is first created from a source; without it, if the shell maker left the book as trilingual when working on it,
        /// then everytime someone created a new book based on it, it too would be trilingual.
        /// </summary>
        public static void SetInitialMultilingualSetting(BookData bookData, int oneTwoOrThreeContentLanguages, CollectionSettings collectionSettings)
        {
            //var multilingualClass =  new string[]{"bloom-monolingual", "bloom-bilingual","bloom-trilingual"}[oneTwoOrThreeContentLanguages-1];

            if (oneTwoOrThreeContentLanguages < 3)
                bookData.RemoveAllForms("contentLanguage3");
            if (oneTwoOrThreeContentLanguages < 2)
                bookData.RemoveAllForms("contentLanguage2");

            bookData.Set("contentLanguage1", collectionSettings.Language1Iso639Code, false);
            if (oneTwoOrThreeContentLanguages > 1)
                bookData.Set("contentLanguage2", collectionSettings.Language2Iso639Code, false);
            if (oneTwoOrThreeContentLanguages > 2 && !string.IsNullOrEmpty(collectionSettings.Language3Iso639Code))
                bookData.Set("contentLanguage3", collectionSettings.Language3Iso639Code, false);
        }
Example #4
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)
        {
            // At least one of these should exist if the source was a derivative, since we don't allow a
            // book to have no license, nor to be uploaded without copyright...unless of course it was derived
            // before 3.9, when we started doing this. In that case the best we can do is record the earliest
            // information we have for this and later adaptations.
            if (bookData.GetMultiTextVariableOrEmpty("originalLicenseUrl").Count > 0 ||
                bookData.GetMultiTextVariableOrEmpty("originalLicenseNotes").Count > 0 ||
                bookData.GetMultiTextVariableOrEmpty("originalCopyright").Count > 0)
            {
                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 = GetMetadata(dom).CopyrightNotice;

            if (string.IsNullOrEmpty(copyrightNotice) && collectionSettings.IsSourceCollection)
            {
                return;
            }
            bookData.Set("originalLicenseUrl", GetLicenseUrl(dom), "*");
            bookData.Set("originalCopyright", System.Web.HttpUtility.HtmlEncode(copyrightNotice), "*");
            bookData.Set("originalLicenseNotes", dom.GetBookSetting("licenseNotes").GetFirstAlternative(), "*");
            bookData.RemoveAllForms("copyright");              // RemoveAllForms does modify the dom
        }
Example #5
0
        private string SetupNewDocumentContents(string sourceFolderPath, string initialPath)
        {
            var storage  = _bookStorageFactory(initialPath);
            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 labelled as "extraPage"
            foreach (XmlElement initialPageDiv in storage.Dom.SafeSelectNodes("/html/body/div[contains(@data-page,'extra')]"))
            {
                initialPageDiv.ParentNode.RemoveChild(initialPageDiv);
            }

            XMatterHelper.RemoveExistingXMatter(storage.Dom);

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

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

            //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);
//			}

            InjectXMatter(initialPath, storage, sizeAndOrientation);

            SetLineageAndId(storage);

            SetBookTitle(storage, bookData);



            //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 intial files name:
            //      storage.UpdateBookFileAndFolderName(_librarySettings);
            return(storage.FolderPath);
        }
Example #6
0
 public static void TransformCreditPageData(HtmlDom dom, BookData bookData, CollectionSettings collectionSettings,
                                            BookStorage storage, bool makingTranslation)
 {
     // If we're deriving a translation from an existing book,
     // we should save the original copyright and license of that book.
     if (makingTranslation)
     {
         SetOriginalCopyrightAndLicense(dom, bookData, collectionSettings);
     }
     // a new book should never have the copyright holder set, whether it's a template, shell, or translation
     bookData.RemoveAllForms("copyright");          // RemoveAllForms does modify the dom
     storage.BookInfo.Copyright = null;             // this might be redundant but let's play safe
     // This is a place to put who it was translated by, usually in a national language.
     // Doesn't apply to templates or (usually) to shells; but a translation can serve again as a shell.
     // In that case, we expect it to be filled in with the new translator's information.
     // Keeping the previous translator's details there is confusing (BL-6271)
     bookData.RemoveAllForms("versionAcknowledgments");
 }
Example #7
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 #8
0
        private void SetBookTitle(BookStorage storage, BookData bookData, bool usingTemplate)
        {
            //This is what we were trying to do: there was a defaultNameForDerivedBooks meta tag in the html
            //which had no language code. It worked fine for English, e.g., naming new English books
            //"My Book" or "My Dictionary" or whatever.
            //But in other cases, it actually hurt because that English name would be hidden down in the new
            //book, where the author wouldn't see it. But some consumer, using English, would see it, and
            //"My Book" is a pretty dumb name for the carefully prepared book to be listed under.
            //
            //Now, if we are making this book from a shell book, we can keep whatever (title,language) pairs it has.
            //Those will be just fine, for example, if we have English as one of our national languages and so get
            // "vaccinations" for free without having to type that in again.
            //
            //But if we are making this from a *template*, then we *don't* want to keep the various ways to say the
            //name of the template. Seeing "Basic Book" as the name of a resulting shell is not helpful.

            //We just don't have a use for this at all anymore: nice idea, doesn't really work:
            storage.Dom.RemoveMetaElement("defaultNameForDerivedBooks");

            // Clear these out let other code set again when there is a real title.
            storage.BookInfo.Title = "";
            storage.Dom.Title      = "";

            //If we're making a book from a template, remove all the titles in all languages
            if (usingTemplate)
            {
                bookData.RemoveAllForms("bookTitle");
            }
            // If we're making a Template, we really want its title to include Template
            // (in hopes the user will keep it at the end so the pages can be used in Add Page)
            if (storage.BookInfo.IsSuitableForMakingShells)
            {
                storage.BookInfo.Title = "My Template";
                storage.Dom.Title      = "My Template";
                storage.Dom.SetBookSetting("bookTitle", "en", "My Template");
                // Yes, we want the English word Template in the vernacular Title. Ugly, but that's
                // what determines the file name, and that's what determines whether Add Page will
                // include it.
                storage.Dom.SetBookSetting("bookTitle", _collectionSettings.Language1Iso639Code, "My Template");
            }
        }
Example #9
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 #10
0
        private string SetupNewDocumentContents(string sourceFolderPath, string initialPath)
        {
            var storage = _bookStorageFactory(initialPath);
            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 labelled as "extraPage"
            foreach (XmlElement initialPageDiv in storage.Dom.SafeSelectNodes("/html/body/div[contains(@data-page,'extra')]"))
            {
                initialPageDiv.ParentNode.RemoveChild(initialPageDiv);
            }

            XMatterHelper.RemoveExistingXMatter(storage.Dom);

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

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

            //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);
            //			}

            InjectXMatter(initialPath, storage, sizeAndOrientation);

            SetLineageAndId(storage);

            SetBookTitle(storage, bookData);

            //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 intial files name:
            //      storage.UpdateBookFileAndFolderName(_librarySettings);
            return storage.FolderPath;
        }
Example #11
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);
        }
Example #12
0
        private static void SetBookTitle(BookStorage storage, BookData bookData, bool usingTemplate)
        {
            //This is what we were trying to do: there was a defaultNameForDerivedBooks meta tag in the html
            //which had no language code. It worked fine for English, e.g., naming new English books
            //"My Book" or "My Dicionary" or whatever.
            //But in other cases, it actually hurt becuase that English name would be hidden down in the new
            //book, where the author wouldn't see it. But some consumer, using English, would see it, and
            //"My Book" is a pretty dumb name for tha carefully prepared book to be listed under.
            //
            //Now, if we are making this book from a shell book, we can keep whatever (title,language) pairs it has.
            //Those will be just fine, for example, if we have English as one of our national langauges and so get
            // "vaccinations" for free wihtout having to type that in again.
            //
            //But if we are making this from a *template*, then we *don't* want to keep the various ways to say the
            //name of the template. Seeing "Basic Book" as the name of a resulting shell is not helpful.

            //We just don't have a use for this at all anymore: nice idea, doesn't really work:
            storage.Dom.RemoveMetaElement("defaultNameForDerivedBooks");

            // Clear these out let other code set again when there is a real title.
            storage.MetaData.Title = "";
            storage.Dom.Title = "";

            //If we're making a book from a template, remove all the titles in all languages
            if(usingTemplate)
            {
                bookData.RemoveAllForms("bookTitle");
            }
        }