You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2018/03/29 19:39:26 UTC

[tika] branch master updated: TIKA-2620 allow configuration of setting KCMS

This is an automated email from the ASF dual-hosted git repository.

tallison pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tika.git


The following commit(s) were added to refs/heads/master by this push:
     new 4cdb330  TIKA-2620 allow configuration of setting KCMS
4cdb330 is described below

commit 4cdb330526e7001997f939271b5185d2efb6451c
Author: tballison <ta...@mitre.org>
AuthorDate: Thu Mar 29 15:39:17 2018 -0400

    TIKA-2620 allow configuration of setting KCMS
---
 .../java/org/apache/tika/parser/pdf/PDFParser.java |  8 +++++++
 .../apache/tika/parser/pdf/PDFParserConfig.java    | 27 ++++++++++++++++++++++
 .../apache/tika/parser/pdf/PDFParser.properties    |  2 ++
 3 files changed, 37 insertions(+)

diff --git a/tika-parsers/src/main/java/org/apache/tika/parser/pdf/PDFParser.java b/tika-parsers/src/main/java/org/apache/tika/parser/pdf/PDFParser.java
index 5149b0d..cd847db 100644
--- a/tika-parsers/src/main/java/org/apache/tika/parser/pdf/PDFParser.java
+++ b/tika-parsers/src/main/java/org/apache/tika/parser/pdf/PDFParser.java
@@ -134,6 +134,9 @@ public class PDFParser extends AbstractParser implements Initializable {
             throws IOException, SAXException, TikaException {
 
         PDFParserConfig localConfig = context.get(PDFParserConfig.class, defaultConfig);
+        if (localConfig.getSetKCMS()) {
+            System.setProperty("sun.java2d.cmm", "sun.java2d.cmm.kcms.KcmsServiceProvider");
+        }
 
         PDDocument pdfDocument = null;
 
@@ -702,6 +705,11 @@ public class PDFParser extends AbstractParser implements Initializable {
     }
 
     @Field
+    void setSetKCMS(boolean setKCMS) {
+        defaultConfig.setSetKCMS(setKCMS);
+    }
+
+    @Field
     void setInitializableProblemHander(String name) {
         if ("ignore".equals(name)) {
             setInitializableProblemHandler(InitializableProblemHandler.IGNORE);
diff --git a/tika-parsers/src/main/java/org/apache/tika/parser/pdf/PDFParserConfig.java b/tika-parsers/src/main/java/org/apache/tika/parser/pdf/PDFParserConfig.java
index 5fc9a7b..a305c4c 100644
--- a/tika-parsers/src/main/java/org/apache/tika/parser/pdf/PDFParserConfig.java
+++ b/tika-parsers/src/main/java/org/apache/tika/parser/pdf/PDFParserConfig.java
@@ -137,6 +137,8 @@ public class PDFParserConfig implements Serializable {
 
     private long maxMainMemoryBytes = -1;
 
+    private boolean setKCMS = false;
+
     public PDFParserConfig() {
         init(this.getClass().getResourceAsStream("PDFParser.properties"));
     }
@@ -215,6 +217,7 @@ public class PDFParserConfig implements Serializable {
 
         setExtractActions(getBooleanProp(props.getProperty("extractActions"), false));
 
+        setSetKCMS(getBooleanProp(props.getProperty("setKCMS"), false));
 
         boolean checkExtractAccessPermission = getBooleanProp(props.getProperty("checkExtractAccessPermission"), false);
         boolean allowExtractionForAccessibility = getBooleanProp(props.getProperty("allowExtractionForAccessibility"), true);
@@ -688,6 +691,30 @@ public class PDFParserConfig implements Serializable {
         this.maxMainMemoryBytes = maxMainMemoryBytes;
     }
 
+    /**
+     * <p>
+     *     Whether to call <code>System.setProperty("sun.java2d.cmm", "sun.java2d.cmm.kcms.KcmsServiceProvider")</code>.
+     *     KCMS is the unmaintained, legacy provider and is far faster than the newer replacement.
+     *     However, there are stability and security risks with using the unmaintained legacy provider.
+     * </p>
+     * <p>
+     *     Note, of course, that this is <b>not</b> thread safe.  If the value is <code>false</code>
+     *     in your first thread, and the second thread changes this to <code>true</code>,
+     *     the system property in the first thread will now be <code>true</code>.
+     * </p>
+     * <p>
+     * Default is <code>false</code>.
+     * </p>
+     * @param setKCMS whether or not to set KCMS
+     */
+    public void setSetKCMS(boolean setKCMS) {
+        this.setKCMS = setKCMS;
+    }
+
+    public boolean getSetKCMS() {
+        return setKCMS;
+    }
+
     private ImageType parseImageType(String ocrImageType) {
         for (ImageType t : ImageType.values()) {
             if (ocrImageType.equalsIgnoreCase(t.toString())) {
diff --git a/tika-parsers/src/main/resources/org/apache/tika/parser/pdf/PDFParser.properties b/tika-parsers/src/main/resources/org/apache/tika/parser/pdf/PDFParser.properties
index 88b1623..f2d3db6 100644
--- a/tika-parsers/src/main/resources/org/apache/tika/parser/pdf/PDFParser.properties
+++ b/tika-parsers/src/main/resources/org/apache/tika/parser/pdf/PDFParser.properties
@@ -37,3 +37,5 @@ ocrImageType gray
 ocrImageScale 2.0
 # Use up to 500MB when loading a pdf into a PDDocument
 maxMainMemoryBytes 524288000
+#whether or not to set KCMS for faster (but legacy/unsupported) image rendering
+setKCMS false

-- 
To stop receiving notification emails like this one, please contact
tallison@apache.org.