jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r511509 - /jackrabbit/trunk/jackrabbit-index-filters/src/main/java/org/apache/jackrabbit/core/query/PdfTextFilter.java
Date Sun, 25 Feb 2007 13:34:33 GMT
Author: jukka
Date: Sun Feb 25 05:34:33 2007
New Revision: 511509

URL: http://svn.apache.org/viewvc?view=rev&rev=511509
Log:
JCR-764: Applied the patch from Fabrizio Giustina with some additional comments.

Modified:
    jackrabbit/trunk/jackrabbit-index-filters/src/main/java/org/apache/jackrabbit/core/query/PdfTextFilter.java

Modified: jackrabbit/trunk/jackrabbit-index-filters/src/main/java/org/apache/jackrabbit/core/query/PdfTextFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-index-filters/src/main/java/org/apache/jackrabbit/core/query/PdfTextFilter.java?view=diff&rev=511509&r1=511508&r2=511509
==============================================================================
--- jackrabbit/trunk/jackrabbit-index-filters/src/main/java/org/apache/jackrabbit/core/query/PdfTextFilter.java
(original)
+++ jackrabbit/trunk/jackrabbit-index-filters/src/main/java/org/apache/jackrabbit/core/query/PdfTextFilter.java
Sun Feb 25 05:34:33 2007
@@ -30,6 +30,7 @@
 import org.apache.jackrabbit.core.state.PropertyState;
 import org.apache.jackrabbit.core.value.BLOBFileValue;
 import org.apache.jackrabbit.core.value.InternalValue;
+import org.pdfbox.cos.COSDocument;
 import org.pdfbox.pdfparser.PDFParser;
 import org.pdfbox.pdmodel.PDDocument;
 import org.pdfbox.util.PDFTextStripper;
@@ -69,7 +70,7 @@
             final BLOBFileValue blob = (BLOBFileValue) values[0].internalValue();
             LazyReader reader = new LazyReader() {
                 protected void initializeReader() throws IOException {
-                    PDFParser parser;
+                    PDFParser parser = null;
                     InputStream in;
                     try {
                         in = blob.getStream();
@@ -96,6 +97,19 @@
                     } catch (Exception e) {
                         // it may happen that PDFParser throws a runtime
                         // exception when parsing certain pdf documents
+
+                        // JCR-764: Check if document is still open and
+                        // close it appropriately. Otherwise some temporary
+                        // files may get left behind and document finalization
+                        // will log a warning.
+                        if (parser != null) {
+                            try {
+                                parser.getDocument().close();
+                            } catch (Exception ioe) {
+                                // ignore, this means doc has not been generated
+                            }
+                        }
+
                         throw new IOException(e.getMessage());
                     } finally {
                         in.close();



Mime
View raw message