mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2024-12-21 19:08:24 +01:00
Switch order of literals to prevent NullPointerException
This commit is contained in:
parent
36c277961f
commit
95471a2fba
@ -16,7 +16,7 @@ public class PropSync {
|
|||||||
Map<String, String> enProps = linesToProps(enLines);
|
Map<String, String> enProps = linesToProps(enLines);
|
||||||
|
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
if (!file.getName().equals("messages_en_GB.properties")) {
|
if (!"messages_en_GB.properties".equals(file.getName())) {
|
||||||
System.out.println("Processing file: " + file.getName());
|
System.out.println("Processing file: " + file.getName());
|
||||||
List<String> lines;
|
List<String> lines;
|
||||||
try {
|
try {
|
||||||
|
@ -25,7 +25,7 @@ public class SPdfApplication {
|
|||||||
public void init() {
|
public void init() {
|
||||||
// Check if the BROWSER_OPEN environment variable is set to true
|
// Check if the BROWSER_OPEN environment variable is set to true
|
||||||
String browserOpenEnv = env.getProperty("BROWSER_OPEN");
|
String browserOpenEnv = env.getProperty("BROWSER_OPEN");
|
||||||
boolean browserOpen = browserOpenEnv != null && browserOpenEnv.equalsIgnoreCase("true");
|
boolean browserOpen = browserOpenEnv != null && "true".equalsIgnoreCase(browserOpenEnv);
|
||||||
|
|
||||||
if (browserOpen) {
|
if (browserOpen) {
|
||||||
try {
|
try {
|
||||||
|
@ -84,7 +84,7 @@ public class ConfigInitializer
|
|||||||
for (String line : templateLines) {
|
for (String line : templateLines) {
|
||||||
String key = extractKey.apply(line);
|
String key = extractKey.apply(line);
|
||||||
|
|
||||||
if (line.trim().equalsIgnoreCase("AutomaticallyGenerated:")) {
|
if ("AutomaticallyGenerated:".equalsIgnoreCase(line.trim())) {
|
||||||
insideAutoGenerated = true;
|
insideAutoGenerated = true;
|
||||||
mergedLines.add(line);
|
mergedLines.add(line);
|
||||||
continue;
|
continue;
|
||||||
|
@ -55,7 +55,7 @@ public class ConvertImgPDFController {
|
|||||||
colorTypeResult = ImageType.BINARY;
|
colorTypeResult = ImageType.BINARY;
|
||||||
}
|
}
|
||||||
// returns bytes for image
|
// returns bytes for image
|
||||||
boolean singleImage = singleOrMultiple.equals("single");
|
boolean singleImage = "single".equals(singleOrMultiple);
|
||||||
byte[] result = null;
|
byte[] result = null;
|
||||||
String filename = Filenames.toSimpleFileName(file.getOriginalFilename()).replaceFirst("[.][^.]+$", "");
|
String filename = Filenames.toSimpleFileName(file.getOriginalFilename()).replaceFirst("[.][^.]+$", "");
|
||||||
try {
|
try {
|
||||||
@ -114,6 +114,6 @@ public class ConvertImgPDFController {
|
|||||||
|
|
||||||
private String getMediaType(String imageFormat) {
|
private String getMediaType(String imageFormat) {
|
||||||
String mimeType = URLConnection.guessContentTypeFromName("." + imageFormat);
|
String mimeType = URLConnection.guessContentTypeFromName("." + imageFormat);
|
||||||
return mimeType.equals("null") ? "application/octet-stream" : mimeType;
|
return "null".equals(mimeType) ? "application/octet-stream" : mimeType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ public class ExtractImageScansController {
|
|||||||
List<String> images = new ArrayList<>();
|
List<String> images = new ArrayList<>();
|
||||||
|
|
||||||
// Check if input file is a PDF
|
// Check if input file is a PDF
|
||||||
if (extension.equalsIgnoreCase("pdf")) {
|
if ("pdf".equalsIgnoreCase(extension)) {
|
||||||
// Load PDF document
|
// Load PDF document
|
||||||
try (PDDocument document = Loader.loadPDF(form.getFileInput().getBytes())) {
|
try (PDDocument document = Loader.loadPDF(form.getFileInput().getBytes())) {
|
||||||
PDFRenderer pdfRenderer = new PDFRenderer(document);
|
PDFRenderer pdfRenderer = new PDFRenderer(document);
|
||||||
|
@ -86,19 +86,19 @@ public class ExtractImagesController {
|
|||||||
// Convert image to desired format
|
// Convert image to desired format
|
||||||
RenderedImage renderedImage = image.getImage();
|
RenderedImage renderedImage = image.getImage();
|
||||||
BufferedImage bufferedImage = null;
|
BufferedImage bufferedImage = null;
|
||||||
if (format.equalsIgnoreCase("png")) {
|
if ("png".equalsIgnoreCase(format)) {
|
||||||
bufferedImage =
|
bufferedImage =
|
||||||
new BufferedImage(
|
new BufferedImage(
|
||||||
renderedImage.getWidth(),
|
renderedImage.getWidth(),
|
||||||
renderedImage.getHeight(),
|
renderedImage.getHeight(),
|
||||||
BufferedImage.TYPE_INT_ARGB);
|
BufferedImage.TYPE_INT_ARGB);
|
||||||
} else if (format.equalsIgnoreCase("jpeg") || format.equalsIgnoreCase("jpg")) {
|
} else if ("jpeg".equalsIgnoreCase(format) || "jpg".equalsIgnoreCase(format)) {
|
||||||
bufferedImage =
|
bufferedImage =
|
||||||
new BufferedImage(
|
new BufferedImage(
|
||||||
renderedImage.getWidth(),
|
renderedImage.getWidth(),
|
||||||
renderedImage.getHeight(),
|
renderedImage.getHeight(),
|
||||||
BufferedImage.TYPE_INT_RGB);
|
BufferedImage.TYPE_INT_RGB);
|
||||||
} else if (format.equalsIgnoreCase("gif")) {
|
} else if ("gif".equalsIgnoreCase(format)) {
|
||||||
bufferedImage =
|
bufferedImage =
|
||||||
new BufferedImage(
|
new BufferedImage(
|
||||||
renderedImage.getWidth(),
|
renderedImage.getWidth(),
|
||||||
|
@ -110,15 +110,15 @@ public class MetadataController {
|
|||||||
for (Entry<String, String> entry : allRequestParams.entrySet()) {
|
for (Entry<String, String> entry : allRequestParams.entrySet()) {
|
||||||
String key = entry.getKey();
|
String key = entry.getKey();
|
||||||
// Check if the key is a standard metadata key
|
// Check if the key is a standard metadata key
|
||||||
if (!key.equalsIgnoreCase("Author")
|
if (!"Author".equalsIgnoreCase(key)
|
||||||
&& !key.equalsIgnoreCase("CreationDate")
|
&& !"CreationDate".equalsIgnoreCase(key)
|
||||||
&& !key.equalsIgnoreCase("Creator")
|
&& !"Creator".equalsIgnoreCase(key)
|
||||||
&& !key.equalsIgnoreCase("Keywords")
|
&& !"Keywords".equalsIgnoreCase(key)
|
||||||
&& !key.equalsIgnoreCase("modificationDate")
|
&& !"modificationDate".equalsIgnoreCase(key)
|
||||||
&& !key.equalsIgnoreCase("Producer")
|
&& !"Producer".equalsIgnoreCase(key)
|
||||||
&& !key.equalsIgnoreCase("Subject")
|
&& !"Subject".equalsIgnoreCase(key)
|
||||||
&& !key.equalsIgnoreCase("Title")
|
&& !"Title".equalsIgnoreCase(key)
|
||||||
&& !key.equalsIgnoreCase("Trapped")
|
&& !"Trapped".equalsIgnoreCase(key)
|
||||||
&& !key.contains("customKey")
|
&& !key.contains("customKey")
|
||||||
&& !key.contains("customValue")) {
|
&& !key.contains("customValue")) {
|
||||||
info.setCustomMetadataValue(key, entry.getValue());
|
info.setCustomMetadataValue(key, entry.getValue());
|
||||||
|
@ -75,7 +75,7 @@ public class OCRController {
|
|||||||
throw new IOException("Please select at least one language.");
|
throw new IOException("Please select at least one language.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ocrRenderType.equals("hocr") && !ocrRenderType.equals("sandwich")) {
|
if (!"hocr".equals(ocrRenderType) && !"sandwich".equals(ocrRenderType)) {
|
||||||
throw new IOException("ocrRenderType wrong");
|
throw new IOException("ocrRenderType wrong");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ public class OCRController {
|
|||||||
if (cleanFinal != null && cleanFinal) {
|
if (cleanFinal != null && cleanFinal) {
|
||||||
command.add("--clean-final");
|
command.add("--clean-final");
|
||||||
}
|
}
|
||||||
if (ocrType != null && !ocrType.equals("")) {
|
if (ocrType != null && !"".equals(ocrType)) {
|
||||||
if ("skip-text".equals(ocrType)) {
|
if ("skip-text".equals(ocrType)) {
|
||||||
command.add("--skip-text");
|
command.add("--skip-text");
|
||||||
} else if ("force-ocr".equals(ocrType)) {
|
} else if ("force-ocr".equals(ocrType)) {
|
||||||
|
@ -96,7 +96,7 @@ public class StampController {
|
|||||||
graphicsState.setNonStrokingAlphaConstant(opacity);
|
graphicsState.setNonStrokingAlphaConstant(opacity);
|
||||||
contentStream.setGraphicsStateParameters(graphicsState);
|
contentStream.setGraphicsStateParameters(graphicsState);
|
||||||
|
|
||||||
if (watermarkType.equalsIgnoreCase("text")) {
|
if ("text".equalsIgnoreCase(watermarkType)) {
|
||||||
addTextStamp(
|
addTextStamp(
|
||||||
contentStream,
|
contentStream,
|
||||||
watermarkText,
|
watermarkText,
|
||||||
@ -110,7 +110,7 @@ public class StampController {
|
|||||||
overrideY,
|
overrideY,
|
||||||
marginFactor,
|
marginFactor,
|
||||||
customColor);
|
customColor);
|
||||||
} else if (watermarkType.equalsIgnoreCase("image")) {
|
} else if ("image".equalsIgnoreCase(watermarkType)) {
|
||||||
addImageStamp(
|
addImageStamp(
|
||||||
contentStream,
|
contentStream,
|
||||||
watermarkImage,
|
watermarkImage,
|
||||||
@ -167,7 +167,7 @@ public class StampController {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!resourceDir.equals("")) {
|
if (!"".equals(resourceDir)) {
|
||||||
ClassPathResource classPathResource = new ClassPathResource(resourceDir);
|
ClassPathResource classPathResource = new ClassPathResource(resourceDir);
|
||||||
String fileExtension = resourceDir.substring(resourceDir.lastIndexOf("."));
|
String fileExtension = resourceDir.substring(resourceDir.lastIndexOf("."));
|
||||||
File tempFile = Files.createTempFile("NotoSansFont", fileExtension).toFile();
|
File tempFile = Files.createTempFile("NotoSansFont", fileExtension).toFile();
|
||||||
|
@ -98,7 +98,7 @@ public class PipelineProcessor {
|
|||||||
for (Resource file : outputFiles) {
|
for (Resource file : outputFiles) {
|
||||||
boolean hasInputFileType = false;
|
boolean hasInputFileType = false;
|
||||||
for (String extension : inputFileTypes) {
|
for (String extension : inputFileTypes) {
|
||||||
if (extension.equals("ALL") || file.getFilename().endsWith(extension)) {
|
if ("ALL".equals(extension) || file.getFilename().endsWith(extension)) {
|
||||||
hasInputFileType = true;
|
hasInputFileType = true;
|
||||||
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
|
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
|
||||||
body.add("fileInput", file);
|
body.add("fileInput", file);
|
||||||
|
@ -77,7 +77,7 @@ public class WatermarkController {
|
|||||||
graphicsState.setNonStrokingAlphaConstant(opacity);
|
graphicsState.setNonStrokingAlphaConstant(opacity);
|
||||||
contentStream.setGraphicsStateParameters(graphicsState);
|
contentStream.setGraphicsStateParameters(graphicsState);
|
||||||
|
|
||||||
if (watermarkType.equalsIgnoreCase("text")) {
|
if ("text".equalsIgnoreCase(watermarkType)) {
|
||||||
addTextWatermark(
|
addTextWatermark(
|
||||||
contentStream,
|
contentStream,
|
||||||
watermarkText,
|
watermarkText,
|
||||||
@ -88,7 +88,7 @@ public class WatermarkController {
|
|||||||
heightSpacer,
|
heightSpacer,
|
||||||
fontSize,
|
fontSize,
|
||||||
alphabet);
|
alphabet);
|
||||||
} else if (watermarkType.equalsIgnoreCase("image")) {
|
} else if ("image".equalsIgnoreCase(watermarkType)) {
|
||||||
addImageWatermark(
|
addImageWatermark(
|
||||||
contentStream,
|
contentStream,
|
||||||
watermarkImage,
|
watermarkImage,
|
||||||
@ -141,7 +141,7 @@ public class WatermarkController {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!resourceDir.equals("")) {
|
if (!"".equals(resourceDir)) {
|
||||||
ClassPathResource classPathResource = new ClassPathResource(resourceDir);
|
ClassPathResource classPathResource = new ClassPathResource(resourceDir);
|
||||||
String fileExtension = resourceDir.substring(resourceDir.lastIndexOf("."));
|
String fileExtension = resourceDir.substring(resourceDir.lastIndexOf("."));
|
||||||
File tempFile = Files.createTempFile("NotoSansFont", fileExtension).toFile();
|
File tempFile = Files.createTempFile("NotoSansFont", fileExtension).toFile();
|
||||||
|
@ -84,7 +84,7 @@ public class MetricsController {
|
|||||||
for (Meter meter : meterRegistry.getMeters()) {
|
for (Meter meter : meterRegistry.getMeters()) {
|
||||||
if (meter.getId().getName().equals("http.requests")) {
|
if (meter.getId().getName().equals("http.requests")) {
|
||||||
String method = meter.getId().getTag("method");
|
String method = meter.getId().getTag("method");
|
||||||
if (method != null && method.equals("GET")) {
|
if (method != null && "GET".equals(method)) {
|
||||||
|
|
||||||
if (endpoint.isPresent() && !endpoint.get().isBlank()) {
|
if (endpoint.isPresent() && !endpoint.get().isBlank()) {
|
||||||
if (!endpoint.get().startsWith("/")) {
|
if (!endpoint.get().startsWith("/")) {
|
||||||
@ -129,7 +129,7 @@ public class MetricsController {
|
|||||||
for (Meter meter : meterRegistry.getMeters()) {
|
for (Meter meter : meterRegistry.getMeters()) {
|
||||||
if (meter.getId().getName().equals("http.requests")) {
|
if (meter.getId().getName().equals("http.requests")) {
|
||||||
String method = meter.getId().getTag("method");
|
String method = meter.getId().getTag("method");
|
||||||
if (method != null && method.equals("GET")) {
|
if (method != null && "GET".equals(method)) {
|
||||||
String uri = meter.getId().getTag("uri");
|
String uri = meter.getId().getTag("uri");
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
double currentCount = counts.getOrDefault(uri, 0.0);
|
double currentCount = counts.getOrDefault(uri, 0.0);
|
||||||
@ -197,7 +197,7 @@ public class MetricsController {
|
|||||||
for (Meter meter : meterRegistry.getMeters()) {
|
for (Meter meter : meterRegistry.getMeters()) {
|
||||||
if (meter.getId().getName().equals("http.requests")) {
|
if (meter.getId().getName().equals("http.requests")) {
|
||||||
String method = meter.getId().getTag("method");
|
String method = meter.getId().getTag("method");
|
||||||
if (method != null && method.equals("POST")) {
|
if (method != null && "POST".equals(method)) {
|
||||||
if (endpoint.isPresent() && !endpoint.get().isBlank()) {
|
if (endpoint.isPresent() && !endpoint.get().isBlank()) {
|
||||||
if (!endpoint.get().startsWith("/")) {
|
if (!endpoint.get().startsWith("/")) {
|
||||||
endpoint = Optional.of("/" + endpoint.get());
|
endpoint = Optional.of("/" + endpoint.get());
|
||||||
@ -235,7 +235,7 @@ public class MetricsController {
|
|||||||
for (Meter meter : meterRegistry.getMeters()) {
|
for (Meter meter : meterRegistry.getMeters()) {
|
||||||
if (meter.getId().getName().equals("http.requests")) {
|
if (meter.getId().getName().equals("http.requests")) {
|
||||||
String method = meter.getId().getTag("method");
|
String method = meter.getId().getTag("method");
|
||||||
if (method != null && method.equals("POST")) {
|
if (method != null && "POST".equals(method)) {
|
||||||
String uri = meter.getId().getTag("uri");
|
String uri = meter.getId().getTag("uri");
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
double currentCount = counts.getOrDefault(uri, 0.0);
|
double currentCount = counts.getOrDefault(uri, 0.0);
|
||||||
|
@ -173,7 +173,7 @@ public class FileToPdf {
|
|||||||
|
|
||||||
// Prioritize 'index.html' if it exists, otherwise use the first .html file
|
// Prioritize 'index.html' if it exists, otherwise use the first .html file
|
||||||
for (Path htmlFile : htmlFiles) {
|
for (Path htmlFile : htmlFiles) {
|
||||||
if (htmlFile.getFileName().toString().equals("index.html")) {
|
if ("index.html".equals(htmlFile.getFileName().toString())) {
|
||||||
return htmlFile;
|
return htmlFile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ public class GeneralUtils {
|
|||||||
|
|
||||||
// loop through the page order array
|
// loop through the page order array
|
||||||
for (String element : pageOrderArr) {
|
for (String element : pageOrderArr) {
|
||||||
if (element.equalsIgnoreCase("all")) {
|
if ("all".equalsIgnoreCase(element)) {
|
||||||
for (int i = 0; i < totalPages; i++) {
|
for (int i = 0; i < totalPages; i++) {
|
||||||
newPageOrder.add(i);
|
newPageOrder.add(i);
|
||||||
}
|
}
|
||||||
@ -137,11 +137,11 @@ public class GeneralUtils {
|
|||||||
|
|
||||||
if (element.contains("n")) {
|
if (element.contains("n")) {
|
||||||
String[] parts = element.split("n");
|
String[] parts = element.split("n");
|
||||||
if (!parts[0].equals("") && parts[0] != null) {
|
if (!"".equals(parts[0]) && parts[0] != null) {
|
||||||
coefficient = Integer.parseInt(parts[0]);
|
coefficient = Integer.parseInt(parts[0]);
|
||||||
coefficientExists = true;
|
coefficientExists = true;
|
||||||
}
|
}
|
||||||
if (parts.length > 1 && !parts[1].equals("") && parts[1] != null) {
|
if (parts.length > 1 && !"".equals(parts[1]) && parts[1] != null) {
|
||||||
constant = Integer.parseInt(parts[1]);
|
constant = Integer.parseInt(parts[1]);
|
||||||
constantExists = true;
|
constantExists = true;
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ public class PDFToFile {
|
|||||||
if (outputFiles.size() == 1) {
|
if (outputFiles.size() == 1) {
|
||||||
// Return single output file
|
// Return single output file
|
||||||
File outputFile = outputFiles.get(0);
|
File outputFile = outputFiles.get(0);
|
||||||
if (outputFormat.equals("txt:Text")) {
|
if ("txt:Text".equals(outputFormat)) {
|
||||||
outputFormat = "txt";
|
outputFormat = "txt";
|
||||||
}
|
}
|
||||||
fileName = pdfBaseName + "." + outputFormat;
|
fileName = pdfBaseName + "." + outputFormat;
|
||||||
|
@ -133,7 +133,7 @@ public class PdfUtils {
|
|||||||
PDFTextStripper textStripper = new PDFTextStripper();
|
PDFTextStripper textStripper = new PDFTextStripper();
|
||||||
String pdfText = "";
|
String pdfText = "";
|
||||||
|
|
||||||
if (pagesToCheck == null || pagesToCheck.equals("all")) {
|
if (pagesToCheck == null || "all".equals(pagesToCheck)) {
|
||||||
pdfText = textStripper.getText(pdfDocument);
|
pdfText = textStripper.getText(pdfDocument);
|
||||||
} else {
|
} else {
|
||||||
// remove whitespaces
|
// remove whitespaces
|
||||||
@ -219,8 +219,8 @@ public class PdfUtils {
|
|||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
|
||||||
if (singleImage) {
|
if (singleImage) {
|
||||||
if (imageType.toLowerCase().equals("tiff")
|
if ("tiff".equals(imageType.toLowerCase())
|
||||||
|| imageType.toLowerCase().equals("tif")) {
|
|| "tif".equals(imageType.toLowerCase())) {
|
||||||
// Write the images to the output stream as a TIFF with multiple frames
|
// Write the images to the output stream as a TIFF with multiple frames
|
||||||
ImageWriter writer = ImageIO.getImageWritersByFormatName("tiff").next();
|
ImageWriter writer = ImageIO.getImageWritersByFormatName("tiff").next();
|
||||||
ImageWriteParam param = writer.getDefaultWriteParam();
|
ImageWriteParam param = writer.getDefaultWriteParam();
|
||||||
@ -321,7 +321,7 @@ public class PdfUtils {
|
|||||||
ImageProcessingUtils.convertColorType(image, colorType);
|
ImageProcessingUtils.convertColorType(image, colorType);
|
||||||
// Use JPEGFactory if it's JPEG since JPEG is lossy
|
// Use JPEGFactory if it's JPEG since JPEG is lossy
|
||||||
PDImageXObject pdImage =
|
PDImageXObject pdImage =
|
||||||
(contentType != null && contentType.equals("image/jpeg"))
|
(contentType != null && "image/jpeg".equals(contentType))
|
||||||
? JPEGFactory.createFromImage(doc, convertedImage)
|
? JPEGFactory.createFromImage(doc, convertedImage)
|
||||||
: LosslessFactory.createFromImage(doc, convertedImage);
|
: LosslessFactory.createFromImage(doc, convertedImage);
|
||||||
addImageToDocument(doc, pdImage, fitOption, autoRotate);
|
addImageToDocument(doc, pdImage, fitOption, autoRotate);
|
||||||
|
Loading…
Reference in New Issue
Block a user