From 63acd274921bbbe6d200da9cf18045d54568b8a4 Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com.> Date: Wed, 2 Jul 2025 10:39:08 +0100 Subject: [PATCH] remove pointless methods --- .../software/common/util/ExceptionUtils.java | 38 ------------------- .../api/converters/ConvertHtmlToPDF.java | 3 +- .../api/converters/ConvertMarkdownToPdf.java | 6 ++- .../api/converters/ConvertWebsiteToPDF.java | 12 ++++-- .../api/misc/ExtractImageScansController.java | 3 +- 5 files changed, 17 insertions(+), 45 deletions(-) diff --git a/common/src/main/java/stirling/software/common/util/ExceptionUtils.java b/common/src/main/java/stirling/software/common/util/ExceptionUtils.java index e3c7779e9..9d9fc514b 100644 --- a/common/src/main/java/stirling/software/common/util/ExceptionUtils.java +++ b/common/src/main/java/stirling/software/common/util/ExceptionUtils.java @@ -156,21 +156,6 @@ public class ExceptionUtils { "error.fileFormatRequired", "File must be in {0} format", "HTML or ZIP"); } - public static IllegalArgumentException createMarkdownFileRequiredException() { - return createIllegalArgumentException( - "error.fileFormatRequired", "File must be in {0} format", "Markdown"); - } - - public static IllegalArgumentException createMarkdownFormatException() { - return createIllegalArgumentException( - "error.fileFormatRequired", "File must be in {0} format", ".md"); - } - - public static IllegalArgumentException createHtmlZipFormatException() { - return createIllegalArgumentException( - "error.fileFormatRequired", "File must be in {0} format", ".html or .zip"); - } - public static IllegalArgumentException createPdfFileRequiredException() { return createIllegalArgumentException( "error.fileFormatRequired", "File must be in {0} format", "PDF"); @@ -201,30 +186,7 @@ public class ExceptionUtils { "error.toolNotInstalled", "{0} is not installed", null, "OCR tools"); } - /** Create URL/website conversion exceptions. */ - public static IllegalArgumentException createInvalidUrlFormatException() { - return createIllegalArgumentException( - "error.invalidFormat", - "Invalid {0} format: {1}", - "URL", - "provided format is invalid"); - } - - public static IllegalArgumentException createUrlNotReachableException() { - return createIllegalArgumentException( - "error.urlNotReachable", "URL is not reachable, please provide a valid URL"); - } - - public static IllegalArgumentException createEndpointDisabledException() { - return createIllegalArgumentException( - "error.endpointDisabled", "This endpoint has been disabled by the admin"); - } - /** Create system requirement exceptions. */ - public static IOException createPythonNotInstalledException() { - return createIOException("error.toolNotInstalled", "{0} is not installed", null, "Python"); - } - public static IOException createPythonRequiredForWebpException() { return createIOException( "error.toolRequired", "{0} is required for {1}", null, "Python", "WebP conversion"); diff --git a/stirling-pdf/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertHtmlToPDF.java b/stirling-pdf/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertHtmlToPDF.java index 689c25909..9b3b64506 100644 --- a/stirling-pdf/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertHtmlToPDF.java +++ b/stirling-pdf/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertHtmlToPDF.java @@ -53,7 +53,8 @@ public class ConvertHtmlToPDF { String originalFilename = Filenames.toSimpleFileName(fileInput.getOriginalFilename()); if (originalFilename == null || (!originalFilename.endsWith(".html") && !originalFilename.endsWith(".zip"))) { - throw ExceptionUtils.createHtmlZipFormatException(); + throw ExceptionUtils.createIllegalArgumentException( + "error.fileFormatRequired", "File must be in {0} format", ".html or .zip"); } boolean disableSanitize = diff --git a/stirling-pdf/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertMarkdownToPdf.java b/stirling-pdf/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertMarkdownToPdf.java index 16b54749e..6cb22be7e 100644 --- a/stirling-pdf/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertMarkdownToPdf.java +++ b/stirling-pdf/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertMarkdownToPdf.java @@ -56,12 +56,14 @@ public class ConvertMarkdownToPdf { MultipartFile fileInput = generalFile.getFileInput(); if (fileInput == null) { - throw ExceptionUtils.createMarkdownFileRequiredException(); + throw ExceptionUtils.createIllegalArgumentException( + "error.fileFormatRequired", "File must be in {0} format", "Markdown"); } String originalFilename = Filenames.toSimpleFileName(fileInput.getOriginalFilename()); if (originalFilename == null || !originalFilename.endsWith(".md")) { - throw ExceptionUtils.createMarkdownFormatException(); + throw ExceptionUtils.createIllegalArgumentException( + "error.fileFormatRequired", "File must be in {0} format", ".md"); } // Convert Markdown to HTML using CommonMark diff --git a/stirling-pdf/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertWebsiteToPDF.java b/stirling-pdf/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertWebsiteToPDF.java index 294988bf1..a764256c8 100644 --- a/stirling-pdf/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertWebsiteToPDF.java +++ b/stirling-pdf/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertWebsiteToPDF.java @@ -51,16 +51,22 @@ public class ConvertWebsiteToPDF { String URL = request.getUrlInput(); if (!applicationProperties.getSystem().getEnableUrlToPDF()) { - throw ExceptionUtils.createEndpointDisabledException(); + throw ExceptionUtils.createIllegalArgumentException( + "error.endpointDisabled", "This endpoint has been disabled by the admin"); } // Validate the URL format if (!URL.matches("^https?://.*") || !GeneralUtils.isValidURL(URL)) { - throw ExceptionUtils.createInvalidUrlFormatException(); + throw ExceptionUtils.createIllegalArgumentException( + "error.invalidFormat", + "Invalid {0} format: {1}", + "URL", + "provided format is invalid"); } // validate the URL is reachable if (!GeneralUtils.isURLReachable(URL)) { - throw ExceptionUtils.createUrlNotReachableException(); + throw ExceptionUtils.createIllegalArgumentException( + "error.urlNotReachable", "URL is not reachable, please provide a valid URL"); } Path tempOutputFile = null; diff --git a/stirling-pdf/src/main/java/stirling/software/SPDF/controller/api/misc/ExtractImageScansController.java b/stirling-pdf/src/main/java/stirling/software/SPDF/controller/api/misc/ExtractImageScansController.java index 48789277d..7ecc04e1a 100644 --- a/stirling-pdf/src/main/java/stirling/software/SPDF/controller/api/misc/ExtractImageScansController.java +++ b/stirling-pdf/src/main/java/stirling/software/SPDF/controller/api/misc/ExtractImageScansController.java @@ -73,7 +73,8 @@ public class ExtractImageScansController { List tempDirs = new ArrayList<>(); if (!CheckProgramInstall.isPythonAvailable()) { - throw ExceptionUtils.createPythonNotInstalledException(); + throw ExceptionUtils.createIOException( + "error.toolNotInstalled", "{0} is not installed", null, "Python"); } String pythonVersion = CheckProgramInstall.getAvailablePythonCommand();