01: // Copyright © 2006-2007 ASERT. Released under the Canoo Webtest license.
02: package com.canoo.webtest.plugins.exceltest;
03:
04: import org.apache.poi.hssf.usermodel.HSSFCell;
05: import org.apache.poi.hssf.util.CellReference;
06:
07: import com.canoo.webtest.engine.StepExecutionException;
08:
09: /**
10: * Base class for steps that deal with an individual cell of an Excel spreadsheet.<p>
11: *
12: * @author Rob Nielsen
13: */
14: public abstract class AbstractExcelCellStep extends
15: AbstractExcelSheetStep {
16: private String fRow;
17: private String fCol;
18: private String fCell;
19:
20: /**
21: * @param cell The index of the sheet to select
22: * @webtest.parameter required="yes/no"
23: * description="The spreadsheet cell to select. eg. A5. Either <em>cell</em> or <em>row</em> and <em>col</em> must be specified."
24: */
25: public void setCell(final String cell) {
26: fCell = cell;
27: }
28:
29: public String getCell() {
30: return fCell;
31: }
32:
33: /**
34: * @param row The row of the sheet to select
35: * @webtest.parameter required="yes/no"
36: * description="The number of the row to select, starting at 1. Either <em>cell</em> or <em>row</em> and <em>col</em> must be specified."
37: */
38: public void setRow(final String row) {
39: fRow = row;
40: }
41:
42: public String getRow() {
43: return fRow;
44: }
45:
46: /**
47: * @param col The column to select
48: * @webtest.parameter required="no"
49: * description="The name or number (starting at 1) of the column to select. eg 1 or A. Either <em>cell</em> or <em>row</em> and <em>col</em> must be specified."
50: */
51: public void setCol(final String col) {
52: fCol = col;
53: }
54:
55: public String getCol() {
56: return fCol;
57: }
58:
59: protected void verifyParameters() {
60: super .verifyParameters();
61: if (getCell() == null && (getRow() == null || getCol() == null)) {
62: throw new StepExecutionException(
63: "You must specify a row and column or a cell reference.",
64: this );
65: }
66: if (getCell() != null && (getRow() != null || getCol() != null)) {
67: throw new StepExecutionException(
68: "You must specify either a row and column or a cell reference.",
69: this );
70: }
71: }
72:
73: protected HSSFCell getExcelCell() {
74: final CellReference cellReference = ExcelCellUtils
75: .getCellReference(this , getCell(), getRow(), getCol());
76: return ExcelCellUtils.getExcelCellAt(this , cellReference
77: .getRow(), cellReference.getCol());
78: }
79:
80: protected String getCellValue() {
81: return ExcelCellUtils.getCellValueAt(getExcelCell());
82: }
83:
84: protected CellReference getCellReference() {
85: return ExcelCellUtils.getCellReference(this, getCell(),
86: getRow(), getCol());
87: }
88: }
|