示例#1
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();
     }
 }
示例#2
0
 /// 
 /// <param name="resource"></param>
 private string getResourceItemPrefix(Resource resource)
 {
     String result;
     if (MediatypeService.isBitmapImage(resource.getMediaType()))
     {
         result = IMAGE_PREFIX;
     }
     else
     {
         result = ITEM_PREFIX;
     }
     return result;
 }
 /// <summary>
 /// Finds the cover resource in the packageDocument and adds it to the book if
 /// found. Keeps the cover resource in the resources map
 /// </summary>
 /// <param>resources</param>
 /// <param name="packageDocument"></param>
 /// <param name="book"></param>
 private static void readCover(XElement packageDocument, Book book)
 {
     List<String> coverHrefs = findCoverHrefs(packageDocument);
     foreach (String coverHref in coverHrefs)
     {
         Resource resource = book.getResources().getByHref(coverHref);
         if (resource == null)
         {
             //log.error("Cover resource " + coverHref + " not found");
             continue;
         }
         if (resource.getMediaType() == MediatypeService.XHTML)
         {
             book.setCoverPage(resource);
         }
         else if (MediatypeService.isBitmapImage(resource.getMediaType()))
         {
             book.setCoverImage(resource);
         }
     }
 }
        /// <summary>
        /// Reads the manifest containing the resource ids, hrefs and mediatypes.
        /// </summary>
        /// <param>book</param>
        /// <param>resourcesByHref</param>
        /// <param>a Map with resources, with their id's as key.</param>
        /// <param name="packageDocument"></param>
        /// <param name="packageHref"></param>
        /// <param name="epubReader"></param>
        /// <param name="resources"></param>
        /// <param name="idMapping"></param>
        private static Resources readManifest(XElement packageDocument, String packageHref, EpubReader epubReader, Resources resources, Dictionary<String, String> idMapping)
        {
            XElement manifestElement = DOMUtil.getFirstElementByTagNameNS(packageDocument, NAMESPACE_OPF, OPFTags.manifest);
            Resources result = new Resources();
            if (manifestElement == null)
            {
                return result;
            }
            var itemElements = packageDocument.Elements(NAMESPACE_OPF + OPFTags.item).Elements<XElement>();

            foreach (XElement itemElement in (from e in itemElements where e.Value.Trim() != string.Empty select e))
            {
                String id = DOMUtil.getAttribute(itemElement, OPFAttributes.id);
                String href = DOMUtil.getAttribute(itemElement, OPFAttributes.href);
                try
                {
                    href = System.Web.HttpUtility.UrlDecode(href, System.Text.Encoding.GetEncoding(Constants.ENCODING));
                }
                catch (Exception e)
                {
                    //log.error(e.getMessage());
                }
                String mediaTypeName = DOMUtil.getAttribute(itemElement, OPFAttributes.media_type);
                Resource resource = resources.remove(href);
                if (resource == null)
                {
                    //log.error("resource with href '" + href + "' not found");
                    continue;
                }
                resource.setId(id);
                MediaType mediaType = MediatypeService.getMediaTypeByName(mediaTypeName);
                if (mediaType != null)
                {
                    resource.setMediaType(mediaType);
                }
                result.add(resource);
                idMapping.Add(id, resource.getId());
            }
            return result;
        }
示例#5
0
        /// <summary>
        /// Creates a resource with the data from the given InputStream at the specified
        /// href. The MediaType will be determined based on the href extension.
        /// </summary>
        /// <see>nl.siegmann.epublib.service.MediatypeService.determineMediaType(String)
        /// Assumes that if the data is of a text type (html/css/etc) then the encoding
        /// will be UTF-8  It is recommended to us the</see>
        /// <see>nl.siegmann.epublib.domain.Resource.Resource(Reader, String) method for
        /// creating textual (html/css/etc) resources to prevent encoding problems. Use
        /// this method only for binary Resources like images, fonts, etc.</see>
        /// <param name="in">The Resource's contents</param>
        /// <param name="href">The location of the resource within the epub. Example:
        /// "cover.jpg".</param>
        public Resource(System.IO.Stream stream, string href)
            : this(null, IOUtil.toByteArray(stream), href, MediatypeService.determineMediaType(href))
        {

        }
示例#6
0
        /// <summary>
        /// Creates a resource with the given data at the specified href. The MediaType
        /// will be determined based on the href extension.  Assumes that if the data is of
        /// a text type (html/css/etc) then the encoding will be UTF-8
        /// </summary>
        /// <see>nl.siegmann.epublib.service.MediatypeService.
        /// determineMediaType(String)</see>
        /// <param name="data">The Resource's contents</param>
        /// <param name="href">The location of the resource within the epub. Example:
        /// "chapter1.html".</param>
        public Resource(byte[] data, string href)
            : this(null, data, href, MediatypeService.determineMediaType(href), Constants.ENCODING)
        {

        }
示例#7
0
        /// <summary>
        /// Creates an empty Resource with the given href.  Assumes that if the data is of
        /// a text type (html/css/etc) then the encoding will be UTF-8
        /// </summary>
        /// <param name="href">The location of the resource within the epub. Example:
        /// "chapter1.html".</param>
        public Resource(string href)
            : this(null, new byte[0], href, MediatypeService.determineMediaType(href))
        {

        }
示例#8
0
 /// <summary>
 /// Creates a Lazy resource, by not actually loading the data for this entry.  The
 /// data will be loaded on the first call to getData()
 /// </summary>
 /// <param name="fileName">the fileName for the epub we're created from.</param>
 /// <param name="size">the size of this resource.</param>
 /// <param name="href">The resource's href within the epub.</param>
 public Resource(string fileName, long size, string href)
     : this(null, null, href, MediatypeService.determineMediaType(href))
 {
     this.fileName = fileName;
     this.cachedSize = size;
 }