Package digilib.servlet
Class ServletOps
- java.lang.Object
-
- digilib.servlet.ServletOps
-
public class ServletOps extends Object
-
-
Field Summary
Fields Modifier and Type Field Description protected static boolean
corsForImageRequests
set CORS header ACAO* for image requestsprotected static boolean
corsForInfoRequests
set CORS header ACAO* for info requestsprotected static DigilibServletConfiguration
dlConfig
protected static org.slf4j.Logger
logger
-
Constructor Summary
Constructors Constructor Description ServletOps()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static File
getConfigFile(File f, javax.servlet.ServletContext sc)
Get a real File for a config File.static DigilibServletConfiguration
getDlConfig()
static File
getFile(File f, javax.servlet.ServletContext sc)
Get a real File for a web app File.static String
getIiifImageUrl(DigilibServletRequest dlReq)
Returns the IIIF URL for the requested image.static String
headersToString(javax.servlet.http.HttpServletRequest req)
Returns text representation of headers for debuggging purposes.static void
htmlMessage(String title, String msg, javax.servlet.http.HttpServletResponse response)
print a servlet responsestatic void
htmlMessage(String msg, javax.servlet.http.HttpServletResponse response)
print a servlet responsestatic void
sendFile(File f, String mt, String name, javax.servlet.http.HttpServletResponse response)
Transfers an image file as-is with the mime type mt.static void
sendFile(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 void
sendIiifInfo(DigilibServletRequest dlReq, javax.servlet.http.HttpServletResponse response, org.slf4j.Logger logger)
Sends IIIF compatible image information as application/json response.static void
sendImage(DocuImage img, String mimeType, javax.servlet.http.HttpServletResponse response)
Write image img to ServletResponse response.static void
sendImage(DocuImage img, String mimeType, javax.servlet.http.HttpServletResponse response, org.slf4j.Logger logger)
Write image img to ServletResponse response as data of mimeType.static void
setDlConfig(DigilibServletConfiguration dlConfig)
protected static void
writeIiifV1Info(jakarta.json.stream.JsonGenerator info, ImageSize size, String url)
Write IIIF Image API version 1 image information to info.protected static void
writeIiifV2Info(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 void
writeIiifV3Info(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 Detail
-
logger
protected static org.slf4j.Logger logger
-
dlConfig
protected static DigilibServletConfiguration dlConfig
-
corsForInfoRequests
protected static boolean corsForInfoRequests
set CORS header ACAO* for info requests
-
corsForImageRequests
protected static boolean corsForImageRequests
set CORS header ACAO* for image requests
-
-
Method Detail
-
getDlConfig
public static DigilibServletConfiguration getDlConfig()
- Returns:
- the dlConfig
-
setDlConfig
public static void setDlConfig(DigilibServletConfiguration dlConfig)
- Parameters:
dlConfig
- the dlConfig to set
-
getFile
public static File getFile(File f, javax.servlet.ServletContext sc)
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
public static File getConfigFile(File f, javax.servlet.ServletContext sc)
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 theOutputStream
of 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 theOutputStream
of 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:
- IIIF Image Information Request
-
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
public static String getIiifImageUrl(DigilibServletRequest dlReq)
Returns the IIIF URL for the requested image.- Parameters:
dlReq
-- Returns:
-
headersToString
public static String headersToString(javax.servlet.http.HttpServletRequest req)
Returns text representation of headers for debuggging purposes.- Parameters:
req
- the HttpServletRequest- Returns:
- the headers string
-
-