KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > test > web > Util


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.test.web;
6
7 import com.meterware.httpunit.*;
8
9 /**
10  * Jun 27, 2004
11  * @author: Tuan Nguyen
12  * @email: tuan08@users.sourceforge.net
13  * @version: $Id: Util.java,v 1.1 2004/10/11 23:36:03 tuan08 Exp $
14  */

15 public class Util {
16     public static WebLink findLink(WebResponse response, WebTable block,
17                                  String JavaDoc text) throws Exception JavaDoc {
18         WebLink link = null ;
19     if(block != null) {
20         for(int i = 0 ; i < block.getRowCount(); i++) {
21             for(int j = 0; j < block.getColumnCount(); j++) {
22                 TableCell cell = block.getTableCell(i, j) ;
23                 link = cell.getFirstMatchingLink( WebLink.MATCH_TEXT, text);
24                 if(link != null) return link ;
25             }
26         }
27         
28     } else {
29         link = response.getFirstMatchingLink(WebLink.MATCH_TEXT, text);
30         if(link != null) return link ;
31     }
32     return null ;
33     }
34     
35     public static WebLink[] findLinks(WebResponse response, WebTable block,
36                                     String JavaDoc text) throws Exception JavaDoc {
37         WebLink[] links = null ;
38     if(block != null) {
39         for(int i = 0 ; i < block.getRowCount(); i++) {
40             for(int j = 0; j < block.getColumnCount(); j++) {
41                 TableCell cell = block.getTableCell(i, j) ;
42                 links = cell.getMatchingLinks(WebLink.MATCH_TEXT , text);
43                 if(links.length > 0) return links ;
44             }
45         }
46         
47     } else {
48         return response.getMatchingLinks(WebLink.MATCH_TEXT , text);
49     }
50     return new WebLink[0] ;
51         
52     }
53   //==============================================================================
54
public static WebLink findLinkWithText(WebResponse response, WebTable block,
55                                                String JavaDoc text) throws Exception JavaDoc{
56         WebLink link = null ;
57     if(block != null) {
58         for(int i = 0 ; i < block.getRowCount(); i++) {
59             for(int j = 0; j < block.getColumnCount(); j++) {
60                 TableCell cell = block.getTableCell(i, j) ;
61                 link = cell.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, text);
62                 if(link != null) return link ;
63             }
64         }
65         
66     } else {
67         link = response.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, text);
68         if(link != null) return link ;
69     }
70     return null ;
71     }
72     
73     public static WebLink[] findLinksWithText(WebResponse response, WebTable block,
74                                             String JavaDoc text) throws Exception JavaDoc{
75         WebLink[] links = null ;
76     if(block != null) {
77         for(int i = 0 ; i < block.getRowCount(); i++) {
78             for(int j = 0; j < block.getColumnCount(); j++) {
79                 TableCell cell = block.getTableCell(i, j) ;
80                 links = cell.getMatchingLinks(WebLink.MATCH_CONTAINED_TEXT , text);
81                 if(links.length > 0) return links ;
82             }
83         }
84         
85     } else {
86         return response.getMatchingLinks(WebLink.MATCH_CONTAINED_TEXT , text);
87     }
88     return new WebLink[0] ;
89     }
90     //==============================================================================
91
public static WebLink findLinkWithURL(WebResponse response, WebTable block,
92                                         String JavaDoc url) throws Exception JavaDoc{
93         WebLink link = null ;
94         if(block != null) {
95             for(int i = 0 ; i < block.getRowCount(); i++) {
96                 for(int j = 0; j < block.getColumnCount(); j++) {
97                     TableCell cell = block.getTableCell(i, j) ;
98                     link = cell.getFirstMatchingLink( WebLink.MATCH_URL_STRING, url);
99                     if(link != null) return link ;
100                 }
101             }
102
103         } else {
104             link = response.getFirstMatchingLink( WebLink.MATCH_URL_STRING, url);
105             if(link != null) return link ;
106         }
107         return null ;
108     }
109     
110     public static WebLink[] findLinksWithURL(WebResponse response, WebTable block,
111                                            String JavaDoc partOfURL) throws Exception JavaDoc{
112         WebLink[] links = null ;
113         if(block != null) {
114             for(int i = 0 ; i < block.getRowCount(); i++) {
115                 for(int j = 0; j < block.getColumnCount(); j++) {
116                     TableCell cell = block.getTableCell(i, j) ;
117                     links = cell.getMatchingLinks(WebLink.MATCH_URL_STRING, partOfURL) ;
118                     if(links.length > 0) return links ;
119                 }
120             }
121
122         } else {
123             return response.getMatchingLinks(WebLink.MATCH_URL_STRING, partOfURL) ;
124         }
125         return new WebLink[0] ;
126     }
127     
128     public static WebForm findFormWithName(WebResponse response, WebTable block,
129                                          String JavaDoc name) throws Exception JavaDoc{
130         WebForm form = null ;
131         if(block != null) {
132             for(int i = 0 ; i < block.getRowCount(); i++) {
133                 for(int j = 0; j < block.getColumnCount(); j++) {
134                     TableCell cell = block.getTableCell(i, j) ;
135                     form = cell.getFormWithName(name) ;
136                     if(form != null) return form ;
137                 }
138             }
139
140         } else {
141             form = response.getFormWithName(name) ;
142             if(form != null) return form ;
143         }
144         return null ;
145     }
146 }
Popular Tags