Exemplo n.º 1
0
 /// <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;
 }
Exemplo n.º 2
0
 /// <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)
 {
 }
Exemplo n.º 3
0
 /// 
 /// <param name="mediaType"></param>
 public void setMediaType(MediaType mediaType)
 {
     this.mediaType = mediaType;
 }
Exemplo n.º 4
0
 /// <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;
 }
Exemplo n.º 5
0
 /// <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)
 {
 }
Exemplo n.º 6
0
 /// 
 /// <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();
     }
 }
Exemplo n.º 7
0
        /// <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;
        }
Exemplo n.º 8
0
 /// <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;
 }
Exemplo n.º 9
0
 /// <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);
 }
Exemplo n.º 10
0
 public static bool isBitmapImage(MediaType mediaType)
 {
     return mediaType == JPG || mediaType == PNG || mediaType == GIF;
 }