|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--com.g11ntoolkit.tokfile.TokFile
Create and maintain a TokFile with its associated buffer and hashtable.
The TokFile is the file that contains the original input file where the strings have been replaced by a token id. It is an intermediate file used by the L10N Leveraging tools.
The input file can be in either a plain text form or in an XML form. Which form is determined by which load method is called.
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.util.Hashtable |
context
Contains a table of context information. |
private int |
currentRecordStart
Beginning position of the current record in the buffer. |
private java.lang.String[] |
dqStyle
Contains the string double-quote style. |
private java.lang.String[] |
fileType
Contains the file type we are given. |
private java.util.ArrayList |
lineStart
Contains the starting positions of the lines from the source file in the buffer. |
private static java.util.logging.Logger |
log
The log used for all messages from this class. |
private boolean |
moreRecords
Indicates that there are more records available in the buffer. |
private static java.util.ResourceBundle |
mrb
Message Resource Bundle. |
private java.util.Hashtable |
revContext
Contains a table of the Tokens associated with their keys. |
private int |
sourceStart
Contains the starting position in the file image. |
private java.lang.StringBuffer |
theBuffer
Collection all the data from the specified input file. |
private java.lang.String |
theImage
Contains the image of the source file. |
private static java.util.ResourceBundle |
vrb
Variables Resource Bundle. |
private static java.util.ResourceBundle |
xrb
Constants, messages, and variables used by the tools and classes for XML processing. |
| Constructor Summary | |
TokFile()
Creates an empty buffer and an empty hashtable. |
|
TokFile(java.io.InputStreamReader isReader)
Creates a buffer that contains the records read from the specified input stream reader. |
|
| Method Summary | |
void |
append(char aChar)
Adds the specified character to the end of the buffer. |
void |
append(java.lang.String aString)
Adds the specified string to the end of the buffer. |
void |
closeFileImageToBuffer()
Place the last part of the image file into the buffer. |
private static java.lang.String |
convertToFileURL(java.lang.String filename)
Returns the filename converted to a file URL. |
void |
copyOf(TokFile tf)
Makes a copy of the specified TokFile object contents 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. |
int |
findOffset(int row,
int col)
Returns the offset into the image area based on the row and col numbers provided. |
java.lang.StringBuffer |
getBuffer()
Returns the buffer. |
TokContext |
getContext(Token tok)
Returns the context for a specified token in the file. |
java.util.Hashtable |
getContextTable()
Returns the context hashtable. |
java.lang.String |
getDQStyle()
Returns the double-quote style for this file. |
java.lang.String |
getFirstRecord()
Returns the first record in the buffer. |
java.lang.String |
getNextRecord()
Returns the next record in the buffer. |
java.lang.String |
getRecord(int offset)
Returns the record at the specified offset in the buffer. |
java.lang.String |
getRecord(java.lang.String aString)
Returns the record for the specified string. |
java.lang.String |
getRecord(Token aToken)
Returns the record for the specified token. |
Token |
getRevContext(TokContext ctx)
Returns the token for a specified context in the file. |
java.util.Hashtable |
getRevContextTable()
Returns the reverse context hashtable. |
java.lang.String |
getType()
Returns the type of file we are dealing with. |
boolean |
hasMoreRecords()
Returns true if there are more records in the buffer. |
int |
length()
Returns the length of this buffer. |
void |
load(java.io.InputStreamReader isReader)
Loads the buffer with the records read from the specified input stream reader. |
void |
load(java.io.InputStreamReader isReader,
boolean xmlfile,
java.lang.String xmlFileName)
Loads the buffer with the records read from the specified input stream reader. |
void |
loadFileImage(java.lang.String inFileName)
Load the source file image. |
java.lang.String[] |
parse(java.lang.String rec)
Parses the specified string into a context string and a token string. |
void |
replaceString(java.lang.String aString,
Token aToken)
Replaces the specified string with a token. |
void |
replaceStringWithToken(int strStartRow,
int strStartCol,
int strEndRow,
int strEndCol,
Token token)
Replaces the string in the file image with a token in the buffer. |
void |
replaceToken(Token aToken,
java.lang.String aString)
Replaces the specified token with a string. |
void |
setBuffer(java.lang.StringBuffer aBuffer)
Set the buffer contents. |
private void |
setContext()
Sets the context for all the tokens in the file based on the context table found in the file. |
void |
setContext(TokContext ctx,
Token tok)
Sets the context for the specified token in the file. |
void |
setContextTable(java.util.Hashtable ch)
Set the context hashtable. |
private void |
setDQStyle()
Determines the double-quote style in the file and remembers it. |
void |
setDQStyle(java.lang.String dqs)
Sets the double-quote style for this file. |
private void |
setRevContext(Token tok,
TokContext ctx)
Sets the token for each context in the file. |
void |
setRevContextTable(java.util.Hashtable rch)
Set the reverse context hashtable. |
private void |
setType()
Determines the type of file we are dealing with and remembers it. |
void |
setType(java.lang.String ft)
Determines the type of file we are dealing with and remembers it. |
void |
write(java.io.OutputStreamWriter osWriter)
Writes the buffer out to the specified output stream writer and closes it. |
void |
writeXML(java.io.OutputStreamWriter osWriter)
Writes the buffer out to the specified output stream writer in XML format. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private static java.util.logging.Logger log
private static java.util.ResourceBundle mrb
private static java.util.ResourceBundle vrb
private static java.util.ResourceBundle xrb
private java.lang.StringBuffer theBuffer
On load, this is the raw data from the file except that all encoded characters have been decoded to their native codes. The buffer can be updated with various methods to replace the strings with tokens.
private int currentRecordStart
private boolean moreRecords
private java.lang.String[] fileType
This is important because we need to know what type of file it is in order to properly parse the file to set up the context hashtables.
private java.lang.String[] dqStyle
This indicates whether the string was wrapped in a pair of double-quotes or not.
private java.util.Hashtable context
This is a table of the keys in the file associated with their tokens.
private java.util.Hashtable revContext
This is a table of the tokens in the file associated with their keys (i.e., a reverse context).
private java.lang.String theImage
private int sourceStart
private java.util.ArrayList lineStart
| Constructor Detail |
public TokFile()
This may be handy if the buffer is going to be used to create a new TokFile.
public TokFile(java.io.InputStreamReader isReader)
throws TokFileError
isReader - an InputStreamReader mapped to the input file
TokFileError - for errors in processing the input file| Method Detail |
public void load(java.io.InputStreamReader isReader)
throws TokFileError
Passes the work on to the load(InputStreamReader, boolean, String) method indicating that the file is in a text form.
isReader - an InputStreamReader mapped to the input file
TokFileError - for errors in processing the input fileload(InputStreamReader, boolean, String)
public void load(java.io.InputStreamReader isReader,
boolean xmlfile,
java.lang.String xmlFileName)
throws TokFileError
The file may be either a text file or an XML file.
The TokFile buffer will contain an exact copy of the data in the file.
isReader - an InputStreamReader mapped to the input file or null if xmlfile is truexmlfile - a boolean specifying whether the file is in XML form (true) or in text form (false)xmlFileName - a String specifying the name of the XML file or null if xmlfile is false
TokFileError - for errors in processing the input fileload(InputStreamReader)public void setType(java.lang.String ft)
ft - a String containing the file typegetType()
private void setType()
throws TokFileError
We take care of setting it for you. This is not something we want to have set from outside the control of this class.
TokFileError - for errors in processing the input filegetType()public java.lang.String getType()
setType(java.lang.String)
private void setDQStyle()
throws TokFileError
TokFileError - for errors in processing the input filegetDQStyle()public void setDQStyle(java.lang.String dqs)
We take care of setting it for you. This is not something we want to have set from outside the control of this class.
dqs - a String containing the double-quote style for the filegetDQStyle()public java.lang.String getDQStyle()
setDQStyle()
public void setContext(TokContext ctx,
Token tok)
setContext() will also set the reverse context since it knows it already.
ctx - a TokContext containing the context for the specified tokentok - a Token containing the token for the specified contextgetContext(com.g11ntoolkit.token.Token)public TokContext getContext(Token tok)
tok - a Token containing the token for which the context is wanted
setContext(com.g11ntoolkit.levblock.TokContext, com.g11ntoolkit.token.Token)
private void setContext()
throws TokFileError
We take care of setting it for you. This is not something we want to have set from outside the control of this class.
TokFileError - for errors in processing the input filegetContext(com.g11ntoolkit.token.Token)public java.lang.String[] parse(java.lang.String rec)
rec - a String containing the record
private void setRevContext(Token tok,
TokContext ctx)
We take care of setting it for you. This is not something we want to have set from outside the control of this class.
tok - a Token containing the tokenctx - a TokContext containing the contextgetRevContext(com.g11ntoolkit.levblock.TokContext)public Token getRevContext(TokContext ctx)
ctx - a TokContext contains the context
setRevContext(com.g11ntoolkit.token.Token, com.g11ntoolkit.levblock.TokContext)
public void write(java.io.OutputStreamWriter osWriter)
throws TokFileError
osWriter - an OutputStreamWriter mapped to the output file
TokFileError - for errors in processing the input file
public void writeXML(java.io.OutputStreamWriter osWriter)
throws TokFileError,
gnu.regexp.REException,
java.io.IOException
osWriter - an OutputStreamWriter mapped to the output file
TokFileError - for errors in processing the buffer
gnu.regexp.REException - for errors in setting up the regular expression
java.io.IOException - for errors in writing the file
public java.lang.String getFirstRecord()
throws RecordNotFound
This resets the current record position to 0 then gets the next record.
RecordNotFound - if no record is available
public java.lang.String getNextRecord()
throws RecordNotFound
RecordNotFound - if no record is available
public java.lang.String getRecord(Token aToken)
throws TokenNotFound
aToken - a Token containing the token for the desired record
TokenNotFound - if the token is not found
public java.lang.String getRecord(java.lang.String aString)
throws StringNotFound
aString - a String containing the string
StringNotFound - if the string is not found
public java.lang.String getRecord(int offset)
throws RecordNotFound
This updates the current record position to point to the position after the returned record. When the end of the buffer is reached a flag is set to indicate that no more records are available in the buffer.
offset - an int specifying the offset for the record
RecordNotFound - if the record is not found
public void replaceString(java.lang.String aString,
Token aToken)
throws TokFileError
aString - a String contains the string to replaceaToken - a Token contains the token to be put in place of the specified string
TokFileError - for errors in processing the input file
public void replaceToken(Token aToken,
java.lang.String aString)
throws TokFileError
aToken - a Token containing the token to be replacedaString - a String containing the string to replace the token
TokFileError - for errors in processing the input filepublic void append(java.lang.String aString)
This will extend the buffer so there will be more records available in the buffer and the flag will be set to show this. Don't forget to add appropriate line breaks if you want them. I don't do it for you.
aString - a String containing the stringpublic void append(char aChar)
This will extend the buffer so there will be more records available in the buffer and the flag will be set to show this.
aChar - a char containing the characterpublic int length()
public boolean hasMoreRecords()
public void setBuffer(java.lang.StringBuffer aBuffer)
aBuffer - a StringBuffer specifying the buffer contentsgetBuffer()public java.lang.StringBuffer getBuffer()
setBuffer(java.lang.StringBuffer)public void setContextTable(java.util.Hashtable ch)
ch - a Hashtable specifying the context hashtable contentsgetContextTable()public java.util.Hashtable getContextTable()
setContextTable(java.util.Hashtable)public void setRevContextTable(java.util.Hashtable rch)
rch - a Hashtable specifying the reverse context hashtable contentsgetRevContextTable()public java.util.Hashtable getRevContextTable()
setRevContextTable(java.util.Hashtable)public void copyOf(TokFile tf)
TokFile object contents in this object.
tf - a TokFile object specifying the TokFile object to copypublic void debugDump()
This version of the method assumes that you want all of the contents.
public void debugDump(java.lang.String what)
You can control what gets dumped by specifying a parameter. The parameter can be ALL, BUFFER, or CONTEXT. The parameter must be specified in all uppercase characters.
what - a String containing the desired part of the object to display on the console
public void loadFileImage(java.lang.String inFileName)
throws java.io.IOException
This is used in replacing the strings in the file with their tokens. This is only done for files parsed by the JavaCC parser.
inFileName - a String specifying the name of the source file to load
java.io.IOException - when an IO error occurs
public void replaceStringWithToken(int strStartRow,
int strStartCol,
int strEndRow,
int strEndCol,
Token token)
This is used when the file is being parsed by the JavaCC parser.
strStartRow - an int specifying the starting line number of the string in the file image that is being replacedstrStartCol - an int specifying the starting column number in the starting line of the string in the file image that is being replacedstrEndRow - an int specifying the ending line number of the string in the file image that is being replacedstrEndCol - an int specifying the ending column number in the ending line of the string in the file image that is being replacedtoken - a Token specifying the token that is replacing the stringpublic void closeFileImageToBuffer()
This is used when the file is being parsed by the JavaCC parser.
public int findOffset(int row,
int col)
This is used when the file is being parsed by the JavaCC parser.
row - an int specifying the line numbercol - an int specifying the column number in the line number
private static java.lang.String convertToFileURL(java.lang.String filename)
filename - a String containing the file name to be converted
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||