renamed GeneralUtil to GeneralUtils

This commit is contained in:
Dario Ghunney Ware 2025-05-22 12:31:25 +01:00
parent 969cd46772
commit 37c7373dc4
35 changed files with 252 additions and 259 deletions

View File

@ -1,44 +0,0 @@
package stirling.software.common.configuration;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.EncodedResource;
@Slf4j
@Configuration
public class YamlConfig {
@Bean
public PropertySource<?> dynamicYamlPropertySource(ConfigurableEnvironment environment)
throws IOException {
String configPath = InstallationPathConfig.getSettingsPath();
log.debug("Attempting to load settings from: " + configPath);
File file = new File(configPath);
if (!file.exists()) {
log.error("Warning: Settings file does not exist at: " + configPath);
}
Resource resource = new FileSystemResource(configPath);
if (!resource.exists()) {
throw new FileNotFoundException("Settings file not found at: " + configPath);
}
EncodedResource encodedResource = new EncodedResource(resource);
PropertySource<?> propertySource =
new YamlPropertySourceFactory().createPropertySource(null, encodedResource);
environment.getPropertySources().addFirst(propertySource);
log.debug("Loaded properties: " + propertySource.getSource());
return propertySource;
}
}

View File

@ -1,5 +1,7 @@
package stirling.software.common.model; package stirling.software.common.model;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
@ -14,21 +16,29 @@ import lombok.Data;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import stirling.software.common.configuration.InstallationPathConfig;
import stirling.software.common.configuration.YamlPropertySourceFactory;
import stirling.software.common.model.exception.UnsupportedProviderException; import stirling.software.common.model.exception.UnsupportedProviderException;
import stirling.software.common.model.oauth2.GitHubProvider; import stirling.software.common.model.oauth2.GitHubProvider;
import stirling.software.common.model.oauth2.GoogleProvider; import stirling.software.common.model.oauth2.GoogleProvider;
import stirling.software.common.model.oauth2.KeycloakProvider; import stirling.software.common.model.oauth2.KeycloakProvider;
import stirling.software.common.model.oauth2.Provider; import stirling.software.common.model.oauth2.Provider;
import stirling.software.common.util.ValidationUtil; import stirling.software.common.util.ValidationUtils;
@Data @Data
@Slf4j
@Component @Component
@Order(Ordered.HIGHEST_PRECEDENCE) @Order(Ordered.HIGHEST_PRECEDENCE)
@ConfigurationProperties(prefix = "") @ConfigurationProperties(prefix = "")
@ -49,6 +59,32 @@ public class ApplicationProperties {
private AutoPipeline autoPipeline = new AutoPipeline(); private AutoPipeline autoPipeline = new AutoPipeline();
private ProcessExecutor processExecutor = new ProcessExecutor(); private ProcessExecutor processExecutor = new ProcessExecutor();
@Bean
public PropertySource<?> dynamicYamlPropertySource(ConfigurableEnvironment environment)
throws IOException {
String configPath = InstallationPathConfig.getSettingsPath();
log.debug("Attempting to load settings from: " + configPath);
File file = new File(configPath);
if (!file.exists()) {
log.error("Warning: Settings file does not exist at: " + configPath);
}
Resource resource = new FileSystemResource(configPath);
if (!resource.exists()) {
throw new FileNotFoundException("Settings file not found at: " + configPath);
}
EncodedResource encodedResource = new EncodedResource(resource);
PropertySource<?> propertySource =
new YamlPropertySourceFactory().createPropertySource(null, encodedResource);
environment.getPropertySources().addFirst(propertySource);
log.debug("Loaded properties: " + propertySource.getSource());
return propertySource;
}
@Data @Data
public static class AutoPipeline { public static class AutoPipeline {
private String outputFolder; private String outputFolder;
@ -208,11 +244,11 @@ public class ApplicationProperties {
} }
public boolean isSettingsValid() { public boolean isSettingsValid() {
return !ValidationUtil.isStringEmpty(this.getIssuer()) return !ValidationUtils.isStringEmpty(this.getIssuer())
&& !ValidationUtil.isStringEmpty(this.getClientId()) && !ValidationUtils.isStringEmpty(this.getClientId())
&& !ValidationUtil.isStringEmpty(this.getClientSecret()) && !ValidationUtils.isStringEmpty(this.getClientSecret())
&& !ValidationUtil.isCollectionEmpty(this.getScopes()) && !ValidationUtils.isCollectionEmpty(this.getScopes())
&& !ValidationUtil.isStringEmpty(this.getUseAsUsername()); && !ValidationUtils.isStringEmpty(this.getUseAsUsername());
} }
@Data @Data

View File

@ -30,7 +30,7 @@ import lombok.extern.slf4j.Slf4j;
import stirling.software.common.configuration.InstallationPathConfig; import stirling.software.common.configuration.InstallationPathConfig;
@Slf4j @Slf4j
public class GeneralUtil { public class GeneralUtils {
public static File convertMultipartFileToFile(MultipartFile multipartFile) throws IOException { public static File convertMultipartFileToFile(MultipartFile multipartFile) throws IOException {
File tempFile = Files.createTempFile("temp", null).toFile(); File tempFile = Files.createTempFile("temp", null).toFile();

View File

@ -84,7 +84,7 @@ public class PdfUtils {
public static boolean hasImages(PDDocument document, String pagesToCheck) throws IOException { public static boolean hasImages(PDDocument document, String pagesToCheck) throws IOException {
String[] pageOrderArr = pagesToCheck.split(","); String[] pageOrderArr = pagesToCheck.split(",");
List<Integer> pageList = List<Integer> pageList =
GeneralUtil.parsePageList(pageOrderArr, document.getNumberOfPages()); GeneralUtils.parsePageList(pageOrderArr, document.getNumberOfPages());
for (int pageNumber : pageList) { for (int pageNumber : pageList) {
PDPage page = document.getPage(pageNumber); PDPage page = document.getPage(pageNumber);
@ -100,7 +100,7 @@ public class PdfUtils {
throws IOException { throws IOException {
String[] pageOrderArr = pageNumbersToCheck.split(","); String[] pageOrderArr = pageNumbersToCheck.split(",");
List<Integer> pageList = List<Integer> pageList =
GeneralUtil.parsePageList(pageOrderArr, document.getNumberOfPages()); GeneralUtils.parsePageList(pageOrderArr, document.getNumberOfPages());
for (int pageNumber : pageList) { for (int pageNumber : pageList) {
PDPage page = document.getPage(pageNumber); PDPage page = document.getPage(pageNumber);

View File

@ -1,10 +1,10 @@
package stirling.software.common.util; package stirling.software.common.util;
import stirling.software.common.model.oauth2.Provider; import stirling.software.common.model.oauth2.Provider;
import static stirling.software.common.util.ValidationUtil.isCollectionEmpty; import static stirling.software.common.util.ValidationUtils.isCollectionEmpty;
import static stirling.software.common.util.ValidationUtil.isStringEmpty; import static stirling.software.common.util.ValidationUtils.isStringEmpty;
public class ProviderUtil { public class ProviderUtils {
public static boolean validateProvider(Provider provider) { public static boolean validateProvider(Provider provider) {
if (provider == null) { if (provider == null) {

View File

@ -1,6 +1,6 @@
package stirling.software.common.util; package stirling.software.common.util;
public class RequestUriUtil { public class RequestUriUtils {
public static boolean isStaticResource(String requestURI) { public static boolean isStaticResource(String requestURI) {
return isStaticResource("", requestURI); return isStaticResource("", requestURI);

View File

@ -2,7 +2,7 @@ package stirling.software.common.util;
import java.util.Collection; import java.util.Collection;
public class ValidationUtil { public class ValidationUtils {
public static boolean isStringEmpty(String input) { public static boolean isStringEmpty(String input) {
return input == null || input.isBlank(); return input == null || input.isBlank();

View File

@ -1,41 +0,0 @@
package stirling.software.common.util;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class GeneralUtilAdditionalTest {
@Test
void testConvertSizeToBytes() {
assertEquals(1024L, GeneralUtil.convertSizeToBytes("1KB"));
assertEquals(1024L * 1024, GeneralUtil.convertSizeToBytes("1MB"));
assertEquals(1024L * 1024 * 1024, GeneralUtil.convertSizeToBytes("1GB"));
assertEquals(100L * 1024 * 1024, GeneralUtil.convertSizeToBytes("100"));
assertNull(GeneralUtil.convertSizeToBytes("invalid"));
assertNull(GeneralUtil.convertSizeToBytes(null));
}
@Test
void testFormatBytes() {
assertEquals("512 B", GeneralUtil.formatBytes(512));
assertEquals("1.00 KB", GeneralUtil.formatBytes(1024));
assertEquals("1.00 MB", GeneralUtil.formatBytes(1024L * 1024));
assertEquals("1.00 GB", GeneralUtil.formatBytes(1024L * 1024 * 1024));
}
@Test
void testURLHelpersAndUUID() {
assertTrue(GeneralUtil.isValidURL("https://example.com"));
assertFalse(GeneralUtil.isValidURL("htp:/bad"));
assertFalse(GeneralUtil.isURLReachable("http://localhost"));
assertFalse(GeneralUtil.isURLReachable("ftp://example.com"));
assertTrue(GeneralUtil.isValidUUID("123e4567-e89b-12d3-a456-426614174000"));
assertFalse(GeneralUtil.isValidUUID("not-a-uuid"));
assertFalse(GeneralUtil.isVersionHigher(null, "1.0"));
assertTrue(GeneralUtil.isVersionHigher("2.0", "1.9"));
assertFalse(GeneralUtil.isVersionHigher("1.0", "1.0.1"));
}
}

View File

@ -0,0 +1,41 @@
package stirling.software.common.util;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class GeneralUtilsAdditionalTest {
@Test
void testConvertSizeToBytes() {
assertEquals(1024L, GeneralUtils.convertSizeToBytes("1KB"));
assertEquals(1024L * 1024, GeneralUtils.convertSizeToBytes("1MB"));
assertEquals(1024L * 1024 * 1024, GeneralUtils.convertSizeToBytes("1GB"));
assertEquals(100L * 1024 * 1024, GeneralUtils.convertSizeToBytes("100"));
assertNull(GeneralUtils.convertSizeToBytes("invalid"));
assertNull(GeneralUtils.convertSizeToBytes(null));
}
@Test
void testFormatBytes() {
assertEquals("512 B", GeneralUtils.formatBytes(512));
assertEquals("1.00 KB", GeneralUtils.formatBytes(1024));
assertEquals("1.00 MB", GeneralUtils.formatBytes(1024L * 1024));
assertEquals("1.00 GB", GeneralUtils.formatBytes(1024L * 1024 * 1024));
}
@Test
void testURLHelpersAndUUID() {
assertTrue(GeneralUtils.isValidURL("https://example.com"));
assertFalse(GeneralUtils.isValidURL("htp:/bad"));
assertFalse(GeneralUtils.isURLReachable("http://localhost"));
assertFalse(GeneralUtils.isURLReachable("ftp://example.com"));
assertTrue(GeneralUtils.isValidUUID("123e4567-e89b-12d3-a456-426614174000"));
assertFalse(GeneralUtils.isValidUUID("not-a-uuid"));
assertFalse(GeneralUtils.isVersionHigher(null, "1.0"));
assertTrue(GeneralUtils.isVersionHigher("2.0", "1.9"));
assertFalse(GeneralUtils.isVersionHigher("1.0", "1.0.1"));
}
}

View File

@ -6,152 +6,152 @@ import java.util.List;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
public class GeneralUtilTest { public class GeneralUtilsTest {
@Test @Test
void testParsePageListWithAll() { void testParsePageListWithAll() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"all"}, 5, false); List<Integer> result = GeneralUtils.parsePageList(new String[] {"all"}, 5, false);
assertEquals(List.of(0, 1, 2, 3, 4), result, "'All' keyword should return all pages."); assertEquals(List.of(0, 1, 2, 3, 4), result, "'All' keyword should return all pages.");
} }
@Test @Test
void testParsePageListWithAllOneBased() { void testParsePageListWithAllOneBased() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"all"}, 5, true); List<Integer> result = GeneralUtils.parsePageList(new String[] {"all"}, 5, true);
assertEquals(List.of(1, 2, 3, 4, 5), result, "'All' keyword should return all pages."); assertEquals(List.of(1, 2, 3, 4, 5), result, "'All' keyword should return all pages.");
} }
@Test @Test
void nFunc() { void nFunc() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"n"}, 5, true); List<Integer> result = GeneralUtils.parsePageList(new String[] {"n"}, 5, true);
assertEquals(List.of(1, 2, 3, 4, 5), result, "'n' keyword should return all pages."); assertEquals(List.of(1, 2, 3, 4, 5), result, "'n' keyword should return all pages.");
} }
@Test @Test
void nFuncAdvanced() { void nFuncAdvanced() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"4n"}, 9, true); List<Integer> result = GeneralUtils.parsePageList(new String[] {"4n"}, 9, true);
// skip 0 as not valid // skip 0 as not valid
assertEquals(List.of(4, 8), result, "'All' keyword should return all pages."); assertEquals(List.of(4, 8), result, "'All' keyword should return all pages.");
} }
@Test @Test
void nFuncAdvancedZero() { void nFuncAdvancedZero() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"4n"}, 9, false); List<Integer> result = GeneralUtils.parsePageList(new String[] {"4n"}, 9, false);
// skip 0 as not valid // skip 0 as not valid
assertEquals(List.of(3, 7), result, "'All' keyword should return all pages."); assertEquals(List.of(3, 7), result, "'All' keyword should return all pages.");
} }
@Test @Test
void nFuncAdvanced2() { void nFuncAdvanced2() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"4n-1"}, 9, true); List<Integer> result = GeneralUtils.parsePageList(new String[] {"4n-1"}, 9, true);
// skip -1 as not valid // skip -1 as not valid
assertEquals(List.of(3, 7), result, "4n-1 should do (0-1), (4-1), (8-1)"); assertEquals(List.of(3, 7), result, "4n-1 should do (0-1), (4-1), (8-1)");
} }
@Test @Test
void nFuncAdvanced3() { void nFuncAdvanced3() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"4n+1"}, 9, true); List<Integer> result = GeneralUtils.parsePageList(new String[] {"4n+1"}, 9, true);
assertEquals(List.of(5, 9), result, "'All' keyword should return all pages."); assertEquals(List.of(5, 9), result, "'All' keyword should return all pages.");
} }
@Test @Test
void nFunc_spaces() { void nFunc_spaces() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"n + 1"}, 9, true); List<Integer> result = GeneralUtils.parsePageList(new String[] {"n + 1"}, 9, true);
assertEquals(List.of(2, 3, 4, 5, 6, 7, 8, 9), result); assertEquals(List.of(2, 3, 4, 5, 6, 7, 8, 9), result);
} }
@Test @Test
void nFunc_consecutive_Ns_nnn() { void nFunc_consecutive_Ns_nnn() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"nnn"}, 9, true); List<Integer> result = GeneralUtils.parsePageList(new String[] {"nnn"}, 9, true);
assertEquals(List.of(1, 8), result); assertEquals(List.of(1, 8), result);
} }
@Test @Test
void nFunc_consecutive_Ns_nn() { void nFunc_consecutive_Ns_nn() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"nn"}, 9, true); List<Integer> result = GeneralUtils.parsePageList(new String[] {"nn"}, 9, true);
assertEquals(List.of(1, 4, 9), result); assertEquals(List.of(1, 4, 9), result);
} }
@Test @Test
void nFunc_opening_closing_round_brackets() { void nFunc_opening_closing_round_brackets() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"(n-1)(n-2)"}, 9, true); List<Integer> result = GeneralUtils.parsePageList(new String[] {"(n-1)(n-2)"}, 9, true);
assertEquals(List.of(2, 6), result); assertEquals(List.of(2, 6), result);
} }
@Test @Test
void nFunc_opening_round_brackets() { void nFunc_opening_round_brackets() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"2(n-1)"}, 9, true); List<Integer> result = GeneralUtils.parsePageList(new String[] {"2(n-1)"}, 9, true);
assertEquals(List.of(2, 4, 6, 8), result); assertEquals(List.of(2, 4, 6, 8), result);
} }
@Test @Test
void nFunc_opening_round_brackets_n() { void nFunc_opening_round_brackets_n() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"n(n-1)"}, 9, true); List<Integer> result = GeneralUtils.parsePageList(new String[] {"n(n-1)"}, 9, true);
assertEquals(List.of(2, 6), result); assertEquals(List.of(2, 6), result);
} }
@Test @Test
void nFunc_closing_round_brackets() { void nFunc_closing_round_brackets() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"(n-1)2"}, 9, true); List<Integer> result = GeneralUtils.parsePageList(new String[] {"(n-1)2"}, 9, true);
assertEquals(List.of(2, 4, 6, 8), result); assertEquals(List.of(2, 4, 6, 8), result);
} }
@Test @Test
void nFunc_closing_round_brackets_n() { void nFunc_closing_round_brackets_n() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"(n-1)n"}, 9, true); List<Integer> result = GeneralUtils.parsePageList(new String[] {"(n-1)n"}, 9, true);
assertEquals(List.of(2, 6), result); assertEquals(List.of(2, 6), result);
} }
@Test @Test
void nFunc_function_surrounded_with_brackets() { void nFunc_function_surrounded_with_brackets() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"(n-1)"}, 9, true); List<Integer> result = GeneralUtils.parsePageList(new String[] {"(n-1)"}, 9, true);
assertEquals(List.of(1, 2, 3, 4, 5, 6, 7, 8), result); assertEquals(List.of(1, 2, 3, 4, 5, 6, 7, 8), result);
} }
@Test @Test
void nFuncAdvanced4() { void nFuncAdvanced4() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"3+2n"}, 9, true); List<Integer> result = GeneralUtils.parsePageList(new String[] {"3+2n"}, 9, true);
assertEquals(List.of(5, 7, 9), result, "'All' keyword should return all pages."); assertEquals(List.of(5, 7, 9), result, "'All' keyword should return all pages.");
} }
@Test @Test
void nFuncAdvancedZerobased() { void nFuncAdvancedZerobased() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"4n"}, 9, false); List<Integer> result = GeneralUtils.parsePageList(new String[] {"4n"}, 9, false);
assertEquals(List.of(3, 7), result, "'All' keyword should return all pages."); assertEquals(List.of(3, 7), result, "'All' keyword should return all pages.");
} }
@Test @Test
void nFuncAdvanced2Zerobased() { void nFuncAdvanced2Zerobased() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"4n-1"}, 9, false); List<Integer> result = GeneralUtils.parsePageList(new String[] {"4n-1"}, 9, false);
assertEquals(List.of(2, 6), result, "'All' keyword should return all pages."); assertEquals(List.of(2, 6), result, "'All' keyword should return all pages.");
} }
@Test @Test
void testParsePageListWithRangeOneBasedOutput() { void testParsePageListWithRangeOneBasedOutput() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"1-3"}, 5, true); List<Integer> result = GeneralUtils.parsePageList(new String[] {"1-3"}, 5, true);
assertEquals(List.of(1, 2, 3), result, "Range should be parsed correctly."); assertEquals(List.of(1, 2, 3), result, "Range should be parsed correctly.");
} }
@Test @Test
void testParsePageListWithRangeZeroBaseOutput() { void testParsePageListWithRangeZeroBaseOutput() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"1-3"}, 5, false); List<Integer> result = GeneralUtils.parsePageList(new String[] {"1-3"}, 5, false);
assertEquals(List.of(0, 1, 2), result, "Range should be parsed correctly."); assertEquals(List.of(0, 1, 2), result, "Range should be parsed correctly.");
} }
@Test @Test
void testParsePageListWithRangeOneBasedOutputFull() { void testParsePageListWithRangeOneBasedOutputFull() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"1,3,7-8"}, 8, true); List<Integer> result = GeneralUtils.parsePageList(new String[] {"1,3,7-8"}, 8, true);
assertEquals(List.of(1, 3, 7, 8), result, "Range should be parsed correctly."); assertEquals(List.of(1, 3, 7, 8), result, "Range should be parsed correctly.");
} }
@Test @Test
void testParsePageListWithRangeOneBasedOutputFullOutOfRange() { void testParsePageListWithRangeOneBasedOutputFullOutOfRange() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"1,3,7-8"}, 5, true); List<Integer> result = GeneralUtils.parsePageList(new String[] {"1,3,7-8"}, 5, true);
assertEquals(List.of(1, 3), result, "Range should be parsed correctly."); assertEquals(List.of(1, 3), result, "Range should be parsed correctly.");
} }
@Test @Test
void testParsePageListWithRangeZeroBaseOutputFull() { void testParsePageListWithRangeZeroBaseOutputFull() {
List<Integer> result = GeneralUtil.parsePageList(new String[] {"1,3,7-8"}, 8, false); List<Integer> result = GeneralUtils.parsePageList(new String[] {"1,3,7-8"}, 8, false);
assertEquals(List.of(0, 2, 6, 7), result, "Range should be parsed correctly."); assertEquals(List.of(0, 2, 6, 7), result, "Range should be parsed correctly.");
} }
} }

View File

@ -16,7 +16,7 @@ import stirling.software.common.model.oauth2.Provider;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
class ProviderUtilTest { class ProviderUtilsTest {
@Test @Test
void testSuccessfulValidation() { void testSuccessfulValidation() {
@ -26,13 +26,13 @@ class ProviderUtilTest {
when(provider.getClientSecret()).thenReturn("clientSecret"); when(provider.getClientSecret()).thenReturn("clientSecret");
when(provider.getScopes()).thenReturn(List.of("read:user")); when(provider.getScopes()).thenReturn(List.of("read:user"));
Assertions.assertTrue(ProviderUtil.validateProvider(provider)); Assertions.assertTrue(ProviderUtils.validateProvider(provider));
} }
@ParameterizedTest @ParameterizedTest
@MethodSource("providerParams") @MethodSource("providerParams")
void testUnsuccessfulValidation(Provider provider) { void testUnsuccessfulValidation(Provider provider) {
Assertions.assertFalse(ProviderUtil.validateProvider(provider)); Assertions.assertFalse(ProviderUtils.validateProvider(provider));
} }
public static Stream<Arguments> providerParams() { public static Stream<Arguments> providerParams() {

View File

@ -7,45 +7,45 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource; import org.junit.jupiter.params.provider.ValueSource;
public class RequestUriUtilTest { public class RequestUriUtilsTest {
@Test @Test
void testIsStaticResource() { void testIsStaticResource() {
// Test static resources without context path // Test static resources without context path
assertTrue( assertTrue(
RequestUriUtil.isStaticResource("/css/styles.css"), "CSS files should be static"); RequestUriUtils.isStaticResource("/css/styles.css"), "CSS files should be static");
assertTrue(RequestUriUtil.isStaticResource("/js/script.js"), "JS files should be static"); assertTrue(RequestUriUtils.isStaticResource("/js/script.js"), "JS files should be static");
assertTrue( assertTrue(
RequestUriUtil.isStaticResource("/images/logo.png"), RequestUriUtils.isStaticResource("/images/logo.png"),
"Image files should be static"); "Image files should be static");
assertTrue( assertTrue(
RequestUriUtil.isStaticResource("/public/index.html"), RequestUriUtils.isStaticResource("/public/index.html"),
"Public files should be static"); "Public files should be static");
assertTrue( assertTrue(
RequestUriUtil.isStaticResource("/pdfjs/pdf.worker.js"), RequestUriUtils.isStaticResource("/pdfjs/pdf.worker.js"),
"PDF.js files should be static"); "PDF.js files should be static");
assertTrue( assertTrue(
RequestUriUtil.isStaticResource("/api/v1/info/status"), RequestUriUtils.isStaticResource("/api/v1/info/status"),
"API status should be static"); "API status should be static");
assertTrue( assertTrue(
RequestUriUtil.isStaticResource("/some-path/icon.svg"), RequestUriUtils.isStaticResource("/some-path/icon.svg"),
"SVG files should be static"); "SVG files should be static");
assertTrue(RequestUriUtil.isStaticResource("/login"), "Login page should be static"); assertTrue(RequestUriUtils.isStaticResource("/login"), "Login page should be static");
assertTrue(RequestUriUtil.isStaticResource("/error"), "Error page should be static"); assertTrue(RequestUriUtils.isStaticResource("/error"), "Error page should be static");
// Test non-static resources // Test non-static resources
assertFalse( assertFalse(
RequestUriUtil.isStaticResource("/api/v1/users"), RequestUriUtils.isStaticResource("/api/v1/users"),
"API users should not be static"); "API users should not be static");
assertFalse( assertFalse(
RequestUriUtil.isStaticResource("/api/v1/orders"), RequestUriUtils.isStaticResource("/api/v1/orders"),
"API orders should not be static"); "API orders should not be static");
assertFalse(RequestUriUtil.isStaticResource("/"), "Root path should not be static"); assertFalse(RequestUriUtils.isStaticResource("/"), "Root path should not be static");
assertFalse( assertFalse(
RequestUriUtil.isStaticResource("/register"), RequestUriUtils.isStaticResource("/register"),
"Register page should not be static"); "Register page should not be static");
assertFalse( assertFalse(
RequestUriUtil.isStaticResource("/api/v1/products"), RequestUriUtils.isStaticResource("/api/v1/products"),
"API products should not be static"); "API products should not be static");
} }
@ -55,24 +55,24 @@ public class RequestUriUtilTest {
// Test static resources with context path // Test static resources with context path
assertTrue( assertTrue(
RequestUriUtil.isStaticResource(contextPath, contextPath + "/css/styles.css"), RequestUriUtils.isStaticResource(contextPath, contextPath + "/css/styles.css"),
"CSS with context path should be static"); "CSS with context path should be static");
assertTrue( assertTrue(
RequestUriUtil.isStaticResource(contextPath, contextPath + "/js/script.js"), RequestUriUtils.isStaticResource(contextPath, contextPath + "/js/script.js"),
"JS with context path should be static"); "JS with context path should be static");
assertTrue( assertTrue(
RequestUriUtil.isStaticResource(contextPath, contextPath + "/images/logo.png"), RequestUriUtils.isStaticResource(contextPath, contextPath + "/images/logo.png"),
"Images with context path should be static"); "Images with context path should be static");
assertTrue( assertTrue(
RequestUriUtil.isStaticResource(contextPath, contextPath + "/login"), RequestUriUtils.isStaticResource(contextPath, contextPath + "/login"),
"Login with context path should be static"); "Login with context path should be static");
// Test non-static resources with context path // Test non-static resources with context path
assertFalse( assertFalse(
RequestUriUtil.isStaticResource(contextPath, contextPath + "/api/v1/users"), RequestUriUtils.isStaticResource(contextPath, contextPath + "/api/v1/users"),
"API users with context path should not be static"); "API users with context path should not be static");
assertFalse( assertFalse(
RequestUriUtil.isStaticResource(contextPath, "/"), RequestUriUtils.isStaticResource(contextPath, "/"),
"Root path with context path should not be static"); "Root path with context path should not be static");
} }
@ -92,7 +92,7 @@ public class RequestUriUtilTest {
}) })
void testIsStaticResourceWithFileExtensions(String path) { void testIsStaticResourceWithFileExtensions(String path) {
assertTrue( assertTrue(
RequestUriUtil.isStaticResource(path), RequestUriUtils.isStaticResource(path),
"Files with specific extensions should be static regardless of path"); "Files with specific extensions should be static regardless of path");
} }
@ -100,59 +100,59 @@ public class RequestUriUtilTest {
void testIsTrackableResource() { void testIsTrackableResource() {
// Test non-trackable resources (returns false) // Test non-trackable resources (returns false)
assertFalse( assertFalse(
RequestUriUtil.isTrackableResource("/js/script.js"), RequestUriUtils.isTrackableResource("/js/script.js"),
"JS files should not be trackable"); "JS files should not be trackable");
assertFalse( assertFalse(
RequestUriUtil.isTrackableResource("/v1/api-docs"), RequestUriUtils.isTrackableResource("/v1/api-docs"),
"API docs should not be trackable"); "API docs should not be trackable");
assertFalse( assertFalse(
RequestUriUtil.isTrackableResource("robots.txt"), RequestUriUtils.isTrackableResource("robots.txt"),
"robots.txt should not be trackable"); "robots.txt should not be trackable");
assertFalse( assertFalse(
RequestUriUtil.isTrackableResource("/images/logo.png"), RequestUriUtils.isTrackableResource("/images/logo.png"),
"Images should not be trackable"); "Images should not be trackable");
assertFalse( assertFalse(
RequestUriUtil.isTrackableResource("/styles.css"), RequestUriUtils.isTrackableResource("/styles.css"),
"CSS files should not be trackable"); "CSS files should not be trackable");
assertFalse( assertFalse(
RequestUriUtil.isTrackableResource("/script.js.map"), RequestUriUtils.isTrackableResource("/script.js.map"),
"Map files should not be trackable"); "Map files should not be trackable");
assertFalse( assertFalse(
RequestUriUtil.isTrackableResource("/icon.svg"), RequestUriUtils.isTrackableResource("/icon.svg"),
"SVG files should not be trackable"); "SVG files should not be trackable");
assertFalse( assertFalse(
RequestUriUtil.isTrackableResource("/popularity.txt"), RequestUriUtils.isTrackableResource("/popularity.txt"),
"Popularity file should not be trackable"); "Popularity file should not be trackable");
assertFalse( assertFalse(
RequestUriUtil.isTrackableResource("/script.js"), RequestUriUtils.isTrackableResource("/script.js"),
"JS files should not be trackable"); "JS files should not be trackable");
assertFalse( assertFalse(
RequestUriUtil.isTrackableResource("/swagger/index.html"), RequestUriUtils.isTrackableResource("/swagger/index.html"),
"Swagger files should not be trackable"); "Swagger files should not be trackable");
assertFalse( assertFalse(
RequestUriUtil.isTrackableResource("/api/v1/info/status"), RequestUriUtils.isTrackableResource("/api/v1/info/status"),
"API info should not be trackable"); "API info should not be trackable");
assertFalse( assertFalse(
RequestUriUtil.isTrackableResource("/site.webmanifest"), RequestUriUtils.isTrackableResource("/site.webmanifest"),
"Webmanifest should not be trackable"); "Webmanifest should not be trackable");
assertFalse( assertFalse(
RequestUriUtil.isTrackableResource("/fonts/font.woff"), RequestUriUtils.isTrackableResource("/fonts/font.woff"),
"Fonts should not be trackable"); "Fonts should not be trackable");
assertFalse( assertFalse(
RequestUriUtil.isTrackableResource("/pdfjs/viewer.js"), RequestUriUtils.isTrackableResource("/pdfjs/viewer.js"),
"PDF.js files should not be trackable"); "PDF.js files should not be trackable");
// Test trackable resources (returns true) // Test trackable resources (returns true)
assertTrue(RequestUriUtil.isTrackableResource("/login"), "Login page should be trackable"); assertTrue(RequestUriUtils.isTrackableResource("/login"), "Login page should be trackable");
assertTrue( assertTrue(
RequestUriUtil.isTrackableResource("/register"), RequestUriUtils.isTrackableResource("/register"),
"Register page should be trackable"); "Register page should be trackable");
assertTrue( assertTrue(
RequestUriUtil.isTrackableResource("/api/v1/users"), RequestUriUtils.isTrackableResource("/api/v1/users"),
"API users should be trackable"); "API users should be trackable");
assertTrue(RequestUriUtil.isTrackableResource("/"), "Root path should be trackable"); assertTrue(RequestUriUtils.isTrackableResource("/"), "Root path should be trackable");
assertTrue( assertTrue(
RequestUriUtil.isTrackableResource("/some-other-path"), RequestUriUtils.isTrackableResource("/some-other-path"),
"Other paths should be trackable"); "Other paths should be trackable");
} }
@ -162,27 +162,27 @@ public class RequestUriUtilTest {
// Test with context path // Test with context path
assertFalse( assertFalse(
RequestUriUtil.isTrackableResource(contextPath, "/js/script.js"), RequestUriUtils.isTrackableResource(contextPath, "/js/script.js"),
"JS files should not be trackable with context path"); "JS files should not be trackable with context path");
assertTrue( assertTrue(
RequestUriUtil.isTrackableResource(contextPath, "/login"), RequestUriUtils.isTrackableResource(contextPath, "/login"),
"Login page should be trackable with context path"); "Login page should be trackable with context path");
// Additional tests with context path // Additional tests with context path
assertFalse( assertFalse(
RequestUriUtil.isTrackableResource(contextPath, "/fonts/custom.woff"), RequestUriUtils.isTrackableResource(contextPath, "/fonts/custom.woff"),
"Font files should not be trackable with context path"); "Font files should not be trackable with context path");
assertFalse( assertFalse(
RequestUriUtil.isTrackableResource(contextPath, "/images/header.png"), RequestUriUtils.isTrackableResource(contextPath, "/images/header.png"),
"Images should not be trackable with context path"); "Images should not be trackable with context path");
assertFalse( assertFalse(
RequestUriUtil.isTrackableResource(contextPath, "/swagger/ui.html"), RequestUriUtils.isTrackableResource(contextPath, "/swagger/ui.html"),
"Swagger UI should not be trackable with context path"); "Swagger UI should not be trackable with context path");
assertTrue( assertTrue(
RequestUriUtil.isTrackableResource(contextPath, "/account/profile"), RequestUriUtils.isTrackableResource(contextPath, "/account/profile"),
"Account page should be trackable with context path"); "Account page should be trackable with context path");
assertTrue( assertTrue(
RequestUriUtil.isTrackableResource(contextPath, "/pdf/view"), RequestUriUtils.isTrackableResource(contextPath, "/pdf/view"),
"PDF view page should be trackable with context path"); "PDF view page should be trackable with context path");
} }
@ -206,7 +206,7 @@ public class RequestUriUtilTest {
}) })
void testNonTrackableResources(String path) { void testNonTrackableResources(String path) {
assertFalse( assertFalse(
RequestUriUtil.isTrackableResource(path), RequestUriUtils.isTrackableResource(path),
"Resources matching patterns should not be trackable: " + path); "Resources matching patterns should not be trackable: " + path);
} }
@ -229,22 +229,22 @@ public class RequestUriUtilTest {
}) })
void testTrackableResources(String path) { void testTrackableResources(String path) {
assertTrue( assertTrue(
RequestUriUtil.isTrackableResource(path), RequestUriUtils.isTrackableResource(path),
"App routes should be trackable: " + path); "App routes should be trackable: " + path);
} }
@Test @Test
void testEdgeCases() { void testEdgeCases() {
// Test with empty strings // Test with empty strings
assertFalse(RequestUriUtil.isStaticResource("", ""), "Empty path should not be static"); assertFalse(RequestUriUtils.isStaticResource("", ""), "Empty path should not be static");
assertTrue(RequestUriUtil.isTrackableResource("", ""), "Empty path should be trackable"); assertTrue(RequestUriUtils.isTrackableResource("", ""), "Empty path should be trackable");
// Test with null-like behavior (would actually throw NPE in real code) // Test with null-like behavior (would actually throw NPE in real code)
// These are not actual null tests but shows handling of odd cases // These are not actual null tests but shows handling of odd cases
assertFalse(RequestUriUtil.isStaticResource("null"), "String 'null' should not be static"); assertFalse(RequestUriUtils.isStaticResource("null"), "String 'null' should not be static");
// Test String "null" as a path // Test String "null" as a path
boolean isTrackable = RequestUriUtil.isTrackableResource("null"); boolean isTrackable = RequestUriUtils.isTrackableResource("null");
assertTrue(isTrackable, "String 'null' should be trackable"); assertTrue(isTrackable, "String 'null' should be trackable");
// Mixed case extensions test - note that Java's endsWith() is case-sensitive // Mixed case extensions test - note that Java's endsWith() is case-sensitive
@ -252,31 +252,31 @@ public class RequestUriUtilTest {
// Always test the lowercase versions which should definitely work // Always test the lowercase versions which should definitely work
assertTrue( assertTrue(
RequestUriUtil.isStaticResource("/logo.png"), "PNG (lowercase) should be static"); RequestUriUtils.isStaticResource("/logo.png"), "PNG (lowercase) should be static");
assertTrue( assertTrue(
RequestUriUtil.isStaticResource("/icon.svg"), "SVG (lowercase) should be static"); RequestUriUtils.isStaticResource("/icon.svg"), "SVG (lowercase) should be static");
// Path with query parameters // Path with query parameters
assertFalse( assertFalse(
RequestUriUtil.isStaticResource("/api/users?page=1"), RequestUriUtils.isStaticResource("/api/users?page=1"),
"Path with query params should respect base path"); "Path with query params should respect base path");
assertTrue( assertTrue(
RequestUriUtil.isStaticResource("/images/logo.png?v=123"), RequestUriUtils.isStaticResource("/images/logo.png?v=123"),
"Static resource with query params should still be static"); "Static resource with query params should still be static");
// Paths with fragments // Paths with fragments
assertTrue( assertTrue(
RequestUriUtil.isStaticResource("/css/styles.css#section1"), RequestUriUtils.isStaticResource("/css/styles.css#section1"),
"CSS with fragment should be static"); "CSS with fragment should be static");
// Multiple dots in filename // Multiple dots in filename
assertTrue( assertTrue(
RequestUriUtil.isStaticResource("/js/jquery.min.js"), RequestUriUtils.isStaticResource("/js/jquery.min.js"),
"JS with multiple dots should be static"); "JS with multiple dots should be static");
// Special characters in path // Special characters in path
assertTrue( assertTrue(
RequestUriUtil.isStaticResource("/images/user's-photo.png"), RequestUriUtils.isStaticResource("/images/user's-photo.png"),
"Path with special chars should be handled correctly"); "Path with special chars should be handled correctly");
} }
@ -284,28 +284,28 @@ public class RequestUriUtilTest {
void testComplexPaths() { void testComplexPaths() {
// Test complex static resource paths // Test complex static resource paths
assertTrue( assertTrue(
RequestUriUtil.isStaticResource("/css/theme/dark/styles.css"), RequestUriUtils.isStaticResource("/css/theme/dark/styles.css"),
"Nested CSS should be static"); "Nested CSS should be static");
assertTrue( assertTrue(
RequestUriUtil.isStaticResource("/fonts/open-sans/bold/font.woff"), RequestUriUtils.isStaticResource("/fonts/open-sans/bold/font.woff"),
"Nested font should be static"); "Nested font should be static");
assertTrue( assertTrue(
RequestUriUtil.isStaticResource("/js/vendor/jquery/3.5.1/jquery.min.js"), RequestUriUtils.isStaticResource("/js/vendor/jquery/3.5.1/jquery.min.js"),
"Versioned JS should be static"); "Versioned JS should be static");
// Test complex paths with context // Test complex paths with context
String contextPath = "/app"; String contextPath = "/app";
assertTrue( assertTrue(
RequestUriUtil.isStaticResource( RequestUriUtils.isStaticResource(
contextPath, contextPath + "/css/theme/dark/styles.css"), contextPath, contextPath + "/css/theme/dark/styles.css"),
"Nested CSS with context should be static"); "Nested CSS with context should be static");
// Test boundary cases for isTrackableResource // Test boundary cases for isTrackableResource
assertFalse( assertFalse(
RequestUriUtil.isTrackableResource("/js-framework/components"), RequestUriUtils.isTrackableResource("/js-framework/components"),
"Path starting with js- should not be treated as JS resource"); "Path starting with js- should not be treated as JS resource");
assertFalse( assertFalse(
RequestUriUtil.isTrackableResource("/fonts-selection"), RequestUriUtils.isTrackableResource("/fonts-selection"),
"Path starting with fonts- should not be treated as font resource"); "Path starting with fonts- should not be treated as font resource");
} }
} }

View File

@ -20,7 +20,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import stirling.software.common.model.ApplicationProperties; import stirling.software.common.model.ApplicationProperties;
import stirling.software.common.util.GeneralUtil; import stirling.software.common.util.GeneralUtils;
@Service @Service
@Slf4j @Slf4j
@ -765,7 +765,7 @@ public class KeygenLicenseVerifier {
} }
private String generateMachineFingerprint() { private String generateMachineFingerprint() {
return GeneralUtil.generateMachineFingerprint(); return GeneralUtils.generateMachineFingerprint();
} }
/** /**

View File

@ -12,7 +12,7 @@ import lombok.extern.slf4j.Slf4j;
import stirling.software.SPDF.EE.KeygenLicenseVerifier.License; import stirling.software.SPDF.EE.KeygenLicenseVerifier.License;
import stirling.software.common.model.ApplicationProperties; import stirling.software.common.model.ApplicationProperties;
import stirling.software.common.util.GeneralUtil; import stirling.software.common.util.GeneralUtils;
@Component @Component
@Slf4j @Slf4j
@ -88,7 +88,7 @@ public class LicenseKeyChecker {
public void updateLicenseKey(String newKey) throws IOException { public void updateLicenseKey(String newKey) throws IOException {
applicationProperties.getPremium().setKey(newKey); applicationProperties.getPremium().setKey(newKey);
GeneralUtil.saveKeyToSettings("EnterpriseEdition.key", newKey); GeneralUtils.saveKeyToSettings("EnterpriseEdition.key", newKey);
checkLicense(); checkLicense();
} }

View File

@ -18,7 +18,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import stirling.software.common.model.ApplicationProperties; import stirling.software.common.model.ApplicationProperties;
import stirling.software.common.util.GeneralUtil; import stirling.software.common.util.GeneralUtils;
@Component @Component
@Slf4j @Slf4j
@ -39,31 +39,31 @@ public class InitialSetup {
public void initUUIDKey() throws IOException { public void initUUIDKey() throws IOException {
String uuid = applicationProperties.getAutomaticallyGenerated().getUUID(); String uuid = applicationProperties.getAutomaticallyGenerated().getUUID();
if (!GeneralUtil.isValidUUID(uuid)) { if (!GeneralUtils.isValidUUID(uuid)) {
// Generating a random UUID as the secret key // Generating a random UUID as the secret key
uuid = UUID.randomUUID().toString(); uuid = UUID.randomUUID().toString();
GeneralUtil.saveKeyToSettings("AutomaticallyGenerated.UUID", uuid); GeneralUtils.saveKeyToSettings("AutomaticallyGenerated.UUID", uuid);
applicationProperties.getAutomaticallyGenerated().setUUID(uuid); applicationProperties.getAutomaticallyGenerated().setUUID(uuid);
} }
} }
public void initSecretKey() throws IOException { public void initSecretKey() throws IOException {
String secretKey = applicationProperties.getAutomaticallyGenerated().getKey(); String secretKey = applicationProperties.getAutomaticallyGenerated().getKey();
if (!GeneralUtil.isValidUUID(secretKey)) { if (!GeneralUtils.isValidUUID(secretKey)) {
// Generating a random UUID as the secret key // Generating a random UUID as the secret key
secretKey = UUID.randomUUID().toString(); secretKey = UUID.randomUUID().toString();
GeneralUtil.saveKeyToSettings("AutomaticallyGenerated.key", secretKey); GeneralUtils.saveKeyToSettings("AutomaticallyGenerated.key", secretKey);
applicationProperties.getAutomaticallyGenerated().setKey(secretKey); applicationProperties.getAutomaticallyGenerated().setKey(secretKey);
} }
} }
public void initEnableCSRFSecurity() throws IOException { public void initEnableCSRFSecurity() throws IOException {
if (GeneralUtil.isVersionHigher( if (GeneralUtils.isVersionHigher(
"0.36.0", applicationProperties.getAutomaticallyGenerated().getAppVersion())) { "0.36.0", applicationProperties.getAutomaticallyGenerated().getAppVersion())) {
Boolean csrf = applicationProperties.getSecurity().getCsrfDisabled(); Boolean csrf = applicationProperties.getSecurity().getCsrfDisabled();
if (!csrf) { if (!csrf) {
GeneralUtil.saveKeyToSettings("security.csrfDisabled", false); GeneralUtils.saveKeyToSettings("security.csrfDisabled", false);
GeneralUtil.saveKeyToSettings("system.enableAnalytics", true); GeneralUtils.saveKeyToSettings("system.enableAnalytics", true);
applicationProperties.getSecurity().setCsrfDisabled(false); applicationProperties.getSecurity().setCsrfDisabled(false);
} }
} }
@ -74,14 +74,14 @@ public class InitialSetup {
String termsUrl = applicationProperties.getLegal().getTermsAndConditions(); String termsUrl = applicationProperties.getLegal().getTermsAndConditions();
if (StringUtils.isEmpty(termsUrl)) { if (StringUtils.isEmpty(termsUrl)) {
String defaultTermsUrl = "https://www.stirlingpdf.com/terms"; String defaultTermsUrl = "https://www.stirlingpdf.com/terms";
GeneralUtil.saveKeyToSettings("legal.termsAndConditions", defaultTermsUrl); GeneralUtils.saveKeyToSettings("legal.termsAndConditions", defaultTermsUrl);
applicationProperties.getLegal().setTermsAndConditions(defaultTermsUrl); applicationProperties.getLegal().setTermsAndConditions(defaultTermsUrl);
} }
// Initialize Privacy Policy // Initialize Privacy Policy
String privacyUrl = applicationProperties.getLegal().getPrivacyPolicy(); String privacyUrl = applicationProperties.getLegal().getPrivacyPolicy();
if (StringUtils.isEmpty(privacyUrl)) { if (StringUtils.isEmpty(privacyUrl)) {
String defaultPrivacyUrl = "https://www.stirlingpdf.com/privacy-policy"; String defaultPrivacyUrl = "https://www.stirlingpdf.com/privacy-policy";
GeneralUtil.saveKeyToSettings("legal.privacyPolicy", defaultPrivacyUrl); GeneralUtils.saveKeyToSettings("legal.privacyPolicy", defaultPrivacyUrl);
applicationProperties.getLegal().setPrivacyPolicy(defaultPrivacyUrl); applicationProperties.getLegal().setPrivacyPolicy(defaultPrivacyUrl);
} }
} }
@ -95,7 +95,7 @@ public class InitialSetup {
appVersion = props.getProperty("version"); appVersion = props.getProperty("version");
} catch (Exception e) { } catch (Exception e) {
} }
GeneralUtil.saveKeyToSettings("AutomaticallyGenerated.appVersion", appVersion); GeneralUtils.saveKeyToSettings("AutomaticallyGenerated.appVersion", appVersion);
applicationProperties.getAutomaticallyGenerated().setAppVersion(appVersion); applicationProperties.getAutomaticallyGenerated().setAppVersion(appVersion);
} }
} }

View File

@ -16,7 +16,7 @@ import jakarta.servlet.http.HttpSession;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import stirling.software.common.util.RequestUriUtil; import stirling.software.common.util.RequestUriUtils;
@Component @Component
@RequiredArgsConstructor @RequiredArgsConstructor
@ -30,7 +30,7 @@ public class MetricsFilter extends OncePerRequestFilter {
throws ServletException, IOException { throws ServletException, IOException {
String uri = request.getRequestURI(); String uri = request.getRequestURI();
if (RequestUriUtil.isTrackableResource(request.getContextPath(), uri)) { if (RequestUriUtils.isTrackableResource(request.getContextPath(), uri)) {
HttpSession session = request.getSession(false); HttpSession session = request.getSession(false);
String sessionId = (session != null) ? session.getId() : "no-session"; String sessionId = (session != null) ? session.getId() : "no-session";
Counter counter = Counter counter =

View File

@ -13,7 +13,7 @@ import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import stirling.software.common.util.RequestUriUtil; import stirling.software.common.util.RequestUriUtils;
@Slf4j @Slf4j
public class CustomAuthenticationSuccessHandler public class CustomAuthenticationSuccessHandler
@ -48,7 +48,7 @@ public class CustomAuthenticationSuccessHandler
: null; : null;
if (savedRequest != null if (savedRequest != null
&& !RequestUriUtil.isStaticResource( && !RequestUriUtils.isStaticResource(
request.getContextPath(), savedRequest.getRedirectUrl())) { request.getContextPath(), savedRequest.getRedirectUrl())) {
// Redirect to the original destination // Redirect to the original destination
super.onAuthenticationSuccess(request, response, authentication); super.onAuthenticationSuccess(request, response, authentication);

View File

@ -20,7 +20,7 @@ import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import stirling.software.SPDF.model.User; import stirling.software.SPDF.model.User;
import stirling.software.common.util.RequestUriUtil; import stirling.software.common.util.RequestUriUtils;
@Slf4j @Slf4j
@Component @Component
@ -40,7 +40,7 @@ public class FirstLoginFilter extends OncePerRequestFilter {
String requestURI = request.getRequestURI(); String requestURI = request.getRequestURI();
String contextPath = request.getContextPath(); String contextPath = request.getContextPath();
// Check if the request is for static resources // Check if the request is for static resources
boolean isStaticResource = RequestUriUtil.isStaticResource(contextPath, requestURI); boolean isStaticResource = RequestUriUtils.isStaticResource(contextPath, requestURI);
// If it's a static resource, just continue the filter chain and skip the logic below // If it's a static resource, just continue the filter chain and skip the logic below
if (isStaticResource) { if (isStaticResource) {
filterChain.doFilter(request, response); filterChain.doFilter(request, response);

View File

@ -9,7 +9,7 @@ import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import stirling.software.common.util.RequestUriUtil; import stirling.software.common.util.RequestUriUtils;
@RequiredArgsConstructor @RequiredArgsConstructor
public class IPRateLimitingFilter implements Filter { public class IPRateLimitingFilter implements Filter {
@ -29,7 +29,7 @@ public class IPRateLimitingFilter implements Filter {
String requestURI = httpRequest.getRequestURI(); String requestURI = httpRequest.getRequestURI();
// Check if the request is for static resources // Check if the request is for static resources
boolean isStaticResource = boolean isStaticResource =
RequestUriUtil.isStaticResource(httpRequest.getContextPath(), requestURI); RequestUriUtils.isStaticResource(httpRequest.getContextPath(), requestURI);
// If it's a static resource, just continue the filter chain and skip the logic below // If it's a static resource, just continue the filter chain and skip the logic below
if (isStaticResource) { if (isStaticResource) {

View File

@ -23,7 +23,7 @@ import stirling.software.SPDF.model.AuthenticationType;
import stirling.software.common.model.ApplicationProperties; import stirling.software.common.model.ApplicationProperties;
import stirling.software.common.model.ApplicationProperties.Security.OAUTH2; import stirling.software.common.model.ApplicationProperties.Security.OAUTH2;
import stirling.software.common.model.exception.UnsupportedProviderException; import stirling.software.common.model.exception.UnsupportedProviderException;
import stirling.software.common.util.RequestUriUtil; import stirling.software.common.util.RequestUriUtils;
@RequiredArgsConstructor @RequiredArgsConstructor
public class CustomOAuth2AuthenticationSuccessHandler public class CustomOAuth2AuthenticationSuccessHandler
@ -56,7 +56,7 @@ public class CustomOAuth2AuthenticationSuccessHandler
: null; : null;
if (savedRequest != null if (savedRequest != null
&& !RequestUriUtil.isStaticResource(contextPath, savedRequest.getRedirectUrl())) { && !RequestUriUtils.isStaticResource(contextPath, savedRequest.getRedirectUrl())) {
// Redirect to the original destination // Redirect to the original destination
super.onAuthenticationSuccess(request, response, authentication); super.onAuthenticationSuccess(request, response, authentication);
} else { } else {

View File

@ -1,8 +1,8 @@
package stirling.software.SPDF.config.security.oauth2; package stirling.software.SPDF.config.security.oauth2;
import static org.springframework.security.oauth2.core.AuthorizationGrantType.AUTHORIZATION_CODE; import static org.springframework.security.oauth2.core.AuthorizationGrantType.AUTHORIZATION_CODE;
import static stirling.software.common.util.ProviderUtil.validateProvider; import static stirling.software.common.util.ProviderUtils.validateProvider;
import static stirling.software.common.util.ValidationUtil.isStringEmpty; import static stirling.software.common.util.ValidationUtils.isStringEmpty;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;

View File

@ -22,7 +22,7 @@ import stirling.software.SPDF.model.AuthenticationType;
import stirling.software.common.model.ApplicationProperties; import stirling.software.common.model.ApplicationProperties;
import stirling.software.common.model.ApplicationProperties.Security.SAML2; import stirling.software.common.model.ApplicationProperties.Security.SAML2;
import stirling.software.common.model.exception.UnsupportedProviderException; import stirling.software.common.model.exception.UnsupportedProviderException;
import stirling.software.common.util.RequestUriUtil; import stirling.software.common.util.RequestUriUtils;
@AllArgsConstructor @AllArgsConstructor
@Slf4j @Slf4j
@ -58,7 +58,7 @@ public class CustomSaml2AuthenticationSuccessHandler
savedRequest != null); savedRequest != null);
if (savedRequest != null if (savedRequest != null
&& !RequestUriUtil.isStaticResource( && !RequestUriUtils.isStaticResource(
contextPath, savedRequest.getRedirectUrl())) { contextPath, savedRequest.getRedirectUrl())) {
log.debug( log.debug(
"Valid saved request found, redirecting to original destination: {}", "Valid saved request found, redirecting to original destination: {}",

View File

@ -33,7 +33,7 @@ import lombok.extern.slf4j.Slf4j;
import stirling.software.SPDF.model.api.general.MergePdfsRequest; import stirling.software.SPDF.model.api.general.MergePdfsRequest;
import stirling.software.common.service.CustomPDFDocumentFactory; import stirling.software.common.service.CustomPDFDocumentFactory;
import stirling.software.common.util.GeneralUtil; import stirling.software.common.util.GeneralUtils;
import stirling.software.common.util.WebResponseUtils; import stirling.software.common.util.WebResponseUtils;
@RestController @RestController
@ -137,7 +137,7 @@ public class MergeController {
for (MultipartFile multipartFile : files) { for (MultipartFile multipartFile : files) {
totalSize += multipartFile.getSize(); totalSize += multipartFile.getSize();
File tempFile = File tempFile =
GeneralUtil.convertMultipartFileToFile( GeneralUtils.convertMultipartFileToFile(
multipartFile); // Convert MultipartFile to File multipartFile); // Convert MultipartFile to File
filesToDelete.add(tempFile); // Add temp file to the list for later deletion filesToDelete.add(tempFile); // Add temp file to the list for later deletion
mergerUtility.addSource(tempFile); // Add source file to the merger utility mergerUtility.addSource(tempFile); // Add source file to the merger utility

View File

@ -28,7 +28,7 @@ import lombok.RequiredArgsConstructor;
import stirling.software.SPDF.model.api.general.OverlayPdfsRequest; import stirling.software.SPDF.model.api.general.OverlayPdfsRequest;
import stirling.software.common.service.CustomPDFDocumentFactory; import stirling.software.common.service.CustomPDFDocumentFactory;
import stirling.software.common.util.GeneralUtil; import stirling.software.common.util.GeneralUtils;
import stirling.software.common.util.WebResponseUtils; import stirling.software.common.util.WebResponseUtils;
@RestController @RestController
@ -56,7 +56,7 @@ public class PdfOverlayController {
try { try {
for (int i = 0; i < overlayFiles.length; i++) { for (int i = 0; i < overlayFiles.length; i++) {
overlayPdfFiles[i] = GeneralUtil.multipartToFile(overlayFiles[i]); overlayPdfFiles[i] = GeneralUtils.multipartToFile(overlayFiles[i]);
} }
String mode = request.getOverlayMode(); // "SequentialOverlay", "InterleavedOverlay", String mode = request.getOverlayMode(); // "SequentialOverlay", "InterleavedOverlay",

View File

@ -25,7 +25,7 @@ import stirling.software.SPDF.model.SortTypes;
import stirling.software.SPDF.model.api.PDFWithPageNums; import stirling.software.SPDF.model.api.PDFWithPageNums;
import stirling.software.SPDF.model.api.general.RearrangePagesRequest; import stirling.software.SPDF.model.api.general.RearrangePagesRequest;
import stirling.software.common.service.CustomPDFDocumentFactory; import stirling.software.common.service.CustomPDFDocumentFactory;
import stirling.software.common.util.GeneralUtil; import stirling.software.common.util.GeneralUtils;
import stirling.software.common.util.WebResponseUtils; import stirling.software.common.util.WebResponseUtils;
@RestController @RestController
@ -56,7 +56,7 @@ public class RearrangePagesPDFController {
String[] pageOrderArr = pagesToDelete.split(","); String[] pageOrderArr = pagesToDelete.split(",");
List<Integer> pagesToRemove = List<Integer> pagesToRemove =
GeneralUtil.parsePageList(pageOrderArr, document.getNumberOfPages(), false); GeneralUtils.parsePageList(pageOrderArr, document.getNumberOfPages(), false);
Collections.sort(pagesToRemove); Collections.sort(pagesToRemove);
@ -262,7 +262,7 @@ public class RearrangePagesPDFController {
&& !"custom".equals(sortType.toLowerCase())) { && !"custom".equals(sortType.toLowerCase())) {
newPageOrder = processSortTypes(sortType, totalPages, pageOrder); newPageOrder = processSortTypes(sortType, totalPages, pageOrder);
} else { } else {
newPageOrder = GeneralUtil.parsePageList(pageOrderArr, totalPages, false); newPageOrder = GeneralUtils.parsePageList(pageOrderArr, totalPages, false);
} }
log.info("newPageOrder = " + newPageOrder); log.info("newPageOrder = " + newPageOrder);
log.info("totalPages = " + totalPages); log.info("totalPages = " + totalPages);

View File

@ -19,7 +19,7 @@ import lombok.RequiredArgsConstructor;
import stirling.software.SPDF.config.EndpointConfiguration; import stirling.software.SPDF.config.EndpointConfiguration;
import stirling.software.common.configuration.InstallationPathConfig; import stirling.software.common.configuration.InstallationPathConfig;
import stirling.software.common.model.ApplicationProperties; import stirling.software.common.model.ApplicationProperties;
import stirling.software.common.util.GeneralUtil; import stirling.software.common.util.GeneralUtils;
@Controller @Controller
@Tag(name = "Settings", description = "Settings APIs") @Tag(name = "Settings", description = "Settings APIs")
@ -40,7 +40,7 @@ public class SettingsController {
"Setting has already been set, To adjust please edit " "Setting has already been set, To adjust please edit "
+ InstallationPathConfig.getSettingsPath()); + InstallationPathConfig.getSettingsPath());
} }
GeneralUtil.saveKeyToSettings("system.enableAnalytics", enabled); GeneralUtils.saveKeyToSettings("system.enableAnalytics", enabled);
applicationProperties.getSystem().setEnableAnalytics(enabled); applicationProperties.getSystem().setEnableAnalytics(enabled);
return ResponseEntity.ok("Updated"); return ResponseEntity.ok("Updated");
} }

View File

@ -26,7 +26,7 @@ import lombok.extern.slf4j.Slf4j;
import stirling.software.SPDF.model.api.general.SplitPdfBySizeOrCountRequest; import stirling.software.SPDF.model.api.general.SplitPdfBySizeOrCountRequest;
import stirling.software.common.service.CustomPDFDocumentFactory; import stirling.software.common.service.CustomPDFDocumentFactory;
import stirling.software.common.util.GeneralUtil; import stirling.software.common.util.GeneralUtils;
import stirling.software.common.util.WebResponseUtils; import stirling.software.common.util.WebResponseUtils;
@RestController @RestController
@ -81,7 +81,7 @@ public class SplitPdfBySizeController {
if (type == 0) { if (type == 0) {
log.debug("Processing split by size"); log.debug("Processing split by size");
long maxBytes = GeneralUtil.convertSizeToBytes(value); long maxBytes = GeneralUtils.convertSizeToBytes(value);
log.debug("Max bytes per document: {}", maxBytes); log.debug("Max bytes per document: {}", maxBytes);
handleSplitBySize(sourceDocument, maxBytes, zipOut, filename); handleSplitBySize(sourceDocument, maxBytes, zipOut, filename);
} else if (type == 1) { } else if (type == 1) {

View File

@ -34,7 +34,7 @@ import stirling.software.SPDF.model.api.converters.ConvertToImageRequest;
import stirling.software.SPDF.model.api.converters.ConvertToPdfRequest; import stirling.software.SPDF.model.api.converters.ConvertToPdfRequest;
import stirling.software.common.service.CustomPDFDocumentFactory; import stirling.software.common.service.CustomPDFDocumentFactory;
import stirling.software.common.util.CheckProgramInstall; import stirling.software.common.util.CheckProgramInstall;
import stirling.software.common.util.GeneralUtil; import stirling.software.common.util.GeneralUtils;
import stirling.software.common.util.PdfUtils; import stirling.software.common.util.PdfUtils;
import stirling.software.common.util.ProcessExecutor; import stirling.software.common.util.ProcessExecutor;
import stirling.software.common.util.ProcessExecutor.ProcessExecutorResult; import stirling.software.common.util.ProcessExecutor.ProcessExecutorResult;
@ -251,7 +251,7 @@ public class ConvertImgPDFController {
// Load the input PDF // Load the input PDF
PDDocument document = pdfDocumentFactory.load(pdfFile); PDDocument document = pdfDocumentFactory.load(pdfFile);
int totalPages = document.getNumberOfPages(); int totalPages = document.getNumberOfPages();
List<Integer> newPageOrder = GeneralUtil.parsePageList(pageOrderArr, totalPages, false); List<Integer> newPageOrder = GeneralUtils.parsePageList(pageOrderArr, totalPages, false);
// Create a new list to hold the pages in the new order // Create a new list to hold the pages in the new order
List<PDPage> newPages = new ArrayList<>(); List<PDPage> newPages = new ArrayList<>();

View File

@ -23,7 +23,7 @@ import stirling.software.SPDF.model.api.converters.UrlToPdfRequest;
import stirling.software.common.configuration.RuntimePathConfig; import stirling.software.common.configuration.RuntimePathConfig;
import stirling.software.common.model.ApplicationProperties; import stirling.software.common.model.ApplicationProperties;
import stirling.software.common.service.CustomPDFDocumentFactory; import stirling.software.common.service.CustomPDFDocumentFactory;
import stirling.software.common.util.GeneralUtil; import stirling.software.common.util.GeneralUtils;
import stirling.software.common.util.ProcessExecutor; import stirling.software.common.util.ProcessExecutor;
import stirling.software.common.util.ProcessExecutor.ProcessExecutorResult; import stirling.software.common.util.ProcessExecutor.ProcessExecutorResult;
import stirling.software.common.util.WebResponseUtils; import stirling.software.common.util.WebResponseUtils;
@ -53,12 +53,12 @@ public class ConvertWebsiteToPDF {
throw new IllegalArgumentException("This endpoint has been disabled by the admin."); throw new IllegalArgumentException("This endpoint has been disabled by the admin.");
} }
// Validate the URL format // Validate the URL format
if (!URL.matches("^https?://.*") || !GeneralUtil.isValidURL(URL)) { if (!URL.matches("^https?://.*") || !GeneralUtils.isValidURL(URL)) {
throw new IllegalArgumentException("Invalid URL format provided."); throw new IllegalArgumentException("Invalid URL format provided.");
} }
// validate the URL is reachable // validate the URL is reachable
if (!GeneralUtil.isURLReachable(URL)) { if (!GeneralUtils.isURLReachable(URL)) {
throw new IllegalArgumentException("URL is not reachable, please provide a valid URL."); throw new IllegalArgumentException("URL is not reachable, please provide a valid URL.");
} }

View File

@ -52,7 +52,7 @@ import lombok.extern.slf4j.Slf4j;
import stirling.software.SPDF.config.EndpointConfiguration; import stirling.software.SPDF.config.EndpointConfiguration;
import stirling.software.SPDF.model.api.misc.OptimizePdfRequest; import stirling.software.SPDF.model.api.misc.OptimizePdfRequest;
import stirling.software.common.service.CustomPDFDocumentFactory; import stirling.software.common.service.CustomPDFDocumentFactory;
import stirling.software.common.util.GeneralUtil; import stirling.software.common.util.GeneralUtils;
import stirling.software.common.util.ProcessExecutor; import stirling.software.common.util.ProcessExecutor;
import stirling.software.common.util.ProcessExecutor.ProcessExecutorResult; import stirling.software.common.util.ProcessExecutor.ProcessExecutorResult;
import stirling.software.common.util.WebResponseUtils; import stirling.software.common.util.WebResponseUtils;
@ -111,7 +111,7 @@ public class CompressController {
scaleFactor, scaleFactor,
jpegQuality, jpegQuality,
convertToGrayscale, convertToGrayscale,
GeneralUtil.formatBytes(originalFileSize)); GeneralUtils.formatBytes(originalFileSize));
try (PDDocument doc = pdfDocumentFactory.load(pdfFile)) { try (PDDocument doc = pdfDocumentFactory.load(pdfFile)) {
// Find all unique images in the document // Find all unique images in the document
@ -145,8 +145,8 @@ public class CompressController {
double overallReduction = 100.0 - ((compressedFileSize * 100.0) / originalFileSize); double overallReduction = 100.0 - ((compressedFileSize * 100.0) / originalFileSize);
log.info( log.info(
"Overall PDF compression: {} → {} (reduced by {}%)", "Overall PDF compression: {} → {} (reduced by {}%)",
GeneralUtil.formatBytes(originalFileSize), GeneralUtils.formatBytes(originalFileSize),
GeneralUtil.formatBytes(compressedFileSize), GeneralUtils.formatBytes(compressedFileSize),
String.format("%.1f", overallReduction)); String.format("%.1f", overallReduction));
return newCompressedPDF; return newCompressedPDF;
} }
@ -316,8 +316,8 @@ public class CompressController {
log.info( log.info(
"Image hash {}: Compressed from {} to {} (reduced by {}%)", "Image hash {}: Compressed from {} to {} (reduced by {}%)",
imageHash, imageHash,
GeneralUtil.formatBytes(originalSize), GeneralUtils.formatBytes(originalSize),
GeneralUtil.formatBytes(compressedSize), GeneralUtils.formatBytes(compressedSize),
String.format("%.1f", reductionPercentage)); String.format("%.1f", reductionPercentage));
} else { } else {
log.info("Image hash {}: Not suitable for compression, skipping", imageHash); log.info("Image hash {}: Not suitable for compression, skipping", imageHash);
@ -456,8 +456,8 @@ public class CompressController {
stats.nestedImages); stats.nestedImages);
log.info( log.info(
"Total original image size: {}, compressed: {} (reduced by {}%)", "Total original image size: {}, compressed: {} (reduced by {}%)",
GeneralUtil.formatBytes(stats.totalOriginalBytes), GeneralUtils.formatBytes(stats.totalOriginalBytes),
GeneralUtil.formatBytes(stats.totalCompressedBytes), GeneralUtils.formatBytes(stats.totalCompressedBytes),
String.format("%.1f", overallImageReduction)); String.format("%.1f", overallImageReduction));
} }
@ -673,7 +673,7 @@ public class CompressController {
Long expectedOutputSize = 0L; Long expectedOutputSize = 0L;
boolean autoMode = false; boolean autoMode = false;
if (expectedOutputSizeString != null && expectedOutputSizeString.length() > 1) { if (expectedOutputSizeString != null && expectedOutputSizeString.length() > 1) {
expectedOutputSize = GeneralUtil.convertSizeToBytes(expectedOutputSizeString); expectedOutputSize = GeneralUtils.convertSizeToBytes(expectedOutputSizeString);
autoMode = true; autoMode = true;
} }
@ -794,7 +794,7 @@ public class CompressController {
throws IOException { throws IOException {
long preQpdfSize = Files.size(currentFile); long preQpdfSize = Files.size(currentFile);
log.info("Pre-QPDF file size: {}", GeneralUtil.formatBytes(preQpdfSize)); log.info("Pre-QPDF file size: {}", GeneralUtils.formatBytes(preQpdfSize));
// Map optimization levels to QPDF compression levels // Map optimization levels to QPDF compression levels
int qpdfCompressionLevel; int qpdfCompressionLevel;
@ -839,7 +839,7 @@ public class CompressController {
double qpdfReduction = 100.0 - ((postQpdfSize * 100.0) / preQpdfSize); double qpdfReduction = 100.0 - ((postQpdfSize * 100.0) / preQpdfSize);
log.info( log.info(
"Post-QPDF file size: {} (reduced by {}%)", "Post-QPDF file size: {} (reduced by {}%)",
GeneralUtil.formatBytes(postQpdfSize), String.format("%.1f", qpdfReduction)); GeneralUtils.formatBytes(postQpdfSize), String.format("%.1f", qpdfReduction));
} catch (Exception e) { } catch (Exception e) {
if (returnCode != null && returnCode.getRc() != 3) { if (returnCode != null && returnCode.getRc() != 3) {

View File

@ -26,7 +26,7 @@ import lombok.RequiredArgsConstructor;
import stirling.software.SPDF.model.api.misc.AddPageNumbersRequest; import stirling.software.SPDF.model.api.misc.AddPageNumbersRequest;
import stirling.software.common.service.CustomPDFDocumentFactory; import stirling.software.common.service.CustomPDFDocumentFactory;
import stirling.software.common.util.GeneralUtil; import stirling.software.common.util.GeneralUtils;
import stirling.software.common.util.WebResponseUtils; import stirling.software.common.util.WebResponseUtils;
@RestController @RestController
@ -80,7 +80,7 @@ public class PageNumbersController {
customText = "{n}"; customText = "{n}";
} }
List<Integer> pagesToNumberList = List<Integer> pagesToNumberList =
GeneralUtil.parsePageList(pagesToNumber.split(","), document.getNumberOfPages()); GeneralUtils.parsePageList(pagesToNumber.split(","), document.getNumberOfPages());
for (int i : pagesToNumberList) { for (int i : pagesToNumberList) {
PDPage page = document.getPage(i); PDPage page = document.getPage(i);

View File

@ -36,7 +36,7 @@ import stirling.software.SPDF.model.api.security.RedactPdfRequest;
import stirling.software.SPDF.model.api.security.RedactionArea; import stirling.software.SPDF.model.api.security.RedactionArea;
import stirling.software.SPDF.pdf.TextFinder; import stirling.software.SPDF.pdf.TextFinder;
import stirling.software.common.service.CustomPDFDocumentFactory; import stirling.software.common.service.CustomPDFDocumentFactory;
import stirling.software.common.util.GeneralUtil; import stirling.software.common.util.GeneralUtils;
import stirling.software.common.util.PdfUtils; import stirling.software.common.util.PdfUtils;
import stirling.software.common.util.WebResponseUtils; import stirling.software.common.util.WebResponseUtils;
import stirling.software.common.util.propertyeditor.StringToArrayListPropertyEditor; import stirling.software.common.util.propertyeditor.StringToArrayListPropertyEditor;
@ -184,7 +184,8 @@ public class RedactController {
String pageNumbersInput = request.getPageNumbers(); String pageNumbersInput = request.getPageNumbers();
String[] parsedPageNumbers = String[] parsedPageNumbers =
pageNumbersInput != null ? pageNumbersInput.split(",") : new String[0]; pageNumbersInput != null ? pageNumbersInput.split(",") : new String[0];
List<Integer> pageNumbers = GeneralUtil.parsePageList(parsedPageNumbers, pagesCount, false); List<Integer> pageNumbers =
GeneralUtils.parsePageList(parsedPageNumbers, pagesCount, false);
Collections.sort(pageNumbers); Collections.sort(pageNumbers);
return pageNumbers; return pageNumbers;
} }

View File

@ -1,6 +1,6 @@
package stirling.software.SPDF.controller.web; package stirling.software.SPDF.controller.web;
import static stirling.software.common.util.ProviderUtil.validateProvider; import static stirling.software.common.util.ProviderUtils.validateProvider;
import java.time.Instant; import java.time.Instant;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;

View File

@ -29,7 +29,7 @@ import stirling.software.SPDF.service.SignatureService;
import stirling.software.common.configuration.InstallationPathConfig; import stirling.software.common.configuration.InstallationPathConfig;
import stirling.software.common.configuration.RuntimePathConfig; import stirling.software.common.configuration.RuntimePathConfig;
import stirling.software.common.service.UserServiceInterface; import stirling.software.common.service.UserServiceInterface;
import stirling.software.common.util.GeneralUtil; import stirling.software.common.util.GeneralUtils;
@Controller @Controller
@Tag(name = "General", description = "General APIs") @Tag(name = "General", description = "General APIs")
@ -240,7 +240,7 @@ public class GeneralWebController {
private List<FontResource> getFontNamesFromLocation(String locationPattern) { private List<FontResource> getFontNamesFromLocation(String locationPattern) {
try { try {
Resource[] resources = Resource[] resources =
GeneralUtil.getResourcesFromLocationPattern(locationPattern, resourceLoader); GeneralUtils.getResourcesFromLocationPattern(locationPattern, resourceLoader);
return Arrays.stream(resources) return Arrays.stream(resources)
.map( .map(
resource -> { resource -> {

View File

@ -12,7 +12,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import stirling.software.common.model.api.PDFFile; import stirling.software.common.model.api.PDFFile;
import stirling.software.common.util.GeneralUtil; import stirling.software.common.util.GeneralUtils;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ -30,6 +30,6 @@ public class PDFWithPageNums extends PDFFile {
@Hidden @Hidden
public List<Integer> getPageNumbersList(PDDocument doc, boolean oneBased) { public List<Integer> getPageNumbersList(PDDocument doc, boolean oneBased) {
int pageCount = doc.getNumberOfPages(); int pageCount = doc.getNumberOfPages();
return GeneralUtil.parsePageList(pageNumbers, pageCount, oneBased); return GeneralUtils.parsePageList(pageNumbers, pageCount, oneBased);
} }
} }