Package net.sf.okapi.common.filters
Class AbstractFilter
- java.lang.Object
-
- net.sf.okapi.common.filters.AbstractFilter
-
- All Implemented Interfaces:
AutoCloseable,Iterator<Event>,IFilter
- Direct Known Subclasses:
AbstractCompoundFilter,AbstractLineFilter,AbstractMarkupFilter,AbstractSubFilter,ArchiveFilter,DoxygenFilter,JSONFilter,MarkdownFilter,ProtoFilter,RegexPlainTextFilter,SubtitleFilter,TEXFilter,WikiFilter,YamlFilter
public abstract class AbstractFilter extends Object implements IFilter
Basic abstract implementation ofIFilter.
-
-
Field Summary
-
Fields inherited from interface net.sf.okapi.common.filters.IFilter
SUB_FILTER
-
-
Constructor Summary
Constructors Constructor Description AbstractFilter()Default constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanaddConfiguration(boolean clearAllExisting, String configId, String name, String description, String parametersLocation)protected booleanaddConfiguration(boolean clearAllExisting, String configId, String name, String description, String parametersLocation, String extensions)voidaddConfiguration(FilterConfiguration configuration)protected booleanaddConfigurations(List<FilterConfiguration> configs)voidcancel()Cancels the current process.voidclose()Closes the input document.protected EventcreateEndFilterEvent()create a END_DOCUMENTEventIFilterWritercreateFilterWriter()Default case.ISkeletonWritercreateSkeletonWriter()Default case.protected EventcreateStartFilterEvent()create a START_DOCUMENTEventprotected FilterConfigurationfindConfiguration(String configId)FilterConfigurationgetConfiguration(String configId)List<FilterConfiguration>getConfigurations()Gets the list of all predefined configurations for this filter.StringgetDisplayName()Gets the localizable display name of this filter.IdGeneratorgetDocumentId()StringgetDocumentName()Gets the START_DOCUMENT name for the current input.EncoderManagergetEncoderManager()Gets the EncoderManager object for this filter.StringgetEncoding()Gets the input document encoding.protected IFilterConfigurationMappergetFilterConfigurationMapper()Gets the filter configuration mapper if available.StringgetMimeType()Gets the input document mime type.StringgetName()Gets the name/identifier of this filter.StringgetNewlineType()Get the newline type used in the input.IParametersgetParameters()Gets the current parameters for this filter.<A> AgetParameters(Class<A> expectedClass)StringgetParametersClassName()StringgetParentId()LocaleIdgetSrcLoc()Gets the input document source locale.LocaleIdgetTrgLoc()booleanisCanceled()Checks if theIFilterhas been canceled.booleanisGenerateSkeleton()booleanisMultilingual()protected booleanisUtf8Bom()Does the input have a UTF-8 Byte Order Mark?protected booleanisUtf8Encoding()Is the input encoded as UTF-8?voidopen(RawDocument input, boolean generateSkeleton)Opens the input document described in a give RawDocument object, and optionally creates skeleton information.booleanremoveConfiguration(String configId)protected voidsetDisplayName(String displayName)protected voidsetDocumentName(String documentName)Allows implementers to set the START_DOCUMENT name for the current input.protected voidsetEncoding(String encoding)Sets the input document encoding.voidsetFilterConfigurationMapper(IFilterConfigurationMapper fcMapper)Sets the filter configuration mapper for this filter.protected voidsetGenerateSkeleton(boolean generateSkeleton)voidsetMimeType(String mimeType)Sets the input document mime type.protected voidsetMultilingual(boolean multilingual)protected voidsetName(String name)protected voidsetNewlineType(String newlineType)Sets the newline type.voidsetOptions(LocaleId sourceLocale, LocaleId targetLocale, String defaultEncoding, boolean generateSkeleton)voidsetParameters(IParameters params)Sets new parameters for this filter.voidsetParentId(String parentId)voidsetSrcLoc(LocaleId srcLoc)Sets the input document source locale.voidsetTrgLoc(LocaleId trgLoc)-
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
-
-
-
-
Method Detail
-
getParameters
public IParameters getParameters()
Description copied from interface:IFilterGets the current parameters for this filter.- Specified by:
getParametersin interfaceIFilter- Returns:
- The current parameters for this filter, or
DefaultParametersif this filter has no parameters.
-
setParameters
public void setParameters(IParameters params)
Description copied from interface:IFilterSets new parameters for this filter.- Specified by:
setParametersin interfaceIFilter- Parameters:
params- The new parameters to use.
-
getParameters
public <A> A getParameters(Class<A> expectedClass)
-
getParametersClassName
public String getParametersClassName()
-
setOptions
public void setOptions(LocaleId sourceLocale, LocaleId targetLocale, String defaultEncoding, boolean generateSkeleton)
EachIFilterhas a small set of options beyond normal configuration that gives theIFilterthe needed information to properly parse the content.- Parameters:
sourceLocale- - source locale of the input documenttargetLocale- - target locale if the input document is multilingual.defaultEncoding- - assumed encoding of the input document. May be overridden if a different encoding is detected.generateSkeleton- - store skeleton (non-translatable parts of the document) along with the extracted text.
-
createStartFilterEvent
protected Event createStartFilterEvent()
create a START_DOCUMENTEvent- Returns:
- the newly created
StartDocumentevent.
-
createEndFilterEvent
protected Event createEndFilterEvent()
create a END_DOCUMENTEvent- Returns:
- the newly created
Endingevent.
-
getConfiguration
public FilterConfiguration getConfiguration(String configId)
-
removeConfiguration
public boolean removeConfiguration(String configId)
-
getConfigurations
public List<FilterConfiguration> getConfigurations()
Description copied from interface:IFilterGets the list of all predefined configurations for this filter.- Specified by:
getConfigurationsin interfaceIFilter- Returns:
- a list of the all predefined configurations for this filter.
-
getEncoderManager
public EncoderManager getEncoderManager()
Description copied from interface:IFilterGets the EncoderManager object for this filter. This encoder manager should provided the mappings to the different MIME types used by the filter.- Specified by:
getEncoderManagerin interfaceIFilter- Returns:
- the EncoderManager for this filter.
-
addConfiguration
protected boolean addConfiguration(boolean clearAllExisting, String configId, String name, String description, String parametersLocation)
-
addConfiguration
protected boolean addConfiguration(boolean clearAllExisting, String configId, String name, String description, String parametersLocation, String extensions)
-
addConfigurations
protected boolean addConfigurations(List<FilterConfiguration> configs)
-
findConfiguration
protected FilterConfiguration findConfiguration(String configId)
-
addConfiguration
public void addConfiguration(FilterConfiguration configuration)
-
cancel
public void cancel()
Description copied from interface:IFilterCancels the current process.
-
close
public 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
-
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.
-
getFilterConfigurationMapper
protected IFilterConfigurationMapper getFilterConfigurationMapper()
Gets the filter configuration mapper if available. This mapper can be used to instantiate sub-filters based on filter configurations.- Returns:
- the filter configuration mapper.
-
setFilterConfigurationMapper
public void setFilterConfigurationMapper(IFilterConfigurationMapper fcMapper)
Description copied from interface:IFilterSets the filter configuration mapper for this filter. This object is used by this filter if it needs to instantiate sub-filters. The implementations of IFilter that do not use sub-filters can use an empty stub for this method.- Specified by:
setFilterConfigurationMapperin interfaceIFilter- Parameters:
fcMapper- the mapper to set.
-
getDocumentName
public String getDocumentName()
Gets the START_DOCUMENT name for the current input.- Returns:
- the document name or path of the current input.
-
setDocumentName
protected void setDocumentName(String documentName)
Allows implementers to set the START_DOCUMENT name for the current input.- Parameters:
documentName- the input document name or path
-
getNewlineType
public String getNewlineType()
Get the newline type used in the input.- Returns:
- the
BOMNewlineEncodingDetector.NewlineTypeone of '\n', '\r' or '\r\n'
-
setNewlineType
protected void setNewlineType(String newlineType)
Sets the newline type.- Parameters:
newlineType- one of '\n', '\r' or '\r\n'.
-
getEncoding
public String getEncoding()
Gets the input document encoding.- Returns:
- the encoding
-
setEncoding
protected void setEncoding(String encoding)
Sets the input document encoding.- Parameters:
encoding- the new encoding
-
getSrcLoc
public LocaleId getSrcLoc()
Gets the input document source locale.- Returns:
- the source locale
-
setSrcLoc
public void setSrcLoc(LocaleId srcLoc)
Sets the input document source locale.- Parameters:
srcLoc- the new source locale
-
getTrgLoc
public LocaleId getTrgLoc()
- Returns:
- the trgLoc
-
setTrgLoc
public void setTrgLoc(LocaleId trgLoc)
- Parameters:
trgLoc- the target locale to set
-
getMimeType
public String getMimeType()
Gets the input document mime type.- Specified by:
getMimeTypein interfaceIFilter- Returns:
- the mime type
-
setMimeType
public void setMimeType(String mimeType)
Sets the input document mime type.- Parameters:
mimeType- the new mime type
-
isCanceled
public boolean isCanceled()
Checks if theIFilterhas been canceled.- Returns:
- true, if is canceled
-
createSkeletonWriter
public ISkeletonWriter createSkeletonWriter()
Default case. Override if needed.- Specified by:
createSkeletonWriterin interfaceIFilter- Returns:
- new instance of
GenericSkeletonWriter
-
createFilterWriter
public IFilterWriter createFilterWriter()
Default case. Override if needed.- Specified by:
createFilterWriterin interfaceIFilter- Returns:
- new instance of
GenericFilterWriter
-
isGenerateSkeleton
public boolean isGenerateSkeleton()
- Returns:
- the generateSkeleton
-
setGenerateSkeleton
protected void setGenerateSkeleton(boolean generateSkeleton)
- Parameters:
generateSkeleton- the generateSkeleton to set
-
isMultilingual
public boolean isMultilingual()
- Specified by:
isMultilingualin interfaceIFilter- Returns:
- the multilingual
-
setMultilingual
protected void setMultilingual(boolean multilingual)
- Parameters:
multilingual- the multilingual to set
-
getName
public String getName()
Description copied from interface:IFilterGets the name/identifier of this filter.
-
setName
protected void setName(String name)
-
getDisplayName
public String getDisplayName()
Description copied from interface:IFilterGets the localizable display name of this filter.- Specified by:
getDisplayNamein interfaceIFilter- Returns:
- the localizable display name of this filter.
-
setDisplayName
protected void setDisplayName(String displayName)
-
getDocumentId
public IdGenerator getDocumentId()
-
getParentId
public String getParentId()
-
setParentId
public void setParentId(String parentId)
-
isUtf8Encoding
protected boolean isUtf8Encoding()
Is the input encoded as UTF-8?- Returns:
- true if the document is in utf8 encoding.
-
isUtf8Bom
protected boolean isUtf8Bom()
Does the input have a UTF-8 Byte Order Mark?- Returns:
- true if the document has a utf-8 byte order mark.
-
-