Bloom.Book.XMatterHelper.InjectXMatter C# (CSharp) Method

InjectXMatter() public method

public InjectXMatter ( string>.Dictionary writingSystemCodes, Layout layout ) : void
writingSystemCodes string>.Dictionary
layout Layout
return void
        public void InjectXMatter(Dictionary<string, string> writingSystemCodes, Layout layout)
        {
            //don't want to pollute shells with this content
            if (!string.IsNullOrEmpty(FolderPathForCopyingXMatterFiles))
            {
                //copy over any image files used by this front matter
                string path = Path.GetDirectoryName(PathToXMatterHtml);
                foreach (var file in Directory.GetFiles(path, "*.png").Concat(Directory.GetFiles(path, "*.jpg").Concat(Directory.GetFiles(path, "*.gif").Concat(Directory.GetFiles(path, "*.bmp")))))
                {
                    RobustFile.Copy(file, FolderPathForCopyingXMatterFiles.CombineForPath(Path.GetFileName(file)), true);
                }
            }

            //note: for debugging the template/css purposes, it makes our life easier if, at runtime, the html is pointing the original.
            //makes it easy to drop into a css editor and fix it up with the content we're looking at.
            //TODO:But then later, we want to save it so that these are found in the same dir as the book.
            _bookDom.AddStyleSheet(PathToStyleSheetForPaperAndOrientation.ToLocalhost());

            //it's important that we append *after* this, so that these values take precendance (the template will just have empty values for this stuff)
            //REVIEW: I think all stylesheets now get sorted once they are all added: see HtmlDoc.SortStyleSheetLinks()
            XmlNode divBeforeNextFrontMattterPage = _bookDom.RawDom.SelectSingleNode("//body/div[@id='bloomDataDiv']");

            foreach (XmlElement xmatterPage in XMatterDom.SafeSelectNodes("/html/body/div[contains(@data-page,'required')]"))
            {
                var newPageDiv = _bookDom.RawDom.ImportNode(xmatterPage, true) as XmlElement;
                //give a new id, else thumbnail caches get messed up becuase every book has, for example, the same id for the cover.
                newPageDiv.SetAttribute("id", Guid.NewGuid().ToString());

                if (IsBackMatterPage(xmatterPage))
                {
                    //note: this is redundant unless this is the 1st backmatterpage in the list
                    divBeforeNextFrontMattterPage = _bookDom.RawDom.SelectSingleNode("//body/div[last()]");
                }

                //we want the xmatter pages to match what we found in the source book
                SizeAndOrientation.UpdatePageSizeAndOrientationClasses(newPageDiv, layout);

                //any @lang attributes that have a metalanguage code (N1, N2, V) get filled with the actual code.
                //note that this older method is crude, as you're in trouble if the user changes one of those to
                //a different language. Instead, use data-metalanguage.
                foreach ( XmlElement node in newPageDiv.SafeSelectNodes("//*[@lang]"))
                {
                    var lang = node.GetAttribute("lang");
                    if (writingSystemCodes.ContainsKey(lang))
                    {
                        node.SetAttribute("lang", writingSystemCodes[lang]);
                    }
                }

                _bookDom.RawDom.SelectSingleNode("//body").InsertAfter(newPageDiv, divBeforeNextFrontMattterPage);
                divBeforeNextFrontMattterPage = newPageDiv;

                //enhance... this is really ugly. I'm just trying to clear out any remaining "{blah}" left over from the template
                foreach (XmlElement e in newPageDiv.SafeSelectNodes("//*[starts-with(text(),'{')]"))
                {
                    foreach ( var node in e.ChildNodes)
                    {
                        XmlText t = node as XmlText;
                        if(t!=null && t.Value.StartsWith("{"))
                            t.Value =""; //otherwise html tidy will through away span's (at least) that are empty, so we never get a chance to fill in the values.
                    }
                }
            }
            InjectFlyleafIfNeeded(layout);
        }

Usage Example

Esempio n. 1
0
        private void InjectXMatter(string initialPath, BookStorage storage, Layout sizeAndOrientation)
        {
            //now add in the xmatter from the currently selected xmatter pack
            if (!TestingSoSkipAddingXMatter)
            {
                var data = new DataSet();
                Debug.Assert(!string.IsNullOrEmpty(_collectionSettings.Language1Iso639Code));
                Debug.Assert(!string.IsNullOrEmpty(_collectionSettings.Language2Iso639Code));
                data.WritingSystemAliases.Add("V", _collectionSettings.Language1Iso639Code);
                data.WritingSystemAliases.Add("N1", _collectionSettings.Language2Iso639Code);
                data.WritingSystemAliases.Add("N2", _collectionSettings.Language3Iso639Code);

                var helper = new XMatterHelper(storage.Dom, _collectionSettings.XMatterPackName, _fileLocator);
                helper.FolderPathForCopyingXMatterFiles = storage.FolderPath;
                helper.InjectXMatter(data.WritingSystemAliases, sizeAndOrientation, _collectionSettings.BrandingProjectKey, storage.FolderPath);
                //TranslationGroupManager.PrepareDataBookTranslationGroups(storage.Dom,languages);
            }
        }
All Usage Examples Of Bloom.Book.XMatterHelper::InjectXMatter