com.g11ntoolkit.strfile
Class JSStrFile

java.lang.Object
  |
  +--com.g11ntoolkit.strfile.StrFile
        |
        +--com.g11ntoolkit.strfile.JSStrFile

public class JSStrFile
extends StrFile

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

This class extends the StrFile class because there are some speicial tags used in the StrFile for extracted JavaScript code.

Version:
2005/07/11
Author:
Tomi Fujinaga, webMethods, Inc.
Copyright © 2003, webMethods, Inc. All rights reserved.
, Bill Rich, Wilandra Consulting LLC
Copyright © 2003-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
private  java.lang.String inputFileName
          The name of the input file.
private static java.util.logging.Logger log
          The log used for all messages from this class.
 
Fields inherited from class com.g11ntoolkit.strfile.StrFile
contextFileName, datatype, elementTable, mrb, productName, productVersion, sourceFileName, stringTable, targetLocale, theBuffer, thisLocale, tokFile, vrb, xliffrb, xrb
 
Constructor Summary
JSStrFile()
          Creates and an empty hashtable.
JSStrFile(java.util.Locale aLocale)
          Creates an empty hashtable.
 
Method Summary
 void append(Token aToken, JSXLEntry aBlock)
          Adds the specified token and string translation entry to the hashtable.
 void copyOf(JSStrFile anotherJSStrFile)
          Creates a copy of the contents of another JSStrFile object in this object.
 void debugDump(java.lang.String what)
          Dumps the contents of the object to the console for debugging.
 boolean findBlock(JSXLEntry aBlock)
          Returns true if the specified string translation entry is in the file.
 java.lang.String getFileName()
          Returns the name of the input file.
 JSXLEntry getJSString(Token aToken)
          Returns the string translation entry for the specified token.
 boolean hasEntries()
          Returns boolean.
 void load(java.util.Locale locale, java.lang.String xmlFileName)
          Loads the string buffer and the hashtable with the records read from either the specified input stream reader or the specified XML file.
 void writeFlatXML(java.io.OutputStreamWriter osWriter, boolean writeBOM)
          Writes the string file out to the specified output stream writer in a flat XML form sorted by Token id.
 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 com.g11ntoolkit.strfile.StrFile
append, append, convertToFileURL, copyOf, debugDump, findString, findToken, getBuffer, getContextFileName, getDatatype, getElementTable, getLocale, getProductName, getProductVersion, getSourceFileName, getString, getString, getStringTable, getTargetLocale, getTokFile, getXLIFFLocaleString, keys, loadXLIFF, setContextFileName, setDatatype, setLocale, setProductName, setProductVersion, setSourceFileName, setTargetLocale, setTokFile
 
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.


inputFileName

private java.lang.String inputFileName
The name of the input file.

Constructor Detail

JSStrFile

public JSStrFile()
Creates and an empty hashtable.

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


JSStrFile

public JSStrFile(java.util.Locale aLocale)
Creates an empty hashtable.

Parameters:
aLocale - a Locale specifying the locale for this object
Method Detail

copyOf

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

Parameters:
anotherJSStrFile - a JSStrFile specifying the JSStrFile object to copy

hasEntries

public boolean hasEntries()
Returns boolean.

Returns:
true or false if no strings exist

load

public void load(java.util.Locale locale,
                 java.lang.String xmlFileName)
          throws StrFileError
Loads the string buffer and the hashtable with the records read from either the specified input stream reader or the specified XML file.

The string buffer will contain the file level information for the file. This usually is nothing but comments. The hashtable will contain the token and string entries for each string in the file. The specified locale will be used for each string entry. It is assumed that the locale is correct and no further checking is done.

Rules for Recognizing Records in the File

The rules for an XML file are contained in the XML Parser used to read the file.

The rules are pretty straight forward.

  1. If the record begins with a #, it is a comment record. A comment applies to the first recognized line which precedes it. If no recognized line precedes it then it is a file level comment.
  2. If the record contains an =, it is a candidate for being a token=string line. In order to fulfill this role, the string which precedes the =, up to the beginning of the line, must be a valid token. If this is so, everything following the =, up to the next valid token at the beginning of another line, is considered part of the string for the token. This also includes any newline characters or other form feed characters which may get in.
  3. If the record does not qualify for either of those types, it is considered part of whatever is active when it is discovered. In other words, if we are looking at a string then any record which is not recognized as something else is treated as part of the string we are currently processing. The same is true with comments. Tokens, on the other hand may not span records. If they do we won't recognize the first of the lines as containing the token because it will not contain the =. Without the = we can not even begin to process a token.

Parameters:
locale - a Locale object or null if xmlfile is true
xmlFileName - a String specifying the name of the XML file or null if xmlfile is false
Throws:
StrFileError - if there is an error when processing the file

writeFlatXML

public void writeFlatXML(java.io.OutputStreamWriter osWriter,
                         boolean writeBOM)
                  throws EmptyStrFile,
                         java.io.IOException
Writes the string file out to the specified output stream writer in a flat XML form sorted by Token id.

This method handles the different tags used in a JSStrFile.

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

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.

Overrides:
writeXLIFF in class StrFile
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

getJSString

public JSXLEntry getJSString(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 JSXLEntry object containing the desired entry or null if the entry does not exist

findBlock

public boolean findBlock(JSXLEntry aBlock)
Returns true if the specified string translation entry is in the file.

Returns:
true if the translation entry is found in this object

getFileName

public java.lang.String getFileName()
Returns the name of the input file.

Returns:
a String representing the input file name

append

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

Parameters:
aToken - a Token object

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.

Overrides:
debugDump in class StrFile
Parameters:
what - a String specifying what to dump