Class AbstractImageResource
- Direct Known Subclasses:
IIIFResource,InformationResource,TileResource
Resource implementations that
respond to requests for images.-
Field Summary
Fields inherited from class is.galia.resource.AbstractResource
PUBLIC_IDENTIFIER_HEADER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanUses anAuthorizerto determine how to respond to the request.protected booleanUses anAuthorizerto determine how to respond to the request.voiddoInit()Initialization method, called after all necessary setters have been called but before any request handler method (likeAbstractResource.doGET()etc.)protected abstract IdentifierReturns the identifier of the source image, which may be a filename, an object store key, or something else.protected abstract MetaIdentifierReturns the decoded meta-identifier path component of the URI, which may include page number or other information.protected intprotected abstract ReferencegetPublicReference(MetaIdentifier newMetaIdentifier) Variant ofAbstractResource.getPublicReference()that replaces the identifier path component's meta-identifier if an identifier path component is available.protected booleanhandleAuthInfo(AuthInfo info) Handles anAuthInfowhich has been constructed from the return value of the pre-authorization or authorization delegate method.protected final booleanReturns whether there is acacheargument set tofalseornocachein the URI query string, indicating that cache reads and writes are both bypassed.protected final booleanReturns whether there is acacheargument set torecachein the URI query string, indicating that cache reads are bypassed.protected final booleanIf 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.Methods inherited from class is.galia.resource.AbstractResource
authenticateUsingBasic, decodePathComponent, destroy, doDELETE, doGET, doHEAD, doOPTIONS, doPATCH, doPOST, doPUT, getCanonicalClientIPAddress, getCommonTemplateVars, getDelegate, getLocalBasePath, getLogger, getPreferredMediaTypes, getPublicReference, getPublicRootReference, getRepresentationDisposition, getRequest, getRequestContext, getResponse, getRoutes, negotiateContentType, setRequest, setResponse
-
Constructor Details
-
AbstractImageResource
public AbstractImageResource()
-
-
Method Details
-
doInit
Description copied from class:AbstractResourceInitialization 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 therequest context.Overrides must call
super.- Overrides:
doInitin classAbstractResource- Throws:
Exception- upon any error. This may be aResourceExceptionto enable a custom status.
-
authorize
Uses an
Authorizerto 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.
falseindicates 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
Uses an
Authorizerto 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.
falseindicates 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
Handles anAuthInfowhich has been constructed from the return value of the pre-authorization or authorization delegate method. TheAuthInfomay 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 eithertrueif the request is authorized as-is, orfalseif not.- Throws:
IOExceptionResourceException
-
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
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
nullif 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,0is returned.
-
getPublicReference
Variant ofAbstractResource.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 acacheargument set tofalseornocachein the URI query string, indicating that cache reads and writes are both bypassed.- Returns:
- Whether there is a
cacheargument set tofalseornocachein the URI query string.
-
isBypassingCacheRead
protected final boolean isBypassingCacheRead()Returns whether there is acacheargument set torecachein the URI query string, indicating that cache reads are bypassed.- Returns:
- Whether there is a
cacheargument set torecachein the URI query string.
-
redirectToNormalizedScaleConstraint
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:
trueif redirecting. Clients should stop processing if this is the case.- Throws:
IOException
-