de.folt.models.documentmodel.xliff
Class XliffDocument

java.lang.Object
  extended by java.util.Observable
      extended by de.folt.models.documentmodel.document.XmlDocument
          extended by de.folt.models.documentmodel.xliff.XliffDocument
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
XliffFile

public class XliffDocument
extends XmlDocument

This class implements several utility functions for reading the main elements and attributes of a XLIFF document.
A key method is the translate method. It translates the xliff document based on source language and target language and similarity using a specific data source. The method supports multi-threading. Depending on the number of processors available it distributes the translation of a set of trans-unit towards several processors. The version currently supports Xliff 1.1 and 1.2.
When using the JDOM Element methods like getChild etc. it is recommended explicitly setting the NAMESPACE. Example: getChild("target", this.getNamespace()) or Element source = new Element("source", this.getNamespace()); As Xliff 1.2 may contain a reference to the Xliff specification like

 <xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" 
        xmlns:tek="http://www.tektronix.com"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2         
        xliff-core-1.2-strict.xsd http://www.tektronix.com tek_code_trial.xsd" 
        version="1.2">
 
this ensures correct getting and setting of the elements.

For details of XLIFF: XLIFF
Currently JDOM is used for parsing the XML XLIFF documents.

Author:
klemens
See Also:
Serialized Form

Constructor Summary
XliffDocument()
           
XliffDocument(java.io.File file)
           
XliffDocument(java.lang.String fileName)
           
 
Method Summary
 void addAltTrans(org.jdom.Element transunit, org.jdom.Element alttrans)
          addAltTrans adds an alt-trans to the given trans-unit
 org.jdom.Element addAltTrans(org.jdom.Element transUnit, MonoLingualObject sourceMono, MonoLingualObject targetMono, int iMatchquality)
          addAltTrans a a new alt-trans using source = sourceMono and target = targetMono
 org.jdom.Element addAltTrans(org.jdom.Element transUnit, MonoLingualObject sourceMono, java.util.Vector<MonoLingualObject> targetmonos, int iMatchquality, java.util.Hashtable<java.lang.String,java.lang.Object> translationParameters)
          addAltTrans a a new alt-trans using source = sourceMono and target = targetMono
 void addAltTransSorted(org.jdom.Element transunit, org.jdom.Element alttrans)
          addAltTransSorted adds an alt-trans to the given trans-unit by searching for the next lower match-quality
 void addPhase(org.jdom.Element phaseGroup, java.lang.String company, java.lang.String processName, java.lang.String tool, java.lang.String jobId, java.lang.String contactName, java.lang.String contactEmail, java.lang.String contactPhone)
          addPhase adds a new phase to a phase group - Example:
 org.jdom.Element[] addSubSegmentTranslationToGlossary(org.jdom.Element file, java.lang.String sourceTerm, java.lang.String targetTerm)
          addSubSegmentTranslationToGlossary add a phrase (source and target) to the internal dictionary
 org.jdom.Element[] addSubSegmentTranslationToGlossary(org.jdom.Element file, java.util.Vector<java.lang.String> sourceTerms, java.util.Vector<java.lang.String> targetTerms)
          addSubSegmentTranslationToGlossary
 boolean bAltTransContained(org.jdom.Element transUnit, MonoLingualObject sourceMono, MonoLingualObject targetmono)
          bAltTransContained check if a source mono / target monos combination already exists in the trans-unit
 boolean bAltTransContained(org.jdom.Element transUnit, MonoLingualObject sourceMono, java.util.Vector<MonoLingualObject> targetmonos)
          bAltTransContained check if a source mono / target monos combination already exists in the trans-unit
 org.jdom.Element convertMonoLingualObjectToElement(org.jdom.Element element, MonoLingualObject mono)
          convertMonoLingualObjectToElement converts a MonoLingualObject to an Element converting the formatted segment to content
 org.jdom.Element convertMonoLingualObjectToSource(MonoLingualObject mono)
          convertMonoLingualObjectToSource converts a MonoLingualObject to a source element converting the formatted segment to content
 org.jdom.Element convertMonoLingualObjectToTarget(MonoLingualObject mono)
          convertMonoLingualObjectToTarget converts a MonoLingualObject to a target element converting the formatted segment to content
 java.lang.String convertTmxSegStringToXliffString(java.lang.String segstring)
          convertTmxSegStringToXliffString converts a tmx seg String to a Xliff segment, esp. type= becomes ctype=
 boolean existsTranslationBasedOnOrigin(org.jdom.Element transUnit, java.lang.String originValue)
          existsTranslationBasedOnOrigin check if for a given origin value a translation exists
 boolean exportInternalOpenTMSTerminology(java.lang.String tbxDocumentName)
          exportInternalOpenTMSTerminology export the internal term dictionary of the xliff file to a tbx file; it creates first a new tbxDocument tbxDocumentName if it does not exist; otherwise appends entries to existing tbx document; it exports all the terms in all files contained in the xliff document.
 boolean exportToTextFile(org.jdom.Element file, java.lang.String fileName, boolean removeCRLF, boolean removeTags)
          exportToTextFile exports the xliff file to a simple line feed separated text file
 java.util.List<org.jdom.Element> getAllTransUnitsList(org.jdom.Element body)
          getAllTransUnitsList get all the trans units of a body including contained in groups
 java.lang.String getAltTransId(org.jdom.Element altrans)
          getAltTransId
 java.util.List<org.jdom.Element> getAltTransList(org.jdom.Element transUnit)
          getAltTransList the alt-trans elements of a trans-unit
 java.lang.String getAltTransMultiCreationId(org.jdom.Element altrans)
          getAltTransMultiId get the creation-id of a an alt-trans match
Example:
<alt-trans><<source...>...
 org.jdom.Element getBody(org.jdom.Element file)
          getBody get the header of the xliff file element
 java.util.List<org.jdom.Element> getFiles()
          getFiles the file (s) elements of an xliff file
 java.lang.String getFileSourceLanguage(org.jdom.Element file)
          getFileSourceLanguage gets the source language of a file element
 java.lang.String getFileTargetLanguage(org.jdom.Element file)
          getFileTargetLanguage gets the target language of a file element
 java.lang.String getGlossary(org.jdom.Element file)
          getGlossary get the glossary element text
 java.util.List<org.jdom.Element> getGroupTransUnitList(org.jdom.Element body)
          getTransUnitList get all the trans units of all the groups in the body
 org.jdom.Element getHeader(org.jdom.Element file)
          getHeader get the header of the xliff file element
 java.lang.String getLanguage(org.jdom.Element element)
          getLanguage gets the language of an element
 float getMatchQualityAsFloat(org.jdom.Element alttrans)
          getMatchQualityAsFloat gets the match quality of an alt-trans element
 int getMatchQualityAsInt(org.jdom.Element alttrans)
          getMatchQualityAsInt gets the match quality of an alt-trans element
 org.jdom.Element getPhaseGroup(org.jdom.Element header)
          getPhaseGroup get the phase group of the header
 java.util.List<org.jdom.Element> getPhases(org.jdom.Element phaseGroup)
          getPhases get all the phases for a file element resp. its header
 org.jdom.Element getRoot()
          getRoot get the root element of the XmlDocument
 org.jdom.Element getSklFile(org.jdom.Element header)
          getSklFile get either the external or internal skl file
 java.lang.String getSourceLanguage()
           
 java.lang.String getSourceLanguage(org.jdom.Element file)
          getSourceLanguage get source language from file element
 java.lang.String getTargetLanguage()
           
 java.lang.String getTargetLanguage(org.jdom.Element file)
          getTargetLanguage get target language from file element
 java.util.List<org.jdom.Element> getTransUnitList(org.jdom.Element body)
          getTransUnitList get all the trans units of a body
 java.util.List<org.jdom.Element> getTransUnitListNoNS(org.jdom.Element body)
          getTransUnitList3 get all the trans units of a body - no namespace used
 java.util.Vector<PhraseTranslateResult> getTransUnitPhraseEntries(org.jdom.Element transUnit)
          getTransUnitPhraseEntries return the phrase entries of the entry Example: <prop-group name="subSegmentTranslate:C:\Program Files\OpenTMS\test\editor\sample.tbx"> <prop xml:lang="de" prop-type="source">Vorwort</prop> <prop xml:lang="en" prop-type="target">Preface</prop> </prop-group></pre>
 org.jdom.Element getTransUnitSegSource(org.jdom.Element transUnit)
          getTransUnitSegSource returns the seg-source element of a trans-unit
 org.jdom.Element getTransUnitSource(org.jdom.Element transUnit)
          getTransUnitSource returns the source element of a trans-unit
 org.jdom.Element getTransUnitTarget(org.jdom.Element transUnit)
          getTransUnitTarget returns the target element of a trans-unit
 org.jdom.Element getXliffBody(org.jdom.Element file)
          getXliffBody gets the body of a file element
 org.jdom.Element getXliffHeader(org.jdom.Element file)
          getXliffHeader gets the header of a file element
 java.lang.String getXliffVersion()
          getXliffVersion get the TMX version of the tmx docuemnt
 boolean isExternalSkl(org.jdom.Element skl)
          isExternalSkl determine if external or internal skl file
 org.jdom.Element linguisticPropertiesToProp(java.lang.String name, LinguisticProperties properties)
          linguisticPropertiesToProp converts Linguistic Properties to a prop-group
 org.jdom.Document loadXmlFile(java.io.File newFile)
          loadXmlFile loads an XML file
 org.jdom.Document loadXmlFile(java.lang.String filename)
          loadXmlFile loads an XML file as a document
static void main(java.lang.String[] args)
          main
 void removeAllAltTransElements(org.jdom.Element body)
          removeAllAltTransElements remove all the alt-trans from the all trans-units
 void removeAllTargetAndAltTransElements(org.jdom.Element body)
          removeAllTargetAndAltTransElements remove all the alt-trans and targets from the all trans-units
 void removeAllTargetElements(org.jdom.Element body)
          removeAllTargetElements remove all the targets from the all trans-units
 boolean removeTranslationBasedOnOrigin(org.jdom.Element transUnit, java.lang.String originValue)
          removeTranslationBasedOnOrigin removes an alt-trans element based on the origin attribute
 void setRoot(org.jdom.Element root)
           
 void setSourceLanguage(org.jdom.Element file, java.lang.String sourceLanguage)
          setSourceLanguage set the source language of a file element
 void setSourceLanguage(java.lang.String sourceLanguage)
           
 void setTargetLanguage(org.jdom.Element file, java.lang.String targetLanguage)
          setSourceLanguage set the target language of a file element
 void setTargetLanguage(java.lang.String targetLanguage)
           
 void subSegmentTranslate(DataSource dataSource, java.util.List<org.jdom.Element> transunits, java.lang.String sourceLanguage, java.lang.String targetLanguage, java.util.Hashtable<java.lang.String,java.lang.Object> translationParameters)
          subSegmentTranslate translates an xliff document based on the source and target language provided on a sub segment bases.
 void subSegmentTranslate(DataSource dataSource, java.lang.String sourceLanguage, java.lang.String targetLanguage, java.util.Hashtable<java.lang.String,java.lang.Object> translationParameters)
          translate translates an xliff document based on the source and target language provided
 void subSegmentTranslate(java.lang.String dataSourceName, java.lang.String sourceLanguage, java.lang.String targetLanguage)
          subSegmentTranslate translates an xliff document based on the source and target language provided; the translation parameters are set to null.
 void translate(DataSource dataSource, org.jdom.Element file, java.util.List<org.jdom.Element> transunits, java.lang.String sourceLanguage, java.lang.String targetLanguage, int matchSimilarity, java.util.Hashtable<java.lang.String,java.lang.Object> translationParameters)
          translate translates an xliff document based on the source and target language provided.
 void translate(DataSource dataSource, java.lang.String sourceLanguage, java.lang.String targetLanguage, int matchSimilarity, int iMaxThreads, java.util.Hashtable<java.lang.String,java.lang.Object> translationParameters)
          translate translates an xliff document based on the source and target language provided
 void translate(java.lang.String dataSourceName, java.lang.String sourceLanguage, java.lang.String targetLanguage, int matchSimilarity, int iMaxThreads)
          translate translates an xliff document based on the source and target language provided;; the translation parameters are set to null.
 MultiLingualObject transUnitToMultiLingualObject(org.jdom.Element element)
          transUnitToMultiLingualObject creates a MUL from source and target of a trans-unit if approved
 MultiLingualObject transUnitToMultiLingualObject(org.jdom.Element element, boolean bLoadAllTargets)
          transUnitToMultiLingualObject creates a MUL from source and target of a trans-unit if approved
static int updateXliffDocument(java.io.File sourceDocument, java.io.File updateDocument)
          updateXliffDocument updates a given xliff document with an update xliff document.
static int updateXliffDocument(java.lang.String sourceDocument, java.lang.String updateDocument)
          updateXliffDocument updates a given xliff document with an update xliff document.
 
Methods inherited from class de.folt.models.documentmodel.document.XmlDocument
bIsXmlDocument, bIsXmLFile, buildElement, createDocument, elementContentToString, elementContentToString, elementToString, getCatalogueDirectory, getDocument, getNamespace, getNamespacelist, getRootElementName, getRootElementName, getsubElementFromElementAttributeNameValue, getsubElementFromElementAttributeNameValueRegExp, getXmlDocumentName, getXmlOutputter, getXmlURL, isBExpandExternalEntities, isValidElement, quoteXMLString, saveToXmlFile, saveToXmlFile, saveToXmlFile, setBExpandExternalEntities, setCatalogueDirectory, setDocument, setNamespace, setNamespacelist, setXmlDocumentName, setXmlURL
 
Methods inherited from class java.util.Observable
addObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XliffDocument

public XliffDocument()

XliffDocument

public XliffDocument(java.io.File file)
Parameters:
file -

XliffDocument

public XliffDocument(java.lang.String fileName)
Parameters:
fileName -
Method Detail

main

public static void main(java.lang.String[] args)
main

Parameters:
args -

updateXliffDocument

public static int updateXliffDocument(java.io.File sourceDocument,
                                      java.io.File updateDocument)
updateXliffDocument updates a given xliff document with an update xliff document. It compares the ids and if matches updates approved status and target.

Parameters:
sourceDocument - the document to update
updateDocument - the document containing changed entries
Returns:
the number of updates done

updateXliffDocument

public static int updateXliffDocument(java.lang.String sourceDocument,
                                      java.lang.String updateDocument)
updateXliffDocument updates a given xliff document with an update xliff document. It compares the ids and if matches updates approved status and target.

Parameters:
sourceDocument - the document to update
updateDocument - the document containing changed entries
Returns:
the number of updates done

addAltTrans

public void addAltTrans(org.jdom.Element transunit,
                        org.jdom.Element alttrans)
addAltTrans adds an alt-trans to the given trans-unit

Parameters:
transunit - the transunit
alttrans - the alt-trans to add

addAltTrans

public org.jdom.Element addAltTrans(org.jdom.Element transUnit,
                                    MonoLingualObject sourceMono,
                                    MonoLingualObject targetMono,
                                    int iMatchquality)
addAltTrans a a new alt-trans using source = sourceMono and target = targetMono

Parameters:
transUnit - the trans-unit
sourceMono - source mono lingual object
targetMono - target mono lingual object
iMatchquality - the matchquality
Returns:
the alt-trans element

addAltTrans

public org.jdom.Element addAltTrans(org.jdom.Element transUnit,
                                    MonoLingualObject sourceMono,
                                    java.util.Vector<MonoLingualObject> targetmonos,
                                    int iMatchquality,
                                    java.util.Hashtable<java.lang.String,java.lang.Object> translationParameters)
addAltTrans a a new alt-trans using source = sourceMono and target = targetMono

Parameters:
transUnit - the trans-unit
sourceMono - source mono lingual object
targetmonos - target mono lingual objects
iMatchquality - the matchquality
translationParameters - a hash table containing key value pairs defining whih attrobutes etc. to add.
ignoreProps = true / do not write attributes from LingustocObjects MUL/MOL
formatMatchPenalty as String - this penalty is subtracted if formatted segment and plain text segment do not match; default = 1; plain text segment = segment where all tags like ph etc. are removed.
Returns:
the alt-trans element

addAltTransSorted

public void addAltTransSorted(org.jdom.Element transunit,
                              org.jdom.Element alttrans)
addAltTransSorted adds an alt-trans to the given trans-unit by searching for the next lower match-quality

Parameters:
transunit - the trans-unit
alttrans - the alt-trans to add sorted

addPhase

public void addPhase(org.jdom.Element phaseGroup,
                     java.lang.String company,
                     java.lang.String processName,
                     java.lang.String tool,
                     java.lang.String jobId,
                     java.lang.String contactName,
                     java.lang.String contactEmail,
                     java.lang.String contactPhone)
addPhase adds a new phase to a phase group - Example:

Parameters:
phaseGroup - the phase group
company - the company name
processName - the process name - if null "OpenTMS Translate" will be used
tool - the tool - if null "OpenTMS Translate" will be used
jobId - - job-id
contactName - -contact-name
contactEmail - contact-email
contactPhone - -contact phone

addSubSegmentTranslationToGlossary

public org.jdom.Element[] addSubSegmentTranslationToGlossary(org.jdom.Element file,
                                                             java.lang.String sourceTerm,
                                                             java.lang.String targetTerm)
addSubSegmentTranslationToGlossary add a phrase (source and target) to the internal dictionary

Parameters:
file - the file element where to add the phrase
sourceTerm - the source term
targetTerm - the target term
Returns:

addSubSegmentTranslationToGlossary

public org.jdom.Element[] addSubSegmentTranslationToGlossary(org.jdom.Element file,
                                                             java.util.Vector<java.lang.String> sourceTerms,
                                                             java.util.Vector<java.lang.String> targetTerms)
addSubSegmentTranslationToGlossary

Parameters:
file -
sourceTerms -
targetTerms -

bAltTransContained

public boolean bAltTransContained(org.jdom.Element transUnit,
                                  MonoLingualObject sourceMono,
                                  MonoLingualObject targetmono)
bAltTransContained check if a source mono / target monos combination already exists in the trans-unit

Parameters:
transUnit - the trans-unit to check
sourceMono - the source mono - sourceMono.getFormattedSegment() used for comparison
targetmono - the target mono - translation
Returns:
true if contained (all targets are contained too!), false otherwise

bAltTransContained

public boolean bAltTransContained(org.jdom.Element transUnit,
                                  MonoLingualObject sourceMono,
                                  java.util.Vector<MonoLingualObject> targetmonos)
bAltTransContained check if a source mono / target monos combination already exists in the trans-unit

Parameters:
transUnit - the trans-unit to check
sourceMono - the source mono - sourceMono.getFormattedSegment() used for comparison
targetmonos - the target monos - targetmonos.get(i).getFormattedSegment() used for comparison; identical targets are removed from targetmonos vector
Returns:
true if contained (all targets are contained too!), false otherwise

convertMonoLingualObjectToElement

public org.jdom.Element convertMonoLingualObjectToElement(org.jdom.Element element,
                                                          MonoLingualObject mono)
                                                   throws OpenTMSException
convertMonoLingualObjectToElement converts a MonoLingualObject to an Element converting the formatted segment to content

Parameters:
element -
mono -
Returns:
Throws:
OpenTMSException

convertMonoLingualObjectToSource

public org.jdom.Element convertMonoLingualObjectToSource(MonoLingualObject mono)
                                                  throws OpenTMSException
convertMonoLingualObjectToSource converts a MonoLingualObject to a source element converting the formatted segment to content

Parameters:
mono - the mono lingual object
Returns:
the source element
Throws:
OpenTMSException

convertMonoLingualObjectToTarget

public org.jdom.Element convertMonoLingualObjectToTarget(MonoLingualObject mono)
                                                  throws OpenTMSException
convertMonoLingualObjectToTarget converts a MonoLingualObject to a target element converting the formatted segment to content

Parameters:
mono - the mono lingual object
Returns:
the target element
Throws:
OpenTMSException

convertTmxSegStringToXliffString

public java.lang.String convertTmxSegStringToXliffString(java.lang.String segstring)
convertTmxSegStringToXliffString converts a tmx seg String to a Xliff segment, esp. type= becomes ctype=

Parameters:
segstring - the tuv segment
Returns:
the xliff formatted sring

existsTranslationBasedOnOrigin

public boolean existsTranslationBasedOnOrigin(org.jdom.Element transUnit,
                                              java.lang.String originValue)
existsTranslationBasedOnOrigin check if for a given origin value a translation exists

Parameters:
transUnit - the tran-unit to check
originValue - the value of the origin attribute
Returns:
true if exists otherwise false

exportInternalOpenTMSTerminology

public boolean exportInternalOpenTMSTerminology(java.lang.String tbxDocumentName)
exportInternalOpenTMSTerminology export the internal term dictionary of the xliff file to a tbx file; it creates first a new tbxDocument tbxDocumentName if it does not exist; otherwise appends entries to existing tbx document; it exports all the terms in all files contained in the xliff document.

Parameters:
tbxDocumentName - the output tbx file name
Returns:
true in case of success, otherwise false

exportToTextFile

public boolean exportToTextFile(org.jdom.Element file,
                                java.lang.String fileName,
                                boolean removeCRLF,
                                boolean removeTags)
exportToTextFile exports the xliff file to a simple line feed separated text file

Parameters:
file - the file to export in the xliff document
fileName - the file name to export to
removeCRLF - true if CR/LF in segments should be removed
removeTags - true if tags in segments should be removed
Returns:
true in case of success

getAllTransUnitsList

public java.util.List<org.jdom.Element> getAllTransUnitsList(org.jdom.Element body)
getAllTransUnitsList get all the trans units of a body including contained in groups

Parameters:
body - the body element
Returns:
the transunits

getAltTransId

public java.lang.String getAltTransId(org.jdom.Element altrans)
getAltTransId

Parameters:
altrans -
Returns:

getAltTransList

public java.util.List<org.jdom.Element> getAltTransList(org.jdom.Element transUnit)
getAltTransList the alt-trans elements of a trans-unit

Parameters:
transUnit - the trans-unit element
Returns:
the alt-trans elements

getAltTransMultiCreationId

public java.lang.String getAltTransMultiCreationId(org.jdom.Element altrans)
getAltTransMultiId get the creation-id of a an alt-trans match
Example:
 <alt-trans><<source...>...<target...>...
<prop-group name="MULTI-624649fa-7e65-42ee-928d-aa2b10b12f27"><prop prop-value="creationid">1233c020bc55054_klemens</prop><prop prop-value="usagecount">0</prop><prop prop-value="entrynumber">21477</prop><prop prop-value="datatype">125447</prop><prop prop-value="changeid">1233c020bc55054_klemens</prop></prop-group>
</alt-trans> getAltTransMultiId(alt-trans) will return "1233c020bc55054_klemens"

Parameters:
altrans - the alt-trans element to search in
Returns:
the creation-id of a an alt-trans match

getBody

public org.jdom.Element getBody(org.jdom.Element file)
getBody get the header of the xliff file element

Parameters:
file - the file element
Returns:
the header element

getFiles

public java.util.List<org.jdom.Element> getFiles()
getFiles the file (s) elements of an xliff file

Returns:
the file elements

getFileSourceLanguage

public java.lang.String getFileSourceLanguage(org.jdom.Element file)
getFileSourceLanguage gets the source language of a file element

Parameters:
file - the file element
Returns:
the source language of the file

getFileTargetLanguage

public java.lang.String getFileTargetLanguage(org.jdom.Element file)
getFileTargetLanguage gets the target language of a file element

Parameters:
file - the file element
Returns:
the target language of the file

getGlossary

public java.lang.String getGlossary(org.jdom.Element file)
getGlossary get the glossary element text

Parameters:
file - the header which contains the glossary
Returns:
the glossary as string

getGroupTransUnitList

public java.util.List<org.jdom.Element> getGroupTransUnitList(org.jdom.Element body)
getTransUnitList get all the trans units of all the groups in the body

Parameters:
body - the body element
Returns:
the transunits

getHeader

public org.jdom.Element getHeader(org.jdom.Element file)
getHeader get the header of the xliff file element

Parameters:
file - the file element
Returns:
the header element

getLanguage

public java.lang.String getLanguage(org.jdom.Element element)
getLanguage gets the language of an element

Parameters:
element - the element with a language code
Returns:
the language code

getMatchQualityAsFloat

public float getMatchQualityAsFloat(org.jdom.Element alttrans)
getMatchQualityAsFloat gets the match quality of an alt-trans element

Parameters:
alttrans - the alt-trans element
Returns:
the match quality, -1 in case of error or match-quality not a numbe

getMatchQualityAsInt

public int getMatchQualityAsInt(org.jdom.Element alttrans)
getMatchQualityAsInt gets the match quality of an alt-trans element

Parameters:
alttrans - the alt-trans element
Returns:
the match quality, -1 in case of error or match-quality not a numbe

getPhaseGroup

public org.jdom.Element getPhaseGroup(org.jdom.Element header)
getPhaseGroup get the phase group of the header

Parameters:
header -
Returns:
the phase-group element

getPhases

public java.util.List<org.jdom.Element> getPhases(org.jdom.Element phaseGroup)
getPhases get all the phases for a file element resp. its header

Parameters:
phaseGroup - the phase group
Returns:
the phases

getRoot

public org.jdom.Element getRoot()
Description copied from class: XmlDocument
getRoot get the root element of the XmlDocument

Overrides:
getRoot in class XmlDocument
Returns:
the root

getSklFile

public org.jdom.Element getSklFile(org.jdom.Element header)
getSklFile get either the external or internal skl file

Parameters:
header - the header element
Returns:
the skl file element or null if not exists

getSourceLanguage

public java.lang.String getSourceLanguage()
Returns:
the sourceLanguage

getSourceLanguage

public java.lang.String getSourceLanguage(org.jdom.Element file)
getSourceLanguage get source language from file element

Parameters:
file - the file element
Returns:
the source language

getTargetLanguage

public java.lang.String getTargetLanguage()
Returns:
the targetLanguage

getTargetLanguage

public java.lang.String getTargetLanguage(org.jdom.Element file)
getTargetLanguage get target language from file element

Parameters:
file - the file element
Returns:
the target language

getTransUnitList

public java.util.List<org.jdom.Element> getTransUnitList(org.jdom.Element body)
getTransUnitList get all the trans units of a body

Parameters:
body - the body element
Returns:
the transunits

getTransUnitListNoNS

public java.util.List<org.jdom.Element> getTransUnitListNoNS(org.jdom.Element body)
getTransUnitList3 get all the trans units of a body - no namespace used

Parameters:
body - the body element
Returns:
the transunits

getTransUnitPhraseEntries

public java.util.Vector<PhraseTranslateResult> getTransUnitPhraseEntries(org.jdom.Element transUnit)
getTransUnitPhraseEntries return the phrase entries of the entry Example:
 <prop-group name="subSegmentTranslate:C:\Program Files\OpenTMS\test\editor\sample.tbx">
   <prop xml:lang="de" prop-type="source">Vorwort</prop>
   <prop xml:lang="en" prop-type="target">Preface</prop>
 </prop-group></pre>

Parameters:
transUnit - the trans-unit with the phrase entries
Returns:
a Vector of elements with the phrases formatted as above

getTransUnitSegSource

public org.jdom.Element getTransUnitSegSource(org.jdom.Element transUnit)
getTransUnitSegSource returns the seg-source element of a trans-unit

Parameters:
transUnit - the trans-unit element
Returns:
the seg-source element

getTransUnitSource

public org.jdom.Element getTransUnitSource(org.jdom.Element transUnit)
getTransUnitSource returns the source element of a trans-unit

Parameters:
transUnit - the trans-unit element
Returns:
the source element

getTransUnitTarget

public org.jdom.Element getTransUnitTarget(org.jdom.Element transUnit)
getTransUnitTarget returns the target element of a trans-unit

Parameters:
transUnit - the trans-unit element
Returns:
the target element

getXliffBody

public org.jdom.Element getXliffBody(org.jdom.Element file)
getXliffBody gets the body of a file element

Parameters:
file - the file element
Returns:
the body element

getXliffHeader

public org.jdom.Element getXliffHeader(org.jdom.Element file)
getXliffHeader gets the header of a file element

Parameters:
file - the file element
Returns:
the header

getXliffVersion

public java.lang.String getXliffVersion()
getXliffVersion get the TMX version of the tmx docuemnt

Returns:
the XLIFF version of the document

isExternalSkl

public boolean isExternalSkl(org.jdom.Element skl)
isExternalSkl determine if external or internal skl file

Parameters:
skl - the skl File element from getSklFile(Element header)
Returns:
true if external, false if internal

linguisticPropertiesToProp

public org.jdom.Element linguisticPropertiesToProp(java.lang.String name,
                                                   LinguisticProperties properties)
linguisticPropertiesToProp converts Linguistic Properties to a prop-group

Parameters:
name - the name for the new prop-group
properties - the linguistic properties
Returns:
the name prop-group

loadXmlFile

public org.jdom.Document loadXmlFile(java.io.File newFile)
Description copied from class: XmlDocument
loadXmlFile loads an XML file

Overrides:
loadXmlFile in class XmlDocument
Parameters:
newFile - the File of the XML File
Returns:
the document loaded / null if file does not exist or is not an xml file

loadXmlFile

public org.jdom.Document loadXmlFile(java.lang.String filename)
Description copied from class: XmlDocument
loadXmlFile loads an XML file as a document

Overrides:
loadXmlFile in class XmlDocument
Parameters:
filename - the file name of the XML file
Returns:
the Document loaded

removeAllAltTransElements

public void removeAllAltTransElements(org.jdom.Element body)
removeAllAltTransElements remove all the alt-trans from the all trans-units

Parameters:
body - the body element of the file element

removeAllTargetAndAltTransElements

public void removeAllTargetAndAltTransElements(org.jdom.Element body)
removeAllTargetAndAltTransElements remove all the alt-trans and targets from the all trans-units

Parameters:
body - the body element of the file element

removeAllTargetElements

public void removeAllTargetElements(org.jdom.Element body)
removeAllTargetElements remove all the targets from the all trans-units

Parameters:
body - the body element of the file element

removeTranslationBasedOnOrigin

public boolean removeTranslationBasedOnOrigin(org.jdom.Element transUnit,
                                              java.lang.String originValue)
removeTranslationBasedOnOrigin removes an alt-trans element based on the origin attribute

Parameters:
transUnit - the transunit to check
originValeu - the value for the origin attribute
Returns:
true if removed, otherwise false

setRoot

public void setRoot(org.jdom.Element root)
Parameters:
root - the root to set

setSourceLanguage

public void setSourceLanguage(org.jdom.Element file,
                              java.lang.String sourceLanguage)
setSourceLanguage set the source language of a file element

Parameters:
file - the file element
sourceLanguage - the source language

setSourceLanguage

public void setSourceLanguage(java.lang.String sourceLanguage)
Parameters:
sourceLanguage - the sourceLanguage to set

setTargetLanguage

public void setTargetLanguage(org.jdom.Element file,
                              java.lang.String targetLanguage)
setSourceLanguage set the target language of a file element

Parameters:
file - the file element
targetLanguage - the target language

setTargetLanguage

public void setTargetLanguage(java.lang.String targetLanguage)
Parameters:
targetLanguage - the targetLanguage to set

subSegmentTranslate

public void subSegmentTranslate(DataSource dataSource,
                                java.util.List<org.jdom.Element> transunits,
                                java.lang.String sourceLanguage,
                                java.lang.String targetLanguage,
                                java.util.Hashtable<java.lang.String,java.lang.Object> translationParameters)
                         throws OpenTMSException
subSegmentTranslate translates an xliff document based on the source and target language provided on a sub segment bases. The method also informs the observers about the translation progress. A vector is supplied where the first element contains the number of trans-units overall to translate and the second element contains the actual translated trans-unit number. (0..trans-unit size - 1). If the trans-unit contains the attribute translate="no" the trans-unit no search is applied.

Parameters:
dataSource - the data source to use
transunits - the trans-units to translate
sourceLanguage - the source language to use
targetLanguage - the target language to use
translationParameters - a hash table with additional translation parameters; usage is up to the implementation
Throws:
OpenTMSXException
OpenTMSException

subSegmentTranslate

public void subSegmentTranslate(DataSource dataSource,
                                java.lang.String sourceLanguage,
                                java.lang.String targetLanguage,
                                java.util.Hashtable<java.lang.String,java.lang.Object> translationParameters)
                         throws OpenTMSException
translate translates an xliff document based on the source and target language provided

Parameters:
dataSource - the data source to use
sourceLanguage - the source language to use
targetLanguage - the target language to use
matchSimilarity - the similarity (fuzzy) match quality (0 - 100) to use
iMaxThreads - the maximum number of threads to use / -1 = use as many threads as processors available; 0 = do not create a thread (run in main process); 1 run in main process; > 1 run dividing trans-units to translate in several threads; maximum is the number of processors; if number of trans-units less that processors use processor = 1
translationParameters - the translation parameters to use; some paramaters supported (written to the phasegroup):
tool = (String) translationParameters.get("tool"); (for this the version is tried to determined by using de.folt.constants.OpenTMSVersionConstants .getVersionString(tool)
jobId = (String) translationParameters.get("jobId");
contactName = (String) translationParameters.get("contactName");
contactEmail = (String) translationParameters.get("contactEmail");
contactPhone = (String) translationParameters.get("contactPhone");
Throws:
OpenTMSXException
OpenTMSException

subSegmentTranslate

public void subSegmentTranslate(java.lang.String dataSourceName,
                                java.lang.String sourceLanguage,
                                java.lang.String targetLanguage)
                         throws OpenTMSException
subSegmentTranslate translates an xliff document based on the source and target language provided; the translation parameters are set to null.

Parameters:
dataSourceName - the name of data source to use
sourceLanguage - the source language to use
targetLanguage - the target language to use
Throws:
OpenTMSXException
OpenTMSException

translate

public void translate(DataSource dataSource,
                      org.jdom.Element file,
                      java.util.List<org.jdom.Element> transunits,
                      java.lang.String sourceLanguage,
                      java.lang.String targetLanguage,
                      int matchSimilarity,
                      java.util.Hashtable<java.lang.String,java.lang.Object> translationParameters)
               throws OpenTMSException
translate translates an xliff document based on the source and target language provided. The method also informs the observers about the translation progress. A vector is supplied where the first element contains the number of trans-units overall to translate and the second element contains the actual translated trans-unit number. (0..trans-unit size - 1). If the trans-unit contains the attribute translate="no" the trans-unit no search is applied. Per default a 100% match is copied to the target (if it is empty). This can be avoided by specifying in the hash table translationParameters "Copy100ToTarget" >> "no". Copy is only done when there is only one 100% match and only one target in this match.

Parameters:
dataSource - the data source to use
file -
transunits - the trans-units to translate
sourceLanguage - the source language to use
targetLanguage - the target language to use
matchSimilarity - the similarity (fuzzy) match quality (0 - 100) to use
translationParameters - a hashtable with additional translation paramters; usage is up to the implementation
Throws:
OpenTMSXException
OpenTMSException

translate

public void translate(DataSource dataSource,
                      java.lang.String sourceLanguage,
                      java.lang.String targetLanguage,
                      int matchSimilarity,
                      int iMaxThreads,
                      java.util.Hashtable<java.lang.String,java.lang.Object> translationParameters)
               throws OpenTMSException
translate translates an xliff document based on the source and target language provided

Parameters:
dataSource - the data source to use
sourceLanguage - the source language to use
targetLanguage - the target language to use
matchSimilarity - the similarity (fuzzy) match quality (0 - 100) to use
iMaxThreads - the maximum number of threads to use / -1 = use as many threads as processors available; 0 = do not create a thread (run in main process); 1 run in main process; > 1 run dividing trans-units to translate in several threads; maximum is the number of processors; if number of trans-units less that processors use processor = 1
translationParameters - the translation parameters to use; some paramaters supported (written to the phasegroup):
tool = (String) translationParameters.get("tool"); (for this the version is tried to determined by using de.folt.constants.OpenTMSVersionConstants .getVersionString(tool)
jobId = (String) translationParameters.get("jobId");
contactName = (String) translationParameters.get("contactName");
contactEmail = (String) translationParameters.get("contactEmail");
contactPhone = (String) translationParameters.get("contactPhone");
Throws:
OpenTMSXException
OpenTMSException

translate

public void translate(java.lang.String dataSourceName,
                      java.lang.String sourceLanguage,
                      java.lang.String targetLanguage,
                      int matchSimilarity,
                      int iMaxThreads)
               throws OpenTMSException
translate translates an xliff document based on the source and target language provided;; the translation parameters are set to null.

Parameters:
dataSourceName - the name of data source to use
sourceLanguage - the source language to use
targetLanguage - the target language to use
matchSimilarity - the similarity (fuzzy) match quality (0 - 100) to use
iMaxThreads - the maximum nuber of threads (processors) to use for translation
Throws:
OpenTMSXException
OpenTMSException

transUnitToMultiLingualObject

public MultiLingualObject transUnitToMultiLingualObject(org.jdom.Element element)
transUnitToMultiLingualObject creates a MUL from source and target of a trans-unit if approved

Parameters:
element - the transunit
Returns:
a MUL object or null if not approved or source or target do not exist

transUnitToMultiLingualObject

public MultiLingualObject transUnitToMultiLingualObject(org.jdom.Element element,
                                                        boolean bLoadAllTargets)
transUnitToMultiLingualObject creates a MUL from source and target of a trans-unit if approved

Parameters:
element - the transunit
bLoadAllTargets - if true loads all target translation irrespectively if approved or not
Returns:
a MUL object or null if not approved or source or target do not exist