Class AbstractFilter

java.lang.Object
org.omegat.filters2.AbstractFilter
All Implemented Interfaces:
IFilter
Direct Known Subclasses:
AbstractXmlFilter, AbstractZipFilter, DokuWikiFilter, HTMLFilter2, ILIASFilter, INIFilter, LatexFilter, MagentoFilter, MoodlePHPFilter, MozillaDTDFilter, MozillaFTLFilter, MozillaLangFilter, OpenDocFilter, OpenXMLFilter, PdfFilter, PoFilter, RcFilter, ResourceBundleFilter, SrtFilter, TextFilter, XMLFilter, XtagFilter, YamlFilter

public abstract class AbstractFilter extends Object implements IFilter
The base class for all filters (aka file handlers). Each filter should extend this class or one of its descendants.

The process how the filter works is the following:

  1. Source text is extracted.
  2. Tags are converted into shortcuts and these shortcuts are temporarily stored
  3. Source text with shortened tags is sent to OmegaT core
  4. Core returns a translation (or the same text if there's no translation)
  5. Tags shortcuts are expanded in translated text
  6. Translated text is written into the output file
  • Field Details

  • Constructor Details

    • AbstractFilter

      public AbstractFilter()
  • Method Details

    • getTargetFilenamePatterns

      public static List<String> getTargetFilenamePatterns()
    • getFileFormatName

      public abstract String getFileFormatName()
      Human-readable name of the File Format this filter supports.
      Specified by:
      getFileFormatName in interface IFilter
      Returns:
      File format name
    • getDefaultInstances

      public abstract Instance[] getDefaultInstances()
      The default list of filter instances that this filter class has. One filter class may have different filter instances, different by source file mask, encoding of the source file etc.

      Note that the user may change the instances freely.

      Specified by:
      getDefaultInstances in interface IFilter
      Returns:
      Default filter instances
    • isSourceEncodingVariable

      public abstract boolean isSourceEncodingVariable()
      Whether source encoding can be varied by the user.

      True means that OmegaT should handle all the encoding mess.

      Return false to state that your filter doesn't need encoding management provided by OmegaT, because it either autodetect the encoding based on file contents (like HTML filter does) or the encoding is fixed (like in OpenOffice files).

      Specified by:
      isSourceEncodingVariable in interface IFilter
      Returns:
      whether source encoding can be changed by the user
    • isTargetEncodingVariable

      public abstract boolean isTargetEncodingVariable()
      Whether target encoding can be varied by the user.

      True means that OmegaT should handle all the encoding mess.

      Return false to state that your filter doesn't need encoding management provided by OmegaT, because the encoding is fixed (like in OpenOffice files), or for some other reason.

      Specified by:
      isTargetEncodingVariable in interface IFilter
      Returns:
      whether target encoding can be changed by the user
    • isFileSupported

      public boolean isFileSupported(File inFile, Map<String,String> config, FilterContext fc)
      Returns whether the file is supported by the filter, given the file and possible file's encoding ( null encoding means autodetect). Default implementation creates a reader and calls isFileSupported(BufferedReader). You should override only one of the two.

      For example, DocBook files have .xml extension, as possibly many other XML files, so the filter should check a DTD of the document.

      Specified by:
      isFileSupported in interface IFilter
      Parameters:
      inFile - Source file.
      fc - Filter context.
      config - filter's configuration options
      Returns:
      Does the filter support the file.
    • getFuzzyMark

      public String getFuzzyMark()
      Define fuzzy mark prefix for source which will be stored in TM. It's 'fuzzy' by default, but each filter can redefine it.
      Specified by:
      getFuzzyMark in interface IFilter
      Returns:
      fuzzy mark prefix
    • getHint

      public String getHint()
      Returns the hint displayed while the user edits the filter, and when she adds/edits the instance of this filter. The hint may be any string, preferably in a non-geek language.
      Specified by:
      getHint in interface IFilter
      Returns:
      The hint for editing the filter in a non-geek language.
    • hasOptions

      public boolean hasOptions()
      OmegaT calls this to see whether the filter has any options. By default, returns false, so filter authors should override this to tell OmegaT core that this filter has options.
      Specified by:
      hasOptions in interface IFilter
      Returns:
      True if the filter has any options, and false otherwise.
    • changeOptions

      @Deprecated public @Nullable Map<String,String> changeOptions(@Nullable Dialog parent, Map<String,String> config)
      Deprecated.
      Description copied from interface: IFilter
      Show change options dialog for able to change options.

      Deprecated; please use IFilter.changeOptions(Window, Map) instead.

      Specified by:
      changeOptions in interface IFilter
      Parameters:
      parent - parent window
      config - old options
      Returns:
      new options or null if options not changed
    • parseFile

      public final void parseFile(File inFile, @Nullable Map<String,String> config, FilterContext fc, IParseCallback callback) throws Exception
      Description copied from interface: IFilter
      Parse single file.
      Specified by:
      parseFile in interface IFilter
      Parameters:
      inFile - file to parse
      config - filter's configuration options
      fc - processing context
      callback - callback for parsed data
      Throws:
      Exception
    • alignFile

      public final void alignFile(File inFile, File outFile, @Nullable Map<String,String> config, FilterContext fc, IAlignCallback callback) throws Exception
      Description copied from interface: IFilter
      Align a source and translated files. NB: this is not used for Tools->align files..., but for aligning in console mode
      Specified by:
      alignFile in interface IFilter
      Parameters:
      inFile - source file
      outFile - translated file
      config - filter's configuration options
      fc - processing context
      callback - callback for store aligned data
      Throws:
      Exception
    • translateFile

      public final void translateFile(File inFile, File outFile, Map<String,String> config, FilterContext fc, ITranslateCallback callback) throws Exception
      Description copied from interface: IFilter
      Create translated file.
      Specified by:
      translateFile in interface IFilter
      Parameters:
      inFile - source file
      outFile - output file
      config - filter's configuration options
      fc - processing context
      callback - callback for get translation
      Throws:
      Exception
    • setCallbacks

      public void setCallbacks(@Nullable IParseCallback parseCallback, @Nullable ITranslateCallback translateCallback)
      Set both callbacks. Used for child XML filters only.
    • getInEncodingLastParsedFile

      public @Nullable String getInEncodingLastParsedFile()
      Description copied from interface: IFilter
      Returns the encoding of the last parsed source file.
      Specified by:
      getInEncodingLastParsedFile in interface IFilter
      Returns:
      the encoding of the last parsed source file, or null when no file has been parsed yet.