1 38 package com.gargoylesoftware.htmlunit.html; 39 40 import java.io.IOException ; 41 import java.net.URL ; 42 import java.util.Map ; 43 44 import com.gargoylesoftware.htmlunit.Page; 45 import com.gargoylesoftware.htmlunit.TextUtil; 46 import com.gargoylesoftware.htmlunit.WebRequestSettings; 47 48 56 public class HtmlAnchor extends FocusableElement { 57 58 59 public static final String TAG_NAME = "a"; 60 61 67 public HtmlAnchor(final HtmlPage page, final Map attributes) { 68 super( page, attributes ); 69 } 70 71 74 public String getTagName() { 75 return TAG_NAME; 76 } 77 78 90 protected Page doClickAction(final Page defaultPage) throws IOException { 91 92 93 final String href = getHrefAttribute(); 94 95 getLog().debug( 96 "do click action in window '" 97 + defaultPage.getEnclosingWindow().getName() 98 + "', using href '" + href + "'"); 99 100 if( href != null && href.length() > 0 ) { 101 final HtmlPage page = getPage(); 102 if( TextUtil.startsWithIgnoreCase(href, "javascript:") ) { 103 return page.executeJavaScriptIfPossible( 104 href, "javascript url", true, this ).getNewPage(); 105 } 106 else { 107 final URL url = page.getFullyQualifiedUrl(href); 108 getLog().debug( 109 "Getting page for " + url.toExternalForm() 110 + ", derived from href '" + href 111 + "', using the originating url " 112 + page.getWebResponse().getUrl()); 113 return page.getWebClient().getPage( 114 page.getEnclosingWindow(), 115 page.getResolvedTarget(getTargetAttribute()), 116 new WebRequestSettings(url)); 117 } 118 } 119 else { 120 return defaultPage; 121 } 122 } 123 124 125 133 public final String getCharsetAttribute() { 134 return getAttributeValue("charset"); 135 } 136 137 138 146 public final String getTypeAttribute() { 147 return getAttributeValue("type"); 148 } 149 150 151 159 public final String getNameAttribute() { 160 return getAttributeValue("name"); 161 } 162 163 164 172 public final String getHrefAttribute() { 173 return getAttributeValue("href"); 174 } 175 176 177 185 public final String getHrefLangAttribute() { 186 return getAttributeValue("hreflang"); 187 } 188 189 190 198 public final String getRelAttribute() { 199 return getAttributeValue("rel"); 200 } 201 202 203 211 public final String getRevAttribute() { 212 return getAttributeValue("rev"); 213 } 214 215 216 224 public final String getAccessKeyAttribute() { 225 return getAttributeValue("accesskey"); 226 } 227 228 229 237 public final String getShapeAttribute() { 238 return getAttributeValue("shape"); 239 } 240 241 242 250 public final String getCoordsAttribute() { 251 return getAttributeValue("coords"); 252 } 253 254 255 263 public final String getTabIndexAttribute() { 264 return getAttributeValue("tabindex"); 265 } 266 267 268 276 public final String getOnFocusAttribute() { 277 return getAttributeValue("onfocus"); 278 } 279 280 281 289 public final String getOnBlurAttribute() { 290 return getAttributeValue("onblur"); 291 } 292 293 294 302 public final String getTargetAttribute() { 303 return getAttributeValue("target"); 304 } 305 } 306 | Popular Tags |