public abstract class AbstractFilter extends java.lang.Object implements IFilter
The process how the filter works is the following:
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ENCODING_AUTO_HUMAN
This value represents to the user that the encoding is determined by the filter itself.
|
protected IAlignCallback |
entryAlignCallback
Callback for align.
|
protected IParseCallback |
entryParseCallback
Callback for parse.
|
protected ITranslateCallback |
entryTranslateCallback
Callback for translate.
|
protected java.lang.String |
inEncodingLastParsedFile |
protected java.util.Map<java.lang.String,java.lang.String> |
processOptions
Options for processing time.
|
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" only
|
static java.lang.String |
TFP_TARGET_COUTRY_CODE
Old spelling of the variable for country "YY" only
|
static java.lang.String |
TFP_TARGET_LANG_CODE
language "XX" only
|
static java.lang.String |
TFP_TARGET_LANGUAGE
"XX-YY", the TMX/XML language code
|
static java.lang.String |
TFP_TARGET_LOCALE
"xx_YY", locale code
|
static 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 and Description |
---|
AbstractFilter() |
Modifier and Type | Method and Description |
---|---|
protected void |
alignFile(java.io.BufferedReader sourceFile,
java.io.BufferedReader translatedFile,
FilterContext fc)
Align source file against translated file.
|
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.
|
protected java.io.BufferedReader |
createReader(java.io.File inFile,
java.lang.String inEncoding)
Creates a reader of an input file.
|
protected java.io.BufferedWriter |
createWriter(java.io.File outFile,
java.lang.String outEncoding)
Creates a writer of the translated file.
|
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.
|
protected java.lang.String |
getInputEncoding(FilterContext fc,
java.io.File inFile)
Get the input encoding.
|
protected java.lang.String |
getOutputEncoding(FilterContext fc)
Get the output encoding.
|
static java.util.List<java.lang.String> |
getTargetFilenamePatterns() |
boolean |
hasOptions()
OmegaT calls this to see whether the filter has any options.
|
protected boolean |
isFileSupported(java.io.BufferedReader reader)
Returns whether the file is supported by the filter, given the reader with file's contents.
|
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.
|
protected java.lang.String |
processEntry(java.lang.String entry)
Call this method to:
Instruct OmegaT what source strings are translatable.
|
protected java.lang.String |
processEntry(java.lang.String entry,
java.lang.String comment)
Call this method to:
Instruct OmegaT what source strings are translatable.
|
protected abstract void |
processFile(java.io.BufferedReader inFile,
java.io.BufferedWriter outFile,
FilterContext fc)
Processes a single file given a reader and a writer.
|
protected void |
processFile(java.io.File inFile,
java.io.File outFile,
FilterContext fc)
Processes a single file given an input and output files (output file may be null while loading files).
|
protected boolean |
requirePrevNextFields()
Method can be overridden to return true, in case you want previous and next segment to be included in the search
for a translation, when alternative translations are provided by the user.
|
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
changeOptions, isBilingual
public static final java.lang.String ENCODING_AUTO_HUMAN
null
is used to represent automatic encoding selection.public static final java.lang.String TFP_FILENAME
public static final java.lang.String TFP_NAMEONLY
public static final java.lang.String TFP_EXTENSION
public static final java.lang.String TFP_TARGET_LOCALE
public static final java.lang.String TFP_TARGET_LANGUAGE
public static final java.lang.String TFP_TARGET_LANG_CODE
public static final java.lang.String TFP_TARGET_COUNTRY_CODE
public static final java.lang.String TFP_TARGET_COUTRY_CODE
public static final java.lang.String TFP_TIMESTAMP_LA
public static final java.lang.String TFP_TIMESTAMP_LD
public static final java.lang.String TFP_TIMESTAMP_LDD
public static final java.lang.String TFP_TIMESTAMP_LH
public static final java.lang.String TFP_TIMESTAMP_LHH
public static final java.lang.String TFP_TIMESTAMP_LM
public static final java.lang.String TFP_TIMESTAMP_LMM
public static final java.lang.String TFP_TIMESTAMP_LS
public static final java.lang.String TFP_TIMESTAMP_LSS
public static final java.lang.String TFP_TIMESTAMP_LYYYY
public static final java.lang.String TFP_TIMESTAMP_UD
public static final java.lang.String TFP_TIMESTAMP_UEEE
public static final java.lang.String TFP_TIMESTAMP_UEEEE
public static final java.lang.String TFP_TIMESTAMP_UH
public static final java.lang.String TFP_TIMESTAMP_UHH
public static final java.lang.String TFP_TIMESTAMP_UM
public static final java.lang.String TFP_TIMESTAMP_UMM
public static final java.lang.String TFP_TIMESTAMP_UMMM
public static final java.lang.String TFP_SYSTEM_OS_NAME
public static final java.lang.String TFP_SYSTEM_OS_VERSION
public static final java.lang.String TFP_SYSTEM_OS_ARCH
public static final java.lang.String TFP_SYSTEM_USER_NAME
public static final java.lang.String TFP_SYSTEM_HOST_NAME
public static final java.lang.String TFP_FILE_SOURCE_ENCODING
public static final java.lang.String TFP_FILE_TARGET_ENCODING
public static final java.lang.String TFP_FILE_FILTER_NAME
public static final java.lang.String TFP_TARGET_LOCALE_LCID
protected java.lang.String inEncodingLastParsedFile
protected IParseCallback entryParseCallback
protected ITranslateCallback entryTranslateCallback
protected IAlignCallback entryAlignCallback
protected java.util.Map<java.lang.String,java.lang.String> processOptions
public static final java.lang.String TARGET_DEFAULT
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.
public static java.util.List<java.lang.String> getTargetFilenamePatterns()
public abstract java.lang.String getFileFormatName()
getFileFormatName
in interface IFilter
public abstract Instance[] getDefaultInstances()
Note that the user may change the instances freely.
getDefaultInstances
in interface IFilter
public abstract boolean isSourceEncodingVariable()
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).
isSourceEncodingVariable
in interface IFilter
public abstract boolean isTargetEncodingVariable()
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.
isTargetEncodingVariable
in interface IFilter
protected boolean isFileSupported(java.io.BufferedReader reader)
#isFileSupported(File, Map, FilterContext))
. You
should override only one of the two.
By default returns true, because this method should be overriden only by filters that differentiate input files not by extensions, but by file's content.
For example, DocBook files have .xml extension, as possibly many other XML files, so the filter should check a DTD of the document.
reader
- The reader of the source filepublic boolean isFileSupported(java.io.File inFile, java.util.Map<java.lang.String,java.lang.String> config, FilterContext fc)
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.
isFileSupported
in interface IFilter
inFile
- Source file.fc
- Filter context.config
- filter's configuration optionspublic java.lang.String getFuzzyMark()
getFuzzyMark
in interface IFilter
public java.lang.String getHint()
public boolean hasOptions()
hasOptions
in interface IFilter
@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; please use IFilter.changeOptions(Window, Map)
instead.
changeOptions
in interface IFilter
parent
- parent windowconfig
- old optionsprotected java.io.BufferedReader createReader(java.io.File inFile, java.lang.String inEncoding) throws java.io.UnsupportedEncodingException, java.io.IOException, TranslationException
inFile
- The source file.inEncoding
- Encoding of the input file, if the filter supports it. Otherwise null.java.io.UnsupportedEncodingException
- Thrown if JVM doesn't support the specified inEncodingjava.io.IOException
- If any I/O Error occurs upon reader creationTranslationException
- Should be thrown when processed file has any format defects.protected java.io.BufferedWriter createWriter(java.io.File outFile, java.lang.String outEncoding) throws java.io.UnsupportedEncodingException, java.io.IOException
outFile
- The target fileoutEncoding
- Encoding of the target file, if the filter supports it. Otherwise null.java.io.UnsupportedEncodingException
- Thrown if JVM doesn't support the specified outEncodingjava.io.IOException
- If any I/O Error occurs upon writer creationprotected abstract void processFile(java.io.BufferedReader inFile, java.io.BufferedWriter outFile, FilterContext fc) throws java.io.IOException, TranslationException
processEntry(String)
method.
Note that outFile is never null, even when the project is loading. (in this case it writes no nowhere, but anyway you may use it...)
If you need more control over processed files, override
processFile(File, File, FilterContext)
instead.
inFile
- Reader of the source file. It's the result of calling
createReader(File,String)
.outFile
- Writer of the target file on compilation (the result of
calling createWriter(File, String)
), or a fictive
writer to /dev/null.TranslationException
- Should be thrown when processed file has any format defects.java.io.IOException
- In case of any I/O error.protected void processFile(java.io.File inFile, java.io.File outFile, FilterContext fc) throws java.io.IOException, TranslationException
Generally this method should read strings from the input reader and write them to the output reader. In
order to let OmegaT know what strings are translatable and to get their translation, filter should call
processEntry(String)
method.
If you override this method and do all the processing here, you should simply implement
#processFile(BufferedReader,BufferedWriter)
with a stub.
Default implementation calls createReader(File,String)
to create a reader,
new BufferedWriter(new StringWriter())
to create a writer for null
output
file, or createWriter(File,String)
to create a writer if output file is not null
;
then calls #processFile(BufferedReader,BufferedWriter)
to process source file, and then closes
reader and writer.
inFile
- The source file.outFile
- The target file.fc
- Filter context.java.io.IOException
- In case of any I/O error.TranslationException
- Should be thrown when processed file has any format defects.protected java.lang.String getInputEncoding(FilterContext fc, java.io.File inFile) throws java.io.IOException
isSourceEncodingVariable()
), try to detect it. The result may be null.fc
- inFile
- java.io.IOException
protected java.lang.String getOutputEncoding(FilterContext fc)
isTargetEncodingVariable()
):
fc
- 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
IFilter
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
IFilter
protected void alignFile(java.io.BufferedReader sourceFile, java.io.BufferedReader translatedFile, FilterContext fc) throws java.lang.Exception
sourceFile
- source filetranslatedFile
- translated filejava.lang.Exception
protected boolean requirePrevNextFields()
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
IFilter
translateFile
in interface IFilter
inFile
- source fileoutFile
- output fileconfig
- filter's configuration optionsfc
- processing contextcallback
- callback for get translationjava.lang.Exception
protected final java.lang.String processEntry(java.lang.String entry)
entry
- Translatable source stringprotected final java.lang.String processEntry(java.lang.String entry, java.lang.String comment)
entryParseCallback
.addEntry or
entryTranslateCallback
.getTranslation instead.entry
- Translatable source stringcomment
- comment on the source string in the source file (if available)public void setCallbacks(IParseCallback parseCallback, ITranslateCallback translateCallback)
parseCallback
- translateCallback
- public java.lang.String getInEncodingLastParsedFile()
IFilter
getInEncodingLastParsedFile
in interface IFilter