Most editable elements in Bloom are multilingual. They have a wrapping
and then inner divs which are visible or not, depending on various settings. This class manages creating those inner divs, and marking them with classes that turn on visibility or move the element around the page, depending on the stylesheet in use. Also, page
s are marked with one of these classes: bloom-monolingual, bloom-bilingual, and bloom-trilingual
The Mother said...
Mama i tok:
abada fakwan
        /// <summary>
        /// Returns the sequence of bloom-editable divs that would normally be created as the content of an empty bloom-translationGroup,
        /// given the current collection and book settings, with the classes that would normally be set on them prior to editing to make the right ones visible etc.
        /// </summary>
        public static string GetDefaultTranslationGroupContent(XmlNode pageOrDocumentNode, Book currentBook)
        {
            // First get a XMLDocument so that we can start creating elements using it.
            XmlDocument ownerDocument = pageOrDocumentNode?.OwnerDocument;

            if (ownerDocument == null)                  // the OwnerDocument child can be null if pageOrDocumentNode is a document itself
            {
                if (pageOrDocumentNode is XmlDocument)
                {
                    ownerDocument = pageOrDocumentNode as XmlDocument;
                }
                else
                {
                    return("");
                }
            }

            // We want to use the usual routines that insert the required bloom-editables and classes into existing translation groups.
            // To make this work we make a temporary translation group
            // Since one of the routines expects the TG to be a descendant of the element passed to it, we make another layer of temporary wrapper around the translation group as well
            var containerElement = ownerDocument.CreateElement("div");

            containerElement.SetAttribute("class", "bloom-translationGroup");

            var wrapper = ownerDocument.CreateElement("div");

            wrapper.AppendChild(containerElement);

            PrepareElementsInPageOrDocument(containerElement, currentBook.BookData);

            TranslationGroupManager.UpdateContentLanguageClasses(wrapper, currentBook.BookData, currentBook.Language1IsoCode,
                                                                 currentBook.Language2IsoCode, currentBook.Language3IsoCode);

            return(containerElement.InnerXml);
        }
Пример #2
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);
        }
Пример #3
0
        public static void SetupPage(XmlElement pageDiv, CollectionSettings collectionSettings, string contentLanguageIso1, string contentLanguageIso2)        //, bool inShellMode)
        {
            TranslationGroupManager.PrepareElementsInPageOrDocument(pageDiv, collectionSettings);

            // a page might be "extra" as far as the template is concerned, but
            // once a page is inserted into book (which may become a shell), it's
            // just a normal page
            pageDiv.SetAttribute("data-page", pageDiv.GetAttribute("data-page").Replace("extra", "").Trim());
            ClearAwayDraftText(pageDiv);
        }
Пример #4
0
        public static void SetupPage(XmlElement pageDiv, BookData bookData)        //, bool inShellMode)
        {
            TranslationGroupManager.PrepareElementsInPageOrDocument(pageDiv, bookData);

            SetLanguageForElementsWithMetaLanguage(pageDiv, bookData);

            // a page might be "extra" as far as the template is concerned, but
            // once a page is inserted into book (which may become a shell), it's
            // just a normal page
            pageDiv.SetAttribute("data-page", pageDiv.GetAttribute("data-page").Replace("extra", "").Trim());
            ClearAwayDraftText(pageDiv);
            ClearAwayPageDescription(pageDiv);
        }
 /// <summary>
 /// bloom-translationGroup elements on the page in audio-reading order.
 /// </summary>
 public static List <XmlElement> SortedGroupsOnPage(XmlElement page, bool omitBoxHeaders = false)
 {
     return(TranslationGroupManager.SortTranslationGroups(GetTranslationGroups(page, omitBoxHeaders)));
 }
Пример #6
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);
        }
Пример #7
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);
        }
 /// <summary>
 /// bloom-translationGroup elements on the page in audio-reading order.
 /// </summary>
 public static List <XmlElement> SortedGroupsOnPage(XmlElement page)
 {
     return(TranslationGroupManager.SortTranslationGroups(page
                                                          .SafeSelectNodes(".//div[contains(@class, 'bloom-translationGroup')]")
                                                          .Cast <XmlElement>()));
 }