Skip to content

Commit 3d4a33d

Browse files
committed
refactor(JF-466): deactivate this feature by default & add switch to turn it on
1 parent 187d261 commit 3d4a33d

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/main/java/org/jadice/filetype/matchers/PDFMatcher.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public class PDFMatcher extends Matcher {
6868
public static final String TEXT_LENGTH_KEY = "text-length";
6969
public static final String TEXT_LENGTH_PER_PAGE_KEY = "text-length-per-page";
7070

71+
private static boolean lookForText() {
72+
return "true".equalsIgnoreCase(System.getProperty(PDFMatcher.class.getName() + ".lookForText", "false"));
73+
}
74+
7175
/*
7276
* (non-Javadoc)
7377
*
@@ -129,8 +133,8 @@ public boolean matches(final Context context) {
129133
fileLength = getFileLength(sis);
130134
}
131135
PDFBoxSignatureUtil.addSignatureInfo(pdfDetails, document, fileLength);
132-
133-
addTextInfo(pdfDetails, document);
136+
if (lookForText())
137+
addTextInfo(pdfDetails, document);
134138
}
135139

136140
return true;

src/test/java/TestPDFMatcher.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ void testSignedPDFs(final String urlString, final int expectedSignatureCount) th
159159
@ParameterizedTest
160160
@CsvFileSource(resources = "/pdf/contains-text.csv", numLinesToSkip = 1)
161161
void testContainsText(final String filePath, final boolean expected) throws IOException {
162+
System.setProperty(PDFMatcher.class.getName() + ".lookForText", "true");
162163
Map<String, Object> result = ANALYZER.analyze(new File(filePath));
163164
assertNotNull(result);
164165
assertTrue(result.containsKey(PDFMatcher.DETAILS_KEY));
@@ -174,6 +175,7 @@ void testContainsText(final String filePath, final boolean expected) throws IOEx
174175
final int sum = textLengthPerPages.stream().mapToInt(Integer::intValue).sum();
175176
assertEquals(totalTextLength, sum);
176177
}
178+
System.clearProperty(PDFMatcher.class.getName() + ".lookForText");
177179
}
178180

179181
private static File[] nullSafe(final File[] filesOrNull) {

0 commit comments

Comments
 (0)