Formatting and OCR fix

This commit is contained in:
Anthony Stirling 2025-03-26 22:29:00 +00:00
parent 52507433c5
commit b5e08f79d9
24 changed files with 56 additions and 76 deletions

View File

@ -6,6 +6,7 @@ import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import stirling.software.SPDF.EE.KeygenLicenseVerifier.License; import stirling.software.SPDF.EE.KeygenLicenseVerifier.License;
import stirling.software.SPDF.model.ApplicationProperties; import stirling.software.SPDF.model.ApplicationProperties;
import stirling.software.SPDF.model.ApplicationProperties.EnterpriseEdition; import stirling.software.SPDF.model.ApplicationProperties.EnterpriseEdition;

View File

@ -26,11 +26,12 @@ import stirling.software.SPDF.utils.GeneralUtils;
@Slf4j @Slf4j
public class KeygenLicenseVerifier { public class KeygenLicenseVerifier {
enum License {
NORMAL,
PRO,
ENTERPRISE
}
enum License{
NORMAL, PRO, ENTERPRISE
}
// License verification configuration // License verification configuration
private static final String ACCOUNT_ID = "e5430f69-e834-4ae4-befd-b602aae5f372"; private static final String ACCOUNT_ID = "e5430f69-e834-4ae4-befd-b602aae5f372";
private static final String BASE_URL = "https://api.keygen.sh/v1/accounts"; private static final String BASE_URL = "https://api.keygen.sh/v1/accounts";
@ -57,18 +58,18 @@ public class KeygenLicenseVerifier {
return resultToEnum(verifyCertificateLicense(licenseKeyOrCert), License.ENTERPRISE); return resultToEnum(verifyCertificateLicense(licenseKeyOrCert), License.ENTERPRISE);
} else if (isJWTLicense(licenseKeyOrCert)) { } else if (isJWTLicense(licenseKeyOrCert)) {
log.info("Detected JWT-style license key. Processing..."); log.info("Detected JWT-style license key. Processing...");
return resultToEnum( verifyJWTLicense(licenseKeyOrCert), License.ENTERPRISE); return resultToEnum(verifyJWTLicense(licenseKeyOrCert), License.ENTERPRISE);
} else { } else {
log.info("Detected standard license key. Processing..."); log.info("Detected standard license key. Processing...");
return resultToEnum( verifyStandardLicense(licenseKeyOrCert), License.PRO); return resultToEnum(verifyStandardLicense(licenseKeyOrCert), License.PRO);
} }
} }
private License resultToEnum(boolean result, License option) { private License resultToEnum(boolean result, License option) {
if(result) { if (result) {
return option; return option;
} }
return License.NORMAL; return License.NORMAL;
} }
private boolean isCertificateLicense(String license) { private boolean isCertificateLicense(String license) {

View File

@ -10,6 +10,7 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import stirling.software.SPDF.EE.KeygenLicenseVerifier.License; import stirling.software.SPDF.EE.KeygenLicenseVerifier.License;
import stirling.software.SPDF.model.ApplicationProperties; import stirling.software.SPDF.model.ApplicationProperties;
import stirling.software.SPDF.utils.GeneralUtils; import stirling.software.SPDF.utils.GeneralUtils;
@ -48,8 +49,8 @@ public class LicenseKeyChecker {
premiumEnabledResult = licenseService.verifyLicense(licenseKey); premiumEnabledResult = licenseService.verifyLicense(licenseKey);
if (License.ENTERPRISE == premiumEnabledResult) { if (License.ENTERPRISE == premiumEnabledResult) {
log.info("License key is Enterprise."); log.info("License key is Enterprise.");
} else if(License.PRO == premiumEnabledResult){ } else if (License.PRO == premiumEnabledResult) {
log.info("License key is Pro."); log.info("License key is Pro.");
} else { } else {
log.info("License key is invalid, defaulting to non pro license."); log.info("License key is invalid, defaulting to non pro license.");
} }

View File

@ -5,7 +5,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;

View File

@ -2,7 +2,6 @@ package stirling.software.SPDF.config.security;
import java.util.Collection; import java.util.Collection;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
import org.springframework.security.authentication.LockedException; import org.springframework.security.authentication.LockedException;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;

View File

@ -3,7 +3,6 @@ package stirling.software.SPDF.config.security;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;

View File

@ -3,7 +3,6 @@ package stirling.software.SPDF.config.security;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;

View File

@ -17,7 +17,6 @@ import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import javax.sql.DataSource; import javax.sql.DataSource;

View File

@ -10,7 +10,6 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import org.apache.pdfbox.multipdf.PDFMergerUtility; import org.apache.pdfbox.multipdf.PDFMergerUtility;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;

View File

@ -8,7 +8,6 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;

View File

@ -5,7 +5,6 @@ import java.io.*;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;

View File

@ -5,7 +5,6 @@ import java.io.InputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
@ -64,9 +63,7 @@ public class PipelineController {
log.info("Received POST request to /handleData with {} files", files.length); log.info("Received POST request to /handleData with {} files", files.length);
List<String> operationNames = List<String> operationNames =
config.getOperations().stream() config.getOperations().stream().map(PipelineOperation::getOperation).toList();
.map(PipelineOperation::getOperation)
.toList();
Map<String, Object> properties = new HashMap<>(); Map<String, Object> properties = new HashMap<>();
properties.put("operations", operationNames); properties.put("operations", operationNames);

View File

@ -11,7 +11,6 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;

View File

@ -1,7 +1,6 @@
package stirling.software.SPDF.controller.api.security; package stirling.software.SPDF.controller.api.security;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.PDDocumentCatalog;

View File

@ -66,11 +66,11 @@ public class SanitizeController {
} }
if (removeXMPMetadata) { if (removeXMPMetadata) {
sanitizeXMPMetadata(document); sanitizeXMPMetadata(document);
} }
if (removeMetadata) { if (removeMetadata) {
sanitizeDocumentInfoMetadata(document); sanitizeDocumentInfoMetadata(document);
} }
if (removeLinks) { if (removeLinks) {
@ -167,8 +167,6 @@ public class SanitizeController {
} }
} }
private void sanitizeLinks(PDDocument document) throws IOException { private void sanitizeLinks(PDDocument document) throws IOException {
for (PDPage page : document.getPages()) { for (PDPage page : document.getPages()) {
for (PDAnnotation annotation : page.getAnnotations()) { for (PDAnnotation annotation : page.getAnnotations()) {

View File

@ -10,7 +10,6 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
@ -58,10 +57,12 @@ public class AccountWebController {
// Assuming you have a repository for user operations // Assuming you have a repository for user operations
private final UserRepository userRepository; private final UserRepository userRepository;
private final boolean runningEE; private final boolean runningEE;
public AccountWebController( public AccountWebController(
ApplicationProperties applicationProperties, ApplicationProperties applicationProperties,
SessionPersistentRegistry sessionPersistentRegistry, SessionPersistentRegistry sessionPersistentRegistry,
UserRepository userRepository, @Qualifier("runningEE") boolean runningEE) { UserRepository userRepository,
@Qualifier("runningEE") boolean runningEE) {
this.applicationProperties = applicationProperties; this.applicationProperties = applicationProperties;
this.sessionPersistentRegistry = sessionPersistentRegistry; this.sessionPersistentRegistry = sessionPersistentRegistry;
this.userRepository = userRepository; this.userRepository = userRepository;
@ -199,9 +200,9 @@ public class AccountWebController {
@PreAuthorize("hasRole('ROLE_ADMIN')") @PreAuthorize("hasRole('ROLE_ADMIN')")
@GetMapping("/usage") @GetMapping("/usage")
public String showUsage() { public String showUsage() {
if(!runningEE) { if (!runningEE) {
return "error"; return "error";
} }
return "usage"; return "usage";
} }

View File

@ -7,7 +7,6 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;

View File

@ -3,7 +3,6 @@ package stirling.software.SPDF.controller.web;
import java.time.Duration; import java.time.Duration;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;

View File

@ -4,7 +4,6 @@ import java.io.File;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
@ -123,7 +122,7 @@ public class OtherWebController {
return Arrays.stream(files) return Arrays.stream(files)
.filter(file -> file.getName().endsWith(".traineddata")) .filter(file -> file.getName().endsWith(".traineddata"))
.map(file -> file.getName().replace(".traineddata", "")) .map(file -> file.getName().replace(".traineddata", ""))
.filter(lang -> !lang.equalsIgnoreCase("osd")) .filter(lang -> !lang.equalsIgnoreCase("osd")).sorted()
.toList(); .toList();
} }
@ -132,7 +131,6 @@ public class OtherWebController {
public ModelAndView ocrPdfPage() { public ModelAndView ocrPdfPage() {
ModelAndView modelAndView = new ModelAndView("misc/ocr-pdf"); ModelAndView modelAndView = new ModelAndView("misc/ocr-pdf");
List<String> languages = getAvailableTesseractLanguages(); List<String> languages = getAvailableTesseractLanguages();
Collections.sort(languages);
modelAndView.addObject("languages", languages); modelAndView.addObject("languages", languages);
modelAndView.addObject("currentPage", "ocr-pdf"); modelAndView.addObject("currentPage", "ocr-pdf");
return modelAndView; return modelAndView;

View File

@ -5,7 +5,6 @@ import static stirling.software.SPDF.model.UsernameAttribute.EMAIL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.stream.Collectors;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -59,8 +58,7 @@ public class Provider {
public void setScopes(String scopes) { public void setScopes(String scopes) {
if (scopes != null && !scopes.isBlank()) { if (scopes != null && !scopes.isBlank()) {
this.scopes = this.scopes = Arrays.stream(scopes.split(",")).map(String::trim).toList();
Arrays.stream(scopes.split(",")).map(String::trim).toList();
} }
} }

View File

@ -68,17 +68,17 @@ public class CustomPDFDocumentFactory {
} }
/** /**
* Main entry point for loading a PDF document from a file. Automatically selects the most * Main entry point for loading a PDF document from a file. Automatically selects the most
* appropriate loading strategy. * appropriate loading strategy.
*/ */
public PDDocument load(File file) throws IOException { public PDDocument load(File file) throws IOException {
return load(file, false); return load(file, false);
} }
/** /**
* Main entry point for loading a PDF document from a file with read-only option. * Main entry point for loading a PDF document from a file with read-only option. Automatically
* Automatically selects the most appropriate loading strategy. * selects the most appropriate loading strategy.
*/ */
public PDDocument load(File file, boolean readOnly) throws IOException { public PDDocument load(File file, boolean readOnly) throws IOException {
if (file == null) { if (file == null) {
throw new IllegalArgumentException("File cannot be null"); throw new IllegalArgumentException("File cannot be null");
@ -95,17 +95,17 @@ public class CustomPDFDocumentFactory {
} }
/** /**
* Main entry point for loading a PDF document from a Path. Automatically selects the most * Main entry point for loading a PDF document from a Path. Automatically selects the most
* appropriate loading strategy. * appropriate loading strategy.
*/ */
public PDDocument load(Path path) throws IOException { public PDDocument load(Path path) throws IOException {
return load(path, false); return load(path, false);
} }
/** /**
* Main entry point for loading a PDF document from a Path with read-only option. * Main entry point for loading a PDF document from a Path with read-only option. Automatically
* Automatically selects the most appropriate loading strategy. * selects the most appropriate loading strategy.
*/ */
public PDDocument load(Path path, boolean readOnly) throws IOException { public PDDocument load(Path path, boolean readOnly) throws IOException {
if (path == null) { if (path == null) {
throw new IllegalArgumentException("File cannot be null"); throw new IllegalArgumentException("File cannot be null");
@ -170,7 +170,8 @@ public class CustomPDFDocumentFactory {
} }
/** Load with password from InputStream and read-only option */ /** Load with password from InputStream and read-only option */
public PDDocument load(InputStream input, String password, boolean readOnly) throws IOException { public PDDocument load(InputStream input, String password, boolean readOnly)
throws IOException {
if (input == null) { if (input == null) {
throw new IllegalArgumentException("InputStream cannot be null"); throw new IllegalArgumentException("InputStream cannot be null");
} }
@ -179,7 +180,8 @@ public class CustomPDFDocumentFactory {
Path tempFile = createTempFile("pdf-stream-"); Path tempFile = createTempFile("pdf-stream-");
Files.copy(input, tempFile, StandardCopyOption.REPLACE_EXISTING); Files.copy(input, tempFile, StandardCopyOption.REPLACE_EXISTING);
PDDocument doc = loadAdaptivelyWithPassword(tempFile.toFile(), Files.size(tempFile), password); PDDocument doc =
loadAdaptivelyWithPassword(tempFile.toFile(), Files.size(tempFile), password);
if (!readOnly) { if (!readOnly) {
postProcessDocument(doc); postProcessDocument(doc);
} }
@ -203,7 +205,7 @@ public class CustomPDFDocumentFactory {
/** Load from a PDFFile object with read-only option */ /** Load from a PDFFile object with read-only option */
public PDDocument load(PDFFile pdfFile, boolean readOnly) throws IOException { public PDDocument load(PDFFile pdfFile, boolean readOnly) throws IOException {
return load(pdfFile.getFileInput(), readOnly); return load(pdfFile.getFileInput(), readOnly);
} }
/** Load from a MultipartFile */ /** Load from a MultipartFile */
@ -213,8 +215,7 @@ public class CustomPDFDocumentFactory {
/** Load from a MultipartFile with read-only option */ /** Load from a MultipartFile with read-only option */
public PDDocument load(MultipartFile pdfFile, boolean readOnly) throws IOException { public PDDocument load(MultipartFile pdfFile, boolean readOnly) throws IOException {
return load(pdfFile.getInputStream(), readOnly); return load(pdfFile.getInputStream(), readOnly);
} }
/** Load with password from MultipartFile */ /** Load with password from MultipartFile */
@ -223,8 +224,9 @@ public class CustomPDFDocumentFactory {
} }
/** Load with password from MultipartFile with read-only option */ /** Load with password from MultipartFile with read-only option */
public PDDocument load(MultipartFile fileInput, String password, boolean readOnly) throws IOException { public PDDocument load(MultipartFile fileInput, String password, boolean readOnly)
return load(fileInput.getInputStream(), password, readOnly); throws IOException {
return load(fileInput.getInputStream(), password, readOnly);
} }
/** /**
@ -471,5 +473,4 @@ public class CustomPDFDocumentFactory {
return saveToBytes(document); return saveToBytes(document);
} }
} }
} }

View File

@ -7,7 +7,6 @@ import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.thymeleaf.util.StringUtils; import org.thymeleaf.util.StringUtils;

View File

@ -9,7 +9,6 @@ import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
@ -172,9 +171,7 @@ public class FileToPdf {
// Search for the main HTML file. // Search for the main HTML file.
try (Stream<Path> walk = Files.walk(tempDirectory)) { try (Stream<Path> walk = Files.walk(tempDirectory)) {
List<Path> htmlFiles = List<Path> htmlFiles = walk.filter(file -> file.toString().endsWith(".html")).toList();
walk.filter(file -> file.toString().endsWith(".html"))
.toList();
if (htmlFiles.isEmpty()) { if (htmlFiles.isEmpty()) {
throw new IOException("No HTML files found in the unzipped directory."); throw new IOException("No HTML files found in the unzipped directory.");