net.sf.okapi.common.filterwriter

## Class TMXWriter

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

-     public class TMXWriter
      extends java.lang.Object

  Writer for TMX documents.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `TMXWriter(java.lang.String path)` Creates a new TMXWriter object.
    `TMXWriter(XMLWriter writer)` Creates a new TMXWriter object.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Closes the current output document if one is opened.
    `int` | `getItemCount()` Gets the number of TU elements that have been written in the current output document.
    `boolean` | `isWriteAllPropertiesAsAttributes()` Write all TU level properties as TMX attributes?
    `void` | `setAltTranslationOption(java.lang.String pattern)` Sets a pattern used to indicate which entries to include when using the `writeAlternate(AltTranslation, TextFragment)` method.
    `void` | `setExclusionOption(java.lang.String pattern)` Sets a pattern of content to not output.
    `void` | `setExpandDuplicateProps(boolean expandDuplicateProps)`
    `void` | `setLetterCodedMode(boolean value, boolean zeroBased)` Sets the flag indicating whether the writer should output letter-coded content (e.g.
    `protected void` | `setPath(java.lang.String path)`
    `void` | `setPropValueSep(java.lang.String propValueSep)`
    `void` | `setQuoteMode(int quoteMode)` Sets the default quote mode to use in escaping the TMX segment content (1 is the default).
    `void` | `setTradosWorkarounds(boolean value)` Sets the flag indicating whether the writer should output workaround codes specific for Trados.
    `void` | `setUseMTPrefix(boolean useMTPrefix)` Sets the flag indicating if entries originating from MT should be written with a special prefix in the source text (forcing a fuzzy match).
    `void` | `setWriteAllPropertiesAsAttributes(boolean writeAllPropertiesAsAttributes)` If true then all TU level properties will be written as TMX attributes.
    `protected void` | `setXmlWriter(XMLWriter writer)`
    `protected void` | `writeAllPropertiesAsAttibutes(XMLWriter writer, java.util.Set<java.lang.String> names, ITextUnit item)`
    `protected void` | `writeAllPropertiesAsAttibutes(XMLWriter writer, java.util.Set<java.lang.String> names, TextContainer item)`
    `void` | `writeAlternate(AltTranslation alt, TextFragment srcOriginal)` Writes the data of an `AltTranslation` to this TMX output.
    `void` | `writeAlternates(ITextUnit tu, LocaleId trgLoc)` Writes the entries of an `AltTranslationsAnnotation` annotation(s) of a given text unit to the TMX document.
    `void` | `writeEndDocument()` Writes the end of the TMX document.
    `void` | `writeItem(ITextUnit tu, java.util.Map<java.lang.String,java.lang.String> attributes)` Writes a given text unit.
    `protected void` | `writeProp(java.lang.String name, java.lang.String value)`
    `protected void` | `writeResourceLevelProperties(java.util.Set<java.lang.String> names, ITextUnit item, TextFragment srcSegment)`
    `void` | `writeStartDocument(LocaleId sourceLocale, LocaleId targetLocale, java.lang.String creationTool, java.lang.String creationToolVersion, java.lang.String segType, java.lang.String originalTMFormat, java.lang.String dataType)` Writes the start of the TMC document.
    `void` | `writeTU(TextFragment source, TextFragment target, java.lang.String tuid, java.util.Map<java.lang.String,java.lang.String> attributes)` Writes a TMX TU element.
    `void` | `writeTU(TextFragment source, TextFragment target, java.lang.String tuid, java.util.Map<java.lang.String,java.lang.String> attributes, LocaleId altTrgLoc)` Writes a TMX TU element.
    `void` | `writeTUFull(ITextUnit item)` Writes a TextUnit (all targets) with all the properties associated to it.
    `void` | `writeTUFull(ITextUnit item, LocaleId sourceLocId)` Writes a TextUnit (all targets) with all the properties associated to it.
    `protected void` | `writeTUV(TextFragment frag, LocaleId locale, TextContainer contForProp)` Writes a TUV element.

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

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

- - ### Constructor Detail

    - #### TMXWriter

          public TMXWriter(java.lang.String path)

      Creates a new TMXWriter object. Creates a new TMX document.
      Parameters:
        `path` - The full path of the TMX document to create. If another document exists already it will be overwritten.

    - #### TMXWriter

          public TMXWriter(XMLWriter writer)

      Creates a new TMXWriter object. Creates a new TMX document.
      Parameters:
        `writer` - an instance of an XMLWriter to use. If another document exists already it will be overwritten.

  - ### Method Detail

    - #### setPath

          protected void setPath(java.lang.String path)

    - #### setXmlWriter

          protected void setXmlWriter(XMLWriter writer)

    - #### close

          public void close()

      Closes the current output document if one is opened.

    - #### getItemCount

          public int getItemCount()

      Gets the number of TU elements that have been written in the current output document.
      Returns:
        The number of TU elements written in the current output document.

    - #### setTradosWorkarounds

          public void setTradosWorkarounds(boolean value)

      Sets the flag indicating whether the writer should output workaround codes specific for Trados.
      Parameters:
        `value` - true to output Trados-specific workarounds. False otherwise.

    - #### setLetterCodedMode

          public void setLetterCodedMode(boolean value,
                                boolean zeroBased)

      Sets the flag indicating whether the writer should output letter-coded content (e.g. to work for OmegaT).
      Parameters:
        `value` - true to output letter-coded content. False otherwise.
        `zeroBased` - true to have 0-based code, false for unaltered IDs.

    - #### setExclusionOption

          public void setExclusionOption(java.lang.String pattern)

      Sets a pattern of content to not output. The given pattern is matched against the source content of each item, if it matches, the item is not written.
      Parameters:
        `pattern` - the regular expression pattern of the contents to not output.

    - #### setAltTranslationOption

          public void setAltTranslationOption(java.lang.String pattern)

      Sets a pattern used to indicate which entries to include when using the `writeAlternate(AltTranslation, TextFragment)` method. When this pattern is set to null (the default) all entries are included.
      Parameters:
        `pattern` - the regular expression of the origin(s) to include. Use null to include all entries.

    - #### setQuoteMode

          public void setQuoteMode(int quoteMode)

      Sets the default quote mode to use in escaping the TMX segment content (1 is the default).
      Parameters:
        `quoteMode` - 0=no quote escaped, 1=apos and quot, 2=#39 and quot, and 3=quot only.

    - #### setUseMTPrefix

          public void setUseMTPrefix(boolean useMTPrefix)

      Sets the flag indicating if entries originating from MT should be written with a special prefix in the source text (forcing a fuzzy match). An entry is deemed originating from MT when its `creationid` attribute is set to ``Util.MTFLAG``.
      Parameters:
        `useMTPrefix` - true to use a prefix for entries originating from MT.

    - #### writeStartDocument

          public void writeStartDocument(LocaleId sourceLocale,
                                LocaleId targetLocale,
                                java.lang.String creationTool,
                                java.lang.String creationToolVersion,
                                java.lang.String segType,
                                java.lang.String originalTMFormat,
                                java.lang.String dataType)

      Writes the start of the TMC document.
      Parameters:
        `sourceLocale` - The source locale (must be set).
        `targetLocale` - The target locale (must be set).
        `creationTool` - The identifier of the creation tool (can be null).
        `creationToolVersion` - The version of the creation tool (can be null).
        `segType` - The type of segments in the output.
        `originalTMFormat` - The identifier for the original TM engine (can be null).
        `dataType` - The type of data to output.

    - #### writeEndDocument

          public void writeEndDocument()

      Writes the end of the TMX document.

    - #### writeItem

          public void writeItem(ITextUnit tu,
                       java.util.Map<java.lang.String,java.lang.String> attributes)

      Writes a given text unit. One TMX TU per segment if the text unit is segment, or one TU for the full content, if the text unit is not segmented.
      Parameters:
        `tu` - The text unit to output.
        `attributes` - The optional set of attribute to put along with the entry.

    - #### writeAlternates

          public void writeAlternates(ITextUnit tu,
                             LocaleId trgLoc)

      Writes the entries of an `AltTranslationsAnnotation` annotation(s) of a given text unit to the TMX document.
      Parameters:
        `tu` - text unit to use.
        `trgLoc` - target locale.

    - #### writeAlternate

          public void writeAlternate(AltTranslation alt,
                            TextFragment srcOriginal)

      Writes the data of an `AltTranslation` to this TMX output.

      Which entries will be output also depends on what patterns have been set with `setAltTranslationOption(String)` and `setExclusionOption(String)`.

      Parameters:
        `alt` - the alternate translation.
        `srcOriginal` - the default source (coming from the segment or container where the annotation was attached to).

    - #### writeTU

          public void writeTU(TextFragment source,
                     TextFragment target,
                     java.lang.String tuid,
                     java.util.Map<java.lang.String,java.lang.String> attributes)

      Writes a TMX TU element.
      Parameters:
        `source` - the fragment for the source text.
        `target` - the fragment for the target text.
        `tuid` - the TUID attribute (can be null).
        `attributes` - the optional set of attribute to put along with the entry.

    - #### writeTU

          public void writeTU(TextFragment source,
                     TextFragment target,
                     java.lang.String tuid,
                     java.util.Map<java.lang.String,java.lang.String> attributes,
                     LocaleId altTrgLoc)

      Writes a TMX TU element.
      Parameters:
        `source` - the fragment for the source text.
        `target` - the fragment for the target text.
        `tuid` - the TUID attribute (can be null).
        `attributes` - the optional set of attribute to put along with the entry.
        `altTrgLoc` - the target locale id to use (in case it is different from the default one, use null to get the default).

    - #### writeTUFull

          public void writeTUFull(ITextUnit item)

      Writes a TextUnit (all targets) with all the properties associated to it.

      Note: If the srclang in the TMX header is "*all*", you must use `writeTUFull(ITextUnit, LocaleId)` instead.

      Parameters:
        `item` - The text unit to write.

    - #### writeTUFull

          public void writeTUFull(ITextUnit item,
                         LocaleId sourceLocId)

      Writes a TextUnit (all targets) with all the properties associated to it.
      Parameters:
        `item` - The text unit to write.
        `sourceLocId` - The source locale id to use for this TU.

    - #### writeResourceLevelProperties

          protected void writeResourceLevelProperties(java.util.Set<java.lang.String> names,
                                          ITextUnit item,
                                          TextFragment srcSegment)

    - #### writeProp

          protected void writeProp(java.lang.String name,
                       java.lang.String value)

    - #### writeAllPropertiesAsAttibutes

          protected void writeAllPropertiesAsAttibutes(XMLWriter writer,
                                           java.util.Set<java.lang.String> names,
                                           ITextUnit item)

    - #### writeAllPropertiesAsAttibutes

          protected void writeAllPropertiesAsAttibutes(XMLWriter writer,
                                           java.util.Set<java.lang.String> names,
                                           TextContainer item)

    - #### writeTUV

          protected void writeTUV(TextFragment frag,
                      LocaleId locale,
                      TextContainer contForProp)

      Writes a TUV element.
      Parameters:
        `frag` - the TextFragment for the content of this TUV. This can be a segment of a TextContainer.
        `locale` - the locale for this TUV.
        `contForProp` - the TextContainer that has the properties to write for this TUV, or null for no properties.

    - #### setWriteAllPropertiesAsAttributes

          public void setWriteAllPropertiesAsAttributes(boolean writeAllPropertiesAsAttributes)

      If true then all TU level properties will be written as TMX attributes.
      Parameters:
        `writeAllPropertiesAsAttributes` - true to write out all TU level properties as TMX attributes.

    - #### isWriteAllPropertiesAsAttributes

          public boolean isWriteAllPropertiesAsAttributes()

      Write all TU level properties as TMX attributes?
      Returns:
        true if all TU level properties will be written, false otherwise.

    - #### setExpandDuplicateProps

          public void setExpandDuplicateProps(boolean expandDuplicateProps)

    - #### setPropValueSep

          public void setPropValueSep(java.lang.String propValueSep)