private string SetupNewDocumentContents(string sourceFolderPath, string initialPath)
{
var storage = _bookStorageFactory(initialPath);
bool usingTemplate = storage.MetaData.IsSuitableForMakingShells;
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"
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);
// }
InjectXMatter(initialPath, storage, sizeAndOrientation);
SetLineageAndId(storage, sourceFolderPath);
SetBookTitle(storage, bookData, usingTemplate);
//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;
}