Class AbstractXmlFilter
- java.lang.Object
-
- org.omegat.filters2.AbstractFilter
-
- org.omegat.filters4.xml.AbstractXmlFilter
-
- All Implemented Interfaces:
IFilter
- Direct Known Subclasses:
Xliff1Filter,Xliff2Filter
public abstract class AbstractXmlFilter extends AbstractFilter
Abstract for StaX-based filters.This class is more low-level than 'filters3' API, but this is necessary to implement bilingual or very complex XML formats.
To implement your own filter based on this class you must implementprocessStartElement,processEndElementandprocessCharacters
Boolean return value will be ignored during reading process (when event writer is null), while during project compilation, it says whenever the event must be kept in the result or not (generally, parts of the XML file which are translated must return false).
-
-
Field Summary
-
Fields inherited from class org.omegat.filters2.AbstractFilter
ENCODING_AUTO_HUMAN, 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 Summary
Constructors Constructor Description AbstractXmlFilter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.BufferedReadercreateReader(java.io.File inFile, java.lang.String inEncoding)Creates a special XML-encoding-aware reader of an input file.java.io.BufferedWritercreateWriter(java.io.File outFile, java.lang.String outEncoding)Creates a writer of the translated file.booleanisSourceEncodingVariable()Whether source encoding can be varied by the user.booleanisTargetEncodingVariable()Whether target encoding can be varied by the user.voidprocessFile(java.io.BufferedReader inReader, java.io.BufferedWriter writer, FilterContext fc)Processes a buffer.voidprocessFile(java.io.File inFile, java.io.File outFile, FilterContext fc)Processes an XML file.-
Methods inherited from class org.omegat.filters2.AbstractFilter
alignFile, changeOptions, getDefaultInstances, getFileFormatName, getFuzzyMark, getHint, getInEncodingLastParsedFile, getTargetFilenamePatterns, hasOptions, isFileSupported, parseFile, setCallbacks, translateFile
-
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
-
-
-
-
Method Detail
-
isSourceEncodingVariable
public boolean isSourceEncodingVariable()
Description copied from class:AbstractFilterWhether 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:
isSourceEncodingVariablein interfaceIFilter- Specified by:
isSourceEncodingVariablein classAbstractFilter- Returns:
- whether source encoding can be changed by the user
-
isTargetEncodingVariable
public boolean isTargetEncodingVariable()
Description copied from class:AbstractFilterWhether 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:
isTargetEncodingVariablein interfaceIFilter- Specified by:
isTargetEncodingVariablein classAbstractFilter- Returns:
- whether target encoding can be changed by the user
-
createReader
public java.io.BufferedReader createReader(java.io.File inFile, java.lang.String inEncoding) throws java.io.UnsupportedEncodingException, java.io.IOExceptionCreates a special XML-encoding-aware reader of an input file.- Parameters:
inFile- The source file.- Returns:
- The reader of the source file.
- Throws:
java.io.UnsupportedEncodingException- Thrown if JVM doesn't support the specified inEncoding.java.io.IOException- If any I/O Error occurs upon reader creation.
-
createWriter
public java.io.BufferedWriter createWriter(java.io.File outFile, java.lang.String outEncoding) throws java.io.UnsupportedEncodingException, java.io.IOExceptionCreates a writer of the translated file. Acceptsnulloutput file -- returns a writer to/dev/nullin this case ;-)- Parameters:
outFile- The target file.outEncoding- Encoding of the target file, if the filter supports it. Otherwise, null.- Returns:
- The writer for the target file.
- Throws:
java.io.UnsupportedEncodingException- Thrown if JVM doesn't support the specified outEncodingjava.io.IOException- If any I/O Error occurs upon writer creation
-
processFile
public void processFile(java.io.File inFile, java.io.File outFile, FilterContext fc) throws java.io.IOException, TranslationExceptionProcesses an XML file. Does encoding/EOL detection, if necessary- Throws:
java.io.IOExceptionTranslationException
-
processFile
public void processFile(java.io.BufferedReader inReader, java.io.BufferedWriter writer, FilterContext fc) throws java.io.IOException, TranslationExceptionProcesses a buffer.This method works only if buffered reader and writer are already configured with correct encoding and EOL.
- Throws:
java.io.IOExceptionTranslationException
-
-