T-Plan Robot Enterprise 3.5.2
Build No. 3.5.2-20140701.1

com.tplan.robot.scripting.commands.impl
Class ExcelCommand

java.lang.Object
  extended by com.tplan.robot.scripting.commands.AbstractCommandHandler
      extended by com.tplan.robot.scripting.commands.impl.AbstractFileResourceCommand
          extended by com.tplan.robot.scripting.commands.impl.ExcelCommand
All Implemented Interfaces:
GUIConstants, Plugin, Configurable, ConfigurationChangeListener, AdvancedCommandHandler, CommandHandler, ContextActionProvider, EditorFriendlyCommandHandler, ScriptListener, EventListener

public class ExcelCommand
extends AbstractFileResourceCommand
implements ScriptListener, AdvancedCommandHandler, EditorFriendlyCommandHandler, ConfigurationChangeListener, ContextActionProvider

Handler implementing functionality of the Excel command.


T-Plan Robot Enterprise, (C) 2009-2014 T-Plan Limited. All rights reserved.


Field Summary
static String ARG_FIND
           
static String ARG_SELECT
           
static String ARG_SET
           
static int ERR_CELL_NOT_FOUND
           
static int ERR_FAILED_TO_CREATE
           
static int ERR_MAX_EXCEL
           
static int ERR_SHEET_NOT_FOUND
           
static String PARAM_COLUMN
           
static String PARAM_EVALUATE
           
static String PARAM_PATTERN
           
static String PARAM_REF
           
static String PARAM_ROW
           
static String PARAM_SHEET
           
static String PARAM_TYPE
           
static String PARAM_VALUE
           
static String VAR_CELL_COLUMN
           
static String VAR_CELL_REF
           
static String VAR_CELL_ROW
           
static String VAR_CELL_TYPE
           
static String VAR_CELL_VALUE
           
static String VAR_ERROR
           
static String VAR_SHEET_COLUMNS
           
static String VAR_SHEET_COUNT
           
static String VAR_SHEET_NAME
           
static String VAR_SHEET_NUMBER
           
static String VAR_SHEET_ROWS
           
 
Fields inherited from class com.tplan.robot.scripting.commands.impl.AbstractFileResourceCommand
ARG_CLOSE, ARG_CREATE, ARG_OPEN, ARGUMENTS, CONTEXT_FILE_CREATE_CACHE, CONTEXT_FILE_MAP, CONTEXT_FILE_OPEN_CACHE, CONTEXT_FILE_RESOURCE_MAP, contextAttributes, contextShortcut, ERR_FAILED_TO_OPEN, ERR_FAILED_TO_SAVE, ERR_MAX, PARAM_ARGUMENT, PARAM_BEAN, PARAM_FILE, PARAM_ID, PARAM_OUTFILE, PARAM_SAVE, PARAMS, VAR_FILE, VAR_FILENAME, VAR_OUTFILE, VAR_OUTFILENAME
 
Fields inherited from class com.tplan.robot.scripting.commands.AbstractCommandHandler
ALT, CONTEXT_COMMAND_CALL_COMPILED_PARAMETER_MAP, CONTEXT_COMMAND_CALL_SOURCE_PARAMETER_MAP, CONTEXT_COMPILE_SINGLE_COMMAND_MODE, CONTEXT_LAST_WAIT_FACTOR, CONTEXT_WAIT_FACTOR_ERR_MSG_SHOWN, CTRL, PARAM_COUNT, PARAM_ONFAIL, PARAM_ONPASS, PARAM_WAIT, SHIFT, WINDOWS
 
Fields inherited from interface com.tplan.robot.scripting.commands.EditorFriendlyCommandHandler
CATEGORY_ADMIN, CATEGORY_DESKTOP, CATEGORY_IMAGE_OPS, CATEGORY_IO, CATEGORY_REPORTING, CATEGORY_UNKNOWN
 
Fields inherited from interface com.tplan.robot.gui.GUIConstants
DEFAULT_TPLAN_ROBOT_FILE_EXTENSION, EVENT_ADD_CUSTOM_ACTION_MSG, EVENT_ADD_STABLE_ACTION_MSG, EVENT_DISPLAY_HASHTABLE, EVENT_DISPLAY_PREFERENCES, EVENT_DOCUMENT_CHANGED, EVENT_MOUSE_MOVED, EVENT_REMOVE_CUSTOM_ACTION_MSG, EVENT_REMOVE_STABLE_ACTION_MSG, EVENT_SELECTION_CHANGED, EVENT_STATUSBAR_MSG, HELP_URL_JAPI, HELP_URL_SPEC, HELP_URLS
 
Constructor Summary
ExcelCommand()
           
 
Method Summary
 void checkVisualParameters(Map<String,CharSequence> parameters, TestScriptInterpret interpret)
          Check (compile) the map of parameters retrieved through the command editor window before they are used to build and/or update the command or Java method call.
protected  void cleanUpAllVars(ScriptingContext ctx)
          Clean up all variables created by the command.
 void configurationChanged(ConfigurationChangeEvent evt)
          This method gets called when a configuration parameter is changed.
protected  void create(AbstractFileBean bean, OutputStream out)
           
protected  AbstractFileBean createBean()
          Create a file bean.
static Workbook createXLSXWorkbook(InputStream in)
           
protected  void defineFileVariables(AbstractFileBean bean, ScriptingContext context)
           
static String evaluateFormula(Cell cell)
           
 int execute(List args, Map values, ScriptingContext context)
          Execute the command.
 int getCategory(StringBuilder description)
          Get the category the command falls to.
static List<String> getCellTypes()
           
static String getCellValue(Cell c, boolean evaluateFormula)
           
 String[] getCommandNames()
          Get command names.
 List<Action> getContextActions(EditorFriendlyInterpret interpret, int offset)
          Get the list of actions available for the specified offset (command line) and script.
protected  JFileChooser getFileChooser(String argument, ScriptingContext context)
           
 List getParameterValues(String paramName, String command, ScriptingContext context)
          Get values of a particular parameter.
 List<Preference> getPreferences()
          Get metadata of displayable/editable configurable parameters.
 String getShortDescription(Map<String,String> parameters, TestScriptInterpret interpret)
          Get short description (up to 50 chars) of what the command does.
 List<Preference> getVisualParameters(LinkedHashMap<String,Object> parameters, TestScriptInterpret interpret)
          Get the list of visual parameters for construction of a dynamic command editor window.
 boolean hasCustomParameterComponent(LinkedHashMap<String,Object> parameters, TestScriptInterpret interpret, PreferencePanel[] panel)
          Specify whether the command provides a custom preference panel.
 boolean hasCustomPropertyDialog(LinkedHashMap<String,Object> parameters, TestScriptInterpret interpret, int offset, Action[] action)
          Specify whether the command provides a custom editor.
 boolean hasFixedArgument(List<String> arguments)
          Defines whether the command uses a fixed argument (one-of-a-list).
 boolean isGlobalPrerequisity(String command)
          This method should return true if the command needs to be executed prior to running part of a test script.
protected  void load(AbstractFileBean bean, InputStream in)
           
protected  void save(AbstractFileBean bean, OutputStream out)
           
 void validate(List args, Map values, Map vt, ScriptingContext context)
          Validate if the command complies with the command syntax.The command is already pre-parsed to a list of parameter names and a map of [name, value] pairs.
 
Methods inherited from class com.tplan.robot.scripting.commands.impl.AbstractFileResourceCommand
addParamToArgumentArray, addSupportedArgsAndParams, canRunWithoutConnection, cleanUpFileVars, closeFileBean, execute, execute, getArguments, getContextArgument, getContextAttributes, getContextShortcut, getParameters, getScriptPath, getUsedFiles, removeVariables, scriptEvent, updateRelativePath
 
Methods inherited from class com.tplan.robot.scripting.commands.AbstractCommandHandler
addCommandListener, checkDependencies, checkPauseAndStop, compileParameters, createConfigureAction, executeFallBackCodeOrProcedure, fireCommandEvent, getBooleanSafely, getCode, getDate, getDescription, getDisplayName, getImplementedInterface, getIntegerSafely, getLowestSupportedVersion, getMessageAfterInstall, getMessageBeforeInstall, getStablePopupMenuItems, getSupportContact, getUniqueId, getVendorHomePage, getVendorName, getVersion, multiplyWaitTime, reloadCommand, removeCommandListener, requiresOriginalValues, requiresRestart, setConfiguration, toLinkedMap, validateOnPassAndOnFail, wait
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.tplan.robot.scripting.ScriptListener
scriptEvent
 
Methods inherited from interface com.tplan.robot.scripting.commands.AdvancedCommandHandler
getArguments, getParameters
 
Methods inherited from interface com.tplan.robot.scripting.commands.CommandHandler
addCommandListener, canRunWithoutConnection, getContextArgument, getContextAttributes, getContextShortcut, getStablePopupMenuItems, removeCommandListener
 

Field Detail

ARG_SELECT

public static final String ARG_SELECT
See Also:
Constant Field Values

ARG_SET

public static final String ARG_SET
See Also:
Constant Field Values

ARG_FIND

public static final String ARG_FIND
See Also:
Constant Field Values

PARAM_SHEET

public static final String PARAM_SHEET
See Also:
Constant Field Values

PARAM_ROW

public static final String PARAM_ROW
See Also:
Constant Field Values

PARAM_COLUMN

public static final String PARAM_COLUMN
See Also:
Constant Field Values

PARAM_VALUE

public static final String PARAM_VALUE
See Also:
Constant Field Values

PARAM_REF

public static final String PARAM_REF
See Also:
Constant Field Values

PARAM_PATTERN

public static final String PARAM_PATTERN
See Also:
Constant Field Values

PARAM_TYPE

public static final String PARAM_TYPE
See Also:
Constant Field Values

PARAM_EVALUATE

public static final String PARAM_EVALUATE
See Also:
Constant Field Values

VAR_SHEET_COUNT

public static final String VAR_SHEET_COUNT
See Also:
Constant Field Values

VAR_SHEET_NAME

public static final String VAR_SHEET_NAME
See Also:
Constant Field Values

VAR_SHEET_NUMBER

public static final String VAR_SHEET_NUMBER
See Also:
Constant Field Values

VAR_SHEET_ROWS

public static final String VAR_SHEET_ROWS
See Also:
Constant Field Values

VAR_SHEET_COLUMNS

public static final String VAR_SHEET_COLUMNS
See Also:
Constant Field Values

VAR_CELL_ROW

public static final String VAR_CELL_ROW
See Also:
Constant Field Values

VAR_CELL_COLUMN

public static final String VAR_CELL_COLUMN
See Also:
Constant Field Values

VAR_CELL_TYPE

public static final String VAR_CELL_TYPE
See Also:
Constant Field Values

VAR_CELL_VALUE

public static final String VAR_CELL_VALUE
See Also:
Constant Field Values

VAR_CELL_REF

public static final String VAR_CELL_REF
See Also:
Constant Field Values

VAR_ERROR

public static final String VAR_ERROR
See Also:
Constant Field Values

ERR_FAILED_TO_CREATE

public static final int ERR_FAILED_TO_CREATE
See Also:
Constant Field Values

ERR_SHEET_NOT_FOUND

public static final int ERR_SHEET_NOT_FOUND
See Also:
Constant Field Values

ERR_CELL_NOT_FOUND

public static final int ERR_CELL_NOT_FOUND
See Also:
Constant Field Values

ERR_MAX_EXCEL

public static final int ERR_MAX_EXCEL
See Also:
Constant Field Values
Constructor Detail

ExcelCommand

public ExcelCommand()
Method Detail

getCommandNames

public String[] getCommandNames()
Description copied from interface: CommandHandler

Get command names. A command name is the first word in a script line, e.g. "Type" or "Press". Though most commands have just one name, you may use this method to define any number of command aliases. You may even use one class to implement more commands if you want. In such a case you need to define more command names and implement a different behavior for each command.

Please note that command name parsing is NOT case sensitive. You don't have to define the names as e.g. { "MyCommand", "mycommand" }. Script parser will always parse the command name in a script and convert it to upper case using the String.toUpperCase(). Such a command name will be then used to look for a command implementation in the command table.

Specified by:
getCommandNames in interface CommandHandler
Specified by:
getCommandNames in class AbstractFileResourceCommand
Returns:
array of command names.

isGlobalPrerequisity

public boolean isGlobalPrerequisity(String command)
Description copied from interface: CommandHandler

This method should return true if the command needs to be executed prior to running part of a test script.

Imagine a following situation. User creates a script:
Var PATH=/usr/java Type {PATH}/bin/java Press Enter

User then selects just the last two commands to be executed. It would of course fail because the PATH variable is not defined. If this method returns true, the command will be executed before running selected commands are executed.

Specified by:
isGlobalPrerequisity in interface CommandHandler
Overrides:
isGlobalPrerequisity in class AbstractFileResourceCommand
Parameters:
command - a command with parameters to be processed.
Returns:
true if the command needs to be executed prior to running of part of the script, false othewise.

validate

public void validate(List args,
                     Map values,
                     Map vt,
                     ScriptingContext context)
              throws SyntaxErrorException
Description copied from interface: CommandHandler
Validate if the command complies with the command syntax.The command is already pre-parsed to a list of parameter names and a map of [name, value] pairs.

Specified by:
validate in interface CommandHandler
Overrides:
validate in class AbstractFileResourceCommand
Parameters:
args - a list of parameters.
values - a map of [param, value] pairs resulted from parsing of the command.
vt - output map for values.
context - execution context.
Throws:
SyntaxErrorException - when the command doesn't meet the required syntax.

execute

public int execute(List args,
                   Map values,
                   ScriptingContext context)
            throws SyntaxErrorException
Description copied from interface: CommandHandler

Execute the command.

Argument context will contain all necessary objects that the command may possibly use, for example the com.tplan.robot.gui.FrameBufferPanel and com.tplan.robot.api.rfb.RfbModule instances etc. If the command e.g. needs to send some key events to the RFB server, you should save the reference to the RfbModuleImpl instance and use its methods to fire the required key events.

Specified by:
execute in interface CommandHandler
Parameters:
args - a list of parameters.
values - a map of [param, value] pairs resulted from parsing of the command.
context - execution context.
Returns:
command exit code.
Throws:
SyntaxErrorException - when the command doesn't meet the required syntax.

defineFileVariables

protected void defineFileVariables(AbstractFileBean bean,
                                   ScriptingContext context)
Overrides:
defineFileVariables in class AbstractFileResourceCommand

evaluateFormula

public static String evaluateFormula(Cell cell)

getCellValue

public static String getCellValue(Cell c,
                                  boolean evaluateFormula)

getCellTypes

public static List<String> getCellTypes()

getPreferences

public List<Preference> getPreferences()
Description copied from interface: Configurable
Get metadata of displayable/editable configurable parameters. This method should declare a list of metadata for all configurable parameters which may be editable in the GUI. If the returned list is not null and contains at least one parameter, it gets picked up by the Preferences dialog which creates a panel with GUI components allowing to edit the declared configuration parameters.

Specified by:
getPreferences in interface Configurable
Overrides:
getPreferences in class AbstractCommandHandler
Returns:
a list of metadata for all public editable configuration parameters.

getParameterValues

public List getParameterValues(String paramName,
                               String command,
                               ScriptingContext context)
Description copied from interface: AdvancedCommandHandler
Get values of a particular parameter. This is to be used for parameters which have a fixed set of acceptable values. The command wizard typically displays the values as a list.

Specified by:
getParameterValues in interface AdvancedCommandHandler
Overrides:
getParameterValues in class AbstractFileResourceCommand
Parameters:
paramName - parameter name.
command - the current conmmand text (complete).
context - a context.
Returns:
list of supported parameter values.

createBean

protected AbstractFileBean createBean()
Description copied from class: AbstractFileResourceCommand
Create a file bean. The implementing class is supposed to subclass the AbstractFileBean one and return its instance. This mechanism allows to define custom fields and methods in the bean managed by this base class.

Specified by:
createBean in class AbstractFileResourceCommand
Returns:
a new instance of the file bean.

cleanUpAllVars

protected void cleanUpAllVars(ScriptingContext ctx)
Description copied from class: AbstractFileResourceCommand
Clean up all variables created by the command. This method is called to clean up the variable map in the context when the file is closed. The subclass should take advantage of the removeVariables() method to remove any variables it produces from the context.

Specified by:
cleanUpAllVars in class AbstractFileResourceCommand
Parameters:
ctx - a script context.

save

protected void save(AbstractFileBean bean,
                    OutputStream out)
             throws FileNotFoundException,
                    IOException
Specified by:
save in class AbstractFileResourceCommand
Throws:
FileNotFoundException
IOException

create

protected void create(AbstractFileBean bean,
                      OutputStream out)
               throws FileNotFoundException,
                      IOException
Specified by:
create in class AbstractFileResourceCommand
Throws:
FileNotFoundException
IOException

load

protected void load(AbstractFileBean bean,
                    InputStream in)
             throws FileNotFoundException,
                    IOException
Specified by:
load in class AbstractFileResourceCommand
Throws:
FileNotFoundException
IOException

createXLSXWorkbook

public static Workbook createXLSXWorkbook(InputStream in)
                                   throws IOException
Throws:
IOException

getFileChooser

protected JFileChooser getFileChooser(String argument,
                                      ScriptingContext context)
Specified by:
getFileChooser in class AbstractFileResourceCommand

configurationChanged

public void configurationChanged(ConfigurationChangeEvent evt)
Description copied from interface: ConfigurationChangeListener
This method gets called when a configuration parameter is changed.

Specified by:
configurationChanged in interface ConfigurationChangeListener
Parameters:
evt - A ConfigurationChangeEvent object describing the event source and the parameter that has changed.

getShortDescription

public String getShortDescription(Map<String,String> parameters,
                                  TestScriptInterpret interpret)
Description copied from interface: EditorFriendlyCommandHandler
Get short description (up to 50 chars) of what the command does. This will be used for the list (menu) of available actions in the GUI.

Specified by:
getShortDescription in interface EditorFriendlyCommandHandler
Parameters:
parameters - map of parameters and their values. All values are in the format recognized by token parser (TokenParserImpl.getParser()) which may be used to convert them to native Java objects such as Number, Point, Rectangle etc.
interpret - test script interpret owning the edited script.
Returns:
short command description.

getVisualParameters

public List<Preference> getVisualParameters(LinkedHashMap<String,Object> parameters,
                                            TestScriptInterpret interpret)
Description copied from interface: EditorFriendlyCommandHandler

Get the list of visual parameters for construction of a dynamic command editor window.

This method will be called only after the EditorFriendlyCommandHandler.hasCustomPropertyDialog(java.util.LinkedHashMap, com.tplan.robot.scripting.interpret.TestScriptInterpret, int, javax.swing.Action[]) and EditorFriendlyCommandHandler.hasCustomParameterComponent(java.util.LinkedHashMap, com.tplan.robot.scripting.interpret.TestScriptInterpret, com.tplan.robot.gui.preferences.PreferencePanel[]) methods return false.

Specified by:
getVisualParameters in interface EditorFriendlyCommandHandler
Parameters:
parameters - input parameters parsed from the already existing command or preselected through the Command Wizard menu.
interpret - test script interpret owning the edited script.
Returns:
list of visual parameters. If the list is null and the command does not provide a custom component through the EditorFriendlyCommandHandler.hasCustomPropertyDialog(java.util.LinkedHashMap, com.tplan.robot.scripting.interpret.TestScriptInterpret, int, javax.swing.Action[]) and EditorFriendlyCommandHandler.hasCustomParameterComponent(java.util.LinkedHashMap, com.tplan.robot.scripting.interpret.TestScriptInterpret, com.tplan.robot.gui.preferences.PreferencePanel[]) methods, it will be considered as not editable through the GUI.

hasFixedArgument

public boolean hasFixedArgument(List<String> arguments)
Description copied from interface: EditorFriendlyCommandHandler
Defines whether the command uses a fixed argument (one-of-a-list). Examples of such commands are Mouse with the arguments of "click", "press" etc. or WaitFor ("match", "mismatch",...). If the command does use a fixed argument it is supposed to return true and populate the argument list with the argument values (if the list is not null).

Specified by:
hasFixedArgument in interface EditorFriendlyCommandHandler
Parameters:
arguments - optional output list for the argument values.
Returns:
true if the command uses fixed argument values, false if not.

getCategory

public int getCategory(StringBuilder description)
Description copied from interface: EditorFriendlyCommandHandler
Get the category the command falls to. The method may return one of the predefined CATEGORY_XXX constants defined by this class. Commands which do not fall into any specified category may return EditorFriendlyCommandHandler.CATEGORY_UNKNOWN or a code outside of the recognized constants and pass the desired category name through the argument string builder instance.

Specified by:
getCategory in interface EditorFriendlyCommandHandler
Parameters:
description - string buffer for category name. It is only used if the returned value is other than the standard ones.
Returns:
category code.

checkVisualParameters

public void checkVisualParameters(Map<String,CharSequence> parameters,
                                  TestScriptInterpret interpret)
                           throws IllegalArgumentException
Description copied from interface: EditorFriendlyCommandHandler

Check (compile) the map of parameters retrieved through the command editor window before they are used to build and/or update the command or Java method call. This method may be also used to remove or filter the parameters. This is especially useful if the command editor uses auxiliary settings which are not recognized by the command or method at runtime.

If the command handler extends the AbstractCommandHandler class, it may take advantage of the AbstractCommandHandler.compileParameters(java.util.Map, com.tplan.robot.scripting.interpret.TestScriptInterpret) method which converts a copy of the input map to the legacy parameter format and passes it to the CommandHandler.validate(java.util.List, java.util.Map, java.util.Map, com.tplan.robot.scripting.ScriptingContext) method to verify whether the parameters are recognized and their values are acceptable. This allows to avoid duplication of parameter parsing and compilation code.

Specified by:
checkVisualParameters in interface EditorFriendlyCommandHandler
Parameters:
parameters - map of parameters and their values. All values are in the format recognized by token parser (TokenParserImpl.getParser()) which may be used to convert them to native Java objects such as Number, Point, Rectangle etc.
interpret - test script interpret owning the edited script.
Throws:
IllegalArgumentException - when one or more parameters is not recognized or its value is invalid. The exception should contain a descriptive message because it will be displayed by the GUI.

hasCustomParameterComponent

public boolean hasCustomParameterComponent(LinkedHashMap<String,Object> parameters,
                                           TestScriptInterpret interpret,
                                           PreferencePanel[] panel)
Description copied from interface: EditorFriendlyCommandHandler
Specify whether the command provides a custom preference panel. If it does it is expected to return true and populate the first field of the panel array with an instance of the panel.

Specified by:
hasCustomParameterComponent in interface EditorFriendlyCommandHandler
Parameters:
parameters - map of parameters and their values. All values are in the format recognized by token parser (TokenParserImpl.getParser()) which may be used to convert them to native Java objects such as Number, Point, Rectangle etc.
interpret - test script interpret owning the edited script.
panel - output array of length=1 which should be populated inside the method with the custom panel instance if the method returns true.
Returns:
true if the command creates its own custom preference panel or false otherwise.

hasCustomPropertyDialog

public boolean hasCustomPropertyDialog(LinkedHashMap<String,Object> parameters,
                                       TestScriptInterpret interpret,
                                       int offset,
                                       Action[] action)
Description copied from interface: EditorFriendlyCommandHandler

Specify whether the command provides a custom editor. If it does it is expected to return true and populate the first field of the action array with an instance of an Action which opens up the dialog.

Even though the method is implemented to return false, it may be also used to preprocess parameters parsed from an existing command call before they reach the command editor window. The method may for example change the parameters or their values in the input map. As the argument map the real one rather than a copy, any data change will hold in there and it will be reflected in the GUI.

Specified by:
hasCustomPropertyDialog in interface EditorFriendlyCommandHandler
Parameters:
parameters - map of parameters and their values. All values are in the format recognized by token parser (TokenParserImpl.getParser()) which may be used to convert them to native Java objects such as Number, Point, Rectangle etc.
interpret - test script interpret owning the edited script.
offset - position in the edited script.
action - output array of length=1 which should be populated inside the method with an Action instance if the method returns true.
Returns:
true if the command creates its own dialog or false otherwise.

getContextActions

public List<Action> getContextActions(EditorFriendlyInterpret interpret,
                                      int offset)
Description copied from interface: ContextActionProvider
Get the list of actions available for the specified offset (command line) and script.

Specified by:
getContextActions in interface ContextActionProvider
Parameters:
interpret - the test script interpret.
offset - the offset in the document where the declaring command is situated.
Returns:
list of actions available for the particular command.

T-Plan Robot Enterprise 3.5.2
Build No. 3.5.2-20140701.1