/// <summary> /// Gets the first resource (random order) with the give mediatype. Useful for /// looking up the table of contents as it's supposed to be the only resource with /// NCX mediatype. /// </summary> /// <param name="resources"></param> /// <param name="mediaType"></param> public static Resource findFirstResourceByMediaType(Dictionary<string, Resource> resources, MediaType mediaType) { foreach (Resource resource in resources.Values) { if (resource.getMediaType() == mediaType) { return resource; } } return null; }
/// <summary> /// Creates a Resource with the given data and MediaType. The href will be /// automatically generated. Assumes that if the data is of a text type /// (html/css/etc) then the encoding will be UTF-8 /// </summary> /// <param name="data">The Resource's contents</param> /// <param name="mediaType">The MediaType of the Resource</param> public Resource(byte[] data, MediaType mediaType) : this(null, data, null, mediaType) { }
/// /// <param name="mediaType"></param> public void setMediaType(MediaType mediaType) { this.mediaType = mediaType; }
/// <summary> /// Creates a resource with the given id, data, mediatype at the specified href. If /// the data is of a text type (html/css/etc) then it will use the given /// inputEncoding. /// </summary> /// <param name="id">The id of the Resource. Internal use only. Will be auto- /// generated if it has a null-value.</param> /// <param name="data">The Resource's contents</param> /// <param name="href">The location of the resource within the epub. Example: /// "chapter1.html".</param> /// <param name="mediaType">The resources MediaType</param> /// <param name="inputEncoding">If the data is of a text type (html/css/etc) then /// it will use the given inputEncoding.</param> public Resource(string id, byte[] data, string href, MediaType mediaType, string inputEncoding) { this.id = id; this.href = href; this.mediaType = mediaType; this.inputEncoding = inputEncoding; this.data = data; }
/// <summary> /// Creates a resource with the given id, data, mediatype at the specified href. /// Assumes that if the data is of a text type (html/css/etc) then the encoding /// will be UTF-8 /// </summary> /// <param name="id">The id of the Resource. Internal use only. Will be auto- /// generated if it has a null-value.</param> /// <param name="data">The Resource's contents</param> /// <param name="href">The location of the resource within the epub. Example: /// "chapter1.html".</param> /// <param name="mediaType">The resources MediaType</param> public Resource(string id, byte[] data, string href, MediaType mediaType) : this(id, data, href, mediaType, Constants.ENCODING) { }
/// /// <param name="mediaType"></param> /// <param name="counter"></param> private string createHref(MediaType mediaType, int counter) { if (MediatypeService.isBitmapImage(mediaType)) { return "image_" + counter + mediaType.getDefaultExtension(); } else { return "item_" + counter + mediaType.getDefaultExtension(); } }
/// <summary> /// All Resources that match any of the given list of MediaTypes /// </summary> /// <param name="mediaTypes"></param> public List<Resource> getResourcesByMediaTypes(MediaType[] mediaTypes) { List<Resource> result = new List<Resource>(); if (mediaTypes == null) { return result; } List<MediaType> lmediaType = new List<MediaType>(mediaTypes); foreach (Resource resource in getAll()) { if (lmediaType.Contains(resource.getMediaType())) { result.Add(resource); } } return result; }
/// <summary> /// All resources that have the given MediaType. /// </summary> /// <param name="mediaType"></param> public List<Resource> getResourcesByMediaType(MediaType mediaType) { List<Resource> result = new List<Resource>(); if (mediaType == null) { return result; } foreach (Resource resource in getAll()) { if (resource.getMediaType() == mediaType) { result.Add(resource); } } return result; }
/// <summary> /// Gets the first resource (random order) with the give mediatype. Useful for /// looking up the table of contents as it's supposed to be the only resource with /// NCX mediatype. /// </summary> /// <param name="mediaType"></param> public Resource findFirstResourceByMediaType(MediaType mediaType) { return findFirstResourceByMediaType(resources, mediaType); }
public static bool isBitmapImage(MediaType mediaType) { return mediaType == JPG || mediaType == PNG || mediaType == GIF; }