net.sf.okapi.common.filters

## Class AbstractFilter

- java.lang.Object
- - net.sf.okapi.common.filters.AbstractFilter

- All Implemented Interfaces:
    java.lang.AutoCloseable, IFilter

      public abstract class AbstractFilter
      extends java.lang.Object
      implements IFilter

  Basic abstract implementation of `IFilter`.

- - ### Field Summary

    - ### Fields inherited from interface net.sf.okapi.common.filters.IFilter

      `SUB_FILTER`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractFilter()` Default constructor

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addConfiguration(FilterConfiguration configuration)`
    `boolean` | `addConfigurations(java.util.List<FilterConfiguration> configs)`
    `void` | `cancel()` Cancels the current process.
    `void` | `close()` Closes the input document.
    `protected Event` | `createEndFilterEvent()` create a END_DOCUMENT `Event`
    `IFilterWriter` | `createFilterWriter()` Creates a new IFilterWriter object from the most appropriate class to use with this filter.
    `ISkeletonWriter` | `createSkeletonWriter()` Creates a new ISkeletonWriter object that corresponds to the type of skeleton this filter uses.
    `protected Event` | `createStartFilterEvent()` create a START_DOCUMENT `Event`
    `FilterConfiguration` | `getConfiguration(java.lang.String configId)`
    `java.util.List<FilterConfiguration>` | `getConfigurations()` Gets the list of all predefined configurations for this filter.
    `java.lang.String` | `getDisplayName()` Gets the localizable display name of this filter.
    `IdGenerator` | `getDocumentId()`
    `java.lang.String` | `getDocumentName()` Gets the START_DOCUMENT name for the current input.
    `EncoderManager` | `getEncoderManager()` Gets the EncoderManager object for this filter.
    `java.lang.String` | `getEncoding()` Gets the input document encoding.
    `protected IFilterConfigurationMapper` | `getFilterConfigurationMapper()` Gets the filter configuration mapper if available.
    `IFilterWriter` | `getFilterWriter()` Gets the filter writer for this filter.
    `java.lang.String` | `getMimeType()` Gets the input document mime type.
    `java.lang.String` | `getName()` Gets the name/identifier of this filter.
    `java.lang.String` | `getNewlineType()` Get the newline type used in the input.
    `java.lang.String` | `getParentId()`
    `LocaleId` | `getSrcLoc()` Gets the input document source locale.
    `LocaleId` | `getTrgLoc()`
    `boolean` | `isCanceled()` Checks if the `IFilter` has been canceled.
    `boolean` | `isGenerateSkeleton()`
    `boolean` | `isMultilingual()`
    `protected abstract boolean` | `isUtf8Bom()` Does the input have a UTF-8 Byte Order Mark?
    `protected abstract boolean` | `isUtf8Encoding()` Is the input encoded as UTF-8?
    `void` | `open(RawDocument input, boolean generateSkeleton)` Opens the input document described in a give RawDocument object, and optionally creates skeleton information.
    `boolean` | `removeConfiguration(java.lang.String configId)`
    `protected void` | `setDisplayName(java.lang.String displayName)`
    `protected void` | `setDocumentName(java.lang.String documentName)` Allows implementers to set the START_DOCUMENT name for the current input.
    `protected void` | `setEncoding(java.lang.String encoding)` Sets the input document encoding.
    `void` | `setFilterConfigurationMapper(IFilterConfigurationMapper fcMapper)` Sets the filter configuration mapper for this filter.
    `void` | `setFilterWriter(IFilterWriter filterWriter)` Sets the filter writer for this filter.
    `protected void` | `setGenerateSkeleton(boolean generateSkeleton)`
    `void` | `setMimeType(java.lang.String mimeType)` Sets the input document mime type.
    `protected void` | `setMultilingual(boolean multilingual)`
    `protected void` | `setName(java.lang.String name)`
    `protected void` | `setNewlineType(java.lang.String newlineType)` Sets the newline type.
    `void` | `setOptions(LocaleId sourceLocale, LocaleId targetLocale, java.lang.String defaultEncoding, boolean generateSkeleton)` Each `IFilter` has a small set of options beyond normal configuration that gives the `IFilter` the needed information to properly parse the content.
    `void` | `setParentId(java.lang.String parentId)`
    `void` | `setSrcLoc(LocaleId srcLoc)` Sets the input document source locale.
    `void` | `setTrgLoc(LocaleId trgLoc)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface net.sf.okapi.common.filters.IFilter

      `getParameters, hasNext, next, open, setParameters`

- - ### Constructor Detail

    - #### AbstractFilter

          public AbstractFilter()

      Default constructor

  - ### Method Detail

    - #### setOptions

          public void setOptions(LocaleId sourceLocale,
                        LocaleId targetLocale,
                        java.lang.String defaultEncoding,
                        boolean generateSkeleton)

      Each `IFilter` has a small set of options beyond normal configuration that gives the `IFilter` the needed information to properly parse the content.
      Parameters:
        `sourceLocale` - - source locale of the input document
        `targetLocale` - - target locale if the input document is multilingual.
        `defaultEncoding` - - assumed encoding of the input document. May be overriden 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_DOCUMENT `Event`
      Returns:
        the newly created `StartDocument` event.

    - #### createEndFilterEvent

          protected Event createEndFilterEvent()

      create a END_DOCUMENT `Event`
      Returns:
        the newly created `Ending` event.

    - #### addConfigurations

          public boolean addConfigurations(java.util.List<FilterConfiguration> configs)

    - #### getConfiguration

          public FilterConfiguration getConfiguration(java.lang.String configId)

    - #### removeConfiguration

          public boolean removeConfiguration(java.lang.String configId)

    - #### getConfigurations

          public java.util.List<FilterConfiguration> getConfigurations()

      Description copied from interface: `IFilter`
      Gets the list of all predefined configurations for this filter.
      Specified by:
        `getConfigurations` in interface `IFilter`
      Returns:
        a list of the all predefined configurations for this filter.

    - #### setFilterConfigurationMapper

          public void setFilterConfigurationMapper(IFilterConfigurationMapper fcMapper)

      Description copied from interface: `IFilter`
      Sets 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:
        `setFilterConfigurationMapper` in interface `IFilter`
      Parameters:
        `fcMapper` - the mapper to set.

    - #### getEncoderManager

          public EncoderManager getEncoderManager()

      Description copied from interface: `IFilter`
      Gets the EncoderManager object for this filter. This encoder manager should provided the mappings to the different MIME types used by the filter.
      Specified by:
        `getEncoderManager` in interface `IFilter`
      Returns:
        the EncoderManager for this filter.

    - #### addConfiguration

          public void addConfiguration(FilterConfiguration configuration)

    - #### cancel

          public void cancel()

      Description copied from interface: `IFilter`
      Cancels the current process.
      Specified by:
        `cancel` in interface `IFilter`

    - #### close

          public void close()

      Description copied from interface: `IFilter`
      Closes 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:
        `close` in interface `java.lang.AutoCloseable`
      Specified by:
        `close` in interface `IFilter`

    - #### open

          public void open(RawDocument input,
                  boolean generateSkeleton)

      Description copied from interface: `IFilter`
      Opens the input document described in a give RawDocument object, and optionally creates skeleton information.
      Specified by:
        `open` in interface `IFilter`
      Parameters:
        `input` - The RawDocument object to use to open the document.
        `generateSkeleton` - true to generate the skeleton data, false otherwise.

    - #### 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.

    - #### setDocumentName

          protected void setDocumentName(java.lang.String documentName)

      Allows implementers to set the START_DOCUMENT name for the current input.
      Parameters:
        `documentName` - the input document name or path

    - #### getDocumentName

          public java.lang.String getDocumentName()

      Gets the START_DOCUMENT name for the current input.
      Returns:
        the document name or path of the current input.

    - #### getNewlineType

          public java.lang.String getNewlineType()

      Get the newline type used in the input.
      Returns:
        the `BOMNewlineEncodingDetector.NewlineType` one of '\n', '\r' or '\r\n'

    - #### setNewlineType

          protected void setNewlineType(java.lang.String newlineType)

      Sets the newline type.
      Parameters:
        `newlineType` - one of '\n', '\r' or '\r\n'.

    - #### getEncoding

          public java.lang.String getEncoding()

      Gets the input document encoding.
      Returns:
        the encoding

    - #### setEncoding

          protected void setEncoding(java.lang.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

    - #### setTrgLoc

          public void setTrgLoc(LocaleId trgLoc)

      Parameters:
        `trgLoc` - the target locale to set

    - #### getTrgLoc

          public LocaleId getTrgLoc()

      Returns:
        the trgLoc

    - #### getMimeType

          public java.lang.String getMimeType()

      Gets the input document mime type.
      Specified by:
        `getMimeType` in interface `IFilter`
      Returns:
        the mime type

    - #### setMimeType

          public void setMimeType(java.lang.String mimeType)

      Sets the input document mime type.
      Parameters:
        `mimeType` - the new mime type

    - #### isCanceled

          public boolean isCanceled()

      Checks if the `IFilter` has been canceled.
      Returns:
        true, if is canceled

    - #### getFilterWriter

          public IFilterWriter getFilterWriter()

      Gets the filter writer for this filter.
      Returns:
        the filter writer.

    - #### setFilterWriter

          public void setFilterWriter(IFilterWriter filterWriter)

      Sets the filter writer for this filter.
      Parameters:
        `filterWriter` - the filter writer to set.

    - #### createSkeletonWriter

          public ISkeletonWriter createSkeletonWriter()

      Description copied from interface: `IFilter`
      Creates a new ISkeletonWriter object that corresponds to the type of skeleton this filter uses.
      Specified by:
        `createSkeletonWriter` in interface `IFilter`
      Returns:
        A new instance of ISkeletonWriter for the type of skeleton this filter uses.

    - #### createFilterWriter

          public IFilterWriter createFilterWriter()

      Description copied from interface: `IFilter`
      Creates a new IFilterWriter object from the most appropriate class to use with this filter.
      Specified by:
        `createFilterWriter` in interface `IFilter`
      Returns:
        A new instance of IFilterWriter for the preferred implementation for this filter.

    - #### setGenerateSkeleton

          protected void setGenerateSkeleton(boolean generateSkeleton)

      Parameters:
        `generateSkeleton` - the generateSkeleton to set

    - #### isGenerateSkeleton

          public boolean isGenerateSkeleton()

      Returns:
        the generateSkeleton

    - #### isUtf8Encoding

          protected abstract boolean isUtf8Encoding()

      Is the input encoded as UTF-8?
      Returns:
        true if the document is in utf8 encoding.

    - #### isUtf8Bom

          protected abstract boolean isUtf8Bom()

      Does the input have a UTF-8 Byte Order Mark?
      Returns:
        true if the document has a utf-8 byte order mark.

    - #### setMultilingual

          protected void setMultilingual(boolean multilingual)

      Parameters:
        `multilingual` - the multilingual to set

    - #### isMultilingual

          public boolean isMultilingual()

      Returns:
        the multilingual

    - #### setName

          protected void setName(java.lang.String name)

    - #### getName

          public java.lang.String getName()

      Description copied from interface: `IFilter`
      Gets the name/identifier of this filter.
      Specified by:
        `getName` in interface `IFilter`
      Returns:
        The name/identifier of the filter.

    - #### getDisplayName

          public java.lang.String getDisplayName()

      Description copied from interface: `IFilter`
      Gets the localizable display name of this filter.
      Specified by:
        `getDisplayName` in interface `IFilter`
      Returns:
        the localizable display name of this filter.

    - #### setDisplayName

          protected void setDisplayName(java.lang.String displayName)

    - #### getDocumentId

          public IdGenerator getDocumentId()

    - #### getParentId

          public java.lang.String getParentId()

    - #### setParentId

          public void setParentId(java.lang.String parentId)