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
public abstract class AbstractFilter extends java.lang.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:
- Source text is extracted.
- Tags are converted into shortcuts and these shortcuts are temporarily stored
- Source text with shortened tags is sent to OmegaT core
- Core returns a translation (or the same text if there's no translation)
- Tags shortcuts are expanded in translated text
- Translated text is written into the output file
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringENCODING_AUTO_HUMANThis value represents to the user that the encoding is determined by the filter itself.static java.lang.StringTARGET_DEFAULTThe default output filename pattern.static java.lang.StringTFP_EXTENSIONThe original file extension.static java.lang.StringTFP_FILE_FILTER_NAMEstatic java.lang.StringTFP_FILE_SOURCE_ENCODINGFile properties.static java.lang.StringTFP_FILE_TARGET_ENCODINGstatic java.lang.StringTFP_FILENAMEThe original filename (with extension).static java.lang.StringTFP_NAMEONLYThe original filename without extension.static java.lang.StringTFP_SYSTEM_HOST_NAMEstatic java.lang.StringTFP_SYSTEM_OS_ARCHstatic java.lang.StringTFP_SYSTEM_OS_NAMEWorkstation properties.static java.lang.StringTFP_SYSTEM_OS_VERSIONstatic java.lang.StringTFP_SYSTEM_USER_NAMEstatic java.lang.StringTFP_TARGET_COUNTRY_CODEcountry "YY" onlystatic java.lang.StringTFP_TARGET_COUTRY_CODEOld spelling of the variable for country "YY" onlystatic java.lang.StringTFP_TARGET_LANG_CODElanguage "XX" onlystatic java.lang.StringTFP_TARGET_LANGUAGE"XX-YY", the TMX/XML language codestatic java.lang.StringTFP_TARGET_LOCALE"xx_YY", locale codestatic java.lang.StringTFP_TARGET_LOCALE_LCIDMicrosoft.static java.lang.StringTFP_TIMESTAMP_LASystem time at generation time in various patterns.static java.lang.StringTFP_TIMESTAMP_LDstatic java.lang.StringTFP_TIMESTAMP_LDDstatic java.lang.StringTFP_TIMESTAMP_LHstatic java.lang.StringTFP_TIMESTAMP_LHHstatic java.lang.StringTFP_TIMESTAMP_LMstatic java.lang.StringTFP_TIMESTAMP_LMMstatic java.lang.StringTFP_TIMESTAMP_LSstatic java.lang.StringTFP_TIMESTAMP_LSSstatic java.lang.StringTFP_TIMESTAMP_LYYYYstatic java.lang.StringTFP_TIMESTAMP_UDstatic java.lang.StringTFP_TIMESTAMP_UEEEstatic java.lang.StringTFP_TIMESTAMP_UEEEEstatic java.lang.StringTFP_TIMESTAMP_UHstatic java.lang.StringTFP_TIMESTAMP_UHHstatic java.lang.StringTFP_TIMESTAMP_UMstatic java.lang.StringTFP_TIMESTAMP_UMMstatic java.lang.StringTFP_TIMESTAMP_UMMM
-
Constructor Summary
Constructors Constructor Description AbstractFilter()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidalignFile(java.io.File inFile, java.io.File outFile, java.util.Map<java.lang.String,java.lang.String> config, FilterContext fc, IAlignCallback callback)Align source and translated files.java.util.Map<java.lang.String,java.lang.String>changeOptions(java.awt.Dialog parent, java.util.Map<java.lang.String,java.lang.String> config)Deprecated.abstract Instance[]getDefaultInstances()The default list of filter instances that this filter class has.abstract java.lang.StringgetFileFormatName()Human-readable name of the File Format this filter supports.java.lang.StringgetFuzzyMark()Define fuzzy mark prefix for source which will be stored in TM.java.lang.StringgetHint()Returns the hint displayed while the user edits the filter, and when she adds/edits the instance of this filter.java.lang.StringgetInEncodingLastParsedFile()Returns the encoding of the last parsed source file.static java.util.List<java.lang.String>getTargetFilenamePatterns()booleanhasOptions()OmegaT calls this to see whether the filter has any options.booleanisFileSupported(java.io.File inFile, java.util.Map<java.lang.String,java.lang.String> config, FilterContext fc)Returns whether the file is supported by the filter, given the file and possible file's encoding (nullencoding means autodetect).abstract booleanisSourceEncodingVariable()Whether source encoding can be varied by the user.abstract booleanisTargetEncodingVariable()Whether target encoding can be varied by the user.voidparseFile(java.io.File inFile, java.util.Map<java.lang.String,java.lang.String> config, FilterContext fc, IParseCallback callback)Parse single file.voidsetCallbacks(IParseCallback parseCallback, ITranslateCallback translateCallback)Set both callbacks.voidtranslateFile(java.io.File inFile, java.io.File outFile, java.util.Map<java.lang.String,java.lang.String> config, FilterContext fc, ITranslateCallback callback)Create translated file.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.omegat.filters2.IFilter
changeOptions, isBilingual, isEnabledInDefault
-
-
-
-
Field Detail
-
ENCODING_AUTO_HUMAN
public static final java.lang.String ENCODING_AUTO_HUMAN
This value represents to the user that the encoding is determined by the filter itself. "In code" thenullis used to represent automatic encoding selection.
-
TFP_FILENAME
public static final java.lang.String TFP_FILENAME
The original filename (with extension).- See Also:
- Constant Field Values
-
TFP_NAMEONLY
public static final java.lang.String TFP_NAMEONLY
The original filename without extension.- See Also:
- Constant Field Values
-
TFP_EXTENSION
public static final java.lang.String TFP_EXTENSION
The original file extension.- See Also:
- Constant Field Values
-
TFP_TARGET_LOCALE
public static final java.lang.String TFP_TARGET_LOCALE
"xx_YY", locale code- See Also:
- Constant Field Values
-
TFP_TARGET_LANGUAGE
public static final java.lang.String TFP_TARGET_LANGUAGE
"XX-YY", the TMX/XML language code- See Also:
- Constant Field Values
-
TFP_TARGET_LANG_CODE
public static final java.lang.String TFP_TARGET_LANG_CODE
language "XX" only- See Also:
- Constant Field Values
-
TFP_TARGET_COUNTRY_CODE
public static final java.lang.String TFP_TARGET_COUNTRY_CODE
country "YY" only- See Also:
- Constant Field Values
-
TFP_TARGET_COUTRY_CODE
public static final java.lang.String TFP_TARGET_COUTRY_CODE
Old spelling of the variable for country "YY" only- See Also:
- Constant Field Values
-
TFP_TIMESTAMP_LA
public static final java.lang.String TFP_TIMESTAMP_LA
System time at generation time in various patterns.- See Also:
- Constant Field Values
-
TFP_TIMESTAMP_LD
public static final java.lang.String TFP_TIMESTAMP_LD
- See Also:
- Constant Field Values
-
TFP_TIMESTAMP_LDD
public static final java.lang.String TFP_TIMESTAMP_LDD
- See Also:
- Constant Field Values
-
TFP_TIMESTAMP_LH
public static final java.lang.String TFP_TIMESTAMP_LH
- See Also:
- Constant Field Values
-
TFP_TIMESTAMP_LHH
public static final java.lang.String TFP_TIMESTAMP_LHH
- See Also:
- Constant Field Values
-
TFP_TIMESTAMP_LM
public static final java.lang.String TFP_TIMESTAMP_LM
- See Also:
- Constant Field Values
-
TFP_TIMESTAMP_LMM
public static final java.lang.String TFP_TIMESTAMP_LMM
- See Also:
- Constant Field Values
-
TFP_TIMESTAMP_LS
public static final java.lang.String TFP_TIMESTAMP_LS
- See Also:
- Constant Field Values
-
TFP_TIMESTAMP_LSS
public static final java.lang.String TFP_TIMESTAMP_LSS
- See Also:
- Constant Field Values
-
TFP_TIMESTAMP_LYYYY
public static final java.lang.String TFP_TIMESTAMP_LYYYY
- See Also:
- Constant Field Values
-
TFP_TIMESTAMP_UD
public static final java.lang.String TFP_TIMESTAMP_UD
- See Also:
- Constant Field Values
-
TFP_TIMESTAMP_UEEE
public static final java.lang.String TFP_TIMESTAMP_UEEE
- See Also:
- Constant Field Values
-
TFP_TIMESTAMP_UEEEE
public static final java.lang.String TFP_TIMESTAMP_UEEEE
- See Also:
- Constant Field Values
-
TFP_TIMESTAMP_UH
public static final java.lang.String TFP_TIMESTAMP_UH
- See Also:
- Constant Field Values
-
TFP_TIMESTAMP_UHH
public static final java.lang.String TFP_TIMESTAMP_UHH
- See Also:
- Constant Field Values
-
TFP_TIMESTAMP_UM
public static final java.lang.String TFP_TIMESTAMP_UM
- See Also:
- Constant Field Values
-
TFP_TIMESTAMP_UMM
public static final java.lang.String TFP_TIMESTAMP_UMM
- See Also:
- Constant Field Values
-
TFP_TIMESTAMP_UMMM
public static final java.lang.String TFP_TIMESTAMP_UMMM
- See Also:
- Constant Field Values
-
TFP_SYSTEM_OS_NAME
public static final java.lang.String TFP_SYSTEM_OS_NAME
Workstation properties.- See Also:
- Constant Field Values
-
TFP_SYSTEM_OS_VERSION
public static final java.lang.String TFP_SYSTEM_OS_VERSION
- See Also:
- Constant Field Values
-
TFP_SYSTEM_OS_ARCH
public static final java.lang.String TFP_SYSTEM_OS_ARCH
- See Also:
- Constant Field Values
-
TFP_SYSTEM_USER_NAME
public static final java.lang.String TFP_SYSTEM_USER_NAME
- See Also:
- Constant Field Values
-
TFP_SYSTEM_HOST_NAME
public static final java.lang.String TFP_SYSTEM_HOST_NAME
- See Also:
- Constant Field Values
-
TFP_FILE_SOURCE_ENCODING
public static final java.lang.String TFP_FILE_SOURCE_ENCODING
File properties.- See Also:
- Constant Field Values
-
TFP_FILE_TARGET_ENCODING
public static final java.lang.String TFP_FILE_TARGET_ENCODING
- See Also:
- Constant Field Values
-
TFP_FILE_FILTER_NAME
public static final java.lang.String TFP_FILE_FILTER_NAME
- See Also:
- Constant Field Values
-
TFP_TARGET_LOCALE_LCID
public static final java.lang.String TFP_TARGET_LOCALE_LCID
Microsoft.- See Also:
- Constant Field Values
-
TARGET_DEFAULT
public static final java.lang.String TARGET_DEFAULT
The default output filename pattern.It is equal to "${filename}", which means that the name of the translated file should be the same as the name of the input file.
- See Also:
- Constant Field Values
-
-
Method Detail
-
getTargetFilenamePatterns
public static java.util.List<java.lang.String> getTargetFilenamePatterns()
-
getFileFormatName
public abstract java.lang.String getFileFormatName()
Human-readable name of the File Format this filter supports.- Specified by:
getFileFormatNamein interfaceIFilter- 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:
getDefaultInstancesin interfaceIFilter- 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 autodetects the encoding based on file contents (like HTML filter does) or the encoding is fixed (like in OpenOffice files).
- Specified by:
isSourceEncodingVariablein interfaceIFilter- 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:
isTargetEncodingVariablein interfaceIFilter- Returns:
- whether target encoding can be changed by the user
-
isFileSupported
public boolean isFileSupported(java.io.File inFile, java.util.Map<java.lang.String,java.lang.String> config, FilterContext fc)Returns whether the file is supported by the filter, given the file and possible file's encoding (nullencoding means autodetect). Default implementation creates a reader and callsisFileSupported(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:
isFileSupportedin interfaceIFilter- Parameters:
inFile- Source file.fc- Filter context.config- filter's configuration options- Returns:
- Does the filter support the file.
-
getFuzzyMark
public java.lang.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:
getFuzzyMarkin interfaceIFilter- Returns:
- fuzzy mark prefix
-
getHint
public java.lang.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.
-
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:
hasOptionsin interfaceIFilter- Returns:
- True if the filter has any options, and false otherwise.
-
changeOptions
@Deprecated public java.util.Map<java.lang.String,java.lang.String> changeOptions(java.awt.Dialog parent, java.util.Map<java.lang.String,java.lang.String> config)Deprecated.Show change options dialog for able to change options.Deprecated; please use
IFilter.changeOptions(Window, Map)instead.- Specified by:
changeOptionsin interfaceIFilter- Parameters:
parent- parent windowconfig- old options- Returns:
- new options or null if options not changed
-
parseFile
public final void parseFile(java.io.File inFile, java.util.Map<java.lang.String,java.lang.String> config, FilterContext fc, IParseCallback callback) throws java.lang.ExceptionDescription copied from interface:IFilterParse single file.
-
alignFile
public final void alignFile(java.io.File inFile, java.io.File outFile, java.util.Map<java.lang.String,java.lang.String> config, FilterContext fc, IAlignCallback callback) throws java.lang.ExceptionDescription copied from interface:IFilterAlign source and translated files. NB: this is not used for Tools->align files..., but for aligning in console mode
-
translateFile
public final void translateFile(java.io.File inFile, java.io.File outFile, java.util.Map<java.lang.String,java.lang.String> config, FilterContext fc, ITranslateCallback callback) throws java.lang.ExceptionDescription copied from interface:IFilterCreate translated file.- Specified by:
translateFilein interfaceIFilter- Parameters:
inFile- source fileoutFile- output fileconfig- filter's configuration optionsfc- processing contextcallback- callback for get translation- Throws:
java.lang.Exception
-
setCallbacks
public void setCallbacks(IParseCallback parseCallback, ITranslateCallback translateCallback)
Set both callbacks. Used for child XML filters only.- Parameters:
parseCallback-translateCallback-
-
getInEncodingLastParsedFile
public java.lang.String getInEncodingLastParsedFile()
Description copied from interface:IFilterReturns the encoding of the last parsed source file.- Specified by:
getInEncodingLastParsedFilein interfaceIFilter- Returns:
- the encoding of the last parsed source file, or null when no file has been parsed yet.
-
-