Class ArchiveFilter
- java.lang.Object
-
- net.sf.okapi.common.filters.AbstractFilter
-
- net.sf.okapi.filters.archive.ArchiveFilter
-
- All Implemented Interfaces:
AutoCloseable,Iterator<Event>,IFilter
- Direct Known Subclasses:
SdlPackageFilter
public class ArchiveFilter extends AbstractFilter
Implements the IFilter interface for archive-based (ZIP) content. This filter generates events for certain files in the archive. Those files are processed with sub-filters that are instantiated automatically based on the file names. Mapping between the file names and filter configurations to be used is defined in the filter parameters. File names in filter parameters may contain wildcards (* and ?). The files, for which file names no sub-filter configId is provided, will be sent as document parts with ZipSkeleton.MIME type of the format supported by the filter is not defined by the filter, but is specified via filter parameters. It allows to use the same filter for different container formats, e.g. DOCX, ODT, etc. by only changing a set of filter parameters.
Please note that when you configure this filter and specify sub-filter classes for the files of interest inside the container, you are responsible to provide visibility of class loaders of those sub-filter classes you specify, otherwise the ArchiveFilter won't be able to instantiate the sub-filters, and an exception will be thrown.
To configure the filter, specify in Parameters the comma-separated lists of file names (may contain wildcards) and their corresponding config Ids.
When specifying congigId for a file, you can choose one of the configurations provided by DefaultFilters class. If the desired configuration is not provided there, you can use setFilterConfigurationMapper() to set your own FilterConfiguationMapper, or alternatively you can get a reference to the default implementation of IFilterConfigurationMapper provided by this class, and use addConfiguration() and other methods to configure it to your desire.
-
-
Field Summary
Fields Modifier and Type Field Description static StringMIME_TYPE-
Fields inherited from interface net.sf.okapi.common.filters.IFilter
SUB_FILTER
-
-
Constructor Summary
Constructors Constructor Description ArchiveFilter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel()Cancels the current process.voidclose()Closes the input document.IFilterWritercreateFilterWriter()Default case.ISkeletonWritercreateSkeletonWriter()Default case.StringgetDisplayName()Gets the localizable display name of this filter.EncoderManagergetEncoderManager()Gets the EncoderManager object for this filter.IFilterConfigurationMappergetFilterConfigurationMapper()Gets the filter configuration mapper if available.StringgetMimeType()Gets the input document mime type.StringgetName()Gets the name/identifier of this filter.ParametersgetParameters()Gets the current parameters for this filter.booleanhasNext()Indicates if there is an event to process.protected booleanisUtf8Bom()Does the input have a UTF-8 Byte Order Mark?protected booleanisUtf8Encoding()Is the input encoded as UTF-8?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.voidsetFilterConfigurationMapper(IFilterConfigurationMapper fcMapper)Sets the filter configuration mapper for this filter.voidsetParameters(IParameters params)Sets new parameters for this filter.-
Methods inherited from class net.sf.okapi.common.filters.AbstractFilter
addConfiguration, addConfiguration, addConfiguration, addConfigurations, createEndFilterEvent, createStartFilterEvent, findConfiguration, getConfiguration, getConfigurations, getDocumentId, getDocumentName, getEncoding, getNewlineType, getParameters, getParametersClassName, getParentId, getSrcLoc, getTrgLoc, isCanceled, isGenerateSkeleton, isMultilingual, removeConfiguration, setDisplayName, setDocumentName, setEncoding, setGenerateSkeleton, setMimeType, setMultilingual, setName, setNewlineType, setOptions, 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
-
MIME_TYPE
public static final String MIME_TYPE
- See Also:
- Constant Field Values
-
-
Method Detail
-
cancel
public void cancel()
Description copied from interface:IFilterCancels the current process.- Specified by:
cancelin interfaceIFilter- Overrides:
cancelin classAbstractFilter
-
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- Overrides:
closein classAbstractFilter
-
createFilterWriter
public IFilterWriter createFilterWriter()
Description copied from class:AbstractFilterDefault case. Override if needed.- Specified by:
createFilterWriterin interfaceIFilter- Overrides:
createFilterWriterin classAbstractFilter- Returns:
- new instance of
GenericFilterWriter
-
createSkeletonWriter
public ISkeletonWriter createSkeletonWriter()
Description copied from class:AbstractFilterDefault case. Override if needed.- Specified by:
createSkeletonWriterin interfaceIFilter- Overrides:
createSkeletonWriterin classAbstractFilter- Returns:
- new instance of
GenericSkeletonWriter
-
getDisplayName
public String getDisplayName()
Description copied from interface:IFilterGets the localizable display name of this filter.- Specified by:
getDisplayNamein interfaceIFilter- Overrides:
getDisplayNamein classAbstractFilter- Returns:
- the localizable display name of 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- Overrides:
getEncoderManagerin classAbstractFilter- Returns:
- the EncoderManager for this filter.
-
getMimeType
public String getMimeType()
Description copied from class:AbstractFilterGets the input document mime type.- Specified by:
getMimeTypein interfaceIFilter- Overrides:
getMimeTypein classAbstractFilter- Returns:
- the mime type
-
getName
public String getName()
Description copied from interface:IFilterGets the name/identifier of this filter.- Specified by:
getNamein interfaceIFilter- Overrides:
getNamein classAbstractFilter- Returns:
- The name/identifier of the filter.
-
getParameters
public Parameters getParameters()
Description copied from interface:IFilterGets the current parameters for this filter.- Specified by:
getParametersin interfaceIFilter- Overrides:
getParametersin classAbstractFilter- Returns:
- The current parameters for this filter, or
DefaultParametersif this filter has no parameters.
-
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.
-
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.
-
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.
-
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- Overrides:
setFilterConfigurationMapperin classAbstractFilter- Parameters:
fcMapper- the mapper to set.
-
getFilterConfigurationMapper
public IFilterConfigurationMapper getFilterConfigurationMapper()
Description copied from class:AbstractFilterGets the filter configuration mapper if available. This mapper can be used to instantiate sub-filters based on filter configurations.- Overrides:
getFilterConfigurationMapperin classAbstractFilter- Returns:
- the filter configuration mapper.
-
setParameters
public void setParameters(IParameters params)
Description copied from interface:IFilterSets new parameters for this filter.- Specified by:
setParametersin interfaceIFilter- Overrides:
setParametersin classAbstractFilter- Parameters:
params- The new parameters to use.
-
isUtf8Encoding
protected boolean isUtf8Encoding()
Description copied from class:AbstractFilterIs the input encoded as UTF-8?- Overrides:
isUtf8Encodingin classAbstractFilter- Returns:
- true if the document is in utf8 encoding.
-
isUtf8Bom
protected boolean isUtf8Bom()
Description copied from class:AbstractFilterDoes the input have a UTF-8 Byte Order Mark?- Overrides:
isUtf8Bomin classAbstractFilter- Returns:
- true if the document has a utf-8 byte order mark.
-
-