ome.services.fulltext
Class FileParser

java.lang.Object
  extended by ome.services.fulltext.FileParser
All Implemented Interfaces:
org.springframework.context.ApplicationContextAware
Direct Known Subclasses:
PdfParser

public class FileParser
extends Object
implements org.springframework.context.ApplicationContextAware

Object which attempts to parse any file given to it. On an exception or empty/missing file, an empty Iterable should be returned rather than throwing an exception. Subclases should follow

Since:
3.0-Beta3
Author:
Josh Moore, josh at glencoesoftware.com

Field Summary
protected  OmeroContext context
           
static Iterable<Reader> EMPTY
          Iterable which returns an empty Iterator.
 
Constructor Summary
FileParser()
           
 
Method Summary
 Iterable<Reader> doParse(File file)
          Template method to parse a File into manageable chunks.
 Iterable<Reader> parse(File file)
          Uses doParse(File) to create manageable chunks of a file for indexing.
 void setApplicationContext(org.springframework.context.ApplicationContext arg0)
           
 Iterable<Reader> wrap(Iterator<Reader> it)
          Wraps an Iterator with an Iterable instance.
 Iterable<Reader> wrap(Reader r)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

context

protected OmeroContext context

EMPTY

public static final Iterable<Reader> EMPTY
Iterable which returns an empty Iterator. This will be used in case

Constructor Detail

FileParser

public FileParser()
Method Detail

setApplicationContext

public void setApplicationContext(org.springframework.context.ApplicationContext arg0)
                           throws org.springframework.beans.BeansException
Specified by:
setApplicationContext in interface org.springframework.context.ApplicationContextAware
Throws:
org.springframework.beans.BeansException

parse

public final Iterable<Reader> parse(File file)
Uses doParse(File) to create manageable chunks of a file for indexing. If the File argument is null or unreadable, then the EMPTY Iterable will be returned. The same holds if a null Iterable is returned or an Exception is thrown. The Iterator returned 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 Iterable which is never null.

doParse

public Iterable<Reader> doParse(File file)
                         throws Exception
Template method to parse a File into 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 dog might be parsed to: The quick brown fox jumps and jumps over the lazy dog. Receives a non-null, readable File instance from parse(File) and can return a possible null Iterable or throw an Exception. In any of the non-successful cases, the EMPTY Iterable will be returned to the consumer.

Throws:
Exception

wrap

public Iterable<Reader> wrap(Iterator<Reader> it)
Wraps an Iterator with an Iterable instance. If the Iterator is null, the EMPTY Iterable will be returned.

Parameters:
it - Can be null.
Returns:
Will never be null

wrap

public Iterable<Reader> wrap(Reader r)


OmeroJava Api

Version: 4.3.3-00d1137e-b2894

Copyright © 2009 The University of Dundee. All Rights Reserved.