Class ResourceRetriever


  • public class ResourceRetriever
    extends Object
    Servlet resource retriever. Can be used to retrieve the content of a file as java.io.InputStream, String or java.util.Properties.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Properties getProperties​(javax.servlet.ServletConfig servletConfig, String paramName, org.apache.logging.log4j.Logger logger)
      Gets the java.util.Properties in the specified servlet web.xml init parameter location.
      static Properties getProperties​(javax.servlet.ServletContext servletCtx, String paramName, org.apache.logging.log4j.Logger logger)
      Gets the java.util.Properties in the specified servlet context web.xml init parameter location.
      static InputStream getStream​(javax.servlet.ServletConfig servletConfig, String paramName, org.apache.logging.log4j.Logger logger)
      Gets the resource in the specified servlet web.xml init parameter location.
      static InputStream getStream​(javax.servlet.ServletContext servletCtx, String paramName, org.apache.logging.log4j.Logger logger)
      Gets the resource in the specified servlet context web.xml init parameter location.
      static String getString​(javax.servlet.ServletContext servletCtx, String paramName, org.apache.logging.log4j.Logger logger)
      Gets the resource in the specified servlet context web.xml init parameter location.
    • Method Detail

      • getStream

        public static InputStream getStream​(javax.servlet.ServletContext servletCtx,
                                            String paramName,
                                            org.apache.logging.log4j.Logger logger)
                                     throws Exception
        Gets the resource in the specified servlet context web.xml init parameter location.
        Parameters:
        servletCtx - The servlet context. Must not be null.
        paramName - The name of the servlet context init parameter specifying the resource file (relative to the web app root). For example, /WEB-INF/authService.properties. Must not be null.
        logger - To log exceptions at ERROR level, null if none.
        Returns:
        The resource as an input stream.
        Throws:
        Exception - On a missing servlet context parameter or a missing resource.
      • getStream

        public static InputStream getStream​(javax.servlet.ServletConfig servletConfig,
                                            String paramName,
                                            org.apache.logging.log4j.Logger logger)
                                     throws Exception
        Gets the resource in the specified servlet web.xml init parameter location.
        Parameters:
        servletConfig - The servlet configuration. Must not be null.
        paramName - The name of the servlet init parameter specifying the resource file (relative to the web app root). For example, /WEB-INF/authService.properties. Must not be null.
        logger - To log exceptions at ERROR level, null if none.
        Returns:
        The resource as an input stream.
        Throws:
        Exception - On a missing servlet init parameter or a missing resource.
      • getString

        public static String getString​(javax.servlet.ServletContext servletCtx,
                                       String paramName,
                                       org.apache.logging.log4j.Logger logger)
                                throws Exception
        Gets the resource in the specified servlet context web.xml init parameter location.
        Parameters:
        servletCtx - The servlet context. Must not be null.
        paramName - The name of the servlet context init parameter specifying the resource file (relative to the web app root). For example, /WEB-INF/authService.properties. Must not be null.
        logger - To log exceptions at ERROR level, null if none.
        Returns:
        The resource as a string.
        Throws:
        Exception - On a missing servlet context parameter or a missing resource.
      • getProperties

        public static Properties getProperties​(javax.servlet.ServletContext servletCtx,
                                               String paramName,
                                               org.apache.logging.log4j.Logger logger)
                                        throws Exception
        Gets the java.util.Properties in the specified servlet context web.xml init parameter location.
        Parameters:
        servletCtx - The servlet context. Must not be null.
        paramName - The name of the servlet context init parameter specifying the properties file (relative to the web app root). For example, /WEB-INF/authService.properties. Must not be null.
        logger - To log exceptions at ERROR level, null if none.
        Returns:
        The properties.
        Throws:
        Exception - On a missing servlet context parameter, missing or bad properties file.
      • getProperties

        public static Properties getProperties​(javax.servlet.ServletConfig servletConfig,
                                               String paramName,
                                               org.apache.logging.log4j.Logger logger)
                                        throws Exception
        Gets the java.util.Properties in the specified servlet web.xml init parameter location.
        Parameters:
        servletConfig - The servlet configuration. Must not be null.
        paramName - The name of the servlet init parameter specifying the properties file (relative to the web app root). For example, /WEB-INF/authService.properties. Must not be null.
        logger - To log exceptions at ERROR level, null if none.
        Returns:
        The properties.
        Throws:
        Exception - On a missing servlet context parameter, missing or bad properties file.