de.folt.models.datamodel.tmxfile
Class TmxFileDataSource

java.lang.Object
  extended by java.util.Observable
      extended by de.folt.models.datamodel.BasicDataSource
          extended by de.folt.models.datamodel.tmxfile.TmxFileDataSource
All Implemented Interfaces:
DataSource, java.util.Enumeration<MultiLingualObject>, java.util.Observer

public class TmxFileDataSource
extends BasicDataSource

This class implements a data source based on a TMX file.

Author:
klemens

Nested Class Summary
 
Nested classes/interfaces inherited from class de.folt.models.datamodel.BasicDataSource
BasicDataSource.BasicDataSourceObserver
 
Constructor Summary
TmxFileDataSource()
           
TmxFileDataSource(DataSourceProperties dataModelProperties)
           
 
Method Summary
 boolean addMultiLingualObject(MultiLingualObject multiLingualObject, boolean mergeObjects)
          addMultiLingualObject adds a MultiLingualObject to the data source
 boolean bPersist()
          bPersist method persists any data in the data source
 void cleanDataSource()
          cleanDataSource method is used to allow some clean operations e.g. after an instance has been loaded.
 boolean clearDataSource()
          clearDataSource removes the content in a data source.
 boolean createDataSource(DataSourceProperties dataModelProperties)
          createDataSource creates a new Data source; this is esp. intended for creating a new database, e.g. in MySQL or Ms SQL Server.
 boolean deleteDataSource(DataSourceProperties dataModelProperties)
          deleteDataSource deletes an existing Data source; this is esp. intended for deleting a database, e.g. in MySQL or Ms SQL Server.
 int exportTmxFile(java.lang.String tmxFile)
          exportTmxFile exports the data source into an tmx file
 int exportXliffFile(java.lang.String xliffFile)
          exportXliffFile export the xliff file from the data source;
 java.lang.String getDataSourceType()
          getDataSourceType get the type of the database
 MonoLingualPartitionedFuzzyNodeTree getFuzzyTree()
          returns the basic fuzzy tree
 MultiLingualObject getMultiLingualObjectFromUniqueId(java.lang.String id)
          getMultiLingualObjectFromUniqueId search an MUL based on its unique id
 java.util.Vector<java.lang.String> getUniqueIds()
          getUniqueIds this method returns a vector of strings which uniquely identify each MUL of the data source
 boolean hasMoreElements()
           
 void initEnumeration()
          initEnumeration initialises the Enumeration of the data source
static void main(java.lang.String[] args)
          main
 MultiLingualObject nextElement()
           
 void removeDataSource()
          removeDataSource method called when the DataSource should be removed
 boolean removeMonoLingualObject(MonoLingualObject monoLingualObject)
          removeMonoLingualObject removes a MonoLingualObject from the data source; not all data source may support this method and may return false in any case (e.g.
 boolean removeMultiLingualObject(MultiLingualObject multiLingualObject)
          removeMultiLingualObject removes a MultiLingualObject from the data source
 boolean saveModifiedMonoLingualObject(MonoLingualObject monoLingualObject)
          saveModifiedMonoLingualObject save a given MonoLingualObject in the data source by replacing the old values.
 boolean saveModifiedMultiLingualObject(MultiLingualObject multiLingualObject)
          saveModifiedMultiLingualObject saves any modification of the MultiLingualObject, esp. doen to the LinguisticProperties
 void setDataSourceType()
          setDataSourceType sets the type of the data source
static void test(java.lang.String[] args)
          test simple test method for generating DataModelInstances
 org.jdom.Element translate(org.jdom.Element transUnit, org.jdom.Element file, XliffDocument xliffDocument, java.lang.String sourceLanguage, java.lang.String targetLanguage, int matchSimilarity, java.util.Hashtable<java.lang.String,java.lang.Object> translationParameters)
          translate translates a trans-unit given the source language, target Language and match similarity
 
Methods inherited from class de.folt.models.datamodel.BasicDataSource
addData, addMonoLingualObject, bAuthenticate, bSupportMultiThreading, changedMonolingualObjects, checkIfTranslationExistsInDataSource, checkIfTranslationExistsInDataSource, containsKey, containsValue, copyFrom, copyTo, currentTimeMillis, getAllAttributes, getChangedIds, getData, getDataSourceName, getDataSourceProperties, getDefaultDataSourceConfigurationsFileName, getIds, getILogLevel, getLastErrorCode, getMonoLingualObjectFromId, getMonoLingualObjectFromUniqueId, getMultiLingualObjectCache, getMultiLingualObjectFromId, importTbxFile, importTmxFile, importXliffFile, isBChanged, isBLoadAttributesLazy, isSyncDataSource, removeData, runFilterMethod, search, searchRegExp, searchWordBased, setBChanged, setBLoadAttributesLazy, setDefaultDataSourceConfigurationsFileName, setILogLevel, setILogLevel, setLastErrorCode, setMultiLingualObjectCache, setOpenTMSPropertiesFile, subSegmentResultsToGlossary, subSegmentTranslate, update, update
 
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

TmxFileDataSource

public TmxFileDataSource()

TmxFileDataSource

public TmxFileDataSource(DataSourceProperties dataModelProperties)
Parameters:
dataModelProperties - the data model parameters
Main Key: dataModelProperties.getDataSourceProperty("tmxfile"); - the tmx file to use (alternatively "tmxFile" or "dataSourceName" can be used too)
Method Detail

main

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

Parameters:
args -
-test - run some test functions
-create create a tmx data source; creates a data source tmx file if it does not exist
-delete deletes a tmx data source; delete the data source tmx file

test

public static void test(java.lang.String[] args)
test simple test method for generating DataModelInstances


addMultiLingualObject

public boolean addMultiLingualObject(MultiLingualObject multiLingualObject,
                                     boolean mergeObjects)
Description copied from interface: DataSource
addMultiLingualObject adds a MultiLingualObject to the data source

Specified by:
addMultiLingualObject in interface DataSource
Overrides:
addMultiLingualObject in class BasicDataSource
Parameters:
multiLingualObject - the object to add
mergeObjects - if true first a search is done if the containing MonoLingualObjects exist in the data source (based on the segment text); if they exist they are merged; if false the MUL is added as new entry
Returns:
true if added; false if not

bPersist

public boolean bPersist()
Description copied from interface: DataSource
bPersist method persists any data in the data source

Specified by:
bPersist in interface DataSource
Overrides:
bPersist in class BasicDataSource
Returns:
true in case of success or false otherwise

cleanDataSource

public void cleanDataSource()
Description copied from interface: DataSource
cleanDataSource method is used to allow some clean operations e.g. after an instance has been loaded.
An example is disposing a tmx document after having read all the entries.

Specified by:
cleanDataSource in interface DataSource
Overrides:
cleanDataSource in class BasicDataSource

clearDataSource

public boolean clearDataSource()
                        throws OpenTMSException
Description copied from interface: DataSource
clearDataSource removes the content in a data source. In addition it can be used to delete a TMX data source.

Specified by:
clearDataSource in interface DataSource
Overrides:
clearDataSource in class BasicDataSource
Returns:
true if success
Throws:
OpenTMSException

createDataSource

public boolean createDataSource(DataSourceProperties dataModelProperties)
                         throws OpenTMSException
Description copied from interface: DataSource
createDataSource creates a new Data source; this is esp. intended for creating a new database, e.g. in MySQL or Ms SQL Server. In addition it can be used to create a new empty TMX data source.

Specified by:
createDataSource in interface DataSource
Overrides:
createDataSource in class BasicDataSource
Parameters:
dataModelProperties - the parameters of the data source
Returns:
true if success
Throws:
OpenTMSException

deleteDataSource

public boolean deleteDataSource(DataSourceProperties dataModelProperties)
                         throws OpenTMSException
Description copied from interface: DataSource
deleteDataSource deletes an existing Data source; this is esp. intended for deleting a database, e.g. in MySQL or Ms SQL Server. In addition it can be used to delete a TMX data source.
Currently supported key values are:
tmxfile, tmxFile, dataSourceName, dataSource, xlifffile, xliffFile - specifies names of the data sources
sourceLanguage if an xliff File datasource is created default = de
targetLanguage if an xliff File datasource is created default = en

Specified by:
deleteDataSource in interface DataSource
Overrides:
deleteDataSource in class BasicDataSource
Parameters:
dataModelProperties - the parameters of the data source
Returns:
true if success
Throws:
OpenTMSException

exportTmxFile

public int exportTmxFile(java.lang.String tmxFile)
Description copied from interface: DataSource
exportTmxFile exports the data source into an tmx file

Specified by:
exportTmxFile in interface DataSource
Overrides:
exportTmxFile in class BasicDataSource
Parameters:
tmxFile - the tmx file to export to
Returns:
the number of entries exported

exportXliffFile

public int exportXliffFile(java.lang.String xliffFile)
Description copied from interface: DataSource
exportXliffFile export the xliff file from the data source;

Specified by:
exportXliffFile in interface DataSource
Overrides:
exportXliffFile in class BasicDataSource
Parameters:
xliffFile - the xliff file to export
Returns:
the number of entries exported

getDataSourceType

public java.lang.String getDataSourceType()
Description copied from interface: DataSource
getDataSourceType get the type of the database

Specified by:
getDataSourceType in interface DataSource
Overrides:
getDataSourceType in class BasicDataSource
Returns:
the data source type

getFuzzyTree

public MonoLingualPartitionedFuzzyNodeTree getFuzzyTree()
returns the basic fuzzy tree

Overrides:
getFuzzyTree in class BasicDataSource
Returns:
the fuzzyTree

getMultiLingualObjectFromUniqueId

public MultiLingualObject getMultiLingualObjectFromUniqueId(java.lang.String id)
Description copied from interface: DataSource
getMultiLingualObjectFromUniqueId search an MUL based on its unique id

Specified by:
getMultiLingualObjectFromUniqueId in interface DataSource
Overrides:
getMultiLingualObjectFromUniqueId in class BasicDataSource
Parameters:
id - the id to search (as String)
Returns:
the MUL found or null otherwise

getUniqueIds

public java.util.Vector<java.lang.String> getUniqueIds()
Description copied from interface: DataSource
getUniqueIds this method returns a vector of strings which uniquely identify each MUL of the data source

Specified by:
getUniqueIds in interface DataSource
Overrides:
getUniqueIds in class BasicDataSource
Returns:

hasMoreElements

public boolean hasMoreElements()
Specified by:
hasMoreElements in interface java.util.Enumeration<MultiLingualObject>
Overrides:
hasMoreElements in class BasicDataSource

initEnumeration

public void initEnumeration()
Description copied from interface: DataSource
initEnumeration initialises the Enumeration of the data source

Specified by:
initEnumeration in interface DataSource
Overrides:
initEnumeration in class BasicDataSource

nextElement

public MultiLingualObject nextElement()
Specified by:
nextElement in interface java.util.Enumeration<MultiLingualObject>
Overrides:
nextElement in class BasicDataSource

removeDataSource

public void removeDataSource()
Description copied from interface: DataSource
removeDataSource method called when the DataSource should be removed

Specified by:
removeDataSource in interface DataSource
Overrides:
removeDataSource in class BasicDataSource

removeMonoLingualObject

public boolean removeMonoLingualObject(MonoLingualObject monoLingualObject)
Description copied from interface: DataSource
removeMonoLingualObject removes a MonoLingualObject from the data source; not all data source may support this method and may return false in any case (e.g. XliffDataSource)

Specified by:
removeMonoLingualObject in interface DataSource
Overrides:
removeMonoLingualObject in class BasicDataSource
Parameters:
monoLingualObject - the MUL to remove
Returns:
true if removed; false if not

removeMultiLingualObject

public boolean removeMultiLingualObject(MultiLingualObject multiLingualObject)
Description copied from interface: DataSource
removeMultiLingualObject removes a MultiLingualObject from the data source

Specified by:
removeMultiLingualObject in interface DataSource
Overrides:
removeMultiLingualObject in class BasicDataSource
Parameters:
multiLingualObject - the MOL to remove
Returns:
true if removed; false if not

saveModifiedMonoLingualObject

public boolean saveModifiedMonoLingualObject(MonoLingualObject monoLingualObject)
Description copied from interface: DataSource
saveModifiedMonoLingualObject save a given MonoLingualObject in the data source by replacing the old values. It is now allowed to change the uniquei and the id of the MOL.

Specified by:
saveModifiedMonoLingualObject in interface DataSource
Overrides:
saveModifiedMonoLingualObject in class BasicDataSource
Parameters:
monoLingualObject - the mono lingual object to save return true for success, false otherwise

saveModifiedMultiLingualObject

public boolean saveModifiedMultiLingualObject(MultiLingualObject multiLingualObject)
Description copied from interface: DataSource
saveModifiedMultiLingualObject saves any modification of the MultiLingualObject, esp. doen to the LinguisticProperties

Specified by:
saveModifiedMultiLingualObject in interface DataSource
Overrides:
saveModifiedMultiLingualObject in class BasicDataSource
Parameters:
multiLingualObject - the MultiLingualObject
Returns:
true if success

setDataSourceType

public void setDataSourceType()
Description copied from interface: DataSource
setDataSourceType sets the type of the data source

Specified by:
setDataSourceType in interface DataSource
Overrides:
setDataSourceType in class BasicDataSource

translate

public org.jdom.Element translate(org.jdom.Element transUnit,
                                  org.jdom.Element file,
                                  XliffDocument xliffDocument,
                                  java.lang.String sourceLanguage,
                                  java.lang.String targetLanguage,
                                  int matchSimilarity,
                                  java.util.Hashtable<java.lang.String,java.lang.Object> translationParameters)
                           throws OpenTMSException
Description copied from interface: DataSource
translate translates a trans-unit given the source language, target Language and match similarity

Specified by:
translate in interface DataSource
Overrides:
translate in class BasicDataSource
Parameters:
transUnit - the trans unit to translate to use
file - the file element currently to translate
xliffDocument - the basic xliff document
sourceLanguage - the source language to use
targetLanguage - the target language to use
matchSimilarity - the similarity (fuzzy) match quality (0 - 100) to use
translationParameters - the hash table contains parameters which control some parameters, e.g. should header/source/target properties be written to alt-trans
Returns:
the modified trans-unit with new translation
Throws:
OpenTMSException