Package ome.services.fulltext
Class FileParser
- java.lang.Object
-
- ome.services.fulltext.FileParser
-
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware
- Direct Known Subclasses:
PdfParser
public class FileParser extends java.lang.Object implements org.springframework.context.ApplicationContextAwareObject which attempts to parse any file given to it. On an exception or empty/missing file, an emptyIterableshould be returned rather than throwing an exception. Subclasses should follow- Since:
- 3.0-Beta3
-
-
Field Summary
Fields Modifier and Type Field Description protected ome.system.OmeroContextcontextstatic java.lang.Iterable<java.io.Reader>EMPTYIterablewhich returns an emptyIterator.protected longmaxFileSize
-
Constructor Summary
Constructors Constructor Description FileParser()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Iterable<java.io.Reader>doParse(java.io.File file)Template method to parse aFileinto manageable chunks.java.lang.Iterable<java.io.Reader>parse(java.io.File file)UsesdoParse(File)to create manageable chunks of a file for indexing.voidsetApplicationContext(org.springframework.context.ApplicationContext arg0)voidsetMaxFileSize(java.lang.Long size)java.lang.Iterable<java.io.Reader>wrap(java.io.Reader r)java.lang.Iterable<java.io.Reader>wrap(java.util.Iterator<java.io.Reader> it)Wraps anIteratorwith anIterableinstance.
-
-
-
Method Detail
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext arg0) throws org.springframework.beans.BeansException- Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
setMaxFileSize
public void setMaxFileSize(java.lang.Long size)
-
parse
public final java.lang.Iterable<java.io.Reader> parse(java.io.File file)
UsesdoParse(File)to create manageable chunks of a file for indexing. If theFileargument is null or unreadable, then theEMPTYIterablewill be returned. The same holds if a nullIterableis returned or anExceptionis thrown. TheIteratorreturned from the instance should always be completely iterated through so that resources can be released. For example,for (String string : parse(file)) { /* possibly ignore string *\/ }- Parameters:
file- Can be null.- Returns:
- An
Iterablewhich is never null.
-
doParse
public java.lang.Iterable<java.io.Reader> doParse(java.io.File file) throws java.lang.ExceptionTemplate method to parse aFileinto manageable chunks. The default implementation reads from the file lazily with chunks overlapping on the final white space. For example a file with:The quick brown fox jumps over the lazy dogmight be parsed to:The quick brown fox jumpsandjumps over the lazy dog. Receives a non-null,readableFileinstance fromparse(File)and can return a possible nullIterableor throw anException. In any of the non-successful cases, theEMPTYIterablewill be returned to the consumer.- Throws:
java.lang.Exception
-
wrap
public java.lang.Iterable<java.io.Reader> wrap(java.util.Iterator<java.io.Reader> it)
Wraps anIteratorwith anIterableinstance. If theIteratoris null, theEMPTYIterablewill be returned.- Parameters:
it- Can be null.- Returns:
- Will never be null
-
wrap
public java.lang.Iterable<java.io.Reader> wrap(java.io.Reader r)
-
-