Package net.sf.okapi.common.filters
Class AbstractLineFilter
- java.lang.Object
-
- net.sf.okapi.common.filters.AbstractFilter
-
- net.sf.okapi.common.filters.AbstractLineFilter
-
- All Implemented Interfaces:
AutoCloseable,Iterator<Event>,IFilter
- Direct Known Subclasses:
BasePlainTextFilter
public abstract class AbstractLineFilter extends AbstractFilter
Base class for the filters which input is processed line-upon-line. Provides low-level skeleton, events, and configuration handling mechanisms.
-
-
Field Summary
Fields Modifier and Type Field Description protected RawDocumentinputstatic StringLINE_NUMBERprotected LocaleIdsrcLangprotected StartDocumentstartDocprotected LocaleIdtrgLang-
Fields inherited from interface net.sf.okapi.common.filters.IFilter
SUB_FILTER
-
-
Constructor Summary
Constructors Constructor Description AbstractLineFilter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddLineBreak()voidcancel()Cancels the current process.voidclose()Closes the input document.protected voiddone()protected GenericSkeletongetActiveSkeleton()protected DocumentPartgetFirstDocumentPart()protected ITextUnitgetFirstTextUnit()protected GenericSkeletongetHeadSkeleton()protected StringgetLineBreak()protected intgetQueueSize()protected LocaleIdgetTargetLocale()booleanhasNext()Indicates if there is an event to process.protected voidinit()Eventnext()Gets the next event available.voidopen(RawDocument input)Opens the input document described in a give RawDocument object.voidopen(RawDocument input, boolean generateSkeleton)Opens the input document described in a give RawDocument object, and optionally creates skeleton information.protected abstract TextProcessingResultprocessLine(TextContainer lineContainer)Called by the filter for every line read from the inputprotected booleansendEvent(int index, EventType eventType, IResource res)protected booleansendEvent(EventType eventType, IResource res)protected voidwaitForLine(boolean lastChance)Called by the filter when there are no input lines (the input has been read).-
Methods inherited from class net.sf.okapi.common.filters.AbstractFilter
addConfiguration, addConfiguration, addConfiguration, addConfigurations, createEndFilterEvent, createFilterWriter, createSkeletonWriter, createStartFilterEvent, findConfiguration, getConfiguration, getConfigurations, getDisplayName, getDocumentId, getDocumentName, getEncoderManager, getEncoding, getFilterConfigurationMapper, getMimeType, getName, getNewlineType, getParameters, getParameters, getParametersClassName, getParentId, getSrcLoc, getTrgLoc, isCanceled, isGenerateSkeleton, isMultilingual, isUtf8Bom, isUtf8Encoding, removeConfiguration, setDisplayName, setDocumentName, setEncoding, setFilterConfigurationMapper, setGenerateSkeleton, setMimeType, setMultilingual, setName, setNewlineType, setOptions, setParameters, setParentId, setSrcLoc, setTrgLoc
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
-
-
-
Field Detail
-
LINE_NUMBER
public static final String LINE_NUMBER
- See Also:
- Constant Field Values
-
srcLang
protected LocaleId srcLang
-
trgLang
protected LocaleId trgLang
-
startDoc
protected StartDocument startDoc
-
input
protected RawDocument input
-
-
Method Detail
-
cancel
public void cancel()
Description copied from interface:IFilterCancels the current process.- Specified by:
cancelin interfaceIFilter- Overrides:
cancelin classAbstractFilter
-
close
public final void close()
Description copied from interface:IFilterCloses the input document. Developers should call this method from within their code before sending the last event: This can allow writer objects to overwrite the input file when they receive the last event. This method must also be safe to call even if the input document is not opened.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceIFilter- Overrides:
closein classAbstractFilter
-
hasNext
public boolean hasNext()
Description copied from interface:IFilterIndicates if there is an event to process.Implementer Note: The caller must be able to call this method several times without changing state.
- Returns:
- True if there is at least one event to process, false if not.
-
open
public void open(RawDocument input)
Description copied from interface:IFilterOpens the input document described in a give RawDocument object. Skeleton information is always created when you use this method.- Parameters:
input- The RawDocument object to use to open the document.
-
open
public void open(RawDocument input, boolean generateSkeleton)
Description copied from interface:IFilterOpens the input document described in a give RawDocument object, and optionally creates skeleton information.- Specified by:
openin interfaceIFilter- Overrides:
openin classAbstractFilter- Parameters:
input- The RawDocument object to use to open the document.generateSkeleton- true to generate the skeleton data, false otherwise.
-
getFirstTextUnit
protected ITextUnit getFirstTextUnit()
-
getFirstDocumentPart
protected DocumentPart getFirstDocumentPart()
-
getTargetLocale
protected LocaleId getTargetLocale()
-
next
public Event next()
Description copied from interface:IFilterGets the next event available. Calling this method can be done only once on each event.- Returns:
- The next event available or null if there are no events.
-
getActiveSkeleton
protected final GenericSkeleton getActiveSkeleton()
-
getHeadSkeleton
protected final GenericSkeleton getHeadSkeleton()
-
getQueueSize
protected final int getQueueSize()
-
sendEvent
protected final boolean sendEvent(int index, EventType eventType, IResource res)- Parameters:
index-eventType-res-
-
getLineBreak
protected final String getLineBreak()
-
addLineBreak
protected final void addLineBreak()
-
init
protected void init()
-
done
protected void done()
-
processLine
protected abstract TextProcessingResult processLine(TextContainer lineContainer)
Called by the filter for every line read from the input- Parameters:
lineContainer-- Returns:
-
waitForLine
protected void waitForLine(boolean lastChance)
Called by the filter when there are no input lines (the input has been read). Used to control implementation-specific internal buffers.- Parameters:
lastChance- True if there are no events in the queue, and if the method will not produce events, the filter will be finished.
-
-