Class Resources

java.lang.Object
nl.siegmann.epublib.domain.Resources
All Implemented Interfaces:
Serializable

public class Resources extends Object implements Serializable
All the resources that make up the book. XHTML files, images and epub xml documents must be here.
See Also:
  • Field Details

  • Constructor Details

    • Resources

      public Resources()
  • Method Details

    • add

      public Resource add(Resource resource)
      Adds a resource to the resources. Fixes the resources id and href if necessary.
      Parameters:
      resource -
      Returns:
      the newly added resource
    • fixResourceId

      public void fixResourceId(Resource resource)
      Checks the id of the given resource and changes to a unique identifier if it isn't one already.
      Parameters:
      resource -
    • makeValidId

      private String makeValidId(String resourceId, Resource resource)
      Check if the id is a valid identifier. if not: prepend with valid identifier
      Parameters:
      resource -
      Returns:
      a valid id
    • getResourceItemPrefix

      private String getResourceItemPrefix(Resource resource)
    • createUniqueResourceId

      private String createUniqueResourceId(Resource resource)
      Creates a new resource id that is guaranteed to be unique for this set of Resources
      Parameters:
      resource -
      Returns:
      a new resource id that is guaranteed to be unique for this set of Resources
    • containsId

      public boolean containsId(String id)
      Whether the map of resources already contains a resource with the given id.
      Parameters:
      id -
      Returns:
      Whether the map of resources already contains a resource with the given id.
    • getById

      public Resource getById(String id)
      Gets the resource with the given id.
      Parameters:
      id -
      Returns:
      null if not found
    • remove

      public Resource remove(String href)
      Remove the resource with the given href.
      Parameters:
      href -
      Returns:
      the removed resource, null if not found
    • fixResourceHref

      private void fixResourceHref(Resource resource)
    • createHref

      private String createHref(MediaType mediaType, int counter)
    • isEmpty

      public boolean isEmpty()
    • size

      public int size()
      The number of resources
      Returns:
      The number of resources
    • getResourceMap

      public Map<String,Resource> getResourceMap()
      The resources that make up this book. Resources can be xhtml pages, images, xml documents, etc.
      Returns:
      The resources that make up this book.
    • getAll

      public Collection<Resource> getAll()
    • containsByHref

      public boolean containsByHref(String href)
      Whether there exists a resource with the given href
      Parameters:
      href -
      Returns:
      Whether there exists a resource with the given href
    • set

      public void set(Collection<Resource> resources)
      Sets the collection of Resources to the given collection of resources
      Parameters:
      resources -
    • addAll

      public void addAll(Collection<Resource> resources)
      Adds all resources from the given Collection of resources to the existing collection.
      Parameters:
      resources -
    • set

      public void set(Map<String,Resource> resources)
      Sets the collection of Resources to the given collection of resources
      Parameters:
      resources - A map with as keys the resources href and as values the Resources
    • getByIdOrHref

      public Resource getByIdOrHref(String idOrHref)
      First tries to find a resource with as id the given idOrHref, if that fails it tries to find one with the idOrHref as href.
      Parameters:
      idOrHref -
      Returns:
      the found Resource
    • getByHref

      public Resource getByHref(String href)
      Gets the resource with the given href. If the given href contains a fragmentId then that fragment id will be ignored.
      Parameters:
      href -
      Returns:
      null if not found.
    • findFirstResourceByMediaType

      public Resource findFirstResourceByMediaType(MediaType mediaType)
      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.
      Parameters:
      mediaType -
      Returns:
      the first resource (random order) with the give mediatype.
    • findFirstResourceByMediaType

      public static Resource findFirstResourceByMediaType(Collection<Resource> resources, MediaType mediaType)
      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.
      Parameters:
      mediaType -
      Returns:
      the first resource (random order) with the give mediatype.
    • getResourcesByMediaType

      public List<Resource> getResourcesByMediaType(MediaType mediaType)
      All resources that have the given MediaType.
      Parameters:
      mediaType -
      Returns:
      All resources that have the given MediaType.
    • getResourcesByMediaTypes

      public List<Resource> getResourcesByMediaTypes(MediaType[] mediaTypes)
      All Resources that match any of the given list of MediaTypes
      Parameters:
      mediaTypes -
      Returns:
      All Resources that match any of the given list of MediaTypes
    • getAllHrefs

      public Collection<String> getAllHrefs()
      All resource hrefs
      Returns:
      all resource hrefs