Class AbstractImageResource

java.lang.Object
is.galia.resource.AbstractResource
is.galia.resource.AbstractImageResource
Direct Known Subclasses:
IIIFResource, InformationResource, TileResource

public abstract class AbstractImageResource extends AbstractResource
Abstract class to be extended by all Resource implementations that respond to requests for images.
  • Constructor Details

    • AbstractImageResource

      public AbstractImageResource()
  • Method Details

    • doInit

      public void doInit() throws Exception
      Description copied from class: AbstractResource

      Initialization method, called after all necessary setters have been called but before any request handler method (like AbstractResource.doGET() etc.)

      If an implementation class has anything to do with image identifiers, it should add the request identifier to the request context.

      Overrides must call super.

      Overrides:
      doInit in class AbstractResource
      Throws:
      Exception - upon any error. This may be a ResourceException to enable a custom status.
    • authorize

      protected boolean authorize() throws IOException, ResourceException

      Uses an Authorizer to determine how to respond to the request. The response is modified if necessary.

      The authorization system supports simple boolean authorization which maps to the HTTP 200 and 403 statuses.

      Authorization can simultaneously be used in the context of the IIIF Authentication API, where it works a little differently. Here, HTTP 401 is returned instead of 403, and the response body does include image information. (See Interaction with Access-Controlled Resources. This means that IIIF information endpoints should swallow any ResourceExceptions with HTTP 401 status.

      Returns:
      Whether authorization was successful. false indicates a redirect, and client code should abort.
      Throws:
      IOException - if there was an I/O error while checking authorization.
      ResourceException - if authorization resulted in an HTTP 400-level response.
    • authorizeBeforeAccess

      protected boolean authorizeBeforeAccess() throws IOException, ResourceException

      Uses an Authorizer to determine how to respond to the request. The response is modified if necessary.

      The authorization system supports simple boolean authorization which maps to the HTTP 200 and 403 statuses.

      Authorization can simultaneously be used in the context of the IIIF Authentication API, where it works a little differently. Here, HTTP 401 is returned instead of 403, and the response body does include image information. (See Interaction with Access-Controlled Resources. This means that IIIF information endpoints should swallow any ResourceExceptions with HTTP 401 status.

      Returns:
      Whether authorization was successful. false indicates a redirect, and client code should abort.
      Throws:
      IOException - if there was an I/O error while checking authorization.
      ResourceException - if authorization resulted in an HTTP 400-level response.
    • handleAuthInfo

      protected boolean handleAuthInfo(AuthInfo info) throws IOException, ResourceException
      Handles an AuthInfo which has been constructed from the return value of the pre-authorization or authorization delegate method. The AuthInfo may signal us to redirect (via HTTP 3xx), to authenticate (via HTTP 401), to forbid (via HTTP 403), or something else. We honor that by setting an appropriate status, setting appropriate response headers, maybe streaming an appropriate response entity, and ultimately returning either true if the request is authorized as-is, or false if not.
      Throws:
      IOException
      ResourceException
    • getIdentifier

      protected abstract Identifier getIdentifier()
      Returns the identifier of the source image, which may be a filename, an object store key, or something else.
      Returns:
      The identifier of the source image.
    • getMetaIdentifier

      protected abstract MetaIdentifier getMetaIdentifier()
      Returns the decoded meta-identifier path component of the URI, which may include page number or other information. (This may not be the path component that the client supplies or sees.)
      Returns:
      Instance corresponding to the first path argument, or null if no path arguments are available.
      See Also:
    • getPageIndex

      protected int getPageIndex()
      Returns:
      The page index (i.e. page number - 1) from the meta-identifier. If it does not exist, 0 is returned.
    • getPublicReference

      protected abstract Reference getPublicReference(MetaIdentifier newMetaIdentifier)
      Variant of AbstractResource.getPublicReference() that replaces the identifier path component's meta-identifier if an identifier path component is available.
      Parameters:
      newMetaIdentifier - Meta-identifier.
    • isBypassingCache

      protected final boolean isBypassingCache()
      Returns whether there is a cache argument set to false or nocache in the URI query string, indicating that cache reads and writes are both bypassed.
      Returns:
      Whether there is a cache argument set to false or nocache in the URI query string.
    • isBypassingCacheRead

      protected final boolean isBypassingCacheRead()
      Returns whether there is a cache argument set to recache in the URI query string, indicating that cache reads are bypassed.
      Returns:
      Whether there is a cache argument set to recache in the URI query string.
    • redirectToNormalizedScaleConstraint

      protected final boolean redirectToNormalizedScaleConstraint() throws IOException

      If an identifier is present in the URI, and it contains a scale constraint suffix in a non-normalized form, this method redirects to a normalized URI.

      Examples:

      1:2
      No redirect
      2:4
      Redirect to 1:2
      1:1 & 5:5
      Redirect to no constraint
      Returns:
      true if redirecting. Clients should stop processing if this is the case.
      Throws:
      IOException