Class ServletOps


  • public class ServletOps
    extends Object
    • Field Detail

      • logger

        protected static org.slf4j.Logger logger
      • corsForInfoRequests

        protected static boolean corsForInfoRequests
        set CORS header ACAO* for info requests
      • corsForImageRequests

        protected static boolean corsForImageRequests
        set CORS header ACAO* for image requests
    • Constructor Detail

      • ServletOps

        public ServletOps()
    • Method Detail

      • 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 File
        sc - 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 File
        sc - 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 msg
        response - 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 title
        msg - the msg
        response - 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 the OutputStream of the ServletResponse. 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 error
        IOException - 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 the OutputStream of the ServletResponse. 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 error
        IOException - 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 DocuImage
        mimeType - the mime-type
        response - the HttpServletResponse
        Throws:
        ImageOpException - on error
        javax.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 DocuImage
        mimeType - the mime-type
        response - the HttpServletResponse
        logger - the Logger
        Throws:
        ImageOpException - on error
        javax.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 DigilibServletRequest
        response - the HttpServletResponse
        logger - 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