Class DefaultStaticResourceService
java.lang.Object
com.bobocode.bring.web.staticcontent.service.impl.DefaultStaticResourceService
- All Implemented Interfaces:
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcheckPathFile(Path path, String requestUri) Checks if the file exists, is not a directory, and is within the specified static folder.getStaticFile(String pathToFile) Retrieves the absolute path for the requested static file.
-
Field Details
-
STATIC_FILE_NOT_FOUND_MESSAGE
- See Also:
-
STATIC_FOLDER_NOT_FOUND_MESSAGE
- See Also:
-
STATIC_FOLDER
- See Also:
-
-
Constructor Details
-
DefaultStaticResourceService
public DefaultStaticResourceService()
-
-
Method Details
-
getStaticFile
Retrieves the absolute path for the requested static file.- Specified by:
getStaticFilein interfaceStaticResourceService- 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
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 aStaticFileNotFoundException.- 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.
-