Class 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 implement processStartElement, processEndElement and processCharacters
    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).

    • Constructor Detail

      • AbstractXmlFilter

        public AbstractXmlFilter()
    • Method Detail

      • isSourceEncodingVariable

        public boolean isSourceEncodingVariable()
        Description copied from class: AbstractFilter
        Whether 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:
        isSourceEncodingVariable in interface IFilter
        Specified by:
        isSourceEncodingVariable in class AbstractFilter
        Returns:
        whether source encoding can be changed by the user
      • isTargetEncodingVariable

        public boolean isTargetEncodingVariable()
        Description copied from class: AbstractFilter
        Whether 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:
        isTargetEncodingVariable in interface IFilter
        Specified by:
        isTargetEncodingVariable in class AbstractFilter
        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.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. Accepts null 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 outEncoding
        java.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,
                                TranslationException
        Processes an XML file. Does encoding/EOL detection, if necessary
        Throws:
        java.io.IOException
        TranslationException
      • processFile

        public void processFile​(java.io.BufferedReader inReader,
                                java.io.BufferedWriter writer,
                                FilterContext fc)
                         throws java.io.IOException,
                                TranslationException
        Processes a buffer.

        This method works only if buffered reader and writer are already configured with correct encoding and EOL.

        Throws:
        java.io.IOException
        TranslationException