File size: 3,056 Bytes
fab29d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using VersOne.Epub.Schema;

namespace VersOne.Epub
{
    /// <summary>
    /// The base class for content file references.
    /// </summary>
    public abstract class EpubContentFileRef
    {
        private readonly EpubContentFileRefMetadata metadata;
        private readonly IEpubContentLoader epubContentLoader;

        /// <summary>
        /// Initializes a new instance of the <see cref="EpubContentFileRef" /> class with a specified metadata and a specified content loader.
        /// </summary>
        /// <param name="metadata">Metadata of this content file reference.</param>
        /// <param name="epubContentLoader">A reference to the EPUB content loader which provides methods to load the content of this file.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="metadata" /> parameter is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="epubContentLoader" /> parameter is <c>null</c>.</exception>
        protected EpubContentFileRef(EpubContentFileRefMetadata metadata, IEpubContentLoader epubContentLoader)
        {
            this.metadata = metadata ?? throw new ArgumentNullException(nameof(metadata));
            this.epubContentLoader = epubContentLoader ?? throw new ArgumentNullException(nameof(epubContentLoader));
        }

        /// <summary>
        /// Gets the content file reference key as it is declared in the EPUB manifest (in the <see cref="EpubManifestItem.Href" /> property).
        /// This is either a relative path of the content file within the EPUB archive (for local content file references)
        /// or an absolute URI of the content file outside of the EPUB archive (for remote content file references).
        /// </summary>
        public string Key => metadata.Key;

        /// <summary>
        /// Gets the type of the content of the file (e.g. <see cref="EpubContentType.XHTML_1_1" /> or <see cref="EpubContentType.IMAGE_JPEG" />).
        /// </summary>
        public EpubContentType ContentType => metadata.ContentType;

        /// <summary>
        /// Gets the MIME type of the content of the file.
        /// </summary>
        public string ContentMimeType => metadata.ContentMimeType;

        /// <summary>
        /// Gets the location of the content file (local or remote).
        /// </summary>
        public abstract EpubContentLocation ContentLocation { get; }

        /// <summary>
        /// Gets the type of the content file reference (text or byte array).
        /// </summary>
        public abstract EpubContentFileType ContentFileType { get; }

        /// <summary>
        /// Gets the metadata of this content file reference.
        /// </summary>
        protected EpubContentFileRefMetadata Metadata => metadata;

        /// <summary>
        /// Gets the reference to the EPUB content loader which provides methods to load the content of this file.
        /// </summary>
        protected IEpubContentLoader EpubContentLoader => epubContentLoader;
    }
}