KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jonasadmin > test > util > JonasAdminUtils


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2005 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or 1any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: JonasAdminUtils.java,v 1.4 2005/07/11 15:57:49 kemlerp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jonasadmin.test.util;
27
28 import org.xml.sax.SAXException JavaDoc;
29
30 import com.meterware.httpunit.TableCell;
31 import com.meterware.httpunit.WebResponse;
32 import com.meterware.httpunit.WebTable;
33
34 /**
35  * Utils
36  * @author kemlerp
37  *
38  */

39 public class JonasAdminUtils {
40
41     /**
42      * A class which represents the row and the column of a cell
43      * @author kemlerp
44      *
45      */

46     public class CoordCell {
47
48         /**
49          * Row of the cell
50          */

51         private Integer JavaDoc row = null;
52
53         /**
54          * Column of the cell
55          */

56         private Integer JavaDoc column = null;
57
58         /**
59          * Constructor
60          * @param row a positive integer
61          * @param column a positive integer
62          */

63         public CoordCell (Integer JavaDoc row, Integer JavaDoc column) {
64             this.row = row;
65             this.column = column;
66         }
67
68         /**
69          * Get column
70          * @return column number
71          */

72         public Integer JavaDoc getColumn() {
73             return column;
74         }
75
76         /**
77          * Set column
78          * @param column a positive integer
79          */

80         public void setColumn(Integer JavaDoc column) {
81             this.column = column;
82         }
83
84         /**
85          * Get row
86          * @return row number
87          */

88         public Integer JavaDoc getRow() {
89             return row;
90         }
91
92         /**
93          * Set row
94          * @param row a positive integer
95          */

96         public void setRow(Integer JavaDoc row) {
97             this.row = row;
98         }
99     }
100
101     /**
102      * Get the last row of table where text is found in the first column
103      * @param text title of the row
104      * @param table the table which contains text
105      * @return -1 if the text was not found in the first column else an integer
106      */

107     public Integer JavaDoc getRow(String JavaDoc text, WebTable table) {
108         Integer JavaDoc row = new Integer JavaDoc(-1);
109         TableCell cell;
110         for (int i = 0; i < table.getRowCount(); i++) {
111             cell = table.getTableCell(i, 0);
112             if (cell.getText().indexOf(text) != -1) {
113                 row = new Integer JavaDoc(i);
114             }
115         }
116         return row;
117     }
118
119     /**
120      * Get the first row of table where text is found in the given column
121      * @param text title of the row
122      * @param table the table which contains text
123      * @param column the column
124      * @return -1 if the text was not found in the first column else an integer
125      */

126     public Integer JavaDoc getFirstRow(String JavaDoc text, WebTable table, int column) {
127         boolean found = false;
128         Integer JavaDoc row = new Integer JavaDoc(-1);
129         TableCell cell;
130         int i = 0;
131         while (i < table.getRowCount() && !found) {
132             cell = table.getTableCell(i, column);
133             if (cell != null && cell.getText().indexOf(text) != -1) {
134                 row = new Integer JavaDoc(i);
135                 found = true;
136             }
137             i++;
138         }
139         return row;
140     }
141
142     /**
143      * Get the last row of table where text is found in the given column
144      * @param text title of the row
145      * @param table the table which contains text
146      * @param column the column
147      * @return -1 if the text was not found in the first column else an integer
148      */

149     public Integer JavaDoc getRow(String JavaDoc text, WebTable table, int column) {
150         Integer JavaDoc row = new Integer JavaDoc(-1);
151         TableCell cell;
152         for (int i = 0; i < table.getRowCount(); i++) {
153             cell = table.getTableCell(i, column);
154             if (cell.getText().indexOf(text) != -1) {
155                 row = new Integer JavaDoc(i);
156             }
157         }
158         return row;
159     }
160
161     /**
162      * Get the last column of table where text is found in the first row
163      * @param text title of the column
164      * @param table the table which contains text
165      * @return -1 if the text was not found in the first row else an integer
166      */

167     public Integer JavaDoc getColumn(String JavaDoc text, WebTable table) {
168         Integer JavaDoc column = new Integer JavaDoc(-1);
169         TableCell cell;
170         for (int i = 0; i < table.getColumnCount(); i++) {
171             cell = table.getTableCell(0, i);
172             if (cell.getText().indexOf(text) != -1) {
173                 column = new Integer JavaDoc(i);
174             }
175         }
176         return column;
177     }
178
179     /**
180      * Get the row and the column of the cell which contains selected item
181      * @param table tree Table
182      * @return Null if no item is selected, else the row and the column
183      */

184     public CoordCell getSelectedItemRow(WebTable table) {
185         Integer JavaDoc row = null;
186         Integer JavaDoc column = null;
187         TableCell cell = null;
188         CoordCell coord = null;
189         String JavaDoc attribut;
190         boolean found = false;
191         int i = 0;
192         int j = 0;
193
194         while (i < table.getRowCount() && !found) {
195             j = 0;
196             while (j < table.getColumnCount() && !found) {
197                 cell = table.getTableCell(i, j);
198                 if (cell.getElementsWithAttribute("class", "tree-control-selected").length == 1) {
199                     found = true;
200                     row = new Integer JavaDoc(i);
201                     column = new Integer JavaDoc(j);
202                     coord = new CoordCell(row, column);
203                 }
204                 j++;
205             }
206             i++;
207         }
208         return coord;
209     }
210
211     /**
212      * Get table num
213      * @param contentFrame the content frame
214      * @param num integer between 0 and number of tables in the cell
215      * @return table
216      * @throws SAXException if a table or a cell doesn't match.
217      */

218     public WebTable getTable(WebResponse contentFrame, int num) throws SAXException JavaDoc {
219         WebTable table = contentFrame.getTables()[1];
220         TableCell cell = table.getTableCell(1, 0);
221         table = cell.getTables()[0];
222         cell = table.getTableCell(0, 0);
223         table = cell.getTables()[0];
224         cell = table.getTableCell(0, 0);
225         // Get the (num+1)th table
226
table = cell.getTables()[num];
227         return table;
228     }
229
230     /**
231      * Get table of tabs
232      * @param contentFrame the content frame
233      * @return table of tabs
234      * @throws SAXException if a table or a cell doesn't match.
235      */

236     public WebTable getTabTable(WebResponse contentFrame) throws SAXException JavaDoc {
237         WebTable table = contentFrame.getTables()[1];
238         TableCell cell = table.getTableCell(0, 0);
239         table = cell.getTables()[0];
240         return table;
241     }
242 }
243
Popular Tags