KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > websphinx > FormButton


1 /*
2  * WebSphinx web-crawling toolkit
3  *
4  * Copyright (c) 1998-2002 Carnegie Mellon University. All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in
16  * the documentation and/or other materials provided with the
17  * distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
20  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
23  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  */

32
33 package websphinx;
34
35 import java.net.URL JavaDoc;
36 import java.net.MalformedURLException JavaDoc;
37
38 /**
39  * Button element in an HTML form -- for example, <INPUT TYPE=submit> or <INPUT TYPE=image>.
40  *
41  * @author Rob Miller
42  * @see Page
43  * @see Link
44  */

45 public class FormButton extends Link {
46
47     Form form;
48
49     /**
50      * Make a LinkElement from a start tag and end tag and its containing form.
51      * The tags and form must be on the same page.
52      * @param startTag Start tag of button
53      * @param endTag End tag of button (or null if none)
54      * @param form Form containing this button
55      */

56     public FormButton (Tag startTag, Tag endTag, Form form) throws MalformedURLException JavaDoc {
57         super (startTag, endTag, null);
58         this.form = form;
59         if (form == null)
60             throw new MalformedURLException JavaDoc ();
61     }
62
63     /**
64      * Get the URL.
65      * @return the URL of the link
66      */

67     public URL JavaDoc getURL () {
68         if (url == null)
69             try {
70                 url = urlFromHref (getStartTag (), null);
71             } catch (MalformedURLException JavaDoc e) {
72                 url = null;
73             }
74
75         return url;
76     }
77
78     /**
79      * Get the form.
80      * @return the form containing this button
81      */

82     public Form getForm () {
83         return form;
84     }
85
86     /**
87      * Get the method used to access this link.
88      * @return GET or POST.
89      */

90     public int getMethod () {
91         return form.getMethod ();
92     }
93
94     /**
95      * Construct the URL for this button, from its start tag and a base URL (for relative references).
96      * @param tag Start tag of button, such as <INPUT TYPE=submit>.
97      * @param base Base URL used for relative references
98      * @return URL to which the button points
99      */

100     protected URL JavaDoc urlFromHref (Tag tag, URL JavaDoc base) throws MalformedURLException JavaDoc {
101         if (parent == null || form == null)
102             // can't figure out URL until we're linked into an HTML element tree
103
// containing our complete form
104
return null;
105         return form.makeQuery (this);
106     }
107
108 }
109
Popular Tags