Interface Delegate
Delegates a variety of methods to user-supplied code.
New instances are generally acquired via DelegateFactory.newDelegate(RequestContext)
.
-
Method Summary
Modifier and TypeMethodDescriptiondefault Object
Returns authorization status for the current request.default Object
Returns authorization status for the current request.default void
Can be used to modify the JSON content of an IIIF Image API 1.x information response.default void
Can be used to modify the JSON content of an IIIF Image API 2.x information response.default void
Can be used to modify the JSON content of an IIIF Image API 3.x information response.deserializeMetaIdentifier
(String metaIdentifier) Deserializes the given meta-identifier string into its component parts.default String
N.B.: this method should not try to perform authorization.Returns one of the following: String URI Map with the following keys:uri
String.default String
Returns XMP metadata to embed in the variant image.Tells the server what overlay, if any, to apply to an image.Draws one or more rectangles over an image in response to a request.default String
Tells the server whichSource
implementation to use for the given identifier.default Object
Invokes an arbitrarily-named method.default String
serializeMetaIdentifier
(Map<String, Object> metaIdentifier) Serializes the given meta-identifier hash, but does not URL-encode it.void
setRequestContext
(RequestContext context) Provides information about the request to the instance.
-
Method Details
-
setRequestContext
Provides information about the request to the instance. This is the first method in this interface to be invoked.- Parameters:
context
- Context to set.- Throws:
DelegateException
- if the delegate object does not contain a setter method for the context.
-
getRequestContext
RequestContext getRequestContext()- Returns:
- The instance passed to
setRequestContext(RequestContext)
.
-
deserializeMetaIdentifier
default Map<String,Object> deserializeMetaIdentifier(String metaIdentifier) throws DelegateException Deserializes the given meta-identifier string into its component parts.
The identifier portion has already been URL-decoded.
This method is used only when the
Key.META_IDENTIFIER_TRANSFORMER
configuration key is set to the simple class name ofDelegateMetaIdentifierTransformer
.The returned instance contains the following keys:
identifier
- String. Required.
page_number
- Integer. Optional.
scale_constraint
- Two-element array of integers with scale constraint numerator at position 0 and denominator at position 1. Optional.
This default implementation supports the
identifier;page_number;sc_numerator:sc_denominator
scheme.- Parameters:
metaIdentifier
- Meta-identifier to deserialize.- Returns:
- See above. The return value must be compatible with the argument
to
serializeMetaIdentifier(Map)
. - Throws:
DelegateException
- if there is any problem generating a result.
-
serializeMetaIdentifier
Serializes the given meta-identifier hash, but does not URL-encode it.
This method is used only when the
Key.META_IDENTIFIER_TRANSFORMER
configuration key is set to the simple class name ofDelegateMetaIdentifierTransformer
.This default implementation supports the
identifier;page_number;sc_numerator:sc_denominator
scheme.- Parameters:
metaIdentifier
- SeedeserializeMetaIdentifier(java.lang.String)
for a description of the map structure.- Returns:
- Serialized meta-identifier compatible with the argument to
deserializeMetaIdentifier(String)
. - Throws:
DelegateException
- if there is any problem generating a result.
-
authorizeBeforeAccess
Returns authorization status for the current request. This method is called upon all requests to all public endpoints early in the request lifecycle, before the image has been accessed. This means that some
request context
keys will not be available yet.This method should implement all possible authorization logic except that which requires any of the context keys that aren't yet available. This will ensure efficient authorization failures.
Implementations should assume that the underlying resource is available, and not try to check for it.
Possible return values:
- Boolean
true
/false
, indicating whether the request is fully authorized or not. If false, the client will receive a 403 Forbidden response. - Hash with a
status_code
key.- If it corresponds to an integer from 200-299, the request is authorized.
- If it corresponds to an integer from 300-399:
- If the hash also contains a
location
key corresponding to a URI string, the request will be redirected to that URI using that code. - If the hash also contains
scale_numerator
andscale_denominator
keys, the request will be redirected using that code to a virtual reduced-scale version of the source image.
- If the hash also contains a
- If it corresponds to 401, the hash must include a
challenge
key corresponding to a WWW-Authenticate header value.
- Returns:
- See above.
- Throws:
DelegateException
- if there is any problem generating a result.
- Boolean
-
authorize
Returns authorization status for the current request. Will be called upon all requests to all public image endpoints.
This is a counterpart of
authorizeBeforeAccess()
that is invoked later in the request cycle, once information about the source image has become available. It should only contain logic that depends on request context keys that aren't available yet fromauthorizeBeforeAccess()
.Implementations should assume that the underlying resource is available, and not try to check for it.
- Returns:
- See the documentation of
authorizeBeforeAccess()
. - Throws:
DelegateException
- if there is any problem generating a result.
-
customizeIIIF1InformationResponse
Can be used to modify the JSON content of an IIIF Image API 1.x information response. See the IIIF Image API 1.1 specification and "endpoints" section of the user manual.
- Parameters:
info
- Modifiable information content.- Throws:
DelegateException
- if there is any problem generating a result.
-
customizeIIIF2InformationResponse
Can be used to modify the JSON content of an IIIF Image API 2.x information response. See the IIIF Image API 2.1 specification and "endpoints" section of the user manual.
- Parameters:
info
- Modifiable information content.- Throws:
DelegateException
- if there is any problem generating a result.
-
customizeIIIF3InformationResponse
Can be used to modify the JSON content of an IIIF Image API 3.x information response. See the IIIF Image API 3.0 specification and "endpoints" section of the user manual.
- Parameters:
info
- Modifiable information content.- Throws:
DelegateException
- if there is any problem generating a result.
-
getSource
Tells the server whichSource
implementation to use for the given identifier.- Returns:
- Source class name.
- Throws:
DelegateException
- if there is any problem generating a result.
-
getFilesystemSourcePathname
N.B.: this method should not try to perform authorization.- Returns:
- Absolute pathname of the image corresponding to the identifier
in the request context, or
null
if not found. - Throws:
DelegateException
- if there is any problem generating a result.
-
getHTTPSourceResourceInfo
Returns one of the following:- String URI
- Map with the following keys:
uri
- String. Required.
username
- For HTTP Basic authentication. Optional.
secret
- For HTTP Basic authentication. Optional.
headers
- Hash of request headers. Optional.
send_head_request
- Optional. Defaults to
true
. See the documentation of theKey.HTTPSOURCE_SEND_HEAD_REQUESTS
configuration key in the sample config file.
null
if not found.
N.B.: This method should not try to perform authorization.
authorize()
should be used instead.- Returns:
- See above.
- Throws:
DelegateException
- if there is any problem generating a result.
-
getMetadata
Returns XMP metadata to embed in the variant image.
Source image metadata is available in the
metadata
request context key, and has the following structure:{ "exif": { "tagSet": "Baseline TIFF", "fields": { "Field1Name": [ value ], "Field2Name": [ value ], "EXIFIFD": { "tagSet": "EXIF", "fields": { "Field1Name": [ value ], "Field2Name": [ value ] } } } }, "iptc": [ "Field1Name": value, "Field2Name": value ], "xmp_string": "<rdf:RDF>...</rdf:RDF>", "xmp_model": See https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/Model.html, "xmp_elements": { "Field1Name": "value", "Field2Name": [ "value1", "value2" ] }, "native": { # structure varies } }
- The
exif
key refers to embedded EXIF data. This also includes IFD0 metadata from source TIFFs, whether or not an EXIF IFD is present. - The
iptc
key refers to embedded IPTC IIM data. - The
xmp_string
key refers to raw embedded XMP data. - The
xmp_model
key contains a Jena Model object pre-loaded with the contents ofxmp_string
. - The
xmp_elements
key contains a view of the embedded XMP data as key-value pairs. This is convenient to use, but won't work correctly with XMP fields that cannot be expressed as key-value pairs. - The
native
key refers to format-specific metadata.
Any combination of the above keys may be present or missing depending on what is available in a particular source image.
Only XMP can be embedded in variant images. See the Guide for examples of working with the XMP model programmatically.
- Returns:
- String or Jena model containing XMP data to embed in the variant
image, or
null
to not embed anything. - Throws:
DelegateException
- if there is any problem generating a result.
- The
-
getOverlayProperties
Tells the server what overlay, if any, to apply to an image. Called upon all image requests to any endpoint if
overlays are enabled
and theoverlay strategy
is set toDelegateStrategy
in the application configuration.Possible return values:
- For string overlays, a map with the following keys:
background_color
- CSS-compliant RGA(A) color.
color
- CSS-compliant RGA(A) color.
font
- Font name.
font_min_size
- Minimum font size in points. Ignored when
word_wrap
istrue
. font_size
- Font size in points.
font_weight
- Font weight based on 1.
glyph_spacing
- Glyph spacing based on 0.
inset
- Pixels of inset.
position
- Position like
top left
,center
,center right
, etc. string
- String to draw.
stroke_color
- CSS-compliant RGB(A) text outline color.
stroke_width
- Text outline width in pixels.
word_wrap
- Whether to wrap long lines within
string
(true
orfalse
).
- For image overlays, a hash with the following keys:
image
- Image pathname or URL.
position
- See above.
inset
- See above.
null
for no overlay.
- Returns:
- See above.
- Throws:
DelegateException
- if there is any problem generating a result.
- For string overlays, a map with the following keys:
-
getRedactions
Draws one or more rectangles over an image in response to a request. Will be called upon all image requests to any endpoint.
- Returns:
- List of maps, each with
x
,y
,width
,height
, andcolor
keys. The first four have integer values, and the last is a valid CSS color. If no redactions are to be applied, an empty list is returned. - Throws:
DelegateException
- if there is any problem generating a result.
-
invoke
Invokes an arbitrarily-named method.
This default implementation simply invokes the method with the given name defined in the same class.
- Parameters:
methodName
- Name of the method to invoke.args
- Arguments to pass to the invocation.- Returns:
- Method return value.
- Throws:
DelegateException
- if there is any problem generating a result.
-