using System; using VersOne.Epub.Internal; namespace VersOne.Epub { /// /// Navigation link representing a pointer to a specific place in the book's content. /// public class EpubNavigationItemLink { /// /// Initializes a new instance of the class using a specified content file URL with anchor and a specified base directory path. /// /// Relative file path of the content file with an optional anchor (as it is specified in the EPUB manifest). /// The path of the directory within the EPUB archive which acts as a base directory for a relative content file path. /// The parameter is null. /// The parameter is null. /// The parameter points to a remote URL. public EpubNavigationItemLink(string contentFileUrlWithAnchor, string baseDirectoryPath) { if (contentFileUrlWithAnchor == null) { throw new ArgumentNullException(nameof(contentFileUrlWithAnchor)); } if (baseDirectoryPath == null) { throw new ArgumentNullException(nameof(baseDirectoryPath)); } if (!ContentPathUtils.IsLocalPath(contentFileUrlWithAnchor)) { throw new ArgumentException($"\"{contentFileUrlWithAnchor}\" points to a remote resource."); } UrlParser urlParser = new(contentFileUrlWithAnchor); ContentFileUrl = urlParser.Path; ContentFilePath = ContentPathUtils.Combine(baseDirectoryPath, ContentFileUrl); Anchor = urlParser.Anchor; } /// /// Initializes a new instance of the class with specified content file URL without anchor, content file path, and anchor. /// /// The file path portion of the content file URL without anchor. /// The file path portion of the content file URL converted to the absolute file path within the EPUB archive. /// The anchor portion of the content file URL. /// The parameter is null. /// The parameter is null. /// The parameter points to a remote URL. public EpubNavigationItemLink(string contentFileUrl, string contentFilePath, string? anchor) { ContentFileUrl = contentFileUrl ?? throw new ArgumentNullException(nameof(contentFileUrl)); ContentFilePath = contentFilePath ?? throw new ArgumentNullException(nameof(contentFilePath)); if (!ContentPathUtils.IsLocalPath(contentFileUrl)) { throw new ArgumentException($"\"{contentFileUrl}\" points to a remote resource."); } Anchor = anchor; } /// /// Gets the file path portion of the content file URL. /// For example, if the content file URL is '../content/chapter1.html#section1', then the value of this property will be '../content/chapter1.html'. /// public string ContentFileUrl { get; } /// /// Gets the file path portion of the content file URL converted to the absolute file path within the EPUB archive. /// For example, if the content file URL is '../content/chapter1.html#section1' and the base directory path is 'OPS/toc', /// then the value of this property will be 'OPS/content/chapter1.html'. /// public string ContentFilePath { get; } /// /// Gets the anchor portion of the content file URL. /// For example, if the content file URL is '../content/chapter1.html#section1', then the value of this property will be 'section1'. /// public string? Anchor { get; } } }