Class DefaultStaticResourceService

java.lang.Object
com.bobocode.bring.web.staticcontent.service.impl.DefaultStaticResourceService
All Implemented Interfaces:
StaticResourceService

public class DefaultStaticResourceService extends Object implements StaticResourceService
Implementation of the StaticResourceService interface for handling static resource requests. Manages the retrieval of absolute paths for requested static files, ensuring file existence and proper conditions.
Since:
1.0
Author:
Blyzhnytsia Team
  • Field Details

  • Constructor Details

    • DefaultStaticResourceService

      public DefaultStaticResourceService()
  • Method Details

    • getStaticFile

      public Path getStaticFile(String pathToFile)
      Retrieves the absolute path for the requested static file.
      Specified by:
      getStaticFile in interface StaticResourceService
      Parameters:
      pathToFile - The path of the requested static file.
      Returns:
      The absolute path of the requested static file.
      Throws:
      StaticFileNotFoundException - If the file is not found or doesn't meet specified conditions.
    • checkPathFile

      private void checkPathFile(Path path, String requestUri)
      Checks if the file exists, is not a directory, and is within the specified static folder. If conditions are not met, logs an error and throws a StaticFileNotFoundException.
      Parameters:
      path - The path of the file to be checked.
      requestUri - The original request URI for logging purposes.
      Throws:
      StaticFileNotFoundException - If the file is not found or doesn't meet specified conditions.