Package org.omegat.filters2.master
Class FilterMaster
java.lang.Object
org.omegat.filters2.master.FilterMaster
A master class that registers and handles all the filters. Singleton - there
can be only one instance of this class.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringCurrently file filters support version.static final Stringname of the filter configuration filestatic final StringThere was no version of file filters support (1.4.5 Beta 1 -- 1.6.0 RC12).static final Stringstatic final StringFile filters support of 1.6.0 RC12a: now upgrading the configuration.static final Stringstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidalignFile(String sourceDir, String fileName, 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 FiltersReverts Filter Configuration to Default values.forFilter(List<Filter.Option> options) Convert options from xml for filter usage.static @Nullable FiltergetDefaultSettingsFromFilter(String filterClassname) Create default filter's config.static @Nullable IFiltergetFilterInstance(String classname) Get filter's instance by filter class name.Queries JRE for the list of supported encodings.getTargetForSource(String sourceDir, String srcRelPath, FilterContext fc) Determines the target file path for a given source file path.booleanisBilingualFile(File file) booleanisFileSupported(File file, boolean quick) Check to see if a file is supported by any filter.static @Nullable FiltersloadConfig(File configFile) Loads information about the filters from an XML file.@Nullable IFilterloadFile(String filename, FilterContext fc, IParseCallback parseCallback) OmegaT core calls this method to load a source file.static StringReturn current system time in the specified date format.static voidsaveConfig(@Nullable Filters config, File configFile) Saves information about the filters to an XML file.static voidsetFilterClasses(List<Class<?>> classes) static voidsetOptions(Filter f, Map<String, String> newOptions) Convert options to XML from a map.voidtranslateFile(String sourcedir, String filename, String targetdir, FilterContext fc, ITranslateCallback translateCallback) OmegaT core calls this method to translate a source file.
-
Field Details
-
FILE_FILTERS
name of the filter configuration file- See Also:
-
INITIAL_VERSION
There was no version of file filters support (1.4.5 Beta 1 -- 1.6.0 RC12).- See Also:
-
OT160RC12A_VERSION
File filters support of 1.6.0 RC12a: now upgrading the configuration.- See Also:
-
OT160FINAL_VERSION
- See Also:
-
OT161_VERSION
- See Also:
-
OT170_VERSION
- See Also:
-
CURRENT_VERSION
Currently file filters support version.- See Also:
-
-
Constructor Details
-
FilterMaster
Create a new FilterMaster.
-
-
Method Details
-
setFilterClasses
-
getConfig
-
getFilterInstance
Get filter's instance by filter class name.- Parameters:
classname- filter's class name- Returns:
- filter instance
-
loadFile
public @Nullable IFilter loadFile(String filename, FilterContext fc, IParseCallback parseCallback) throws 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:
IOExceptionTranslationException- See Also:
-
translateFile
public void translateFile(String sourcedir, String filename, String targetdir, FilterContext fc, ITranslateCallback translateCallback) throws IOException, TranslationException OmegaT 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:
IOExceptionTranslationException
-
alignFile
public void alignFile(String sourceDir, String fileName, String targetdir, FilterContext fc, IAlignCallback alignCallback) throws Exception - Throws:
Exception
-
isFileSupported
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 the file is supported
-
isBilingualFile
- Throws:
Exception
-
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
Reverts Filter Configuration to Default values. Basically- Sets up built-in filters
- Reloads the plugins
- Loads filters from plugins
- Saves the configuration
-
loadConfig
Loads information about the filters from an XML file. If there's an error loading a file, it callssetupDefaultFilters.- Parameters:
configFile- the file from which the filter configuration is to be loaded- Returns:
- an instance of
Filterscontaining the loaded configuration, or a newFiltersinstance if an error occurs or a new configuration is generated - Throws:
IOException- if an I/O error occurs while reading the configuration file
-
saveConfig
Saves information about the filters to an XML file. If the configuration is null, the file will be deleted. The configuration is written in a pretty-printed format.- Parameters:
config- The configuration object to be saved. If null, the file is deleted.configFile- The file to save the configuration to.- Throws:
IOException- If an error occurs while saving the configuration or deleting the file.
-
now
Return current system time in the specified date format.- Parameters:
dateFormat- Date format for java.text.SimpleDateFormat.
-
getTargetForSource
public String getTargetForSource(String sourceDir, String srcRelPath, FilterContext fc) throws TranslationException Determines the target file path for a given source file path.- Parameters:
sourceDir- the root directory of the source filesrcRelPath- the relative path of the source file within the source directoryfc- the filter context containing relevant translation parameters- Returns:
- the target file path corresponding to the source file
- Throws:
TranslationException- if an error occurs during the translation processingIllegalArgumentException- if the specified sourceDir and srcRelPath do not point to an existing file
-
cloneConfig
Clone config for editing- Returns:
- new config instance
-
cloneFilter
Clone one filter's config for editing.- Parameters:
filter- one filter's config- Returns:
- new config instance
-
getDefaultSettingsFromFilter
Create default filter's config.- Parameters:
filterClassname- filter's classname- Returns:
- default filter's config
-
forFilter
Convert options from xml for filter usage.- Parameters:
options- xml options- Returns:
- options for filter usage
-
setOptions
Convert options to XML from a map.- Parameters:
f- filternewOptions- options
-