1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package eteg.sinon.core;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28 /***
29 * Class that represents the processing of a Web page in Sinon.
30 *
31 * @author <a href="mailto:thiagohp at users.sourceforge.net">Thiago H. de Paula Figueiredo</a>
32 * @author Last modified by $Author: thiagohp $
33 * @version $Revision: 1.2 $
34 */
35 public class Page {
36
37 /***
38 * Constant that defines the POST method to <code>method</code> property.
39 */
40 public static final boolean POST_METHOD = true;
41
42 /***
43 * Constant that GET method to <code>method</code> property.
44 */
45 public static final boolean GET_METHOD = false;
46
47 /***
48 * Page identifier.
49 */
50 private String id;
51
52 /***
53 * Page URL.
54 */
55 private String url;
56
57 /***
58 * Tells if page redirections must be followed.
59 * Default: true
60 */
61 private boolean followRedirects;
62
63 /***
64 * Method used to pass parameters: {@link #POST_METHOD} ou
65 * {@link #GET_METHOD}.
66 * Default: {@link #GET_METHOD}.
67 */
68 private boolean method;
69
70 /***
71 * Page storage configuration.
72 */
73 private PageStorageConfiguration storageConfiguration;
74
75 /***
76 * Ordered list of extraction steps of this page.
77 * Extrações de dados desta página.
78 */
79 private List extractionSteps;
80
81 /***
82 * Ordered list of actions to be taken after this page is processed.
83 */
84 private List actions;
85
86 /***
87 * Error listener.
88 */
89 private String errorListenerClassName;
90
91 /***
92 * Page state listener fully qualified class name.
93 */
94 private String pageStateListenerClassName;
95
96 /***
97 * Prompt listener fully qualified class name.
98 */
99 private String promptListenerClassName;
100
101 /***
102 * Page configurations.
103 */
104 private PageConfiguration configuration;
105
106 /***
107 * Constructor without parameters.
108 */
109 public Page() {
110
111 actions = new ArrayList();
112 extractionSteps = new ArrayList();
113 pageStateListenerClassName = null;
114 method = GET_METHOD;
115 errorListenerClassName = null;
116 promptListenerClassName = null;
117 storageConfiguration = new PageStorageConfiguration();
118 followRedirects = true;
119
120 }
121
122 /***
123 * Returns the value of the <code>id</code> property.
124 * @return a <code>String</code>.
125 */
126 public String getId() {
127 return id;
128 }
129
130 /***
131 * Sets the value of the <code>id</code> property.
132 * @param id the new <code>id</code> value.
133 */
134 public void setId(String id) {
135 this.id = id;
136 }
137
138 /***
139 * Returns the value of the <code>method</code> property.
140 * @return {@link #GET_METHOD} or {@link #POST_METHOD}.
141 */
142 public boolean getMethod() {
143 return method;
144 }
145
146 /***
147 * Sets the value of the <code>method</code> property.
148 * @param method {@link #GET_METHOD} or {@link #POST_METHOD}.
149 */
150 public void setMethod(boolean method) {
151 this.method = method;
152 }
153
154 /***
155 * Returns the value of the <code>url</code> property.
156 * @return a <code>String</code>.
157 */
158 public String getUrl() {
159 return url;
160 }
161
162 /***
163 * Sets the value of the <code>url</code> property.
164 * @param url the new <code>url</code> value.
165 */
166 public void setUrl(String url) {
167 this.url = url;
168 }
169
170 /***
171 * Returns the value of the <code>followRedirects</code> property.
172 * @return a <code>boolean</code>.
173 */
174 public boolean getFollowRedirects() {
175 return followRedirects;
176 }
177
178 /***
179 * Sets the value of the <code>followRedirects</code> property.
180 * @param followRedirects the new <code>followRedirects</code> value.
181 */
182 public void setFollowRedirects(boolean followRedirects) {
183 this.followRedirects = followRedirects;
184 }
185
186 /***
187 * Returns the value of the <code>storageConfiguration</code> property.
188 * @return a <code>String</code>.
189 */
190 public PageStorageConfiguration getStorageConfiguration() {
191 return storageConfiguration;
192 }
193
194 /***
195 * Sets the value of the <code>storageConfiguration</code> property.
196 * @param storageConfiguration the new <code>storageConfiguration</code>
197 * value.
198 */
199 public void setStorageConfiguration(
200 PageStorageConfiguration storageConfiguration) {
201 this.storageConfiguration = storageConfiguration;
202 }
203
204 /***
205 * Adds a {@link Step} to this page.
206 * @param step a {@link Step} instance.
207 */
208 public void addStep(Step step) {
209 extractionSteps.add(step);
210 }
211
212 /***
213 * Returns the value of the <code>steps</code> property.
214 * @return a {@link Step} array.
215 */
216 public Step[] getSteps() {
217
218 Step[] extractions =
219 new Step[extractionSteps.size()];
220
221 extractionSteps.toArray(extractions);
222
223 return extractions;
224
225 }
226
227 /***
228 * Adds an {@link Action} to this page.
229 * @param action a {@link Action} instance.
230 */
231 public void addAction(Action action) {
232 actions.add(action);
233 }
234
235 /***
236 * Returns the value of the <code>actions</code> property.
237 * @return a {@link Action} array.
238 */
239 public Action[] getActions() {
240
241 Action[] actionArray = new Action[actions.size()];
242
243 actions.toArray(actionArray);
244
245 return actionArray;
246
247 }
248
249 /***
250 * Returns the value of the <code>configuration</code> property.
251 * @return a <code>String</code>.
252 */
253 public PageConfiguration getConfiguration() {
254 return configuration;
255 }
256
257 /***
258 * Sets the value of the <code>configuration</code> property.
259 * @param configuration the new <code>configuration</code> value.
260 */
261 public void setConfiguration(PageConfiguration configuration) {
262 this.configuration = configuration;
263 }
264
265 /***
266 * Returns the value of the <code>errorListenerClassName</code> property.
267 * @return a <code>String</code>.
268 */
269 public String getErrorListenerClassName() {
270 return errorListenerClassName;
271 }
272
273 /***
274 * Sets the value of the <code>errorListenerClassName</code> property.
275 * @param errorListenerClassName the new <code>errorListenerClassName</code>
276 * value.
277 */
278 public void setErrorListenerClassName(String errorListenerClassName) {
279 this.errorListenerClassName = errorListenerClassName;
280 }
281
282 /***
283 * Returns the value of the <code>pageStateListenerClassName</code> property.
284 * @return a <code>String</code>.
285 */
286 public String getPageStateListenerClassName() {
287 return pageStateListenerClassName;
288 }
289
290 /***
291 * Sets the value of the <code>pageStateListenerClassName</code> property.
292 * @param pageStateListenerClassName the new
293 * <code>pageStateListenerClassName</code> value.
294 */
295 public void setPageStateListenerClassName(
296 String pageStateListenerClassName) {
297
298 this.pageStateListenerClassName = pageStateListenerClassName;
299
300 }
301
302 /***
303 * Returns the value of the <code>promptListenerClassName</code> property.
304 * @return a <code>String</code>.
305 */
306 public String getPromptListenerClassName() {
307 return promptListenerClassName;
308 }
309
310 /***
311 * Sets the value of the <code>promptListenerClassName</code> property.
312 * @param promptListenerClassName the new
313 * <code>promptListenerClassName</code> value.
314 */
315 public void setPromptListenerClassName(String promptListenerClassName) {
316 this.promptListenerClassName = promptListenerClassName;
317 }
318
319 }