net.sf.okapi.lib.xliff2.writer

## Class XLIFFWriter

- java.lang.Object
- - net.sf.okapi.lib.xliff2.writer.XLIFFWriter

- All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

      public class XLIFFWriter
      extends java.lang.Object
      implements java.io.Closeable

  Provides the methods to create an XLIFF document or to re-write an existing one.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `XLIFFWriter()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Closes the output document.
    `void` | `create(java.io.File file, java.lang.String sourceLang)` Creates a new XLIFF document
    `void` | `create(java.io.File file, java.lang.String sourceLang, java.lang.String targetLang)` Creates a new document with a given file, with a source language and a target language.
    `void` | `create(java.io.Writer output, java.lang.String sourceLang)` Creates a new document for a given writer and a source language.
    `void` | `create(java.io.Writer output, java.lang.String sourceLang, java.lang.String targetLang)` Creates a new XLIFF document.
    `java.lang.String` | `getLineBreak()` Gets the line break to use for this document.
    `javax.xml.namespace.NamespaceContext` | `getNamespaceContext()` Gets the namespace context for this writer.
    `boolean` | `getWithOriginalData()` Gets the flag indicating whether or not to output original data entries.
    `void` | `setLineBreak(java.lang.String lineBreak)` Sets the line break to use for this document.
    `void` | `setStartFileData(StartFileData startFileData)` Sets the `StartFileData` object to use for the next `writeStartFile(StartFileData)` call.
    `void` | `setUseIndentation(boolean useIndentation)` Sets whether or not indentations should be used for this document.
    `void` | `setUseInsignificantParts(boolean useInsignificantParts)`
    `void` | `setWithOriginalData(boolean withOriginalData)` Sets the flag indicating whether or not to output original data entries.
    `void` | `writeEndDocument()` Writes the end of the document (the `</xliff>` tag).
    `void` | `writeEndFile()` Writes the end of the file (the `</file>` tag).
    `void` | `writeEndGroup()` Writes the end of a <group> element.
    `void` | `writeEvent(Event event)` Writes a given event.
    `void` | `writeMidFile(MidFileData midFileData)` Writes the mid part of an <file> document.
    `void` | `writeSkeleton(Skeleton skelData)` Writes the element.
    `void` | `writeStartDocument(StartXliffData docData, java.lang.String comment)` Writes the start of the document (the `<xliff>` tag).
    `void` | `writeStartFile(StartFileData newFileData)` Writes the start of a <file> element.
    `void` | `writeStartGroup(StartGroupData startGroupData)` Writes the start of a <group> element.
    `void` | `writeUnit(Unit unit)` Writes a `<unit>` element.

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

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

- - ### Constructor Detail

    - #### XLIFFWriter

          public XLIFFWriter()

  - ### Method Detail

    - #### create

          public void create(java.io.File file,
                    java.lang.String sourceLang,
                    java.lang.String targetLang)

      Creates a new document with a given file, with a source language and a target language.
      Parameters:
        `file` - the file where to create this document. If needed directories will be created automatically to create this file.
        `sourceLang` - the source language for this document (can be null if set later).
        `targetLang` - the target language for this document (can be null).
      Throws:
        `XLIFFWriterException` - if an error occurs.

    - #### create

          public void create(java.io.File file,
                    java.lang.String sourceLang)

      Creates a new XLIFF document
      Parameters:
        `file` - the output file where to write this document.
        `sourceLang` - the source language for this document (can be null if set later).

    - #### create

          public void create(java.io.Writer output,
                    java.lang.String sourceLang,
                    java.lang.String targetLang)

      Creates a new XLIFF document.
      Parameters:
        `output` - the writer to use to output this document.
        `sourceLang` - the source language for this document (can be null if set later).
        `targetLang` - the target language for this document (can be null).

    - #### create

          public void create(java.io.Writer output,
                    java.lang.String sourceLang)

      Creates a new document for a given writer and a source language.
      Parameters:
        `output` - the writer to use to output this document.
        `sourceLang` - the source language for this document (cannot be null or empty).

    - #### setWithOriginalData

          public void setWithOriginalData(boolean withOriginalData)

      Sets the flag indicating whether or not to output original data entries.
      Parameters:
        `withOriginalData` - true to output the original data, false otherwise.

    - #### getWithOriginalData

          public boolean getWithOriginalData()

      Gets the flag indicating whether or not to output original data entries.
      Returns:
        true if the output is done with the original data, false otherwise.

    - #### setLineBreak

          public void setLineBreak(java.lang.String lineBreak)

      Sets the line break to use for this document. You must set this before calling any of the `create()` methods. By default the line-break used is the one of the OS.
      Parameters:
        `lineBreak` - the line break to use for this document.

    - #### getLineBreak

          public java.lang.String getLineBreak()

      Gets the line break to use for this document.
      Returns:
        the line break to use for this document.

    - #### setUseIndentation

          public void setUseIndentation(boolean useIndentation)

      Sets whether or not indentations should be used for this document.
      Parameters:
        `useIndentation` - true to use indentation, false to not use indentations.

    - #### setUseInsignificantParts

          public void setUseInsignificantParts(boolean useInsignificantParts)

    - #### close

          public void close()

      Closes the output document.

      If `writeEndDocument()` has not been called, it is called automatically.

      Specified by:
        `close` in interface `java.io.Closeable`
      Specified by:
        `close` in interface `java.lang.AutoCloseable`

    - #### writeEvent

          public void writeEvent(Event event)

      Writes a given event.
      Parameters:
        `event` - the event to output.

    - #### writeUnit

          public void writeUnit(Unit unit)

      Writes a `<unit>` element.

      If `writeStartFile(StartFileData)` has not been called yet, it is called automatically.

      Parameters:
        `unit` - the `Unit` object to write.

    - #### writeStartDocument

          public void writeStartDocument(StartXliffData docData,
                                java.lang.String comment)

      Writes the start of the document (the `<xliff>` tag).
      Parameters:
        `docData` - the document data.
        `comment` - an optional comment that is placed just after the `<xliff>` tag (use null for no comment).

    - #### writeEndDocument

          public void writeEndDocument()

      Writes the end of the document (the `</xliff>` tag).

      If `writeEndFile()` has not been called, it is called automatically.

    - #### setStartFileData

          public void setStartFileData(StartFileData startFileData)

      Sets the `StartFileData` object to use for the next `writeStartFile(StartFileData)` call. You can use this method to set the file-level data to use next time the `writeStartFile(StartFileData)` method is automatically call or called with a null parameter. This can be use to avoid writing the start of the <file> element directly in case there is no data to extract for example. This object stays available until the next `writeEndFile()` call.
      Parameters:
        `startFileData` - the object to use for the next `writeStartFile(StartFileData)` call.

    - #### writeStartFile

          public void writeStartFile(StartFileData newFileData)

      Writes the start of a <file> element.

      If needed `writeStartDocument(StartXliffData, String)` is called automatically before.

      Parameters:
        `newFileData` - the data associated with the start of a XLIFF <file> element (can be null). You can use `setStartFileData(StartFileData)` to set this parameter before calling this method (then use null here).

    - #### writeMidFile

          public void writeMidFile(MidFileData midFileData)

      Writes the mid part of an <file> document.

      If needed `writeStartFile(StartFileData)` is called automatically before.

      Parameters:
        `midFileData` - the data associated with a mid part of a <file> element (can be null).

    - #### writeSkeleton

          public void writeSkeleton(Skeleton skelData)

      Writes the element.

      If `writeStartFile(StartFileData)` has not been called, it is called automatically.

      If the `skeleton` attribute was used in `<file>`, an error occurs.

      Parameters:
        `skelData` - the `Skeleton` object (must not be null).
      Throws:
        `XLIFFWriterException` - if an error occurs.

    - #### writeEndFile

          public void writeEndFile()

      Writes the end of the file (the `</file>` tag).

      Nothing is written if no file has been started.

    - #### writeStartGroup

          public void writeStartGroup(StartGroupData startGroupData)

      Writes the start of a <group> element.

      If needed `writeStartFile(StartFileData)` is called before.

      Parameters:
        `startGroupData` - the data associated with the group (can be null).

    - #### writeEndGroup

          public void writeEndGroup()

      Writes the end of a <group> element.

    - #### getNamespaceContext

          public javax.xml.namespace.NamespaceContext getNamespaceContext()

      Gets the namespace context for this writer.
      Returns:
        the namespace context for this writer.