KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > gargoylesoftware > htmlunit > html > HtmlArea


1 /*
2  * Copyright (c) 2002, 2005 Gargoyle Software Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * 3. The end-user documentation included with the redistribution, if any, must
13  * include the following acknowledgment:
14  *
15  * "This product includes software developed by Gargoyle Software Inc.
16  * (http://www.GargoyleSoftware.com/)."
17  *
18  * Alternately, this acknowledgment may appear in the software itself, if
19  * and wherever such third-party acknowledgments normally appear.
20  * 4. The name "Gargoyle Software" must not be used to endorse or promote
21  * products derived from this software without prior written permission.
22  * For written permission, please contact info@GargoyleSoftware.com.
23  * 5. Products derived from this software may not be called "HtmlUnit", nor may
24  * "HtmlUnit" appear in their name, without prior written permission of
25  * Gargoyle Software Inc.
26  *
27  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
28  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
29  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARGOYLE
30  * SOFTWARE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
33  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
36  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  */

38 package com.gargoylesoftware.htmlunit.html;
39
40 import java.io.IOException JavaDoc;
41 import java.net.MalformedURLException JavaDoc;
42 import java.net.URL JavaDoc;
43 import java.util.Map JavaDoc;
44
45 import com.gargoylesoftware.htmlunit.Page;
46 import com.gargoylesoftware.htmlunit.SubmitMethod;
47 import com.gargoylesoftware.htmlunit.WebClient;
48 import com.gargoylesoftware.htmlunit.WebRequestSettings;
49 import com.gargoylesoftware.htmlunit.WebWindow;
50
51 /**
52  * Wrapper for the html element "area".
53  *
54  * @version $Revision: 100 $
55  * @author <a HREF="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
56  * @author David K. Taylor
57  * @author <a HREF="mailto:cse@dynabean.de">Christian Sell</a>
58  */

59 public class HtmlArea extends FocusableElement {
60
61     /** the HTML tag represented by this element */
62     public static final String JavaDoc TAG_NAME = "area";
63
64     /**
65      * Create an instance of HtmlArea
66      *
67      * @param page The HtmlPage that contains this element.
68      * @param attributes the initial attributes
69      */

70     public HtmlArea( final HtmlPage page, final Map JavaDoc attributes ) {
71         super( page, attributes );
72     }
73
74     /**
75      * @return the HTML tag name
76      */

77     public String JavaDoc getTagName() {
78         return TAG_NAME;
79     }
80
81     /**
82      * This method will be called if there either wasn't an onclick handler or there was
83      * but the result of that handler was true. This is the default behaviour of clicking
84      * the element. The default implementation returns the current page - subclasses
85      * requiring different behaviour (like {@link HtmlSubmitInput}) will override this
86      * method.
87      *
88      * @param defaultPage The default page to return if the action does not
89      * load a new page.
90      * @return The page that is currently loaded after execution of this method
91      * @throws IOException If an IO error occured
92      */

93     protected Page doClickAction(final Page defaultPage) throws IOException JavaDoc {
94         final HtmlPage enclosingPage = getPage();
95         final WebClient webClient = enclosingPage.getWebClient();
96
97         final String JavaDoc href = getHrefAttribute();
98         if( href != null && href.length() > 0 ) {
99             final URL JavaDoc url;
100             try {
101                 url = enclosingPage.getFullyQualifiedUrl( getHrefAttribute() );
102             }
103             catch( final MalformedURLException JavaDoc e ) {
104                 throw new IllegalStateException JavaDoc(
105                     "Not a valid url: " + getHrefAttribute() );
106             }
107             final WebRequestSettings settings = new WebRequestSettings(url,
108                     SubmitMethod.getInstance(getAttributeValue("method")));
109             final WebWindow webWindow = enclosingPage.getEnclosingWindow();
110             return webClient.getPage(
111                     webWindow,
112                     enclosingPage.getResolvedTarget(getTargetAttribute()),
113                     settings);
114         }
115         else {
116             return defaultPage;
117         }
118     }
119
120     /**
121      * Return the value of the attribute "shape". Refer to the
122      * <a HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a>
123      * documentation for details on the use of this attribute.
124      *
125      * @return The value of the attribute "shape"
126      * or an empty string if that attribute isn't defined.
127      */

128     public final String JavaDoc getShapeAttribute() {
129         return getAttributeValue("shape");
130     }
131
132
133     /**
134      * Return the value of the attribute "coords". Refer to the
135      * <a HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a>
136      * documentation for details on the use of this attribute.
137      *
138      * @return The value of the attribute "coords"
139      * or an empty string if that attribute isn't defined.
140      */

141     public final String JavaDoc getCoordsAttribute() {
142         return getAttributeValue("coords");
143     }
144
145
146     /**
147      * Return the value of the attribute "href". Refer to the
148      * <a HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a>
149      * documentation for details on the use of this attribute.
150      *
151      * @return The value of the attribute "href"
152      * or an empty string if that attribute isn't defined.
153      */

154     public final String JavaDoc getHrefAttribute() {
155         return getAttributeValue("href");
156     }
157
158
159     /**
160      * Return the value of the attribute "nohref". Refer to the
161      * <a HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a>
162      * documentation for details on the use of this attribute.
163      *
164      * @return The value of the attribute "nohref"
165      * or an empty string if that attribute isn't defined.
166      */

167     public final String JavaDoc getNoHrefAttribute() {
168         return getAttributeValue("nohref");
169     }
170
171
172     /**
173      * Return the value of the attribute "alt". Refer to the
174      * <a HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a>
175      * documentation for details on the use of this attribute.
176      *
177      * @return The value of the attribute "alt"
178      * or an empty string if that attribute isn't defined.
179      */

180     public final String JavaDoc getAltAttribute() {
181         return getAttributeValue("alt");
182     }
183
184
185     /**
186      * Return the value of the attribute "tabindex". Refer to the
187      * <a HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a>
188      * documentation for details on the use of this attribute.
189      *
190      * @return The value of the attribute "tabindex"
191      * or an empty string if that attribute isn't defined.
192      */

193     public final String JavaDoc getTabIndexAttribute() {
194         return getAttributeValue("tabindex");
195     }
196
197
198     /**
199      * Return the value of the attribute "accesskey". Refer to the
200      * <a HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a>
201      * documentation for details on the use of this attribute.
202      *
203      * @return The value of the attribute "accesskey"
204      * or an empty string if that attribute isn't defined.
205      */

206     public final String JavaDoc getAccessKeyAttribute() {
207         return getAttributeValue("accesskey");
208     }
209
210
211     /**
212      * Return the value of the attribute "onfocus". Refer to the
213      * <a HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a>
214      * documentation for details on the use of this attribute.
215      *
216      * @return The value of the attribute "onfocus"
217      * or an empty string if that attribute isn't defined.
218      */

219     public final String JavaDoc getOnFocusAttribute() {
220         return getAttributeValue("onfocus");
221     }
222
223
224     /**
225      * Return the value of the attribute "onblur". Refer to the
226      * <a HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a>
227      * documentation for details on the use of this attribute.
228      *
229      * @return The value of the attribute "onblur"
230      * or an empty string if that attribute isn't defined.
231      */

232     public final String JavaDoc getOnBlurAttribute() {
233         return getAttributeValue("onblur");
234     }
235
236
237     /**
238      * Return the value of the attribute "target". Refer to the
239      * <a HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a>
240      * documentation for details on the use of this attribute.
241      *
242      * @return The value of the attribute "target"
243      * or an empty string if that attribute isn't defined.
244      */

245     public final String JavaDoc getTargetAttribute() {
246         return getAttributeValue("target");
247     }
248 }
249
Popular Tags