KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > recorder > Response


1 /*
2  * $Id: Response.java,v 1.3 2004/12/01 07:54:26 hengels Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.recorder;
15
16 import java.util.regex.Matcher JavaDoc;
17 import java.util.regex.Pattern JavaDoc;
18
19 /**
20  * Completely useless at the moment! This should become a handy tool for
21  * examination of result pages.
22  */

23 public class Response {
24     private String JavaDoc body;
25
26     public Response(String JavaDoc body) {
27         this.body = body;
28     }
29
30     public String JavaDoc getBody() {
31         return body;
32     }
33
34     public String JavaDoc getTextValue(String JavaDoc name) {
35         Pattern JavaDoc p = Pattern.compile("name ?= ?\"" + name + "\" .* value ?= ?\"([^\"]*)\"");
36         Matcher JavaDoc m = p.matcher(body);
37         m.find();
38         return m.group(1);
39     }
40
41     public boolean isCheckBoxSelected(String JavaDoc name) {
42         Pattern JavaDoc p = Pattern.compile("name ?= ?\"" + name + "\" .* checked ?= ?\"([^\"]*)\"");
43         Matcher JavaDoc m = p.matcher(body);
44         m.find();
45         String JavaDoc s = m.group(1);
46         return "1".equals(s) || "on".equals(s) || "yes".equals(s);
47     }
48 }
49
Popular Tags