javatools.util
Class ScriptCatcher

java.lang.Object
  |
  +--javatools.util.ScriptCatcher
Direct Known Subclasses:
TableStructureCatcher

public class ScriptCatcher
extends java.lang.Object

It's a class to catch text from a script file and to divide it into commands.


Constructor Summary
ScriptCatcher()
          Creates new ScriptCatcher
 
Method Summary
 void addCommand(java.lang.String value)
          Adds a new command.
 void clear()
          Removes all the commands.
 void constructCommands(java.lang.String textScript)
          Construct commands fromf a given string (textScript) instead of a file.
 java.util.ArrayList getCommandList()
          Returns the commands as a list.
 java.lang.String[] getCommands()
          Returns the commands as an array.
 java.lang.String getCommandText(int numCommand)
          Returns the command text of command numCommand.
 java.lang.String getCommentdelimiter()
          Returns the string who represents the start of a comment.
 char getDivideCommandChar()
          Returns the character who represents the end of a command.
 int getNumCommands()
          Returns the number of commands.
 boolean getRemoveFormat()
          Returns the property about removing formatting items (spaces and new-lines)
 java.lang.Character getStringDelimiterChar()
          Returns the character who represents the start/end of a string in the script.
 java.util.Iterator iterator()
          Returns an iterator to iterate commands.
 void loadScript(java.lang.String fileName)
          Loads a script whose path is in "fileName" string, divides it into commands and make them available.
 java.lang.String removeComments(java.lang.String inStr)
          Removes comments from a script (string inStr).
 java.lang.String removeSpaces(java.lang.String cmdText)
          Removes unuseful spaces, tabs and CRs from a command.
 void saveScript(java.lang.String fileName)
          Saves a script using saved command texts into "fileName".
 void setCommandText(int numCommand, java.lang.String value)
          Sets the text for command numCommand with the string value.
 void setCommentDelimiter(java.lang.String inStr)
          Sets the string who represents the start of a comment.
 void setDivideCommandChar(char inChar)
          Sets the character who represents the end of a command.
 void setNumCommands(int numCommands)
          Sets the number of commands.
 void setRemoveFormat(boolean value)
          Controls whether formatting items (spaces and new-lines) are going to be removed.
 void setStringDelimiterChar(java.lang.Character inChar)
          Sets the character who represents the start/end of a string in the script.
static java.lang.String textFile2String(java.lang.String fileName)
          Loads text file "fileName" and puts its content into a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScriptCatcher

public ScriptCatcher()
Creates new ScriptCatcher

Method Detail

setRemoveFormat

public void setRemoveFormat(boolean value)
Controls whether formatting items (spaces and new-lines) are going to be removed.

Parameters:
value - true: formatting items will be removed; false: formatting items will NOT be removed.

getRemoveFormat

public boolean getRemoveFormat()
Returns the property about removing formatting items (spaces and new-lines)

Returns:
true: formatting items will be removed; false: formatting items will NOT be removed.

loadScript

public void loadScript(java.lang.String fileName)
                throws java.io.FileNotFoundException
Loads a script whose path is in "fileName" string, divides it into commands and make them available.

Parameters:
fileName - Path to the file to be processed.
Throws:
java.io.FileNotFoundException - If "fileName" is not found

saveScript

public void saveScript(java.lang.String fileName)
                throws java.io.IOException
Saves a script using saved command texts into "fileName".

Parameters:
fileName - Path to file to be saved.
Throws:
java.io.IOException - If some I/O error occurs

constructCommands

public void constructCommands(java.lang.String textScript)
Construct commands fromf a given string (textScript) instead of a file.

Parameters:
textScript - The string containing the script to be processed.

removeSpaces

public java.lang.String removeSpaces(java.lang.String cmdText)
Removes unuseful spaces, tabs and CRs from a command. WARNING! The text has to be a command WITHOUT command delimiter (default ;)!

Parameters:
cmdText - String containing the command to be processed.
Returns:
A string "purged" of unuseful spaces.

removeComments

public java.lang.String removeComments(java.lang.String inStr)
Removes comments from a script (string inStr).

Parameters:
inStr - The string containing the string to be processed.
Returns:
A string which represents the script WITHOUT comments.

clear

public void clear()
Removes all the commands.


getNumCommands

public int getNumCommands()
Returns the number of commands.

Returns:
Number of commands contained.

setNumCommands

public void setNumCommands(int numCommands)
                    throws java.lang.IndexOutOfBoundsException
Sets the number of commands. There's no need to use it if you are loading a script file or using a script string. You need it ONLY if you are going to give commands one by one. All previous saved commands will be erased.

Parameters:
numCommands - The number of commands to be generated.
Throws:
java.lang.IndexOutOfBoundsException - if numCommands is less than 1.

getCommandText

public java.lang.String getCommandText(int numCommand)
                                throws java.lang.IndexOutOfBoundsException
Returns the command text of command numCommand.

Parameters:
numCommand - the number of the interested command, between 0 and getNumCommands()-1
Returns:
The needed command text.
Throws:
java.lang.IndexOutOfBoundsException - If numCommand is not valid

getCommands

public java.lang.String[] getCommands()
Returns the commands as an array.

Returns:
The commands as an array.

getCommandList

public java.util.ArrayList getCommandList()
Returns the commands as a list.

Returns:
The commands as a list.

iterator

public java.util.Iterator iterator()
Returns an iterator to iterate commands.

Returns:
The needed iterator.

addCommand

public void addCommand(java.lang.String value)
Adds a new command.

Parameters:
value - The command to add.

setCommandText

public void setCommandText(int numCommand,
                           java.lang.String value)
                    throws java.lang.IndexOutOfBoundsException
Sets the text for command numCommand with the string value.

Parameters:
numCommand - The number of the interested command, between 0 and getNumCommands()-1.
value - The command text, WITHOUT command delimiter!
Throws:
java.lang.IndexOutOfBoundsException - If numCommand is not valid.

setDivideCommandChar

public void setDivideCommandChar(char inChar)
Sets the character who represents the end of a command.

Parameters:
inChar - The character which will be interpreted as a command delimiter.

getDivideCommandChar

public char getDivideCommandChar()
Returns the character who represents the end of a command.

Returns:
The needed character.

setStringDelimiterChar

public void setStringDelimiterChar(java.lang.Character inChar)
Sets the character who represents the start/end of a string in the script.

Parameters:
inChar - The character which will be interpreted as a string delimiter.

getStringDelimiterChar

public java.lang.Character getStringDelimiterChar()
Returns the character who represents the start/end of a string in the script.

Returns:
The needed character.

setCommentDelimiter

public void setCommentDelimiter(java.lang.String inStr)
Sets the string who represents the start of a comment.

Parameters:
inStr - The string which will be interpreted as a comment delimiter.

getCommentdelimiter

public java.lang.String getCommentdelimiter()
Returns the string who represents the start of a comment.

Returns:
The needed string.

textFile2String

public static java.lang.String textFile2String(java.lang.String fileName)
                                        throws java.io.FileNotFoundException
Loads text file "fileName" and puts its content into a string.

Parameters:
fileName - Path to file to be loaded.
Returns:
The string representing the content of the text file.
Throws:
java.io.FileNotFoundException - If the file "fileName" is not found.