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