Package org.omegat.filters2.master
Class FilterMaster
- java.lang.Object
-
- org.omegat.filters2.master.FilterMaster
-
public class FilterMaster extends java.lang.ObjectA master class that registers and handles all the filters. Singleton - there can be only one instance of this class.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCURRENT_VERSIONCurrently file filters support version.static java.lang.StringFILE_FILTERSname of the filter configuration filestatic java.lang.StringINITIAL_VERSIONThere was no version of file filters support (1.4.5 Beta 1 -- 1.6.0 RC12).static java.lang.StringOT160FINAL_VERSIONstatic java.lang.StringOT160RC12A_VERSIONFile filters support of 1.6.0 RC12a: now upgrading the configuration.static java.lang.StringOT161_VERSIONstatic java.lang.StringOT170_VERSION
-
Constructor Summary
Constructors Constructor Description FilterMaster(Filters config)Create a new FilterMaster.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidalignFile(java.lang.String sourceDir, java.lang.String fileName, java.lang.String targetdir, FilterContext fc, IAlignCallback alignCallback)static FilterscloneConfig(Filters orig)Clone config for editingstatic FiltercloneFilter(Filter filter)Clone one filter's config for editing.static FilterscreateDefaultFiltersConfig()Reverts Filter Configuration to Default values.static java.util.Map<java.lang.String,java.lang.String>forFilter(java.util.List<Filter.Option> options)Convert options from xml for filter usage.FiltersgetConfig()static FiltergetDefaultSettingsFromFilter(java.lang.String filterClassname)Create default filter's config.static IFiltergetFilterInstance(java.lang.String classname)Get filter's instance by filter class name.static java.util.List<java.lang.String>getSupportedEncodings()Queries JRE for the list of supported encodings.java.lang.StringgetTargetForSource(java.lang.String sourceDir, java.lang.String srcRelPath, FilterContext fc)Calculate the target path corresponding to the given source file.booleanisBilingualFile(java.io.File file)booleanisFileSupported(java.io.File file, boolean quick)Check to see if a file is supported by any filter.static FiltersloadConfig(java.io.File configFile)Loads information about the filters from an XML file.IFilterloadFile(java.lang.String filename, FilterContext fc, IParseCallback parseCallback)OmegaT core calls this method to load a source file.static java.lang.Stringnow(java.lang.String dateFormat)Return current system time in the specified date format.static voidsaveConfig(Filters config, java.io.File configFile)Saves information about the filters to an XML file.static voidsetFilterClasses(java.util.List<java.lang.Class<?>> classes)static voidsetOptions(Filter f, java.util.Map<java.lang.String,java.lang.String> newOptions)Convert options to xml from map.voidtranslateFile(java.lang.String sourcedir, java.lang.String filename, java.lang.String targetdir, FilterContext fc, ITranslateCallback translateCallback)OmegaT core calls this method to translate a source file.
-
-
-
Field Detail
-
FILE_FILTERS
public static final java.lang.String FILE_FILTERS
name of the filter configuration file- See Also:
- Constant Field Values
-
INITIAL_VERSION
public static final java.lang.String INITIAL_VERSION
There was no version of file filters support (1.4.5 Beta 1 -- 1.6.0 RC12).- See Also:
- Constant Field Values
-
OT160RC12A_VERSION
public static final java.lang.String OT160RC12A_VERSION
File filters support of 1.6.0 RC12a: now upgrading the configuration.- See Also:
- Constant Field Values
-
OT160FINAL_VERSION
public static final java.lang.String OT160FINAL_VERSION
- See Also:
- Constant Field Values
-
OT161_VERSION
public static final java.lang.String OT161_VERSION
- See Also:
- Constant Field Values
-
OT170_VERSION
public static final java.lang.String OT170_VERSION
- See Also:
- Constant Field Values
-
CURRENT_VERSION
public static final java.lang.String CURRENT_VERSION
Currently file filters support version.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FilterMaster
public FilterMaster(Filters config)
Create a new FilterMaster.
-
-
Method Detail
-
setFilterClasses
public static void setFilterClasses(java.util.List<java.lang.Class<?>> classes)
-
getConfig
public Filters getConfig()
-
getFilterInstance
public static IFilter getFilterInstance(java.lang.String classname)
Get filter's instance by filter class name.- Parameters:
classname- filter's class name- Returns:
- filter instance
-
loadFile
public IFilter loadFile(java.lang.String filename, FilterContext fc, IParseCallback parseCallback) throws java.io.IOException, TranslationException
OmegaT core calls this method to load a source file.- Parameters:
filename- The name of the source file to load.- Returns:
- Whether the file was handled by one of OmegaT filters.
- Throws:
java.io.IOExceptionTranslationException- See Also:
translateFile(String, String, String, FilterContext, ITranslateCallback)
-
translateFile
public void translateFile(java.lang.String sourcedir, java.lang.String filename, java.lang.String targetdir, FilterContext fc, ITranslateCallback translateCallback) throws java.io.IOException, TranslationExceptionOmegaT core calls this method to translate a source file.- OmegaT first looks through registered filter instances to find filter(s) that can handle this file.
- Tests if filter(s) want to handle it.
- If the filter accepts the file,
- Filter is asked to process the file.
- Parameters:
sourcedir- The folder of the source inFile.filename- The name of the source inFile to process (only the part, relative to source folder).targetdir- The folder to place the translated inFile to.fc- Filter context.- Throws:
java.io.IOExceptionTranslationException
-
alignFile
public void alignFile(java.lang.String sourceDir, java.lang.String fileName, java.lang.String targetdir, FilterContext fc, IAlignCallback alignCallback) throws java.lang.Exception- Throws:
java.lang.Exception
-
isFileSupported
public boolean isFileSupported(java.io.File file, boolean quick)Check to see if a file is supported by any filter. Whenquickis true, only the filename will be checked to see if it matches known supported patterns. When false, the filter may have to actually load some or all of the file in order to determine whether or not it is supported.- Parameters:
file- The file to checkquick- When true, check only the file name- Returns:
- Whether or not the file is supported
-
isBilingualFile
public boolean isBilingualFile(java.io.File file) throws java.lang.Exception- Throws:
java.lang.Exception
-
getSupportedEncodings
public static java.util.List<java.lang.String> getSupportedEncodings()
Queries JRE for the list of supported encodings. Also adds the human name for no/automatic inEncoding.- Returns:
- names of all the encodings in an array
-
createDefaultFiltersConfig
public static Filters createDefaultFiltersConfig()
Reverts Filter Configuration to Default values. Basically- Sets up built-in filters
- Reloads the plugins
- Loads filters from plugins
- Saves the configuration
-
loadConfig
public static Filters loadConfig(java.io.File configFile) throws java.io.IOException
Loads information about the filters from an XML file. If there's an error loading a file, it callssetupDefaultFilters.- Throws:
java.io.IOException
-
saveConfig
public static void saveConfig(Filters config, java.io.File configFile) throws java.io.IOException
Saves information about the filters to an XML file.- Throws:
java.io.IOException
-
now
public static java.lang.String now(java.lang.String dateFormat)
Return current system time in the specified date format.- Parameters:
dateFormat- Date format for java.text.SimpleDateFormat.
-
getTargetForSource
public java.lang.String getTargetForSource(java.lang.String sourceDir, java.lang.String srcRelPath, FilterContext fc) throws java.io.IOException, TranslationExceptionCalculate the target path corresponding to the given source file.- Parameters:
sourceDir- Path to the project'ssourcedirsrcRelPath- Relative path undersourceDirof the source filefc- Filter context- Returns:
- The relative path under
targetof the corresponding target file - Throws:
java.io.IOExceptionTranslationException
-
cloneConfig
public static Filters cloneConfig(Filters orig)
Clone config for editing- Returns:
- new config instance
-
cloneFilter
public static Filter cloneFilter(Filter filter)
Clone one filter's config for editing.- Parameters:
f- one filter's config- Returns:
- new config instance
-
getDefaultSettingsFromFilter
public static Filter getDefaultSettingsFromFilter(java.lang.String filterClassname)
Create default filter's config.- Parameters:
filterClassname- filter's classname- Returns:
- default filter's config
-
forFilter
public static java.util.Map<java.lang.String,java.lang.String> forFilter(java.util.List<Filter.Option> options)
Convert options from xml for filter usage.- Parameters:
options- xml options- Returns:
- options for filter usage
-
setOptions
public static void setOptions(Filter f, java.util.Map<java.lang.String,java.lang.String> newOptions)
Convert options to xml from map.- Parameters:
f- filternewOptions- options
-
-