com.g11ntoolkit.levblock
Class LeverageBlock

java.lang.Object
  |
  +--com.g11ntoolkit.levblock.LeverageBlock

public class LeverageBlock
extends java.lang.Object

The set of information for a token that can be used to leverage existing translations.

Each entry is made up of a token, token comments, a source translation entry, and one or more target translation entries. The target entries table may be null. The token and the source translation entry may not be null.

A leverage block when seen in a file has a definite format:

  1. token
  2. optional token comments - may be more than one line
  3. source translation entry - includes locale and string
  4. optional source translation entry comments - may be more than one line
  5. target translation entry 1 - includes locale and string
  6. optional target translation entry 1 comments - may be more than one line
  7. target translation entry n - includes locale and string
  8. optional target translation entry n comments - may be more than one line
The block divider is only for appearance sake in the file. The line is deemed to be a divider if there are at least 15 -'s on the line beginning at the third character of the line. Fewer -'s, we don't know so we make it a comment for whatever part of the block we are in. More -'s we don't care, it is still a divider. If the line contains text following at 15 -'s it is ignored also. These lines are not preserved with the file. If needed later they will be generated. These lines can be treated as the beginning of a block or the end of a block, it makes no difference. They are found by their pattern wherever they may appear.

Version:
2005/06/20
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.

See Also:
XLEntry, Token

Field Summary
private static java.util.logging.Logger log
          The log used for all messages from this class.
private static java.util.ResourceBundle mrb
          Message Resource Bundle.
private  XLEntry sourceEntry
          The source entry for this block.
private  java.util.Hashtable targetEntries
          The target entries for the block.
private  int targetEntryCount
          The current number of entries in the target entries table.
private  Token token
          The token for this block.
private  java.lang.String tokenComments
          The token comments for this block.
private static java.util.ResourceBundle vrb
          Constants Resource Bundle.
private static java.util.ResourceBundle xrb
          Constants, messages, and variables used by the tools and classes for XML processing.
 
Constructor Summary
LeverageBlock()
          Creates an empty instance of LeverageBlock so it is ready to receive data via the set methods.
LeverageBlock(java.lang.StringBuffer someRecords)
          Creates an instance of LeverageBlock from the specified string buffer.
LeverageBlock(Token aToken)
          Creates an instance of LeverageBlock for the specified token.
LeverageBlock(Token aToken, XLEntry aSource, XLEntry aTarget)
          Creates an instance of LeverageBlock for the specified token, source entry, and target entry.
 
Method Summary
 void addTarget(XLEntry aTarget)
          Adds a target entry to the current set of target entries for this block.
 void addTokenComment(java.lang.String aComment)
          Adds the specified comment to the token comments for this block.
 void debugDump()
          Prints the entire contents of this object to the console for debugging purposes.
 void debugDump(java.lang.String what)
          Prints the contents of this object to the console for debugging purposes.
 boolean equals(LeverageBlock anotherBlock)
          Returns true if this block is equal to the specified block.
 boolean equals(java.lang.Object anotherBlock)
          Returns true if this block is equal to the specified object.
 int getCount()
          Returns the count of target entry blocks.
 XLEntry getSource()
          Returns the source entry for this block.
 java.util.Hashtable getTargets()
          Returns the target entries for this block.
 Token getToken()
          Returns the token for this block.
 java.lang.String getTokenComments()
          Returns the token comments for this block.
 int hashCode()
          Returns a hash code for this leverage block.
 boolean hasSource()
          Returns true if the block has a source translation entry.
 boolean hasTargets()
          Returns true if the block has a target translation entry.
 boolean hasToken()
          Returns true if the block has a token.
 boolean hasTokenComments()
          Returns true if the block has a token comments.
 void setSource(XLEntry aSource)
          Sets the source entry for this block.
 void setTargets(java.util.Hashtable someTargets)
          Sets the target entries for this block to the specified set of target entries.
 void setToken(Token aToken)
          Sets the token for this block.
 void setToken(Token aToken, java.lang.String aComment)
          Sets the token and its comments for this block.
 void setTokenComments(java.lang.String aComment)
          Sets the token comments for this block.
 java.lang.String toString()
          Returns the contents of this block as a string.
 boolean validate()
          Returns true if this block is well formed.
 void writeXML(java.io.Writer out)
          Writes the contents of the object to the specified writer in XML form.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

log

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


mrb

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


vrb

private static java.util.ResourceBundle vrb
Constants Resource Bundle.


xrb

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


token

private Token token
The token for this block.


tokenComments

private java.lang.String tokenComments
The token comments for this block.


sourceEntry

private XLEntry sourceEntry
The source entry for this block.

There can be only one source entry for a block. The source entry is made up of a locale, a string, and some comments. Comments are optional.


targetEntries

private java.util.Hashtable targetEntries
The target entries for the block.

Each target entry may be for the same locale or for different locales. The key to this table is a sequence number for the entry in the target entries. The keys in the table begin with 1. There is no theoretical upper limit on the number of entries in the table.


targetEntryCount

private int targetEntryCount
The current number of entries in the target entries table.

This index is used as the key for each target entry.

Constructor Detail

LeverageBlock

public LeverageBlock()
Creates an empty instance of LeverageBlock so it is ready to receive data via the set methods.


LeverageBlock

public LeverageBlock(Token aToken)
Creates an instance of LeverageBlock for the specified token.

It is assumed that the data will be added later via the set methods.

Parameters:
aToken - a Token object

LeverageBlock

public LeverageBlock(Token aToken,
                     XLEntry aSource,
                     XLEntry aTarget)
Creates an instance of LeverageBlock for the specified token, source entry, and target entry.

The source or target entries may be null.

Parameters:
aToken - a Token object
aSource - a XLEntry object specifying the source translation entry
aTarget - a XLEntry object specifying the target translation entry

LeverageBlock

public LeverageBlock(java.lang.StringBuffer someRecords)
              throws LeverageBlockError
Creates an instance of LeverageBlock from the specified string buffer.

Parse the buffer to find the token information, the source translation entry, and the target translation entries.

Parameters:
someRecords - a StringBuffer object specifying the records for this object
Throws:
LeverageBlockError - when there is an error in processing the records
Method Detail

setToken

public void setToken(Token aToken)
Sets the token for this block.

If the token already exists it will be replaced. If the token or its comments already exist they will be replaced. If the token is replaced, it is assumed that it does not conflict with and information in any of the targets which may exist. No checking is done in this method.

Parameters:
aToken - a Token specifying the Token value
See Also:
getToken()

setToken

public void setToken(Token aToken,
                     java.lang.String aComment)
Sets the token and its comments for this block.

If the token or its comments already exist they will be replaced. If the token is replaced, it is assumed that it does not conflict with and information in any of the targets which may exist. No checking is done in this method.

Parameters:
aToken - a Token object specifying the token
aComment - a String specifying the comment
See Also:
getToken()

setTokenComments

public void setTokenComments(java.lang.String aComment)
Sets the token comments for this block.

If the token comments already exist they will be replaced.

If the string begins with the comment delimiter, the delimiter is removed before making the string the comment.

Parameters:
aComment - a String specifying the token comments value
See Also:
getTokenComments()

addTokenComment

public void addTokenComment(java.lang.String aComment)
Adds the specified comment to the token comments for this block.

A single blank will added to the comments before the new comment is added.

If the string begins with the comment delimiter, the delimiter is removed before adding the string to the comments.

Parameters:
aComment - a String specifying the comment

setSource

public void setSource(XLEntry aSource)
Sets the source entry for this block.

If the source entry already exists it will be replaced. If the source entry is replaced, it is assumed that it does not conflict with any target entries which may exist and that it is the correct string for the token which may exist. No checking is done in this method.

Parameters:
aSource - an XLEntry object specifying the source value
See Also:
getSource()

setTargets

public void setTargets(java.util.Hashtable someTargets)
Sets the target entries for this block to the specified set of target entries.

The specified hashtable is assumed to contain the correct target entries for this instance of LeverageBlock. This means that the sequence number keys and the XLEntries have the proper information in them. No checking is done in this method.

Parameters:
someTargets - a Hashtable object specifying the targets
See Also:
getTargets()

addTarget

public void addTarget(XLEntry aTarget)
Adds a target entry to the current set of target entries for this block.

It is assumed that the specified XLEntry contains the correct locale and string information for the current instance of LeverageBlock. No checking is done. in this method.

Parameters:
aTarget - a XLEntry object specifying the target entry

getToken

public Token getToken()
Returns the token for this block.

Returns:
the Token value or null if no token is set
See Also:
setToken(com.g11ntoolkit.token.Token)

getTokenComments

public java.lang.String getTokenComments()
Returns the token comments for this block.

Returns:
a String representing the token comments value or null if no comments are set
See Also:
setTokenComments(java.lang.String)

getSource

public XLEntry getSource()
Returns the source entry for this block.

Returns:
a XLEntry object representing the source value or null if no source entry is set
See Also:
setSource(com.g11ntoolkit.levblock.XLEntry)

getTargets

public java.util.Hashtable getTargets()
Returns the target entries for this block.

Returns:
a Hashtable object representing the targets or null if no target entries are available
See Also:
setTargets(java.util.Hashtable)

getCount

public int getCount()
Returns the count of target entry blocks.

Returns:
an int representing the count value

hasToken

public boolean hasToken()
Returns true if the block has a token.

Returns:
a boolean true if this object has a token

hasTokenComments

public boolean hasTokenComments()
Returns true if the block has a token comments.

Returns:
a boolean true if this object has token comments

hasSource

public boolean hasSource()
Returns true if the block has a source translation entry.

Returns:
a boolean true if this object has a source translation entry

hasTargets

public boolean hasTargets()
Returns true if the block has a target translation entry.

Returns:
a boolean true if this object has a target translation entry

hashCode

public int hashCode()
Returns a hash code for this leverage block.

The hash code for a leverage block is the sum of the hash code for its token, the hash code for its source translation entry, and the sum of the hash codes for all of its target entries.

Overrides:
hashCode in class java.lang.Object
Returns:
an int that contains the hash code for this object
See Also:
Token.hashCode(), XLEntry.hashCode()

equals

public boolean equals(LeverageBlock anotherBlock)
Returns true if this block is equal to the specified block.

This method uses the equals methods of the various objects contained in this block to perform its comparisons.

Parameters:
anotherBlock - a LeverageBlock object
Returns:
a boolean true if this object is equal to the specified leverage block

equals

public boolean equals(java.lang.Object anotherBlock)
Returns true if this block is equal to the specified object.

Overrides:
equals in class java.lang.Object
Parameters:
anotherBlock - an Object that purports to be a leverage block
Returns:
a boolean true if the specified object is a leverage block and it is equal to this object
See Also:
equals(com.g11ntoolkit.levblock.LeverageBlock)

validate

public boolean validate()
Returns true if this block is well formed.

Well formed means that the block has a valid token and a well formed source entry. It is not required to have any comments nor is it required to have any targets. If there are any target entries then they each must be well formed. This method is needed because the block can be made up in bits and pieces so we need to be able to determine if the block is complete.

Returns:
a boolean true if this object is a valid leverage block

toString

public java.lang.String toString()
Returns the contents of this block as a string.

Overrides:
toString in class java.lang.Object
Returns:
a String containing the contents of this object in a string form

writeXML

public void writeXML(java.io.Writer out)
              throws java.io.IOException
Writes the contents of the object to the specified writer in XML form.

Parameters:
out - a Writer to use for the output
Throws:
java.io.IOException - for any errors detected by the specified Writer

debugDump

public void debugDump()
Prints the entire contents of this object to the console for debugging purposes.


debugDump

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

Takes a parameter to control what it dumps. The parameter can be ALL, TOKEN, SOURCE, or TARGET to get the various parts of the block or all of it. The parameter must be in uppercase.

Parameters:
what - a String indicating what information is to be dumped