Class SkeletonMergerWriter

  • All Implemented Interfaces:
    AutoCloseable, IFilterWriter

    public class SkeletonMergerWriter
    extends Object
    implements IFilterWriter
    Basic class for skeleton-based merging. Override for specific behaviors.

    Takes a skeleton file and Events from a translated document. Translated segments are merged into the skeleton TextUnit events and written out using the default IFilterWriter

    Author:
    jimh
    • Constructor Detail

      • SkeletonMergerWriter

        public SkeletonMergerWriter()
      • SkeletonMergerWriter

        public SkeletonMergerWriter​(ITextUnitMerger textUnitMerger)
      • SkeletonMergerWriter

        public SkeletonMergerWriter​(IFilter skeletonFilter,
                                    IFilterWriter writer,
                                    ITextUnitMerger textUnitMerger)
        Use specific IFilter and IFilterWriter implementations
        Parameters:
        skeletonFilter - - IFilter used to read skeleton, can be serialized events or original source file. ASSUME FILTER OPEN ALREADY CALLED
        writer - - override the writer specified in the skeleton StartDocument event. Can use null value for writer to use the default writer.
        textUnitMerger - user created ITextUnitMerger
      • SkeletonMergerWriter

        public SkeletonMergerWriter​(IFilter skeletonFilter,
                                    ITextUnitMerger textUnitMerger)
        Use specific IFilter and IFilterWriter implementations
        Parameters:
        skeletonFilter - - IFilter used to read skeleton, can be serialized events or original source file. ASSUME FILTER OPEN ALREADY CALLED writer to use the default writer.
        textUnitMerger - user created ITextUnitMerger
    • Method Detail

      • getName

        public String getName()
        Description copied from interface: IFilterWriter
        Gets the name of this writer.
        Specified by:
        getName in interface IFilterWriter
        Returns:
        The name of the writer.
      • setOptions

        public void setOptions​(LocaleId targetLocale,
                               String defaultEncoding)
        Description copied from interface: IFilterWriter
        Sets the options for this writer.
        Specified by:
        setOptions in interface IFilterWriter
        Parameters:
        targetLocale - the output locale.
        defaultEncoding - Name of the character set encoding for the output.
      • setOutput

        public void setOutput​(String path)
        Description copied from interface: IFilterWriter
        Sets the output through the path of the output file.
        Specified by:
        setOutput in interface IFilterWriter
        Parameters:
        path - Full path of the output file.
      • setOutput

        public void setOutput​(OutputStream output)
        Description copied from interface: IFilterWriter
        Sets the output through its output stream.
        Specified by:
        setOutput in interface IFilterWriter
        Parameters:
        output - Output stream to use for the output.
      • handleEvent

        public Event handleEvent​(Event event)
        Description copied from interface: IFilterWriter
        Handles the filter events.
        Specified by:
        handleEvent in interface IFilterWriter
        Parameters:
        event - The event to process.
        Returns:
        The event that was processed.
      • close

        public void close()
        Description copied from interface: IFilterWriter
        Closes the output. Developers must make sure this method is safe to call even if there is nothing to close.
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface IFilterWriter
      • getParameters

        public Parameters getParameters()
        Description copied from interface: IFilterWriter
        Gets the current parameters for this writer.
        Specified by:
        getParameters in interface IFilterWriter
        Returns:
        The current parameters for this writer.
      • setParameters

        public void setParameters​(IParameters params)
        Description copied from interface: IFilterWriter
        Sets new parameters for this writer.
        Specified by:
        setParameters in interface IFilterWriter
        Parameters:
        params - The new parameters to use.
      • cancel

        public void cancel()
        Description copied from interface: IFilterWriter
        Cancels the current process.
        Specified by:
        cancel in interface IFilterWriter
      • getEncoderManager

        public EncoderManager getEncoderManager()
        Description copied from interface: IFilterWriter
        Gets the current encoder manager for this writer. Some special implementation of IFilterWriter may not use an encoder manager (for example writers that do not use skeleton).
        Specified by:
        getEncoderManager in interface IFilterWriter
        Returns:
        the current encoder manager for this writer, or null if none exists for this writer.
      • getSkeletonWriter

        public ISkeletonWriter getSkeletonWriter()
        Description copied from interface: IFilterWriter
        Gets the skeleton writer associated with this writer. Some implementation of IFilterWriter may not use a skeleton writer.
        Specified by:
        getSkeletonWriter in interface IFilterWriter
        Returns:
        the skeleton writer associated with this writer or null if none is associated.
      • processTextUnit

        protected void processTextUnit​(Event event)
        Take the translated TextUnit and match it up with its corresponding skeleton version. Call ITextUnitMerger to merge the translated segments into the skeleton TextUnit
        Parameters:
        event - - the translated version of the ITextUnit event
      • processUntilTextUnit

        protected Event processUntilTextUnit()
        Get events in the original document until the next text unit. Any event before is passed to the writer.
        Returns:
        the event of the next text unit, or null if no next text unit is found.
      • processEndDocument

        protected void processEndDocument()
        There are no more TextUnits. Read the remaining skeleton events and write them out.
      • setWriter

        public void setWriter​(IFilterWriter writer)
        Set the IFilterWriter used to write out the skeleton events. This will override the internal writer as defined by StartDocument in the skeleton.

        Must be called immediately after construction!!

        Parameters:
        writer - - IFilterWriter used to write out the skeleton events
      • setFilter

        public void setFilter​(IFilter skeletonFilter)
        Set the IFilter needed to process the skeleton file (normally the original document)
        Parameters:
        skeletonFilter -