Package net.sf.okapi.lib.xliff2.writer
Class XLIFFWriter
- java.lang.Object
-
- net.sf.okapi.lib.xliff2.writer.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 Summary
Constructors Constructor Description XLIFFWriter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the output document.voidcreate(File file, String sourceLang)Creates a new XLIFF documentvoidcreate(File file, String sourceLang, String targetLang)Creates a new document with a given file, with a source language and a target language.voidcreate(Writer output, String sourceLang)Creates a new document for a given writer and a source language.voidcreate(Writer output, String sourceLang, String targetLang)Creates a new XLIFF document.booleangetForceUniqueIds()StringgetLineBreak()Gets the line break to use for this document.NamespaceContextgetNamespaceContext()Gets the namespace context for this writer.booleangetWithOriginalData()Gets the flag indicating whether or not to output original data entries.voidsetForceUniqueIds(boolean forceUniqueIds)voidsetLineBreak(String lineBreak)Sets the line break to use for this document.voidsetStartFileData(StartFileData startFileData)Sets theStartFileDataobject to use for the nextwriteStartFile(StartFileData)call.voidsetUseIndentation(boolean useIndentation)Sets whether or not indentations should be used for this document.voidsetUseInsignificantParts(boolean useInsignificantParts)voidsetWithOriginalData(boolean withOriginalData)Sets the flag indicating whether or not to output original data entries.voidwriteEndDocument()Writes the end of the document (the</xliff>tag).voidwriteEndFile()Writes the end of the file (the</file>tag).voidwriteEndGroup()Writes the end of a <group> element.voidwriteEvent(Event event)Writes a given event.voidwriteMidFile(MidFileData midFileData)Writes the mid part of an <file> document.voidwriteSkeleton(Skeleton skelData)Writes theelement. voidwriteStartDocument(StartXliffData docData, String comment)Writes the start of the document (the<xliff>tag).voidwriteStartFile(StartFileData newFileData)Writes the start of a <file> element.voidwriteStartGroup(StartGroupData startGroupData)Writes the start of a <group> element.voidwriteUnit(Unit unit)Writes a<unit>element.
-
-
-
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 thecreate()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)
-
close
public void close()
Closes the output document.If
writeEndDocument()has not been called, it is called automatically.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
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- theUnitobject 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.
-
setStartFileData
public void setStartFileData(StartFileData startFileData)
Sets theStartFileDataobject to use for the nextwriteStartFile(StartFileData)call. You can use this method to set the file-level data to use next time thewriteStartFile(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 nextwriteEndFile()call.- Parameters:
startFileData- the object to use for the nextwriteStartFile(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 usesetStartFileData(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 theelement. If
writeStartFile(StartFileData)has not been called, it is called automatically.If the
skeletonattribute was used in<file>, an error occurs.- Parameters:
skelData- theSkeletonobject (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.
-
-