public abstract class XMLFilter extends AbstractFilter
ENCODING_AUTO_HUMAN, entryAlignCallback, entryParseCallback, entryTranslateCallback, inEncodingLastParsedFile, processOptions, TARGET_DEFAULT, TFP_EXTENSION, TFP_FILE_FILTER_NAME, TFP_FILE_SOURCE_ENCODING, TFP_FILE_TARGET_ENCODING, TFP_FILENAME, TFP_NAMEONLY, TFP_SYSTEM_HOST_NAME, TFP_SYSTEM_OS_ARCH, TFP_SYSTEM_OS_NAME, TFP_SYSTEM_OS_VERSION, TFP_SYSTEM_USER_NAME, TFP_TARGET_COUNTRY_CODE, TFP_TARGET_COUTRY_CODE, TFP_TARGET_LANG_CODE, TFP_TARGET_LANGUAGE, TFP_TARGET_LOCALE, TFP_TARGET_LOCALE_LCID, TFP_TIMESTAMP_LA, TFP_TIMESTAMP_LD, TFP_TIMESTAMP_LDD, TFP_TIMESTAMP_LH, TFP_TIMESTAMP_LHH, TFP_TIMESTAMP_LM, TFP_TIMESTAMP_LMM, TFP_TIMESTAMP_LS, TFP_TIMESTAMP_LSS, TFP_TIMESTAMP_LYYYY, TFP_TIMESTAMP_UD, TFP_TIMESTAMP_UEEE, TFP_TIMESTAMP_UEEEE, TFP_TIMESTAMP_UH, TFP_TIMESTAMP_UHH, TFP_TIMESTAMP_UM, TFP_TIMESTAMP_UMM, TFP_TIMESTAMP_UMMM
Constructor and Description |
---|
XMLFilter(XMLDialect dialect)
Creates a new instance of XMLFilter
|
Modifier and Type | Method and Description |
---|---|
void |
comment(java.lang.String comment)
Process comment.
|
java.io.BufferedReader |
createReader(java.io.File inFile,
java.lang.String inEncoding)
Creates a special XML-encoding-aware reader of an input file.
|
java.io.BufferedWriter |
createWriter(java.io.File outFile,
java.lang.String outEncoding)
Creates a writer of the translated file.
|
XMLDialect |
getDialect()
Gives the dialect
|
Language |
getSourceLanguage() |
Language |
getTargetLanguage() |
boolean |
isFileSupported(java.io.BufferedReader reader)
Returns whether the XML file is supported by the filter.
|
boolean |
isInIgnored()
Returns true if current section should be ignored by parser.
|
boolean |
isSourceEncodingVariable()
Whether source encoding can be varied by the user.
|
boolean |
isTargetEncodingVariable()
Target encoding can be varied by the user.
|
protected void |
processFile(java.io.BufferedReader inFile,
java.io.BufferedWriter outFile,
FilterContext fc)
Processes a single file given a reader and a writer.
|
void |
processFile(java.io.File inFile,
java.io.File outFile,
FilterContext fc)
Processes an XML file.
|
void |
tagEnd(java.lang.String path)
Finish tag translation.
|
void |
tagStart(java.lang.String path,
org.xml.sax.Attributes atts)
Start tag translation.
|
void |
text(java.lang.String text)
Process text.
|
java.lang.String |
translate(java.lang.String entry,
java.util.List<ProtectedPart> protectedParts)
The method the Handler would call to pass translatable content to OmegaT core and receive translation.
|
alignFile, alignFile, changeOptions, getDefaultInstances, getFileFormatName, getFuzzyMark, getHint, getInEncodingLastParsedFile, getInputEncoding, getOutputEncoding, getTargetFilenamePatterns, hasOptions, isFileSupported, parseFile, processEntry, processEntry, requirePrevNextFields, setCallbacks, translateFile
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
changeOptions, isBilingual
public XMLFilter(XMLDialect dialect)
public XMLDialect getDialect()
public java.io.BufferedReader createReader(java.io.File inFile, java.lang.String inEncoding) throws java.io.UnsupportedEncodingException, java.io.IOException
createReader
in class AbstractFilter
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 inEncoding.java.io.IOException
- If any I/O Error occurs upon reader creation.public java.io.BufferedWriter createWriter(java.io.File outFile, java.lang.String outEncoding) throws java.io.UnsupportedEncodingException, java.io.IOException
null
output file -- returns a writer to
/dev/null
in this case ;-)createWriter
in class AbstractFilter
outFile
- The target file.outEncoding
- 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 creationpublic Language getTargetLanguage()
public Language getSourceLanguage()
public void processFile(java.io.File inFile, java.io.File outFile, FilterContext fc) throws java.io.IOException, TranslationException
processFile
in class AbstractFilter
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 void processFile(java.io.BufferedReader inFile, java.io.BufferedWriter outFile, FilterContext fc) throws java.io.IOException, TranslationException
AbstractFilter
AbstractFilter.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
AbstractFilter.processFile(File, File, FilterContext)
instead.
processFile
in class AbstractFilter
inFile
- Reader of the source file. It's the result of calling
AbstractFilter.createReader(File,String)
.outFile
- Writer of the target file on compilation (the result of
calling AbstractFilter.createWriter(File, String)
), or a fictive
writer to /dev/null.java.io.IOException
- In case of any I/O error.TranslationException
- Should be thrown when processed file has any format defects.public boolean isSourceEncodingVariable()
false
by default.isSourceEncodingVariable
in interface IFilter
isSourceEncodingVariable
in class AbstractFilter
false
public boolean isTargetEncodingVariable()
isTargetEncodingVariable
in interface IFilter
isTargetEncodingVariable
in class AbstractFilter
true
public java.lang.String translate(java.lang.String entry, java.util.List<ProtectedPart> protectedParts)
public boolean isFileSupported(java.io.BufferedReader reader)
OConsts.READ_AHEAD_LIMIT
and tries to detect constrained text and match
constraints defined in XMLDialect
against them.isFileSupported
in class AbstractFilter
reader
- The reader of the source filepublic void tagStart(java.lang.String path, org.xml.sax.Attributes atts)
path
- path in the XMLatts
- attributespublic void tagEnd(java.lang.String path)
path
- path in the XMLpublic void comment(java.lang.String comment)
public void text(java.lang.String text)
public boolean isInIgnored()