Beispiel #1
0
        /// <summary>
        /// Constructor with file parameter
        /// </summary>
        /// <param name="filePath"></param>
        public ePUBPackage(string packRelativFileName)
        {
            Manifest       = new ePUBManifest();
            Metadata       = new ePUBMetadata();
            TableOfContent = new ePUBTableNCX();
            Spine          = new ePUBSpine();
            Guide          = new ePUBGuide();

            RelativPackageFolder = Path.GetDirectoryName(packRelativFileName);
            PackageFileName      = Path.GetFileName(packRelativFileName);
        }
Beispiel #2
0
        private void ParseTOC(ePUB docPUB, Stream content)
        {
            try
            {
                //reading
                XmlDocument doc = GetDocumentWithNoValidation(content);

                XmlNode root = doc.DocumentElement;                 //<ncx>

                // resolve <ncx>
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
                ResolveNamespaces(nsmgr, root);

                ePUBTableNCX toc = docPUB.Container.Package.TableOfContent;
                toc.Title = root.SelectSingleNode("//ROOT:docTitle/ROOT:text", nsmgr).InnerText;

                XmlNodeList listNode;
                listNode = root.SelectNodes("child::ROOT:navMap/ROOT:navPoint", nsmgr);

                List <ePUBNavPoint> navMapList = new List <ePUBNavPoint>();
                foreach (XmlNode navPoint in listNode)
                {
                    ePUBNavPoint item = new ePUBNavPoint()
                    {
                        Id        = TryGetAttributeString(navPoint, "id"),
                        PlayOrder = TryGetAttributeInt(navPoint, "playOrder"),
                        Label     = navPoint.SelectSingleNode("child::ROOT:navLabel/ROOT:text", nsmgr).InnerText,
                        Content   = TryGetAttributeString(navPoint.SelectSingleNode("child::ROOT:content", nsmgr), "src")
                    };
                    string[] parts = item.Content.Split('#');
                    item.PageSource = parts[0];
                    if (parts.Count() == 2)
                    {
                        item.TargetId = parts[2];
                    }
                    item.XamlId = docPUB.Container.Package.Manifest.Items.Single(p => p.hRef == item.PageSource).XamlId;

                    //is there any bookmark?
                    if (item.Content.IndexOf('#') != -1)
                    {
                        item.Content = item.Content.Split('#')[1];
                    }

                    navMapList.Add(item);

                    item.Items = ParseNavRecursif(docPUB, navPoint, nsmgr);
                }
                toc.Items = navMapList;
            }
            catch (Exception err)
            {
                LogHelper.Manage("ePUBManager:ParseTOC", err);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="filePath"></param>
        public ePUBPackage()
        {
            Manifest       = new ePUBManifest();
            Metadata       = new ePUBMetadata();
            TableOfContent = new ePUBTableNCX();
            Spine          = new ePUBSpine();
            Guide          = new ePUBGuide();

            RelativPackageFolder = ePUBHelper.Files.PackageFolder;
            PackageFileName      = ePUBHelper.Files.PackageFile;
        }