mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-11-16 01:21:16 +01:00
refactor(pdf-conversion): improve request token handling and resource validation
- Added null checks for PDResources to prevent possible null pointer exceptions - Streamlined request token processing by normalizing input directly in initialization - Simplified filter logic for profile matching by leveraging pre-normalized tokens - Removed redundant option from the PDF/A format dropdown in the UI template Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
This commit is contained in:
parent
a5e55e598a
commit
69140b4b03
@ -537,6 +537,8 @@ public class ConvertPDFToPDFA {
|
||||
|
||||
PDResources loRes = loPage.getResources();
|
||||
PDResources baseRes = basePage.getResources();
|
||||
if (loRes == null || baseRes == null) continue;
|
||||
|
||||
Set<COSName> toReplace = detectTransparentXObjects(basePage);
|
||||
|
||||
for (COSName name : toReplace) {
|
||||
@ -1189,7 +1191,10 @@ public class ConvertPDFToPDFA {
|
||||
this.suffix = suffix;
|
||||
this.compatibilityLevel = compatibilityLevel;
|
||||
this.preflightFormat = preflightFormat;
|
||||
this.requestTokens = Arrays.asList(requestTokens);
|
||||
this.requestTokens =
|
||||
Arrays.stream(requestTokens)
|
||||
.map(token -> token.toLowerCase(Locale.ROOT))
|
||||
.toList();
|
||||
}
|
||||
|
||||
static PdfaProfile fromRequest(String requestToken) {
|
||||
@ -1199,11 +1204,7 @@ public class ConvertPDFToPDFA {
|
||||
String normalized = requestToken.trim().toLowerCase(Locale.ROOT);
|
||||
Optional<PdfaProfile> match =
|
||||
Arrays.stream(values())
|
||||
.filter(
|
||||
profile ->
|
||||
profile.requestTokens.stream()
|
||||
.map(token -> token.toLowerCase(Locale.ROOT))
|
||||
.anyMatch(token -> token.equals(normalized)))
|
||||
.filter(profile -> profile.requestTokens.contains(normalized))
|
||||
.findFirst();
|
||||
|
||||
return match.orElse(PDF_A_2B);
|
||||
@ -1251,7 +1252,10 @@ public class ConvertPDFToPDFA {
|
||||
this.suffix = suffix;
|
||||
this.compatibilityLevel = compatibilityLevel;
|
||||
this.pdfxVersion = pdfxVersion;
|
||||
this.requestTokens = Arrays.asList(requestTokens);
|
||||
this.requestTokens =
|
||||
Arrays.stream(requestTokens)
|
||||
.map(token -> token.toLowerCase(Locale.ROOT))
|
||||
.toList();
|
||||
}
|
||||
|
||||
static PdfXProfile fromRequest(String requestToken) {
|
||||
@ -1261,11 +1265,7 @@ public class ConvertPDFToPDFA {
|
||||
String normalized = requestToken.trim().toLowerCase(Locale.ROOT);
|
||||
Optional<PdfXProfile> match =
|
||||
Arrays.stream(values())
|
||||
.filter(
|
||||
profile ->
|
||||
profile.requestTokens.stream()
|
||||
.map(token -> token.toLowerCase(Locale.ROOT))
|
||||
.anyMatch(token -> token.equals(normalized)))
|
||||
.filter(profile -> profile.requestTokens.contains(normalized))
|
||||
.findFirst();
|
||||
|
||||
return match.orElse(PDF_X_4);
|
||||
|
||||
@ -25,7 +25,6 @@
|
||||
<select class="form-control" name="outputFormat" id="outputFormat">
|
||||
<optgroup th:label="#{pdfToPDFA.pdfaFormats}">
|
||||
<option value="pdfa-1">PDF/A-1b</option>
|
||||
<option value="pdfa-2">PDF/A-2b</option>
|
||||
<option selected="selected" value="pdfa">PDF/A-2b (default)</option>
|
||||
<option value="pdfa-3">PDF/A-3b</option>
|
||||
</optgroup>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user