Class XLIFFWriter

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class XLIFFWriter
    extends Object
    implements Closeable
    Provides the methods to create an XLIFF document or to re-write an existing one.
    • Constructor Detail

      • XLIFFWriter

        public XLIFFWriter()
    • Method Detail

      • create

        public void create​(File file,
                           String sourceLang,
                           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​(File file,
                           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​(Writer output,
                           String sourceLang,
                           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​(Writer output,
                           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.
      • setForceUniqueIds

        public void setForceUniqueIds​(boolean forceUniqueIds)
      • getForceUniqueIds

        public boolean getForceUniqueIds()
      • setLineBreak

        public void setLineBreak​(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 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)
      • 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,
                                       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.

      • 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 NamespaceContext getNamespaceContext()
        Gets the namespace context for this writer.
        Returns:
        the namespace context for this writer.