Class IIIFUtils


  • @Component
    public class IIIFUtils
    extends Object
    • Constructor Detail

      • IIIFUtils

        public IIIFUtils()
    • Method Detail

      • isIIIFEnabled

        public boolean isIIIFEnabled​(Item item)
      • getIIIFBitstreams

        public List<Bitstream> getIIIFBitstreams​(Context context,
                                                 Item item)
        Return all the bitstreams in the item to be used as IIIF resources
        Parameters:
        context - the DSpace Context
        item - the DSpace item
        Returns:
        a not null list of bitstreams to use as IIIF resources in the manifest
      • getIIIFBitstreams

        public List<Bitstream> getIIIFBitstreams​(Context context,
                                                 Bundle bundle)
        Return all the bitstreams in the bundle to be used as IIIF resources
        Parameters:
        context - the DSpace Context
        bundle - the DSpace Bundle
        Returns:
        a not null list of bitstreams to use as IIIF resources in the manifest
      • isIIIFBitstream

        public boolean isIIIFBitstream​(Context context,
                                       Bitstream b)
        Utility method to check is a bitstream can be used as IIIF resources
        Parameters:
        b - the DSpace bitstream to check
        Returns:
        true if the bitstream can be used as IIIF resource
      • getBitstreamMimeType

        public String getBitstreamMimeType​(Bitstream bitstream,
                                           Context context)
        Returns the bitstream mime type
        Parameters:
        bitstream - DSpace bitstream
        context - DSpace context
        Returns:
        mime type
      • isSearchable

        public boolean isSearchable​(Item item)
        Checks to see if the item is searchable. Based on the METADATA_IIIF_SEARCH_ENABLED metadata.
        Parameters:
        item - DSpace item
        Returns:
        true if the iiif search is enabled
      • getBitstreamForCanvas

        public Bitstream getBitstreamForCanvas​(Context context,
                                               Item item,
                                               int canvasPosition)
        Retrives a bitstream based on its position in the IIIF bundle.
        Parameters:
        context - DSpace Context
        item - DSpace Item
        canvasPosition - bitstream position
        Returns:
        bitstream or null if the specified canvasPosition doesn't exist in the manifest
      • getCanvasId

        public int getCanvasId​(String canvasId)
        Extracts canvas position from the URL input path.
        Parameters:
        canvasId - e.g. "c12"
        Returns:
        the position, e.g. 12
      • getCanvasId

        public String getCanvasId​(int position)
        Returns the canvas path with position. The path returned is partial, not the fully qualified URI.
        Parameters:
        position - position of the bitstream in the DSpace bundle.
        Returns:
        partial canvas path.
      • asJson

        public String asJson​(de.digitalcollections.iiif.model.sharedcanvas.Resource<?> resource)
        Serializes the json response.
        Parameters:
        resource - to be serialized
        Returns:
      • getSeeAlsoBitstreams

        public List<Bitstream> getSeeAlsoBitstreams​(Item item)
        Return all the bitstreams in the item to be used as annotations
        Parameters:
        item - the DSpace item
        Returns:
        a not null list of bitstreams to use as IIIF resources in the manifest
      • getIIIFLabel

        public String getIIIFLabel​(DSpaceObject dso,
                                   String defaultLabel)
        Return the custom iiif label for the resource or the provided default if none
        Parameters:
        dso - the dspace object to use as iiif resource
        defaultLabel - the default label to return if none is specified in the metadata
        Returns:
        the iiif label for the dspace object
      • getIIIFDescription

        public String getIIIFDescription​(DSpaceObject dso,
                                         String defaultDescription)
        Return the custom iiif description for the resource or the provided default if none
        Parameters:
        dso - the dspace object to use as iiif resource
        defaultDescription - the default description to return if none is specified in the metadata
        Returns:
        the iiif label for the dspace object
      • getIIIFToCs

        public List<String> getIIIFToCs​(Bitstream bitstream,
                                        String prefix)
        Return the table of contents (toc) positions in the iiif structure where the resource appears. Please note that the same resource can belong to multiple ranges (i.e. a page that contains the last paragraph of a section and start the new section)
        Parameters:
        bitstream - the dspace bitstream
        prefix - a string to add to all the returned toc inherited from the parent dspace object
        Returns:
        the iiif tocs for the dspace object
      • getImageDimensions

        @Cacheable(key="#bitstream.getID().toString()",
                   cacheNames="canvasdimensions")
        public int[] getImageDimensions​(Bitstream bitstream)
        Retrieves image dimensions from the image server (IIIF Image API v.2.1.1).
        Parameters:
        bitstream - the bitstream DSO
        Returns:
        image dimensions
      • hasWidthMetadata

        public boolean hasWidthMetadata​(Bitstream bitstream)
        Test to see if the bitstream contains iiif image width metadata.
        Parameters:
        bitstream - the bitstream DSo
        Returns:
        true if width metadata was found
      • getBundleIIIFToC

        public String getBundleIIIFToC​(Bundle bundle)
        Return the iiif toc for the specified bundle
        Parameters:
        bundle - the dspace bundle
        Returns:
        the iiif toc for the specified bundle
      • getIIIFViewingHint

        public String getIIIFViewingHint​(Item item,
                                         String defaultHint)
        Return the iiif viewing hint for the item
        Parameters:
        item - the dspace item
        defaultHint - the default hint to apply if nothing else is defined at the item leve
        Returns:
        the iiif viewing hint for the item
      • getCanvasWidth

        public int getCanvasWidth​(Bitstream bitstream,
                                  Bundle bundle,
                                  Item item,
                                  int defaultWidth)
        Return the width for the canvas associated with the bitstream. If the bitstream doesn't provide directly the information it is retrieved from the bundle, item or default.
        Parameters:
        bitstream - the dspace bitstream used in the canvas
        bundle - the bundle the bitstream belong to
        item - the item the bitstream belong to
        defaultWidth - the default width to apply if no other preferences are found
        Returns:
        the width in pixel for the canvas associated with the bitstream
      • getCanvasHeight

        public int getCanvasHeight​(Bitstream bitstream,
                                   Bundle bundle,
                                   Item item,
                                   int defaultHeight)
        Return the height for the canvas associated with the bitstream. If the bitstream doesn't provide directly the information it is retrieved from the bundle, item or default.
        Parameters:
        bitstream - the dspace bitstream used in the canvas
        bundle - the bundle the bitstream belong to
        item - the item the bitstream belong to
        defaultHeight - the default width to apply if no other preferences are found
        Returns:
        the height in pixel for the canvas associated with the bitstream
      • getCanvasNaming

        public String getCanvasNaming​(Item item,
                                      String defaultNaming)
        Return the prefix to use to generate canvas name for canvas that has no an explicit IIIF label
        Parameters:
        item - the DSpace Item
        defaultNaming - a default to return if the item has not a custom value
        Returns:
        the prefix to use to generate canvas name for canvas that has no an explicit IIIF label