com.g11ntoolkit.strfile
Class StrFile

java.lang.Object
  |
  +--com.g11ntoolkit.strfile.StrFile
Direct Known Subclasses:
JSStrFile

public class StrFile
extends java.lang.Object

Creates and maintains a string file with its associated buffer and hashtable.

The string file is the file that contains the association between token ids and the strings they represent. It is an intermediate file used by the L10N Leveraging tools. The file is written in XLIFF format and follows the conventions of XLIFF 1.1.

Version:
2005/07/12
Author:
Bill Rich, Wilandra Consulting LLC
Copyright © 2001-2005, Wilandra Consulting LLC. All rights reserved.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

See License Agreement.


Field Summary
protected  java.lang.String contextFileName
          The Context File for the strings that were extracted.
protected  java.lang.String datatype
          The data type of the source file.
protected  java.util.Hashtable elementTable
          A collection of the associations between the tokens and the context element ids.
private static java.util.logging.Logger log
          The log used for all messages from this class.
protected static java.util.ResourceBundle mrb
          Message Resource Bundle.
protected  java.lang.String productName
          The Product Name.
protected  java.lang.String productVersion
          The Product Version.
protected  java.lang.String sourceFileName
          The Source File from which the strings were extracted.
protected  java.util.Hashtable stringTable
          A collection of strings and their associated tokens.
protected  java.util.Locale targetLocale
          The target locale.
protected  java.lang.StringBuffer theBuffer
          A collection of all the file level data from the specified input file.
protected  java.util.Locale thisLocale
          The locale.
protected  TokFile tokFile
          The TokFile that contains the skeleton of the source file.
protected static java.util.ResourceBundle vrb
          Constants and variables used by the tools and classes.
protected static java.util.ResourceBundle xliffrb
          Constants, messages, and variables used by the tools and classes for XLIFF processing.
protected static java.util.ResourceBundle xrb
          Constants, messages, and variables used by the tools and classes for XML processing.
 
Constructor Summary
StrFile()
          Creates an empty buffer and an empty hashtable and sets the log to the default output stream.
 
Method Summary
 void append(java.lang.String aString)
          Adds the specified string to the end of the buffer.
 void append(Token aToken, XLEntry aString)
          Adds the specified token and string translation entry to the hashtable.
protected static java.lang.String convertToFileURL(java.lang.String filename)
          Returns the filename converted to a file URL.
 void copyOf(StrFile anotherStrFile)
          Creates a copy of the contents of another StrFile object in this object.
 void debugDump()
          Dumps the contents of the object to the console for debugging.
 void debugDump(java.lang.String what)
          Dumps the contents of the object to the console for debugging.
 boolean findString(XLEntry aString)
          Returns true if the specified string translation entry is in the file.
 boolean findToken(Token aToken)
          Returns true if the specified token is in the file.
 java.lang.StringBuffer getBuffer()
          Returns the buffer.
 java.lang.String getContextFileName()
          Returns the Context File Name.
 java.lang.String getDatatype()
          Returns the data type of the source file.
 java.util.Hashtable getElementTable()
          Returns the element table.
 java.util.Locale getLocale()
          Returns the locale.
 java.lang.String getProductName()
          Returns the Product Name.
 java.lang.String getProductVersion()
          Returns the Product Version.
 java.lang.String getSourceFileName()
          Returns the Source File Name.
 XLEntry getString(java.lang.String anElementId)
          Returns the string translation entry that has the specified element id in its context.
 XLEntry getString(Token aToken)
          Returns the string translation entry for the specified token.
 java.util.Hashtable getStringTable()
          Returns the string table.
 java.util.Locale getTargetLocale()
          Returns the target locale.
 TokFile getTokFile()
          Returns the TokFile.
 java.lang.String getXLIFFLocaleString()
          Returns the locale string suitable for use in an XLIFF file.
 java.util.Enumeration keys()
          Returns an enumeration of the keys (Tokens) for all the strings in the file.
 void loadXLIFF(java.lang.String xf, TokFile tf)
          Loads the StrFile and TokFile objects with the records read from the specified XLIFF file.
 void setContextFileName(java.lang.String cf)
          Sets the Context File Name.
 void setDatatype(java.lang.String dt)
          Sets the data type of the source file.
 void setLocale(java.util.Locale aLocale)
          Set the locale for this object to the specified Locale object.
 void setProductName(java.lang.String pn)
          Sets the Product Name.
 void setProductVersion(java.lang.String pv)
          Sets the Product Version.
 void setSourceFileName(java.lang.String sf)
          Sets the Source File Name.
 void setTargetLocale(java.util.Locale tloc)
          Set the target locale for this object to the specified Locale object.
 void setTokFile(TokFile tf)
          Sets the TokFile.
 void writeXLIFF(java.io.OutputStreamWriter osWriter, boolean writeBOM, boolean sourceonly)
          Writes the string file out to the specified output stream writer in XLIFF form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static java.util.logging.Logger log
The log used for all messages from this class.


mrb

protected static java.util.ResourceBundle mrb
Message Resource Bundle.


vrb

protected static java.util.ResourceBundle vrb
Constants and variables used by the tools and classes.


xrb

protected static java.util.ResourceBundle xrb
Constants, messages, and variables used by the tools and classes for XML processing.


xliffrb

protected static java.util.ResourceBundle xliffrb
Constants, messages, and variables used by the tools and classes for XLIFF processing.


stringTable

protected java.util.Hashtable stringTable
A collection of strings and their associated tokens.

The key to the table is the token and the value is a translation entry for the string. The string can have comments which will be preserved in the string entry.

See Also:
Token, XLEntry

theBuffer

protected java.lang.StringBuffer theBuffer
A collection of all the file level data from the specified input file.

This is only the stuff that comes before the first token id in the file. It is usually just comments.


elementTable

protected java.util.Hashtable elementTable
A collection of the associations between the tokens and the context element ids.

The key to the table is the token and the value is a string for the element id in the TokContext object.

See Also:
Token, TokContext

thisLocale

protected java.util.Locale thisLocale
The locale. It is needed for writeXML().


tokFile

protected TokFile tokFile
The TokFile that contains the skeleton of the source file.

This is needed for the XLIFF file format.


sourceFileName

protected java.lang.String sourceFileName
The Source File from which the strings were extracted.

This is needed for the XLIFF file format.


contextFileName

protected java.lang.String contextFileName
The Context File for the strings that were extracted.

This is needed for the XLIFF file format.


targetLocale

protected java.util.Locale targetLocale
The target locale.

This is needed for the XLIFF file format.


productName

protected java.lang.String productName
The Product Name.

This is needed for the XLIFF file format.


productVersion

protected java.lang.String productVersion
The Product Version.

This is needed for the XLIFF file format.


datatype

protected java.lang.String datatype
The data type of the source file.

This is needed for the XLIFF file format. The value must be one of the values specified in the xliff.datatype section of the xliffres.java file.

See Also:
xliffres
Constructor Detail

StrFile

public StrFile()
Creates an empty buffer and an empty hashtable and sets the log to the default output stream.

This may be handy if the buffer is going to be used to create a new string file.

Method Detail

copyOf

public void copyOf(StrFile anotherStrFile)
Creates a copy of the contents of another StrFile object in this object.

Parameters:
anotherStrFile - a StrFile specifying the StrFile object to copy

getBuffer

public java.lang.StringBuffer getBuffer()
Returns the buffer.

Returns:
a StringBuffer representing the buffer in this object or null if no buffer exists

getStringTable

public java.util.Hashtable getStringTable()
Returns the string table.

Returns:
a Hashtable representing the string table in this object or null if no strings exist

getElementTable

public java.util.Hashtable getElementTable()
Returns the element table.

Returns:
a Hashtable representing the element table in this object or null if no elements exist

setLocale

public void setLocale(java.util.Locale aLocale)
Set the locale for this object to the specified Locale object.

Parameters:
aLocale - a Locale specifying the locale for this object
See Also:
getLocale()

getLocale

public java.util.Locale getLocale()
Returns the locale.

Returns:
a Locale representing the locale in this object or null if no locale is set
See Also:
setLocale(java.util.Locale)

getXLIFFLocaleString

public java.lang.String getXLIFFLocaleString()
Returns the locale string suitable for use in an XLIFF file.

Returns:
a String representing the locale in this object or null if no locale is set

loadXLIFF

public void loadXLIFF(java.lang.String xf,
                      TokFile tf)
               throws StrFileError
Loads the StrFile and TokFile objects with the records read from the specified XLIFF file.

Parameters:
xf - a String specifying the name of the XLIFF file
tf - a TokFile specifying the TokFile fill in
Throws:
StrFileError - if there is an error when processing the file

setDatatype

public void setDatatype(java.lang.String dt)
Sets the data type of the source file.

Parameters:
dt - a String specifying the data type of the source file
See Also:
getDatatype(), datatype

getDatatype

public java.lang.String getDatatype()
Returns the data type of the source file.

Returns:
a String representing the data type of the source file
See Also:
setDatatype(java.lang.String), datatype

setProductVersion

public void setProductVersion(java.lang.String pv)
Sets the Product Version.

Parameters:
pv - a String specifying the version of the product
See Also:
getProductVersion()

getProductVersion

public java.lang.String getProductVersion()
Returns the Product Version.

Returns:
a String representing the version of the product
See Also:
setProductVersion(java.lang.String)

setProductName

public void setProductName(java.lang.String pn)
Sets the Product Name.

Parameters:
pn - a String specifying the name of the product
See Also:
getProductName()

getProductName

public java.lang.String getProductName()
Returns the Product Name.

Returns:
a String representing the name of the product
See Also:
setProductName(java.lang.String)

setTargetLocale

public void setTargetLocale(java.util.Locale tloc)
Set the target locale for this object to the specified Locale object.

Parameters:
tloc - a Locale specifying the target locale for this object
See Also:
getTargetLocale()

getTargetLocale

public java.util.Locale getTargetLocale()
Returns the target locale.

Returns:
a Locale representing the target locale in this object or null if no target locale is set
See Also:
setLocale(java.util.Locale)

setSourceFileName

public void setSourceFileName(java.lang.String sf)
Sets the Source File Name.

Parameters:
sf - a String specifying the name of the source file from which the strings were extracted
See Also:
getSourceFileName()

getSourceFileName

public java.lang.String getSourceFileName()
Returns the Source File Name.

Returns:
a String representing the name of the source file from which the strings were extracted
See Also:
setSourceFileName(java.lang.String)

setContextFileName

public void setContextFileName(java.lang.String cf)
Sets the Context File Name.

Parameters:
cf - a String specifying the name of the source file from which the strings were extracted
See Also:
getContextFileName()

getContextFileName

public java.lang.String getContextFileName()
Returns the Context File Name.

Returns:
a String representing the name of the source file from which the strings were extracted
See Also:
setContextFileName(java.lang.String)

setTokFile

public void setTokFile(TokFile tf)
Sets the TokFile.

Parameters:
tf - a TokFile specifying the TokFile object that contains the source file skeleton
See Also:
getTokFile()

getTokFile

public TokFile getTokFile()
Returns the TokFile.

Returns:
a TokFile representing the TokFile object that contains the source file skeleton
See Also:
setTokFile(com.g11ntoolkit.tokfile.TokFile)

writeXLIFF

public void writeXLIFF(java.io.OutputStreamWriter osWriter,
                       boolean writeBOM,
                       boolean sourceonly)
                throws EmptyStrFile,
                       java.io.IOException
Writes the string file out to the specified output stream writer in XLIFF form.

Parameters:
osWriter - an OutputStreamWriter object
writeBOM - a boolean indicating whether to write a Byte Order Mark (true) or not (false)
sourceonly - a boolean indicating whether to write a source only file (true) or a source and target file (false)
Throws:
EmptyStrFile - if there is nothing to write out
java.io.IOException - if any error is detected for the output writer

keys

public java.util.Enumeration keys()
Returns an enumeration of the keys (Tokens) for all the strings in the file.

Returns:
an Enumeration object containing the tokens

getString

public XLEntry getString(Token aToken)
Returns the string translation entry for the specified token.

Parameters:
aToken - a Token object specifying the key of the desired entry
Returns:
a XLEntry object containing the desired entry or null if the entry does not exist

findToken

public boolean findToken(Token aToken)
Returns true if the specified token is in the file.

Parameters:
aToken - a Token object containing the desired token
Returns:
true if the token is found in this object

findString

public boolean findString(XLEntry aString)
Returns true if the specified string translation entry is in the file.

Parameters:
aString - a XLEntry object containing the desired string
Returns:
true if the translation entry is found in this object

getString

public XLEntry getString(java.lang.String anElementId)
Returns the string translation entry that has the specified element id in its context.

Parameters:
anElementId - a String
Returns:
an XLEntry object

append

public void append(Token aToken,
                   XLEntry aString)
Adds the specified token and string translation entry to the hashtable.

Parameters:
aToken - a Token object
aString - a XLEntry object

append

public void append(java.lang.String aString)
Adds the specified string to the end of the buffer.

This becomes a file level comment. If write is called, this string, as well as all the other file level comments, will be written out before the actual token/string entries. It is assumed that the string is a properly formatted comment record. No checking is done.

Parameters:
aString - a String specifying the string to append to the object

debugDump

public void debugDump()
Dumps the contents of the object to the console for debugging.

This version of the method assumes that you want all of the contents.


debugDump

public void debugDump(java.lang.String what)
Dumps the contents of the object to the console for debugging.

You can control what gets dumped by specifying a parameter. The parameter can be ALL, BUFFER, or STRINGS. The parameter must be specified in all uppercase characters.

Parameters:
what - a String specifying what to dump

convertToFileURL

protected static java.lang.String convertToFileURL(java.lang.String filename)
Returns the filename converted to a file URL.

Parameters:
filename - a String containing the file name to be converted
Returns:
String containing the converted file name