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.String
ENCODING_AUTO_HUMAN
This value represents to the user that the encoding is determined by the filter itself.static java.lang.String
TARGET_DEFAULT
The default output filename pattern.static java.lang.String
TFP_EXTENSION
The original file extension.static java.lang.String
TFP_FILE_FILTER_NAME
static java.lang.String
TFP_FILE_SOURCE_ENCODING
File properties.static java.lang.String
TFP_FILE_TARGET_ENCODING
static java.lang.String
TFP_FILENAME
The original filename (with extension).static java.lang.String
TFP_NAMEONLY
The original filename without extension.static java.lang.String
TFP_SYSTEM_HOST_NAME
static java.lang.String
TFP_SYSTEM_OS_ARCH
static java.lang.String
TFP_SYSTEM_OS_NAME
Workstation properties.static java.lang.String
TFP_SYSTEM_OS_VERSION
static java.lang.String
TFP_SYSTEM_USER_NAME
static java.lang.String
TFP_TARGET_COUNTRY_CODE
country "YY" onlystatic java.lang.String
TFP_TARGET_COUTRY_CODE
Old spelling of the variable for country "YY" onlystatic java.lang.String
TFP_TARGET_LANG_CODE
language "XX" onlystatic java.lang.String
TFP_TARGET_LANGUAGE
"XX-YY", the TMX/XML language codestatic java.lang.String
TFP_TARGET_LOCALE
"xx_YY", locale codestatic java.lang.String
TFP_TARGET_LOCALE_LCID
Microsoft.static java.lang.String
TFP_TIMESTAMP_LA
System time at generation time in various patterns.static java.lang.String
TFP_TIMESTAMP_LD
static java.lang.String
TFP_TIMESTAMP_LDD
static java.lang.String
TFP_TIMESTAMP_LH
static java.lang.String
TFP_TIMESTAMP_LHH
static java.lang.String
TFP_TIMESTAMP_LM
static java.lang.String
TFP_TIMESTAMP_LMM
static java.lang.String
TFP_TIMESTAMP_LS
static java.lang.String
TFP_TIMESTAMP_LSS
static java.lang.String
TFP_TIMESTAMP_LYYYY
static java.lang.String
TFP_TIMESTAMP_UD
static java.lang.String
TFP_TIMESTAMP_UEEE
static java.lang.String
TFP_TIMESTAMP_UEEEE
static java.lang.String
TFP_TIMESTAMP_UH
static java.lang.String
TFP_TIMESTAMP_UHH
static java.lang.String
TFP_TIMESTAMP_UM
static java.lang.String
TFP_TIMESTAMP_UMM
static java.lang.String
TFP_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 void
alignFile(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.String
getFileFormatName()
Human-readable name of the File Format this filter supports.java.lang.String
getFuzzyMark()
Define fuzzy mark prefix for source which will be stored in TM.java.lang.String
getHint()
Returns the hint displayed while the user edits the filter, and when she adds/edits the instance of this filter.java.lang.String
getInEncodingLastParsedFile()
Returns the encoding of the last parsed source file.static java.util.List<java.lang.String>
getTargetFilenamePatterns()
boolean
hasOptions()
OmegaT calls this to see whether the filter has any options.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 (null
encoding means autodetect).abstract boolean
isSourceEncodingVariable()
Whether source encoding can be varied by the user.abstract boolean
isTargetEncodingVariable()
Whether target encoding can be varied by the user.void
parseFile(java.io.File inFile, java.util.Map<java.lang.String,java.lang.String> config, FilterContext fc, IParseCallback callback)
Parse single file.void
setCallbacks(IParseCallback parseCallback, ITranslateCallback translateCallback)
Set both callbacks.void
translateFile(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" thenull
is 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:
getFileFormatName
in 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:
getDefaultInstances
in 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:
isSourceEncodingVariable
in 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:
isTargetEncodingVariable
in 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 (null
encoding 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:
isFileSupported
in 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:
getFuzzyMark
in 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:
hasOptions
in 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:
changeOptions
in 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.Exception
Description copied from interface:IFilter
Parse 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.Exception
Description copied from interface:IFilter
Align 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.Exception
Description copied from interface:IFilter
Create translated file.- Specified by:
translateFile
in 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:IFilter
Returns the encoding of the last parsed source file.- Specified by:
getInEncodingLastParsedFile
in interfaceIFilter
- Returns:
- the encoding of the last parsed source file, or null when no file has been parsed yet.
-
-