Class IIIFUtils
- java.lang.Object
-
- org.dspace.app.iiif.service.utils.IIIFUtils
-
@Component public class IIIFUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description protected BitstreamServicebitstreamServiceprotected com.fasterxml.jackson.databind.module.SimpleModuleiiifModuleprotected com.fasterxml.jackson.databind.ObjectMappermapperstatic StringMETADATA_IIIF_CANVAS_NAMINGstatic StringMETADATA_IIIF_DESCRIPTIONstatic StringMETADATA_IIIF_ENABLEDstatic StringMETADATA_IIIF_LABELstatic StringMETADATA_IIIF_SEARCH_ENABLEDstatic StringMETADATA_IIIF_TOCstatic StringMETADATA_IIIF_VIEWING_HINTstatic StringMETADATA_IMAGE_HEIGHTstatic StringMETADATA_IMAGE_WIDTHprotected static StringOTHER_CONTENT_BUNDLEstatic StringTOC_SEPARATORstatic StringTOC_SEPARATOR_REGEX
-
Constructor Summary
Constructors Constructor Description IIIFUtils()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringasJson(de.digitalcollections.iiif.model.sharedcanvas.Resource<?> resource)Serializes the json response.BitstreamgetBitstreamForCanvas(Context context, Item item, int canvasPosition)Retrives a bitstream based on its position in the IIIF bundle.StringgetBitstreamMimeType(Bitstream bitstream, Context context)Returns the bitstream mime typeStringgetBundleIIIFToC(Bundle bundle)Return the iiif toc for the specified bundleintgetCanvasHeight(Bitstream bitstream, Bundle bundle, Item item, int defaultHeight)Return the height for the canvas associated with the bitstream.StringgetCanvasId(int position)Returns the canvas path with position.intgetCanvasId(String canvasId)Extracts canvas position from the URL input path.StringgetCanvasNaming(Item item, String defaultNaming)Return the prefix to use to generate canvas name for canvas that has no an explicit IIIF labelintgetCanvasWidth(Bitstream bitstream, Bundle bundle, Item item, int defaultWidth)Return the width for the canvas associated with the bitstream.List<Bitstream>getIIIFBitstreams(Context context, Bundle bundle)Return all the bitstreams in the bundle to be used as IIIF resourcesList<Bitstream>getIIIFBitstreams(Context context, Item item)Return all the bitstreams in the item to be used as IIIF resourcesList<Bundle>getIIIFBundles(Item item)StringgetIIIFDescription(DSpaceObject dso, String defaultDescription)Return the custom iiif description for the resource or the provided default if noneStringgetIIIFLabel(DSpaceObject dso, String defaultLabel)Return the custom iiif label for the resource or the provided default if noneList<String>getIIIFToCs(Bitstream bitstream, String prefix)Return the table of contents (toc) positions in the iiif structure where the resource appears.StringgetIIIFViewingHint(Item item, String defaultHint)Return the iiif viewing hint for the itemint[]getImageDimensions(Bitstream bitstream)Retrieves image dimensions from the image server (IIIF Image API v.2.1.1).List<Bitstream>getSeeAlsoBitstreams(Item item)Return all the bitstreams in the item to be used as annotationsbooleanhasWidthMetadata(Bitstream bitstream)Test to see if the bitstream contains iiif image width metadata.booleanisIIIFBitstream(Context context, Bitstream b)Utility method to check is a bitstream can be used as IIIF resourcesbooleanisIIIFEnabled(Item item)booleanisSearchable(Item item)Checks to see if the item is searchable.
-
-
-
Field Detail
-
OTHER_CONTENT_BUNDLE
protected static final String OTHER_CONTENT_BUNDLE
- See Also:
- Constant Field Values
-
METADATA_IIIF_ENABLED
public static final String METADATA_IIIF_ENABLED
- See Also:
- Constant Field Values
-
METADATA_IIIF_SEARCH_ENABLED
public static final String METADATA_IIIF_SEARCH_ENABLED
- See Also:
- Constant Field Values
-
METADATA_IIIF_LABEL
public static final String METADATA_IIIF_LABEL
- See Also:
- Constant Field Values
-
METADATA_IIIF_DESCRIPTION
public static final String METADATA_IIIF_DESCRIPTION
- See Also:
- Constant Field Values
-
METADATA_IIIF_TOC
public static final String METADATA_IIIF_TOC
- See Also:
- Constant Field Values
-
METADATA_IIIF_CANVAS_NAMING
public static final String METADATA_IIIF_CANVAS_NAMING
- See Also:
- Constant Field Values
-
METADATA_IIIF_VIEWING_HINT
public static final String METADATA_IIIF_VIEWING_HINT
- See Also:
- Constant Field Values
-
METADATA_IMAGE_WIDTH
public static final String METADATA_IMAGE_WIDTH
- See Also:
- Constant Field Values
-
METADATA_IMAGE_HEIGHT
public static final String METADATA_IMAGE_HEIGHT
- See Also:
- Constant Field Values
-
TOC_SEPARATOR
public static final String TOC_SEPARATOR
- See Also:
- Constant Field Values
-
TOC_SEPARATOR_REGEX
public static final String TOC_SEPARATOR_REGEX
- See Also:
- Constant Field Values
-
iiifModule
protected com.fasterxml.jackson.databind.module.SimpleModule iiifModule
-
mapper
protected com.fasterxml.jackson.databind.ObjectMapper mapper
-
bitstreamService
@Autowired protected BitstreamService bitstreamService
-
-
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 Contextitem- 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 Contextbundle- 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 bitstreamcontext- DSpace context- Returns:
- mime type
-
isSearchable
public boolean isSearchable(Item item)
Checks to see if the item is searchable. Based on theMETADATA_IIIF_SEARCH_ENABLEDmetadata.- 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 Contextitem- DSpace ItemcanvasPosition- 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 resourcedefaultLabel- 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 resourcedefaultDescription- 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 bitstreamprefix- 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 itemdefaultHint- 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 canvasbundle- the bundle the bitstream belong toitem- the item the bitstream belong todefaultWidth- 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 canvasbundle- the bundle the bitstream belong toitem- the item the bitstream belong todefaultHeight- 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 ItemdefaultNaming- 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
-
-