net.sf.okapi.common.filterwriter

## Class XLIFFWriter

- java.lang.Object
- - net.sf.okapi.common.filterwriter.XLIFFWriter

- All Implemented Interfaces:
    java.lang.AutoCloseable, IFilterWriter

      public class XLIFFWriter
      extends java.lang.Object
      implements IFilterWriter

  Writer for creating XLIFF document.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `OKP_ENGINE` Name of the Okapi XLIFF extension engine.
    `static java.lang.String` | `OKP_MATCHTYPE` Name of the Okapi XLIFF extension matchType.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `XLIFFWriter()` Creates an XLIFF writer object.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `cancel()` Cancels the current process.
    `void` | `close()` Writes the end of this the document and close it.
    `void` | `create(java.lang.String xliffPath, java.lang.String skeletonPath, LocaleId srcLoc, LocaleId trgLoc, java.lang.String dataType, java.lang.String original, java.lang.String message)` Creates a new XLIFF document.
    `EncoderManager` | `getEncoderManager()` Gets the current encoder manager for this writer.
    `java.lang.String` | `getName()` Gets the name of this writer.
    `XLIFFWriterParameters` | `getParameters()` Gets the current parameters for this writer.
    `ISkeletonWriter` | `getSkeletonWriter()` Gets the skeleton writer associated with this writer.
    `XLIFFContent` | `getXLIFFContent()`
    `Event` | `handleEvent(Event event)` Handles the filter events.
    `void` | `setAnnotatorsRef(java.lang.String values)` Updates the current ITS annotators references based on a given set of values.
    `void` | `setOptions(LocaleId locale, java.lang.String defaultEncoding)` Sets the options for this writer.
    `void` | `setOutput(java.io.OutputStream output)` Sets the output through its output stream.
    `void` | `setOutput(java.lang.String path)` Sets the output through the path of the output file.
    `void` | `setParameters(IParameters params)` Sets new parameters for this writer.
    `void` | `writeEndFile()` Writes the end of a <file> element.
    `void` | `writeEndGroup()` Writes the end of a <group> element.
    `void` | `writeStartFile(java.lang.String original, java.lang.String dataType, java.lang.String skeletonPath)` Writes the start of a <file> element.
    `void` | `writeStartFile(java.lang.String original, java.lang.String dataType, java.lang.String skeletonPath, java.lang.String extraForHeader)` Writes the start of a <file> element.
    `void` | `writeStartGroup(StartGroup resource)` Writes the start of a <group> element.
    `void` | `writeTextUnit(ITextUnit tu)` Writes a text unit as a <trans-unit> element.
    `void` | `writeTextUnit(ITextUnit tu, java.lang.String phaseName)` Writes a text unit as a <trans-unit> element.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### OKP_MATCHTYPE

          public static final java.lang.String OKP_MATCHTYPE

      Name of the Okapi XLIFF extension matchType.
      See Also:
        Constant Field Values

    - #### OKP_ENGINE

          public static final java.lang.String OKP_ENGINE

      Name of the Okapi XLIFF extension engine.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### XLIFFWriter

          public XLIFFWriter()

      Creates an XLIFF writer object.

  - ### Method Detail

    - #### create

          public void create(java.lang.String xliffPath,
                             java.lang.String skeletonPath,
                             LocaleId srcLoc,
                             LocaleId trgLoc,
                             java.lang.String dataType,
                             java.lang.String original,
                             java.lang.String message)

      Creates a new XLIFF document.
      Parameters:
        `xliffPath` - the full path of the document to create.
        `skeletonPath` - the path for the skeleton, or null for no skeleton.
        `srcLoc` - the source locale.
        `trgLoc` - the target locale, or null for no target.
        `dataType` - the value for the `datatype` attribute.
        `original` - the value for the `original` attribute.
        `message` - optional comment to put at the top of the document (can be null).

    - #### close

          public void close()

      Writes the end of this the document and close it. If a <file> element is currently opened, it is closed automatically.
      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Specified by:
        `close` in interface `IFilterWriter`

    - #### writeStartFile

          public void writeStartFile(java.lang.String original,
                                     java.lang.String dataType,
                                     java.lang.String skeletonPath)

      Writes the start of a <file> element.

      each call to this method must have a corresponding call to `writeEndFile()`.

      Parameters:
        `original` - the value for the `original` attribute. If null: "unknown" is used.
        `dataType` - the value for the `datatype` attribute. If null: "x-undefined" is used.
        `skeletonPath` - optional external skeleton information, or null.
      See Also:
        `writeEndFile()`

    - #### writeStartFile

          public void writeStartFile(java.lang.String original,
                                     java.lang.String dataType,
                                     java.lang.String skeletonPath,
                                     java.lang.String extraForHeader)

      Writes the start of a <file> element.

      each call to this method must have a corresponding call to `writeEndFile()`.

      Parameters:
        `original` - the value for the `original` attribute. If null: "unknown" is used.
        `dataType` - the value for the `datatype` attribute. If null: "x-undefined" is used.
        `skeletonPath` - optional external skeleton information, or null.
        `extraForHeader` - optional extra raw valid XLIFF to place in the header, or null.
      See Also:
        `writeEndFile()`

    - #### writeEndFile

          public void writeEndFile()

      Writes the end of a <file> element. This method should be called for each call to `writeStartFile(String, String, String)`.
      See Also:
        `writeStartFile(String, String, String)`

    - #### writeStartGroup

          public void writeStartGroup(StartGroup resource)

      Writes the start of a <group> element.
      See Also:
        `writeEndGroup()`

    - #### writeEndGroup

          public void writeEndGroup()

      Writes the end of a <group> element.
      See Also:
        `writeStartGroup(StartGroup)`

    - #### writeTextUnit

          public void writeTextUnit(ITextUnit tu)

      Writes a text unit as a <trans-unit> element.
      Parameters:
        `tu` - the text unit to output.

    - #### writeTextUnit

          public void writeTextUnit(ITextUnit tu,
                                    java.lang.String phaseName)

      Writes a text unit as a <trans-unit> element.
      Parameters:
        `tu` - the text unit to output.
        `phaseName` - the value of `phase-name` (can be null).

    - #### 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.

    - #### getName

          public java.lang.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.

    - #### getParameters

          public XLIFFWriterParameters 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.

    - #### 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.

    - #### setOptions

          public void setOptions(LocaleId locale,
                                 java.lang.String defaultEncoding)

      Description copied from interface: `IFilterWriter`
      Sets the options for this writer.
      Specified by:
        `setOptions` in interface `IFilterWriter`
      Parameters:
        `locale` - the output locale.
        `defaultEncoding` - Name of the character set encoding for the output.

    - #### setOutput

          public void setOutput(java.lang.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(java.io.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.

    - #### 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.

    - #### setAnnotatorsRef

          public void setAnnotatorsRef(java.lang.String values)

      Updates the current ITS annotators references based on a given set of values.
      Parameters:
        `values` - the annotators references values to use to update the existing ones. The annotation will be output in the next element that can carry it.

    - #### getXLIFFContent

          public XLIFFContent getXLIFFContent()