file2xliff4j
Class TuStrings

java.lang.Object
  extended by file2xliff4j.TuStrings

public class TuStrings
extends java.lang.Object

This class encapsulates the target strings that an XLIFF file contains for a specified language. (Note: It might be later enhanced to be able to hold the source strings rather than a target string.)

Author:
Weldon Whipple <weldon@lingotek.com>

Constructor Summary
TuStrings()
          Creates a new instance of TuStrings
 
Method Summary
static java.lang.String escapeTuString(java.lang.String in)
          Escape string to store safely as valid XML
 java.lang.String getTu(java.lang.String id)
          Passed a trans-unit identifier, return the target string associated with it.
 java.lang.String getTu(java.lang.String id, java.lang.String datatype)
          Passed a trans-unit identifier, return the target string associated with it.
 java.lang.String getTu(java.lang.String id, java.lang.String datatype, boolean followNextAttr)
          Passed a trans-unit identifier, return the target string associated with it.
 java.lang.String getTu(java.lang.String id, java.lang.String datatype, boolean followNextAttr, boolean validate)
          Passed a trans-unit identifier, return the target string associated with it.
 void loadStrings(java.lang.String xliffFile, java.util.Locale lang, java.lang.String phaseName, int maxPhase, boolean ampEntities)
          Passed the name of an XLIFF file and a target Locale, read the strings for the specified locale from the file and place them in a HashMap for later access.
static java.lang.String unEscapeTuString(java.lang.String in)
          Un-do the escaping performed by escapeTuString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TuStrings

public TuStrings()
Creates a new instance of TuStrings

Method Detail

getTu

public java.lang.String getTu(java.lang.String id)
Passed a trans-unit identifier, return the target string associated with it.

Parameters:
id - The trans-unit identifier
Returns:
The string associated with the identifier

getTu

public java.lang.String getTu(java.lang.String id,
                              java.lang.String datatype)
Passed a trans-unit identifier, return the target string associated with it.

Parameters:
id - The trans-unit identifier
datatype - The datatype of the native file from which the XLIFF was created
Returns:
The string associated with the identifier

getTu

public java.lang.String getTu(java.lang.String id,
                              java.lang.String datatype,
                              boolean followNextAttr)
Passed a trans-unit identifier, return the target string associated with it.

Parameters:
id - The trans-unit identifier
datatype - The datatype of the native file from which the XLIFF was created
followNextAttr - Boolean value indicating whether to follow the lt:next-tu-id attribute (referring to a "chain" of adjacent sentence segments). If set to true, the return string will include multiple TUs concatenated together.
Returns:
The string associated with the identifier

getTu

public java.lang.String getTu(java.lang.String id,
                              java.lang.String datatype,
                              boolean followNextAttr,
                              boolean validate)
Passed a trans-unit identifier, return the target string associated with it.

Parameters:
id - The trans-unit identifier
datatype - The datatype of the native file from which the XLIFF was created
followNextAttr - Boolean value indicating whether to follow the lt:next-tu-id attribute (referring to a "chain" of adjacent sentence segments). If set to true, the return string will include multiple TUs concatenated together.
validate - If true: in the process of retrieving the target, validate (and repair if appropriate) the core text of the target. If false: don't validate (and repair).
Returns:
The string associated with the identifier

loadStrings

public void loadStrings(java.lang.String xliffFile,
                        java.util.Locale lang,
                        java.lang.String phaseName,
                        int maxPhase,
                        boolean ampEntities)
                 throws ConversionException
Passed the name of an XLIFF file and a target Locale, read the strings for the specified locale from the file and place them in a HashMap for later access.

Parameters:
xliffFile - Fully-qualified name of the xliff file
lang - The language whose strings we're interested in.
phaseName - The phase-name of the targets we are requesting. If your XLIFF doesn't use targets, specify null, and loadStrings will use the first target it finds for each target language.

If phaseName if formatted like an integer greater than 1 and a matching phase is not found, loadStrings will search recursively for a matching target, decrementing the phase "number" until phase "1" has been reached.

maxPhase - If phaseName is specified as "0" and maxPhase is a non-negative integer, search for the highest "numbered" phase, starting at maxPhase, and searching down to phase "1".
ampEntities - If true, convert all bare ampersands (in error messages for "not yet translated" segments) to the amp entity.
Throws:
ConversionException - If unable to load the XLIFF file

escapeTuString

public static java.lang.String escapeTuString(java.lang.String in)
Escape string to store safely as valid XML

Parameters:
in - String to be escaped.
Returns:
The string appropriately escaped

unEscapeTuString

public static java.lang.String unEscapeTuString(java.lang.String in)
Un-do the escaping performed by escapeTuString

Parameters:
in - String to be unescaped.
Returns:
The string appropriately unescaped