Package digilib.servlet
Class ServletOps
java.lang.Object
digilib.servlet.ServletOps
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static booleanset CORS header ACAO* for image requestsprotected static booleanset CORS header ACAO* for info requestsprotected static DigilibServletConfigurationprotected static org.slf4j.Logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FilegetConfigFile(File f, javax.servlet.ServletContext sc) Get a real File for a config File.static DigilibServletConfigurationstatic FileGet a real File for a web app File.static StringReturns the IIIF URL for the requested image.static StringheadersToString(javax.servlet.http.HttpServletRequest req) Returns text representation of headers for debuggging purposes.static voidhtmlMessage(String title, String msg, javax.servlet.http.HttpServletResponse response) print a servlet responsestatic voidhtmlMessage(String msg, javax.servlet.http.HttpServletResponse response) print a servlet responsestatic voidTransfers an image file as-is with the mime type mt.static voidsendFile(File f, String mt, String name, javax.servlet.http.HttpServletResponse response, org.slf4j.Logger logger) Transfers an image file as-is with the mime type mt.static voidsendIiifInfo(DigilibServletRequest dlReq, javax.servlet.http.HttpServletResponse response, org.slf4j.Logger logger) Sends IIIF compatible image information as application/json response.static voidWrite image img to ServletResponse response.static voidsendImage(DocuImage img, String mimeType, javax.servlet.http.HttpServletResponse response, org.slf4j.Logger logger) Write image img to ServletResponse response as data of mimeType.static voidsetDlConfig(DigilibServletConfiguration dlConfig) protected static voidwriteIiifV1Info(jakarta.json.stream.JsonGenerator info, ImageSize size, String url) Write IIIF Image API version 1 image information to info.protected static voidwriteIiifV2Info(jakarta.json.stream.JsonGenerator info, org.slf4j.Logger logger, ImageSize size, ImageSet imageSet, String url) Write IIIF Image API version 2 image information to info.protected static voidwriteIiifV3Info(jakarta.json.stream.JsonGenerator info, org.slf4j.Logger logger, ImageSize size, ImageSet imageSet, String url) Write IIIF Image API version 3 image information to info.
-
Field Details
-
logger
protected static org.slf4j.Logger logger -
dlConfig
-
corsForInfoRequests
protected static boolean corsForInfoRequestsset CORS header ACAO* for info requests -
corsForImageRequests
protected static boolean corsForImageRequestsset CORS header ACAO* for image requests
-
-
Constructor Details
-
ServletOps
public ServletOps()
-
-
Method Details
-
getDlConfig
- Returns:
- the dlConfig
-
setDlConfig
- Parameters:
dlConfig- the dlConfig to set
-
getFile
Get a real File for a web app File. If the File is not absolute the path is appended to the base directory of the web-app. If the file does not exist in the web-app directory it is considered relative to the Java working directory.- Parameters:
f- the Filesc- the ServletContext- Returns:
- the File
-
getConfigFile
Get a real File for a config File. If the File is not absolute the path is appended to the WEB-INF directory of the web-app. If the file does not exist in the WEB-INF directory it is considered relative to the Java working directory.- Parameters:
f- the Filesc- the ServletContext- Returns:
- the File
-
htmlMessage
public static void htmlMessage(String msg, javax.servlet.http.HttpServletResponse response) throws IOException print a servlet response- Parameters:
msg- the msgresponse- the HttpServletResponse- Throws:
IOException- on error
-
htmlMessage
public static void htmlMessage(String title, String msg, javax.servlet.http.HttpServletResponse response) throws IOException print a servlet response- Parameters:
title- the titlemsg- the msgresponse- the HttpServletResponse- Throws:
IOException- on error
-
sendFile
public static void sendFile(File f, String mt, String name, javax.servlet.http.HttpServletResponse response) throws ImageOpException, IOException Transfers an image file as-is with the mime type mt. The local file is copied to theOutputStreamof theServletResponse. If mt is null then the mime-type is auto-detected with mimeForFile.- Parameters:
f- Image file to be sent.mt- mime-type of the file.name- name of the download file (for application/x)response- ServletResponse where the image file will be sent.- Throws:
ImageOpException- on errorIOException- on error
-
sendFile
public static void sendFile(File f, String mt, String name, javax.servlet.http.HttpServletResponse response, org.slf4j.Logger logger) throws ImageOpException, IOException Transfers an image file as-is with the mime type mt. The local file is copied to theOutputStreamof theServletResponse. If mt is null then the mime-type is auto-detected with mimeForFile.- Parameters:
f- Image file to be sent.mt- mime-type of the file.name- name of the download file (for application/x)response- ServletResponse where the image file will be sent.logger- Logger to use- Throws:
ImageOpException- on errorIOException- on error
-
sendImage
public static void sendImage(DocuImage img, String mimeType, javax.servlet.http.HttpServletResponse response) throws ImageOpException, IOException Write image img to ServletResponse response.- Parameters:
img- the DocuImagemimeType- the mime-typeresponse- the HttpServletResponse- Throws:
ImageOpException- on errorjavax.servlet.ServletException- Exception on sending data.IOException
-
sendImage
public static void sendImage(DocuImage img, String mimeType, javax.servlet.http.HttpServletResponse response, org.slf4j.Logger logger) throws ImageOpException, IOException Write image img to ServletResponse response as data of mimeType. If mimeType is null, use heuristics for type.- Parameters:
img- the DocuImagemimeType- the mime-typeresponse- the HttpServletResponselogger- the Logger- Throws:
ImageOpException- on errorjavax.servlet.ServletException- Exception on sending data.IOException
-
sendIiifInfo
public static void sendIiifInfo(DigilibServletRequest dlReq, javax.servlet.http.HttpServletResponse response, org.slf4j.Logger logger) throws javax.servlet.ServletException Sends IIIF compatible image information as application/json response.- Parameters:
dlReq- the DigilibServletRequestresponse- the HttpServletResponselogger- the Logger- Throws:
javax.servlet.ServletException- on error- See Also:
-
writeIiifV1Info
protected static void writeIiifV1Info(jakarta.json.stream.JsonGenerator info, ImageSize size, String url) throws IOException Write IIIF Image API version 1 image information to info.- Parameters:
info-size-url-- Throws:
IOException
-
writeIiifV2Info
protected static void writeIiifV2Info(jakarta.json.stream.JsonGenerator info, org.slf4j.Logger logger, ImageSize size, ImageSet imageSet, String url) throws IOException Write IIIF Image API version 2 image information to info.- Parameters:
info-logger-size-imageSet-url-- Throws:
IOException
-
writeIiifV3Info
protected static void writeIiifV3Info(jakarta.json.stream.JsonGenerator info, org.slf4j.Logger logger, ImageSize size, ImageSet imageSet, String url) throws IOException Write IIIF Image API version 3 image information to info.- Parameters:
info-logger-size-imageSet-url-- Throws:
IOException
-
getIiifImageUrl
Returns the IIIF URL for the requested image.- Parameters:
dlReq-- Returns:
-
headersToString
Returns text representation of headers for debuggging purposes.- Parameters:
req- the HttpServletRequest- Returns:
- the headers string
-