jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r409517 - in /jackrabbit/branches/1.0/textfilters: ./ src/java/org/apache/jackrabbit/core/query/
Date Fri, 26 May 2006 00:20:15 GMT
Author: jukka
Date: Thu May 25 17:20:14 2006
New Revision: 409517

URL: http://svn.apache.org/viewvc?rev=409517&view=rev
Log:
1.0: Merged revision 392211: JCR-264

Added:
    jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/LazyReader.java
      - copied unchanged from r392211, jackrabbit/trunk/textfilters/src/java/org/apache/jackrabbit/core/query/LazyReader.java
Modified:
    jackrabbit/branches/1.0/textfilters/project.xml
    jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/HTMLTextFilter.java
    jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/MsExcelTextFilter.java
    jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/MsPowerPointTextFilter.java
    jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/MsWordTextFilter.java
    jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/OpenOfficeTextFilter.java
    jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/PdfTextFilter.java
    jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/RTFTextFilter.java
    jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/XMLTextFilter.java

Modified: jackrabbit/branches/1.0/textfilters/project.xml
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.0/textfilters/project.xml?rev=409517&r1=409516&r2=409517&view=diff
==============================================================================
--- jackrabbit/branches/1.0/textfilters/project.xml (original)
+++ jackrabbit/branches/1.0/textfilters/project.xml Thu May 25 17:20:14 2006
@@ -174,6 +174,12 @@
       <type>jar</type>
     </dependency>
     <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <version>1.0</version>
+      <type>jar</type>
+    </dependency>
+    <dependency>
       <groupId>log4j</groupId>
       <artifactId>log4j</artifactId>
       <version>1.2.8</version>

Modified: jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/HTMLTextFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/HTMLTextFilter.java?rev=409517&r1=409516&r2=409517&view=diff
==============================================================================
--- jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/HTMLTextFilter.java
(original)
+++ jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/HTMLTextFilter.java
Thu May 25 17:20:14 2006
@@ -16,6 +16,8 @@
 package org.apache.jackrabbit.core.query;
 
 import java.io.StringReader;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -72,28 +74,35 @@
 
         InternalValue[] values = data.getValues();
         if (values.length > 0) {
-            try {
-                try {
-                    BLOBFileValue blob =
-                            (BLOBFileValue) values[0].internalValue();
-
-                    SAXSource source =
-                            new SAXSource(parser,
-                                    new InputSource(blob.getStream()));
-                    transformer.transform(source, result);
-
-                    String text = parser.getContents();
-
-                    Map result = new HashMap();
-                    result.put(FieldNames.FULLTEXT, new StringReader(text));
-                    return result;
-                } catch (TransformerException te) {
-                    throw new RepositoryException(te);
+            final BLOBFileValue blob = (BLOBFileValue) values[0].internalValue();
+            LazyReader reader = new LazyReader() {
+                protected void initializeReader() throws IOException {
+                    InputStream in;
+                    try {
+                        in = blob.getStream();
+                    } catch (RepositoryException e) {
+                        throw new IOException(e.getMessage());
+                    }
+                    try {
+                        SAXSource source =
+                                new SAXSource(parser,
+                                        new InputSource(in));
+                        transformer.transform(source, result);
+
+                        String text = parser.getContents();
+
+                        delegate = new StringReader(text);
+                    } catch (TransformerException e) {
+                        throw new IOException(e.getMessage());
+                    } finally {
+                        in.close();
+                    }
                 }
+            };
 
-            } catch (IllegalStateException e) {
-                throw new RepositoryException(e);
-            }
+            Map result = new HashMap();
+            result.put(FieldNames.FULLTEXT, reader);
+            return result;
         } else {
             // multi value not supported
             throw new RepositoryException("Multi-valued binary properties not supported.");

Modified: jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/MsExcelTextFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/MsExcelTextFilter.java?rev=409517&r1=409516&r2=409517&view=diff
==============================================================================
--- jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/MsExcelTextFilter.java
(original)
+++ jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/MsExcelTextFilter.java
Thu May 25 17:20:14 2006
@@ -18,6 +18,7 @@
 import java.io.CharArrayReader;
 import java.io.CharArrayWriter;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -59,51 +60,61 @@
     public Map doFilter(PropertyState data, String encoding) throws RepositoryException {
         InternalValue[] values = data.getValues();
         if (values.length > 0) {
-            BLOBFileValue blob = (BLOBFileValue) values[0].internalValue();
-                
-            try {
-                CharArrayWriter writer = new CharArrayWriter();
-    
-                POIFSFileSystem fs = new POIFSFileSystem(blob.getStream());
-                HSSFWorkbook workbook = new HSSFWorkbook(fs);
-    
-                for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
-                    HSSFSheet sheet = workbook.getSheetAt(i);
-    
-                    Iterator rows = sheet.rowIterator();
-                    while (rows.hasNext()) {
-                        HSSFRow row = (HSSFRow) rows.next();
-    
-                        Iterator cells = row.cellIterator();
-                        while (cells.hasNext()) {
-                            HSSFCell cell = (HSSFCell) cells.next();
-                            switch (cell.getCellType()) {
-                            case HSSFCell.CELL_TYPE_NUMERIC:
-                                String num = Double.toString(cell.getNumericCellValue()).trim();
-                                if (num.length() > 0) {
-                                    writer.write(num + " ");
-                                }
-                                break;
-                            case HSSFCell.CELL_TYPE_STRING:
-                                String text = cell.getStringCellValue().trim();
-                                if (text.length() > 0) {
-                                    writer.write(text + " ");
+            final BLOBFileValue blob = (BLOBFileValue) values[0].internalValue();
+            LazyReader reader = new LazyReader() {
+                protected void initializeReader() throws IOException {
+                    CharArrayWriter writer = new CharArrayWriter();
+
+                    InputStream in;
+                    try {
+                        in = blob.getStream();
+                    } catch (RepositoryException e) {
+                        throw new IOException(e.getMessage());
+                    }
+
+                    try {
+                        POIFSFileSystem fs = new POIFSFileSystem(in);
+                        HSSFWorkbook workbook = new HSSFWorkbook(fs);
+
+                        for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
+                            HSSFSheet sheet = workbook.getSheetAt(i);
+
+                            Iterator rows = sheet.rowIterator();
+                            while (rows.hasNext()) {
+                                HSSFRow row = (HSSFRow) rows.next();
+
+                                Iterator cells = row.cellIterator();
+                                while (cells.hasNext()) {
+                                    HSSFCell cell = (HSSFCell) cells.next();
+                                    switch (cell.getCellType()) {
+                                    case HSSFCell.CELL_TYPE_NUMERIC:
+                                        String num = Double.toString(cell.getNumericCellValue()).trim();
+                                        if (num.length() > 0) {
+                                            writer.write(num + " ");
+                                        }
+                                        break;
+                                    case HSSFCell.CELL_TYPE_STRING:
+                                        String text = cell.getStringCellValue().trim();
+                                        if (text.length() > 0) {
+                                            writer.write(text + " ");
+                                        }
+                                        break;
+                                    }
                                 }
-                                break;
                             }
                         }
+
+                        delegate = new CharArrayReader(writer.toCharArray());
+                    } finally {
+                        in.close();
                     }
                 }
-                
-                Map result = new HashMap();
-                result.put(FieldNames.FULLTEXT, new CharArrayReader(writer.toCharArray()));
-                return result;
-            } 
-            catch (IOException ex) {
-                throw new RepositoryException(ex);
-            }
-        } 
-        else {
+            };
+
+            Map result = new HashMap();
+            result.put(FieldNames.FULLTEXT, reader);
+            return result;
+        } else {
             // multi value not supported
             throw new RepositoryException("Multi-valued binary properties not supported.");
         }

Modified: jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/MsPowerPointTextFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/MsPowerPointTextFilter.java?rev=409517&r1=409516&r2=409517&view=diff
==============================================================================
--- jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/MsPowerPointTextFilter.java
(original)
+++ jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/MsPowerPointTextFilter.java
Thu May 25 17:20:14 2006
@@ -20,6 +20,7 @@
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -99,22 +100,35 @@
 		InternalValue[] values = data.getValues();
 
 		if (values.length == 1) {
-			BLOBFileValue blob = (BLOBFileValue) values[0].internalValue();
+			final BLOBFileValue blob = (BLOBFileValue) values[0].internalValue();
 
-			try {
-				ByteArrayOutputStream baos = new ByteArrayOutputStream();
-				MsPowerPointListener listener = new MsPowerPointListener(baos);
-				POIFSReader reader = new POIFSReader();
-				reader.registerListener(listener);
-				reader.read(blob.getStream());
-				Map result = new HashMap();
-				result.put(FieldNames.FULLTEXT, new InputStreamReader(
-						new ByteArrayInputStream(baos.toByteArray())));
-				
-				return result;
-			} catch (IOException ex) {
-				throw new RepositoryException(ex);
-			}
+            LazyReader reader = new LazyReader() {
+                protected void initializeReader() throws IOException {
+                    InputStream in;
+                    try {
+                        in = blob.getStream();
+                    } catch (RepositoryException e) {
+                        throw new IOException(e.getMessage());
+                    }
+                    try {
+                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                        MsPowerPointListener listener = new MsPowerPointListener(baos);
+                        POIFSReader reader = new POIFSReader();
+                        reader.registerListener(listener);
+                        reader.read(in);
+
+                        delegate = new InputStreamReader(
+                            new ByteArrayInputStream(baos.toByteArray()));
+                    } finally {
+                        in.close();
+                    }
+                }
+            };
+
+            Map result = new HashMap();
+            result.put(FieldNames.FULLTEXT, reader);
+
+            return result;
 		} else {
 			// multi value not supported
 			throw new RepositoryException(

Modified: jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/MsWordTextFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/MsWordTextFilter.java?rev=409517&r1=409516&r2=409517&view=diff
==============================================================================
--- jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/MsWordTextFilter.java
(original)
+++ jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/MsWordTextFilter.java
Thu May 25 17:20:14 2006
@@ -16,6 +16,8 @@
 package org.apache.jackrabbit.core.query;
 
 import java.io.StringReader;
+import java.io.InputStream;
+import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -51,26 +53,39 @@
      * @throws RepositoryException if data is a multi-value property or it does not
      * contain valid MS Word document.
      */
-    public Map doFilter(PropertyState data, String encoding) throws RepositoryException {
+    public Map doFilter(PropertyState data, String encoding)
+            throws RepositoryException {
         InternalValue[] values = data.getValues();
         if (values.length > 0) {
-            BLOBFileValue blob = (BLOBFileValue) values[0].internalValue();
-                
-            try {
-                WordExtractor  extractor = new WordExtractor();
-                
-                // This throws raw Exception - not nice
-                String text = extractor.extractText(blob.getStream());          
-                
-                Map result = new HashMap();
-                result.put(FieldNames.FULLTEXT, new StringReader(text));
-                return result;
-            } 
-            catch (Exception ex) {
-                throw new RepositoryException(ex);
-            }
-        } 
-        else {
+            final BLOBFileValue blob = (BLOBFileValue) values[0].internalValue();
+
+            LazyReader reader = new LazyReader() {
+                protected void initializeReader() throws IOException {
+                    InputStream in;
+                    try {
+                        in = blob.getStream();
+                    } catch (RepositoryException e) {
+                        throw new IOException(e.getMessage());
+                    }
+                    try {
+                        WordExtractor extractor = new WordExtractor();
+
+                        // This throws raw Exception - not nice
+                        String text = extractor.extractText(in);
+
+                        delegate = new StringReader(text);
+                    } catch (Exception e) {
+                        throw new IOException(e.getMessage());
+                    } finally {
+                        in.close();
+                    }
+                }
+            };
+
+            Map result = new HashMap();
+            result.put(FieldNames.FULLTEXT, reader);
+            return result;
+        } else {
             // multi value not supported
             throw new RepositoryException("Multi-valued binary properties not supported.");
         }

Modified: jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/OpenOfficeTextFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/OpenOfficeTextFilter.java?rev=409517&r1=409516&r2=409517&view=diff
==============================================================================
--- jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/OpenOfficeTextFilter.java
(original)
+++ jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/OpenOfficeTextFilter.java
Thu May 25 17:20:14 2006
@@ -24,6 +24,7 @@
 
 import java.io.IOException;
 import java.io.StringReader;
+import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.zip.ZipInputStream;
@@ -33,6 +34,7 @@
 
 import org.xml.sax.InputSource;
 import org.xml.sax.XMLReader;
+import org.xml.sax.SAXException;
 
 /**
  * Extracts texts from OpenOffice document data.
@@ -51,39 +53,48 @@
 
     public Map doFilter(PropertyState data, String encoding)
             throws RepositoryException {
-        ZipInputStream zis = null;
         if (xmlReader == null) {
             initParser();
         }
 
         InternalValue[] values = data.getValues();
         if (values.length > 0) {
-            BLOBFileValue blob = (BLOBFileValue) values[0].internalValue();
+            final BLOBFileValue blob = (BLOBFileValue) values[0].internalValue();
 
-            try {
-                zis = new ZipInputStream(blob.getStream());
-                ZipEntry ze = zis.getNextEntry();
-                while (!ze.getName().equals("content.xml"))
-                    ze = zis.getNextEntry();
-                OOoContentHandler contentHandler = new OOoContentHandler();
-                xmlReader.setContentHandler(contentHandler);
-                xmlReader.parse(new InputSource(zis));
-                zis.close();
-
-                Map result = new HashMap();
-                result.put(FieldNames.FULLTEXT, new StringReader(contentHandler.getContent()));
-                return result;
-            } catch (Exception ex) {
-                throw new RepositoryException(ex);
-            } finally {
-                if (zis != null) {
+            LazyReader reader = new LazyReader() {
+                protected void initializeReader() throws IOException {
+                    InputStream in;
                     try {
-                        zis.close();
-                    } catch (IOException ioe) {
-                        ioe.printStackTrace();
+                        in = blob.getStream();
+                    } catch (RepositoryException e) {
+                        throw new IOException(e.getMessage());
+                    }
+                    try {
+                        ZipInputStream zis = new ZipInputStream(in);
+                        ZipEntry ze = zis.getNextEntry();
+                        while (!ze.getName().equals("content.xml")) {
+                            ze = zis.getNextEntry();
+                        }
+                        OOoContentHandler contentHandler = new OOoContentHandler();
+                        xmlReader.setContentHandler(contentHandler);
+                        try {
+                            xmlReader.parse(new InputSource(zis));
+                        } catch (SAXException e) {
+                            throw new IOException(e.getMessage());
+                        } finally {
+                            zis.close();
+                        }
+
+                        delegate = new StringReader(contentHandler.getContent());
+                    } finally {
+                        in.close();
                     }
                 }
-            }
+            };
+
+            Map result = new HashMap();
+            result.put(FieldNames.FULLTEXT, reader);
+            return result;
         } else {
             // multi value not supported
             throw new RepositoryException("Multi-valued binary properties not supported.");

Modified: jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/PdfTextFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/PdfTextFilter.java?rev=409517&r1=409516&r2=409517&view=diff
==============================================================================
--- jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/PdfTextFilter.java
(original)
+++ jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/PdfTextFilter.java
Thu May 25 17:20:14 2006
@@ -18,6 +18,8 @@
 import java.io.CharArrayReader;
 import java.io.CharArrayWriter;
 import java.io.IOException;
+import java.io.BufferedInputStream;
+import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -56,32 +58,43 @@
     public Map doFilter(PropertyState data, String encoding) throws RepositoryException {
         InternalValue[] values = data.getValues();
         if (values.length > 0) {
-            BLOBFileValue blob = (BLOBFileValue) values[0].internalValue();
-                
-            try {
-                PDFParser parser = new PDFParser(blob.getStream());
-                parser.parse();
-    
-                PDDocument document = parser.getPDDocument();
-    
-                CharArrayWriter writer = new CharArrayWriter();
-    
-                PDFTextStripper stripper = new PDFTextStripper();
-                stripper.setLineSeparator("\n");
-                stripper.writeText(document, writer);
-    
-                document.close();
-                writer.close();
-                
-                Map result = new HashMap();
-                result.put(FieldNames.FULLTEXT, new CharArrayReader(writer.toCharArray()));
-                return result;
-            } 
-            catch (IOException ex) {
-                throw new RepositoryException(ex);
-            }
-        } 
-        else {
+            final BLOBFileValue blob = (BLOBFileValue) values[0].internalValue();
+            LazyReader reader = new LazyReader() {
+                protected void initializeReader() throws IOException {
+                    PDFParser parser;
+                    InputStream in;
+                    try {
+                        in = blob.getStream();
+                    } catch (RepositoryException e) {
+                        throw new IOException(e.getMessage());
+                    }
+
+                    try {
+                        parser = new PDFParser(new BufferedInputStream(in));
+                        parser.parse();
+
+                        PDDocument document = parser.getPDDocument();
+                        try {
+                            CharArrayWriter writer = new CharArrayWriter();
+
+                            PDFTextStripper stripper = new PDFTextStripper();
+                            stripper.setLineSeparator("\n");
+                            stripper.writeText(document, writer);
+
+                            delegate = new CharArrayReader(writer.toCharArray());
+                        } finally {
+                            document.close();
+                        }
+                    } finally {
+                        in.close();
+                    }
+                }
+            };
+
+            Map result = new HashMap();
+            result.put(FieldNames.FULLTEXT, reader);
+            return result;
+        } else {
             // multi value not supported
             throw new RepositoryException("Multi-valued binary properties not supported.");
         }

Modified: jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/RTFTextFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/RTFTextFilter.java?rev=409517&r1=409516&r2=409517&view=diff
==============================================================================
--- jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/RTFTextFilter.java
(original)
+++ jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/RTFTextFilter.java
Thu May 25 17:20:14 2006
@@ -17,6 +17,7 @@
 
 import java.io.IOException;
 import java.io.StringReader;
+import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -62,23 +63,31 @@
 
         InternalValue[] values = data.getValues();
         if (values.length > 0) {
-            try {
-                BLOBFileValue blob = (BLOBFileValue) values[0].internalValue();
-
-                doc.remove(0, doc.getLength());
-                rek.read(blob.getStream(), doc, 0);
-                String text = doc.getText(0, doc.getLength());
-
-                Map result = new HashMap();
-                result.put(FieldNames.FULLTEXT, new StringReader(text));
-                return result;
-            } catch (BadLocationException ble) {
-                throw new RepositoryException(ble);
-            } catch (IOException ioe) {
-                throw new RepositoryException(ioe);
-            } catch (IllegalStateException e) {
-                throw new RepositoryException(e);
-            }
+            final BLOBFileValue blob = (BLOBFileValue) values[0].internalValue();
+            LazyReader reader = new LazyReader() {
+                protected void initializeReader() throws IOException {
+                    InputStream in;
+                    try {
+                        in = blob.getStream();
+                    } catch (RepositoryException e) {
+                        throw new IOException(e.getMessage());
+                    }
+                    try {
+                        doc.remove(0, doc.getLength());
+                        rek.read(in, doc, 0);
+                        String text = doc.getText(0, doc.getLength());
+                        delegate = new StringReader(text);
+                    } catch (BadLocationException e) {
+                        throw new IOException(e.getMessage());
+                    } finally {
+                        in.close();
+                    }
+                }
+            };
+
+            Map result = new HashMap();
+            result.put(FieldNames.FULLTEXT, reader);
+            return result;
         } else {
             // multi value not supported
             throw new RepositoryException("Multi-valued binary properties not supported.");

Modified: jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/XMLTextFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/XMLTextFilter.java?rev=409517&r1=409516&r2=409517&view=diff
==============================================================================
--- jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/XMLTextFilter.java
(original)
+++ jackrabbit/branches/1.0/textfilters/src/java/org/apache/jackrabbit/core/query/XMLTextFilter.java
Thu May 25 17:20:14 2006
@@ -73,22 +73,28 @@
 
         InternalValue[] values = data.getValues();
         if (values.length > 0) {
-            try {
-                try {
-                    BLOBFileValue blob = (BLOBFileValue) values[0].internalValue();
-                    parser.parse(blob.getStream());
-                    String text = parser.getContents();
-
-                    Map result = new HashMap();
-                    result.put(FieldNames.FULLTEXT, new StringReader(text));
-                    return result;
-                } catch (IOException ioe) {
-                    throw new RepositoryException(ioe);
+            final BLOBFileValue blob = (BLOBFileValue) values[0].internalValue();
+            LazyReader reader = new LazyReader() {
+                protected void initializeReader() throws IOException {
+                    InputStream in;
+                    try {
+                        in = blob.getStream();
+                    } catch (RepositoryException e) {
+                        throw new IOException(e.getMessage());
+                    }
+                    try {
+                        parser.parse(in);
+                        String text = parser.getContents();
+                        delegate = new StringReader(text);
+                    } finally {
+                        in.close();
+                    }
                 }
+            };
 
-            } catch (IllegalStateException e) {
-                throw new RepositoryException(e);
-            }
+            Map result = new HashMap();
+            result.put(FieldNames.FULLTEXT, reader);
+            return result;
         } else {
             // multi value not supported
             throw new RepositoryException("Multi-valued binary properties not supported.");
@@ -181,7 +187,7 @@
                 InputSource source = new InputSource(is);
                 xmlReader.parse(source);
             } catch (SAXException se) {
-                // ignore errors
+                throw new IOException(se.getMessage());
             }
         }
 



Mime
View raw message