Compare commits

...

2 Commits

Author SHA1 Message Date
stirlingbot[bot]
394ecfb08c
📁 pre-commit
Signed-off-by: stirlingbot[bot] <stirlingbot[bot]@users.noreply.github.com>
2025-09-06 19:30:54 +00:00
Balázs Szücs
8192b1a44f
performance: Use StringBuilder instead of string concatenation for building strings (#4193) 2025-09-06 20:27:11 +01:00
4 changed files with 32 additions and 25 deletions

View File

@ -552,10 +552,10 @@ public class PdfUtils {
public boolean containsTextInFile(PDDocument pdfDocument, String text, String pagesToCheck)
throws IOException {
PDFTextStripper textStripper = new PDFTextStripper();
String pdfText = "";
StringBuilder pdfText = new StringBuilder();
if (pagesToCheck == null || "all".equals(pagesToCheck)) {
pdfText = textStripper.getText(pdfDocument);
pdfText = new StringBuilder(textStripper.getText(pdfDocument));
} else {
// remove whitespaces
pagesToCheck = pagesToCheck.replaceAll("\\s+", "");
@ -571,21 +571,21 @@ public class PdfUtils {
for (int i = startPage; i <= endPage; i++) {
textStripper.setStartPage(i);
textStripper.setEndPage(i);
pdfText += textStripper.getText(pdfDocument);
pdfText.append(textStripper.getText(pdfDocument));
}
} else {
// Handle individual page
int page = Integer.parseInt(splitPoint);
textStripper.setStartPage(page);
textStripper.setEndPage(page);
pdfText += textStripper.getText(pdfDocument);
pdfText.append(textStripper.getText(pdfDocument));
}
}
}
pdfDocument.close();
return pdfText.contains(text);
return pdfText.toString().contains(text);
}
public boolean pageCount(PDDocument pdfDocument, int pageCount, String comparator)

View File

@ -94,14 +94,14 @@ public class AutoRenameController {
// Merge lines with same font size
List<LineInfo> mergedLineInfos = new ArrayList<>();
for (int i = 0; i < lineInfos.size(); i++) {
String mergedText = lineInfos.get(i).text;
StringBuilder mergedText = new StringBuilder(lineInfos.get(i).text);
float fontSize = lineInfos.get(i).fontSize;
while (i + 1 < lineInfos.size()
&& lineInfos.get(i + 1).fontSize == fontSize) {
mergedText += " " + lineInfos.get(i + 1).text;
mergedText.append(" ").append(lineInfos.get(i + 1).text);
i++;
}
mergedLineInfos.add(new LineInfo(mergedText, fontSize));
mergedLineInfos.add(new LineInfo(mergedText.toString(), fontSize));
}
// Sort lines by font size in descending order and get the first one

View File

@ -38,7 +38,8 @@ public class ShowJavascript {
description = "desc. Input:PDF Output:JS Type:SISO")
public ResponseEntity<byte[]> extractHeader(@ModelAttribute PDFFile file) throws Exception {
MultipartFile inputFile = file.getFileInput();
String script = "";
StringBuilder script = new StringBuilder();
boolean foundScript = false;
try (PDDocument document = pdfDocumentFactory.load(inputFile)) {
@ -55,28 +56,31 @@ public class ShowJavascript {
PDActionJavaScript jsAction = entry.getValue();
String jsCodeStr = jsAction.getAction();
script +=
"// File: "
+ Filenames.toSimpleFileName(
inputFile.getOriginalFilename())
+ ", Script: "
+ name
+ "\n"
+ jsCodeStr
+ "\n";
if (jsCodeStr != null && !jsCodeStr.trim().isEmpty()) {
script.append("// File: ")
.append(
Filenames.toSimpleFileName(
inputFile.getOriginalFilename()))
.append(", Script: ")
.append(name)
.append("\n")
.append(jsCodeStr)
.append("\n");
foundScript = true;
}
}
}
}
if (script.isEmpty()) {
if (!foundScript) {
script =
"PDF '"
+ Filenames.toSimpleFileName(inputFile.getOriginalFilename())
+ "' does not contain Javascript";
new StringBuilder("PDF '")
.append(Filenames.toSimpleFileName(inputFile.getOriginalFilename()))
.append("' does not contain Javascript");
}
return WebResponseUtils.bytesToWebResponse(
script.getBytes(StandardCharsets.UTF_8),
script.toString().getBytes(StandardCharsets.UTF_8),
Filenames.toSimpleFileName(inputFile.getOriginalFilename()) + ".js",
MediaType.TEXT_PLAIN);
}

View File

@ -75,8 +75,11 @@ public class CustomUserDetailsService implements UserDetailsService {
*/
private AuthenticationType determinePreferredSSOType() {
// Check what SSO types are enabled and prefer in order: OAUTH2 > SAML2 > fallback to OAUTH2
boolean oauth2Enabled = securityProperties.getOauth2() != null && securityProperties.getOauth2().getEnabled();
boolean saml2Enabled = securityProperties.getSaml2() != null && securityProperties.getSaml2().getEnabled();
boolean oauth2Enabled =
securityProperties.getOauth2() != null
&& securityProperties.getOauth2().getEnabled();
boolean saml2Enabled =
securityProperties.getSaml2() != null && securityProperties.getSaml2().getEnabled();
if (oauth2Enabled) {
return AuthenticationType.OAUTH2;