Package net.sf.okapi.lib.xliff2.document
Class XLIFFDocument
- java.lang.Object
-
- net.sf.okapi.lib.xliff2.document.XLIFFDocument
-
public class XLIFFDocument extends Object
Represents a complete parsed XLIFF document in memory.
-
-
Constructor Summary
Constructors Constructor Description XLIFFDocument()XLIFFDocument(String sourceLang, String version)Creates a newXLIFFDocument()with given source and version.XLIFFDocument(StartXliffData sxd)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FileNodeaddFileNode(String id)Adds aFileNodeobject to this document.Iterator<Event>createEventIterator()Creates an iterator for the events of this document.ObjectfetchReference(URIParser up)Retrieves the object corresponding to a given URI fragment.FilegetFile()Gets the File object associated with this document.FileNodegetFileNode(String id)Gets theFileNodefrom a given file id.List<String>getFileNodeIds()Gets the IDs of allFileNodein this XLIFF document.GroupNodegetGroupNode(String fileId, String groupId)Gets theGroupNodefrom a given file id and a given group id.StartXliffDatagetStartXliffData()Gets the document-level data for this document.UnitNodegetUnitNode(String fileId, String unitId)Gets theUnitNodefrom a given file id and a given unit id.List<Unit>getUnits()Gets a list of all the units in this document.voidload(File file)Loads a document from a given file, with maximum validation.voidload(File file, int validation)Loads a document from a given File.voidload(String input, int validation)Loads a document from a string.voidload(URI inputURI, int validation)Loads a document from a given URI.voidsave()Saves this document to the current file.voidsave(Writer outputWriter)Saves this document to a writer.voidsaveAs(File outputFile)Saves this document to a specified file.voidsetLineBreak(String lineBreak)Sets the line break to use when writing out this document.
-
-
-
Constructor Detail
-
XLIFFDocument
public XLIFFDocument()
-
XLIFFDocument
public XLIFFDocument(StartXliffData sxd)
-
XLIFFDocument
public XLIFFDocument(String sourceLang, String version)
Creates a newXLIFFDocument()with given source and version.- Parameters:
sourceLang- the source language.version- version of the XLIFF document (use null for the default).
-
-
Method Detail
-
load
public void load(File file)
Loads a document from a given file, with maximum validation.- Parameters:
file- the file to load.
-
load
public void load(File file, int validation)
Loads a document from a given File.- Parameters:
file- the file to load.validation- one of the VALIDATION_* constants or a ORed combination.
-
load
public void load(URI inputURI, int validation)
Loads a document from a given URI.- Parameters:
inputURI- the URI to load from.validation- one of the VALIDATION_* constants or a ORed combination.
-
load
public void load(String input, int validation)
Loads a document from a string.- Parameters:
input- the content of the document to load.validation- one of the VALIDATION_* constants or a ORed combination.
-
saveAs
public void saveAs(File outputFile)
Saves this document to a specified file. If needed directories are created.- Parameters:
outputFile- the output file.- See Also:
save()
-
save
public void save()
Saves this document to the current file. The current file is not null when you have calledload(File),load(File, int)orsaveAs(File)before.- See Also:
saveAs(File)
-
save
public void save(Writer outputWriter)
Saves this document to a writer. The writer must use an encoding that supports all Unicode characters without escaping (e.g. UTF-8)- Parameters:
outputWriter- the output writer.
-
getStartXliffData
public StartXliffData getStartXliffData()
Gets the document-level data for this document.- Returns:
- the document-level data of this document.
-
getFileNode
public FileNode getFileNode(String id)
Gets theFileNodefrom a given file id.- Parameters:
id- the id of the file to lookup.- Returns:
- the
FileNodeobject or null if not found.
-
getFileNodeIds
public List<String> getFileNodeIds()
Gets the IDs of allFileNodein this XLIFF document. The order of IDs is the insertion order of files.- Returns:
- the list of IDs.
-
getGroupNode
public GroupNode getGroupNode(String fileId, String groupId)
Gets theGroupNodefrom a given file id and a given group id.- Parameters:
fileId- the id of the file where the group is.groupId- the id of the group to lookup.- Returns:
- the
GroupNodeor null if not found.
-
getUnitNode
public UnitNode getUnitNode(String fileId, String unitId)
Gets theUnitNodefrom a given file id and a given unit id.- Parameters:
fileId- the id of the file where the unit is.unitId- the id of the unit to lookup.- Returns:
- the
UnitNodeor null if not found.
-
createEventIterator
public Iterator<Event> createEventIterator()
Creates an iterator for the events of this document.- Returns:
- a new iterator for the events of this document.
-
fetchReference
public Object fetchReference(URIParser up)
Retrieves the object corresponding to a given URI fragment.- Parameters:
up- theURIParserrepresenting the fragment to resolve.- Returns:
- the object found, or null if the object was not found or is external to this document.
-
getUnits
public List<Unit> getUnits()
Gets a list of all the units in this document.- Returns:
- the list of all units in this document.
-
getFile
public File getFile()
Gets the File object associated with this document. It can be null if the document we not read from a File. This object is automatically set when you callload(File),load(File, int)andsaveAs(File).- Returns:
- the File object for this document (or null if none is associated.
-
addFileNode
public FileNode addFileNode(String id)
Adds aFileNodeobject to this document.- Parameters:
id- the ID of the file to add.- Returns:
- the new
FileNodeobject.
-
setLineBreak
public void setLineBreak(String lineBreak)
Sets the line break to use when writing out this document. By default the line-break used is the one of the OS.- Parameters:
lineBreak- the line break to use for this document.
-
-