Beispiel #1
0
        public void AddXHTMLTextItem(IBaseXHTMLFile baseXhtmlFile)
        {
            var bookItem = new ManifestItemV3
            {
                HRef      = baseXhtmlFile.HRef,
                ID        = baseXhtmlFile.Id,
                MediaType = EPubCoreMediaType.ApplicationXhtmlXml
            };

            _manifest.Add(bookItem);

            if (baseXhtmlFile.GuideRole != GuideTypeEnum.Ignore) // we do not add objects that to be ignored
            {
                var bookSpine = new SpineItemV3 {
                    Name = baseXhtmlFile.Id
                };
                if (V3StandardChecker.IsRenditionFlowAllowedByStandard(_standard))
                {
                    bookSpine.Flow = SpineItemV3.FlowOptions.Auto;
                    //TODO: make this optional, based on settings to define look and find best properties for defaults
                }
                _spine.Add(bookSpine);
            }
            _guide.AddDocumentToNavigation(baseXhtmlFile);
        }
Beispiel #2
0
        protected void AddMetaDataToContentDocument(XElement document)
        {
            var metadata = new XElement(EPubNamespaces.OpfNameSpace + "metadata");

            metadata.Add(new XAttribute(XNamespace.Xmlns + "dc", PURLNamespaces.DCElements));
            metadata.Add(new XAttribute(XNamespace.Xmlns + "xsi", WWWNamespaces.XSI));
            metadata.Add(new XAttribute(XNamespace.Xmlns + "dcterms", PURLNamespaces.DCTerms));
            metadata.Add(new XAttribute(XNamespace.Xmlns + "opf", EPubNamespaces.FakeOpf.NamespaceName));

            Onix5SchemaConverter source = null;

            foreach (var identifierItem in BookInformation.Identifiers)
            {
                var schemaConverter = new Onix5SchemaConverter(identifierItem);
                var identifier      = new XElement(PURLNamespaces.DCElements + "identifier", schemaConverter.GetIdentifier());
                identifier.Add(new XAttribute("id", identifierItem.IdentifierName));
                metadata.Add(identifier);

                var metaRefine = new XElement(EPubNamespaces.FakeOpf + "meta", schemaConverter.GetIdentifierType());
                metaRefine.Add(new XAttribute("refines", "#" + identifierItem.IdentifierName));
                metaRefine.Add(new XAttribute("property", "identifier-type"));
                metaRefine.Add(new XAttribute("scheme", Onix5SchemaConverter.GetScheme()));
                metadata.Add(metaRefine);

                if (source == null && schemaConverter.IsISBN())
                {
                    source = schemaConverter;
                }
            }


            int titleIdCounter = 0;

            foreach (var titleItem in BookInformation.BookTitles)
            {
                string idString     = string.Format("t{0}", ++titleIdCounter);
                var    titleElement = new XElement(PURLNamespaces.DCElements + "title", titleItem.TitleName);
                titleElement.Add(new XAttribute("id", idString));
                metadata.Add(titleElement);

                var metaRefineType = new XElement(EPubNamespaces.FakeOpf + "meta", GetTitleType(titleItem));
                metaRefineType.Add(new XAttribute("refines", "#" + idString));
                metaRefineType.Add(new XAttribute("property", "title-type"));
                metadata.Add(metaRefineType);

                var metaRefineDisplay = new XElement(EPubNamespaces.FakeOpf + "meta", titleIdCounter);
                metaRefineDisplay.Add(new XAttribute("refines", "#" + idString));
                metaRefineDisplay.Add(new XAttribute("property", "display-seq"));
                metadata.Add(metaRefineDisplay);
            }

            foreach (var languageItem in BookInformation.Languages)
            {
                var language = new XElement(PURLNamespaces.DCElements + "language", languageItem);
                metadata.Add(language);
            }



            int creatorCounter = 0;

            foreach (var creatorItem in BookInformation.Creators)
            {
                if (!string.IsNullOrEmpty(creatorItem.PersonName))
                {
                    string creatorId = string.Format("creator{0}", ++creatorCounter);
                    var    creator   = new XElement(PURLNamespaces.DCElements + "creator", creatorItem.PersonName);
                    creator.Add(new XAttribute("id", creatorId));
                    metadata.Add(creator);

                    var metaRefineRole = new XElement(EPubNamespaces.FakeOpf + "meta", EPubRoles.ConvertEnumToAttribute(creatorItem.Role));
                    metaRefineRole.Add(new XAttribute("refines", "#" + creatorId));
                    metaRefineRole.Add(new XAttribute("property", "role"));
                    metaRefineRole.Add(new XAttribute("scheme", "marc:relators"));
                    metadata.Add(metaRefineRole);

                    if (!string.IsNullOrEmpty(creatorItem.FileAs))
                    {
                        var metaRefineFileAs = new XElement(EPubNamespaces.FakeOpf + "meta", creatorItem.FileAs);
                        metaRefineFileAs.Add(new XAttribute("refines", "#" + creatorId));
                        metaRefineFileAs.Add(new XAttribute("property", "file-as"));
                        metadata.Add(metaRefineFileAs);
                    }

                    var metaRefineDisplay = new XElement(EPubNamespaces.FakeOpf + "meta", creatorCounter);
                    metaRefineDisplay.Add(new XAttribute("refines", "#" + creatorId));
                    metaRefineDisplay.Add(new XAttribute("property", "display-seq"));
                    metadata.Add(metaRefineDisplay);
                }
            }

            int contributorCounter = 0;

            foreach (var contributorItem in BookInformation.Contributors)
            {
                if (!string.IsNullOrEmpty(contributorItem.PersonName))
                {
                    string contributorId = string.Format("contributor{0}", ++contributorCounter);
                    var    contributor   = new XElement(PURLNamespaces.DCElements + "contributor", contributorItem.PersonName);
                    contributor.Add(new XAttribute("id", contributorId));
                    metadata.Add(contributor);


                    var metaRefineRole = new XElement(EPubNamespaces.FakeOpf + "meta", EPubRoles.ConvertEnumToAttribute(contributorItem.Role));
                    metaRefineRole.Add(new XAttribute("refines", "#" + contributorId));
                    metaRefineRole.Add(new XAttribute("property", "role"));
                    metaRefineRole.Add(new XAttribute("scheme", "marc:relators"));
                    metadata.Add(metaRefineRole);


                    if (!string.IsNullOrEmpty(contributorItem.FileAs))
                    {
                        var metaRefineFileAs = new XElement(EPubNamespaces.FakeOpf + "meta", contributorItem.FileAs);
                        metaRefineFileAs.Add(new XAttribute("refines", "#" + contributorId));
                        metaRefineFileAs.Add(new XAttribute("property", "file-as"));
                        metadata.Add(metaRefineFileAs);
                    }

                    var metaRefineDisplay = new XElement(EPubNamespaces.FakeOpf + "meta", contributorCounter);
                    metaRefineDisplay.Add(new XAttribute("refines", "#" + contributorId));
                    metaRefineDisplay.Add(new XAttribute("property", "display-seq"));
                    metadata.Add(metaRefineDisplay);
                }
            }
            if (CreatorSoftwareString != null)
            {
                string contributorId = string.Format("contributor{0}", ++contributorCounter);
                var    maker         = new XElement(PURLNamespaces.DCElements + "contributor", CreatorSoftwareString);
                maker.Add(new XAttribute("id", contributorId));
                metadata.Add(maker);

                var metaRefineRole = new XElement(EPubNamespaces.FakeOpf + "meta", EPubRoles.ConvertEnumToAttribute(RolesEnum.BookProducer));
                metaRefineRole.Add(new XAttribute("refines", "#" + contributorId));
                metaRefineRole.Add(new XAttribute("property", "role"));
                metaRefineRole.Add(new XAttribute("scheme", "marc:relators"));
                metadata.Add(metaRefineRole);

                var metaRefineDisplay = new XElement(EPubNamespaces.FakeOpf + "meta", contributorCounter);
                metaRefineDisplay.Add(new XAttribute("refines", "#" + contributorId));
                metaRefineDisplay.Add(new XAttribute("property", "display-seq"));
                metadata.Add(metaRefineDisplay);
            }


            // date
            if (BookInformation.DatePublished.HasValue)
            {
                var xDate = new XElement(PURLNamespaces.DCElements + "date", BookInformation.DatePublished.Value.Year);
                metadata.Add(xDate);
            }


            // source
            if (source != null)
            {
                var sourceElm = new XElement(PURLNamespaces.DCElements + "source", source.GetIdentifier());
                sourceElm.Add(new XAttribute("id", "src_id"));
                metadata.Add(sourceElm);

                var metaRefine = new XElement(EPubNamespaces.FakeOpf + "meta", source.GetIdentifierType());
                metaRefine.Add(new XAttribute("refines", "#" + "src_id"));
                metaRefine.Add(new XAttribute("property", "identifier-type"));
                metaRefine.Add(new XAttribute("scheme", Onix5SchemaConverter.GetScheme()));
                metadata.Add(metaRefine);
            }

            // description
            if (!string.IsNullOrEmpty(BookInformation.Description.DescInfo))
            {
                var description = new XElement(PURLNamespaces.DCElements + "description", BookInformation.Description.DescInfo);
                if (!string.IsNullOrEmpty(BookInformation.Description.Language))
                {
                    description.Add(new XAttribute(XNamespace.Xml + "lang", BookInformation.Description.Language));
                }
                description.Add(new XAttribute("id", "id_desc"));
                metadata.Add(description);

                var metaRefineDisplay = new XElement(EPubNamespaces.FakeOpf + "meta", 1);
                metaRefineDisplay.Add(new XAttribute("refines", "#id_desc"));
                metaRefineDisplay.Add(new XAttribute("property", "display-seq"));
                metadata.Add(metaRefineDisplay);
            }


            // publisher
            if (!string.IsNullOrEmpty(BookInformation.Publisher.PublisherName))
            {
                var publisher = new XElement(PURLNamespaces.DCElements + "publisher", BookInformation.Publisher.PublisherName);
                if (!string.IsNullOrEmpty(BookInformation.Publisher.Language))
                {
                    publisher.Add(new XAttribute(XNamespace.Xml + "lang", BookInformation.Publisher.Language));
                }
                metadata.Add(publisher);
            }


            // subject
            int subjectCount = 0;

            foreach (var subjectItem in BookInformation.Subjects)
            {
                if (!string.IsNullOrEmpty(subjectItem.SubjectInfo))
                {
                    string subjectID = string.Format("subj_{0}", ++subjectCount);
                    var    subject   = new XElement(PURLNamespaces.DCElements + "subject", subjectItem.SubjectInfo);
                    subject.Add(new XAttribute("id", subjectID));
                    if (!string.IsNullOrEmpty(subjectItem.Language))
                    {
                        subject.Add(new XAttribute(XNamespace.Xml + "lang", subjectItem.Language));
                    }
                    metadata.Add(subject);

                    var metaRefineDisplay = new XElement(EPubNamespaces.FakeOpf + "meta", subjectCount);
                    metaRefineDisplay.Add(new XAttribute("refines", "#" + subjectID));
                    metaRefineDisplay.Add(new XAttribute("property", "display-seq"));
                    metadata.Add(metaRefineDisplay);
                }
            }

            // meta modified
            string modifiedDate = DateTime.UtcNow.ToString("s") + "Z";

            if (BookInformation.DataFileModification.HasValue)
            {
                modifiedDate = BookInformation.DataFileModification.Value.ToUniversalTime().ToString("s") + "Z";
            }
            var metaModified = new XElement(EPubNamespaces.FakeOpf + "meta", modifiedDate);

            metaModified.Add(new XAttribute("property", "dcterms:modified"));
            metadata.Add(metaModified);

            // series
            if (V3StandardChecker.IsCollectionsAllowedByStandard(_standard) && BookInformation.SeriesCollection != null)
            {
                EPubSeriesCollections bookData = BookInformation.SeriesCollection as EPubSeriesCollections;
                if (bookData != null)
                {
                    bookData.AddCollectionsToElement(metadata);
                }
            }
            document.Add(metadata);
        }