Package org.omegat.filters3.xml
Class XMLFilter
- java.lang.Object
-
- org.omegat.filters2.AbstractFilter
-
- org.omegat.filters3.xml.XMLFilter
-
- All Implemented Interfaces:
IFilter
- Direct Known Subclasses:
AndroidFilter
,CamtasiaWindowsFilter
,DocBookFilter
,FlashFilter
,HelpAndManualFilter
,InfixFilter
,L10nmgrFilter
,OpenDocXMLFilter
,OpenXMLXMLFilter
,PropertiesFilter
,RelaxNGFilter
,ResXFilter
,SchematronFilter
,ScribusFilter
,SvgFilter
,TXMLFilter
,Typo3Filter
,VisioFilter
,WiXFilter
,WordpressFilter
,XHTMLFilter
,XLIFFFilter
,XMLSpreadsheetFilter
public abstract class XMLFilter extends AbstractFilter
Abstract basis filter for XML format filters: OpenDocument, DocBook etc. Ideally should allow creation of a new XML dialect filter by simply specifying translatable tags and attributes.
-
-
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 XMLFilter(XMLDialect dialect)
Creates a new instance of XMLFilter
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
comment(java.lang.String 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 dialectLanguage
getSourceLanguage()
Language
getTargetLanguage()
boolean
isFileSupported(java.io.BufferedReader reader)
Returns whether the XML file is supported by the filter.boolean
isInIgnored()
boolean
isSourceEncodingVariable()
Whether source encoding can be varied by the user.boolean
isTargetEncodingVariable()
Target encoding can be varied by the user.void
processFile(java.io.File inFile, java.io.File outFile, FilterContext fc)
Processes an XML file.void
tagEnd(java.lang.String path)
void
tagStart(java.lang.String path, org.xml.sax.Attributes atts)
void
text(java.lang.String 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.-
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
-
-
-
-
Constructor Detail
-
XMLFilter
public XMLFilter(XMLDialect dialect)
Creates a new instance of XMLFilter
-
-
Method Detail
-
getDialect
public XMLDialect getDialect()
Gives the dialect
-
createReader
public java.io.BufferedReader createReader(java.io.File inFile, java.lang.String inEncoding) throws java.io.UnsupportedEncodingException, java.io.IOException
Creates 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.IOException
Creates a writer of the translated file. Acceptsnull
output file -- returns a writer to/dev/null
in 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
-
getTargetLanguage
public Language getTargetLanguage()
- Returns:
- The target language of the project
-
getSourceLanguage
public Language getSourceLanguage()
- Returns:
- The source language of the project
-
processFile
public void processFile(java.io.File inFile, java.io.File outFile, FilterContext fc) throws java.io.IOException, TranslationException
Processes an XML file.- Throws:
java.io.IOException
TranslationException
-
isSourceEncodingVariable
public boolean isSourceEncodingVariable()
Whether source encoding can be varied by the user. If XML file has no encoding declaration, UTF-8 will be used, hence returnsfalse
by default.- Specified by:
isSourceEncodingVariable
in interfaceIFilter
- Specified by:
isSourceEncodingVariable
in classAbstractFilter
- Returns:
false
-
isTargetEncodingVariable
public boolean isTargetEncodingVariable()
Target encoding can be varied by the user.- Specified by:
isTargetEncodingVariable
in interfaceIFilter
- Specified by:
isTargetEncodingVariable
in classAbstractFilter
- Returns:
true
-
translate
public 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.
-
isFileSupported
public boolean isFileSupported(java.io.BufferedReader reader)
Returns whether the XML file is supported by the filter.
ReadsOConsts.READ_AHEAD_LIMIT
and tries to detect constrained text and match constraints defined inXMLDialect
against them.
-
tagStart
public void tagStart(java.lang.String path, org.xml.sax.Attributes atts)
-
tagEnd
public void tagEnd(java.lang.String path)
-
comment
public void comment(java.lang.String comment)
-
text
public void text(java.lang.String text)
-
isInIgnored
public boolean isInIgnored()
-
-