예제 #1
0
        internal static OpfPackage CreatePackage(XElement element, ZipStorer gz, string opsFolder, out string ncx)
        {
            var package = new OpfPackage
            {
                Version    = element.Attribute("version").Value,
                Identifier = element.Attribute("unique-identifier").Value,
                MetaData   = MetaData.CreateMetaData(element.Element(OpfNameSpace + "metadata")),
                Spine      = Spine.CreateSpine(element.Element(OpfNameSpace + "spine"))
            };
            var manifestElement = element.Element(OpfNameSpace + "manifest");
            var ncxElement      = package.Spine.Toc;

            // we need to pull it directly from XML as this file does not become part of the items
            ncx = manifestElement
                  .Elements(OpfNameSpace + "item")
                  .First(item => item.Attribute("id").Value == ncxElement)
                  .Attribute("href")
                  .Value;
            package.Manifest = Manifest.CreateManifest(gz, manifestElement, ncxElement, opsFolder);
            package.Guide    = Guide.CreateGuide(element);
            return(package);
        }
예제 #2
0
        internal static XElement CreateXElement(Spine spine)
        {
            var xe = new XElement("spine", new XAttribute("toc", spine.Toc));

            foreach (var iref in spine.ItemRefs)
            {
                var ielement = new XElement("itemref", new XAttribute(Helper.GetAttributeName <ItemRef, EPubAttribute>(m => m.IdRef), iref.IdRef ?? String.Empty));
                if (iref.Linear.HasValue)
                {
                    ielement.Add(new XAttribute(Helper.GetAttributeName <ItemRef, EPubAttribute>(m => m.Linear), iref.Linear.Value ? "yes" : "no"));
                }
                if (!String.IsNullOrEmpty(iref.Identifier))
                {
                    ielement.Add(new XAttribute(Helper.GetAttributeName <ItemRef, EPubAttribute>(m => m.Id), iref.Identifier ?? String.Empty));
                }
                if (!String.IsNullOrEmpty(iref.Properties))
                {
                    ielement.Add(new XAttribute(Helper.GetAttributeName <ItemRef, EPubAttribute>(m => m.Properties), iref.Properties ?? String.Empty));
                }
                xe.Add(ielement);
            }
            return(xe);
        }
예제 #3
0
        internal static Spine CreateSpine(XElement e)
        {
            var spine = new Spine {
                Identifier = (e.Attribute(XmlHelper.GetAttributeName <Spine, EPubAttribute>(m => m.Identifier))).NullSafeString(),
                Toc        = (e.Attribute(XmlHelper.GetAttributeName <Spine, EPubAttribute>(m => m.Toc))).NullSafeString()
            };
            var dir = (e.Attribute(XmlHelper.GetAttributeName <Spine, EPubAttribute>(m => m.PageProgressionDirection))).NullSafeString();

            if (!String.IsNullOrEmpty(dir))
            {
                spine.PageProgressionDirection = (ProgressionDirection)Enum.Parse(typeof(ProgressionDirection), dir, true);
            }
            var ns = e.Document.Root.GetDefaultNamespace();

            spine.ItemRefs = e.Descendants(ns + "itemref")
                             .Select(itemref => new ItemRef {
                Identifier = itemref.Attribute(XmlHelper.GetAttributeName <ItemRef, EPubAttribute>(m => m.Identifier)).NullSafeString(),
                IdRef      = itemref.Attribute(XmlHelper.GetAttributeName <ItemRef, EPubAttribute>(m => m.IdRef)).NullSafeString(),
                Linear     = itemref.Attribute(XmlHelper.GetAttributeName <ItemRef, EPubAttribute>(m => m.Linear)).NullSafeBool(),
                Properties = itemref.Attribute(XmlHelper.GetAttributeName <ItemRef, EPubAttribute>(m => m.Properties)).NullSafeString()
            }).ToList();
            return(spine);
        }